[jboss-cvs] JBossAS SVN: r88012 - in branches/Branch_5_x: varia/src/main/org/jboss/services/binding and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Apr 29 12:14:25 EDT 2009
Author: bstansberry at jboss.com
Date: 2009-04-29 12:14:25 -0400 (Wed, 29 Apr 2009)
New Revision: 88012
Added:
branches/Branch_5_x/varia/src/main/org/jboss/services/binding/ServiceBindingMapper.java
Modified:
branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ServiceBindingManagedObjectsTestCase.java
branches/Branch_5_x/varia/src/main/org/jboss/services/binding/ServiceBinding.java
branches/Branch_5_x/varia/src/main/org/jboss/services/binding/ServiceBindingManager.java
branches/Branch_5_x/varia/src/main/org/jboss/services/binding/ServiceBindingMetadata.java
Log:
[JBAS-6259] Tweak the SBM management interface
Modified: branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ServiceBindingManagedObjectsTestCase.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ServiceBindingManagedObjectsTestCase.java 2009-04-29 15:46:01 UTC (rev 88011)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ServiceBindingManagedObjectsTestCase.java 2009-04-29 16:14:25 UTC (rev 88012)
@@ -29,6 +29,9 @@
import org.jboss.managed.api.ComponentType;
import org.jboss.managed.api.ManagedComponent;
import org.jboss.managed.api.ManagedProperty;
+import org.jboss.metatype.api.values.ArrayValue;
+import org.jboss.metatype.api.values.CollectionValue;
+import org.jboss.metatype.api.values.CompositeValue;
import org.jboss.metatype.api.values.MetaValue;
import org.jboss.metatype.api.values.SimpleValue;
@@ -72,6 +75,12 @@
Map<String, ManagedProperty> properties = component.getProperties();
assertNotNull(properties);
+ getLog().debug("ServiceBindingManager properties: ");
+ for (Map.Entry<String, ManagedProperty> entry : properties.entrySet())
+ {
+ getLog().debug(entry.getKey() + " = " + entry.getValue());
+ }
+
ManagedProperty prop = properties.get("serverName");
assertNotNull("Missing property serverName", prop);
MetaValue val = prop.getValue();
@@ -81,16 +90,71 @@
prop = properties.get("serviceBindings");
assertNotNull("Missing property serviceBindings", prop);
+ log.info("serviceBindings: " + prop);
val = prop.getValue();
// FIXME not sure why this doesn't work
-// assertNotNull("property serviceBindings has no value", val);
-// assertTrue("property serviceBindings value is CollectionValue", val instanceof CollectionValue);
-// getLog().info(((CollectionValue) val).getElements());
+ assertNotNull("property serviceBindings has no value", val);
+ assertTrue("property serviceBindings value is CollectionValue", val instanceof CollectionValue);
+ CollectionValue colVal = (CollectionValue) val;
+ getLog().info(colVal.getElements());
+ for (MetaValue element : colVal.getElements())
+ {
+ serviceBindingTest(element);
+ }
- // [serverName, state, serviceBindings]
- assertEquals("Unexpected number of properties: "+properties.keySet(), 3, properties.size());
+ boolean hasState = properties.get("state") != null;
+ assertEquals("Unexpected number of properties", hasState ? 3 : 2, properties.size());
}
+ private void serviceBindingTest(MetaValue element)
+ {
+ assertTrue(element instanceof CompositeValue);
+
+ CompositeValue compValue = (CompositeValue) element;
+
+ MetaValue metaval = compValue.get("serviceName");
+ assertNotNull("has serviceName", metaval);
+ assertTrue(metaval instanceof SimpleValue);
+ assertTrue(((SimpleValue) metaval).getValue() instanceof String);
+
+ metaval = compValue.get("bindingName");
+ if (metaval != null)
+ {
+ assertTrue(metaval instanceof SimpleValue);
+ Object val = ((SimpleValue) metaval).getValue();
+ assertTrue(val instanceof String);
+ }
+
+ metaval = compValue.get("fullyQualifiedName");
+ assertNotNull("has fullyQualifiedName", metaval);
+ assertTrue(metaval instanceof SimpleValue);
+ assertTrue(((SimpleValue) metaval).getValue() instanceof String);
+
+ metaval = compValue.get("description");
+ if (metaval != null)
+ {
+ assertTrue(metaval instanceof SimpleValue);
+ Object val = ((SimpleValue) metaval).getValue();
+ assertTrue(val instanceof String);
+ }
+
+ metaval = compValue.get("hostName");
+ assertNotNull("has hostName", metaval);
+ assertTrue(metaval instanceof SimpleValue);
+ assertTrue(((SimpleValue) metaval).getValue() instanceof String);
+
+ metaval = compValue.get("bindAddress");
+ assertNotNull("has bindAddress", metaval);
+ assertTrue(metaval instanceof ArrayValue);
+ Object val = ((ArrayValue) metaval).getValue();
+ assertTrue(val instanceof byte[]);
+
+ metaval = compValue.get("port");
+ assertNotNull("has port", metaval);
+ assertTrue(metaval instanceof SimpleValue);
+ assertEquals("type of port value isn't int", int.class.getName(), metaval.getMetaType().getClassName());
+ }
+
/**
* <p>
* Validates the {@code ServiceBindingStore} managed component.
@@ -159,6 +223,7 @@
ManagedProperty prop = properties.get("name");
assertNotNull("Missing property name", prop);
+ getLog().debug("name: " + prop);
MetaValue val = prop.getValue();
assertNotNull("property name has no value", val);
assertTrue("property name value is SimpleValue", val instanceof SimpleValue);
@@ -166,6 +231,7 @@
prop = properties.get("defaultHostName");
assertNotNull("Missing property defaultHostName", prop);
+ getLog().debug("defaultHostName: " + prop);
val = prop.getValue();
assertNotNull("property defaultHostName has no value", val);
assertEquals("type of defaultHostName value isn't String", String.class.getName(), val.getMetaType().getClassName());
@@ -174,6 +240,7 @@
prop = properties.get("portOffset");
assertNotNull("Missing property portOffset", prop);
+ getLog().debug("portOffset: " + prop);
val = prop.getValue();
assertNotNull("property portOffset has no value", val);
assertTrue("property portOffset value is SimpleValue", val instanceof SimpleValue);
@@ -181,6 +248,7 @@
prop = properties.get("overrideBindings");
assertNotNull("Missing property overrideBindings", prop);
+ getLog().debug("overrideBindings: " + prop);
// FIXME not sure why this doesn't work
// val = prop.getValue();
// assertNotNull("property overrideBindings has no value", val);
@@ -195,7 +263,7 @@
ComponentType type = new ComponentType("MCBean", "ServiceBindingMetadata");
Set<ManagedComponent> mcs = managementView.getComponentsForType(type);
assertTrue("There are ServiceBindingMetadata components", mcs.size() > 0);
- super.getLog().debug("MCBeans: " + mcs);
+ getLog().debug("ServiceBindingMetadata components: " + mcs);
// Not all bindings have a val for bindingName or hostName,
// so check until we find one that does
@@ -251,7 +319,7 @@
assertNotNull("property port has no value", val);
assertTrue("property port value is SimpleValue", val instanceof SimpleValue);
assertNotNull("property port value is not null", ((SimpleValue) val).getValue());
- assertEquals("type of port value isn't Integer", int.class.getName(), val.getMetaType().getClassName());
+ assertEquals("type of port value isn't int", int.class.getName(), val.getMetaType().getClassName());
assertNotNull("property port value is not null", ((SimpleValue) val).getValue());
prop = properties.get("description");
@@ -264,6 +332,24 @@
assertTrue("property description value is SimpleValue", val instanceof SimpleValue);
assertEquals("type of description value isn't String", String.class.getName(), val.getMetaType().getClassName());
}
+
+ prop = properties.get("fixedPort");
+ assertNotNull("Missing property fixedPort", prop);
+ val = prop.getValue();
+ assertNotNull("property port has no value", val);
+ assertTrue("property port value is SimpleValue", val instanceof SimpleValue);
+ assertNotNull("property port value is not null", ((SimpleValue) val).getValue());
+ assertEquals("type of port value isn't boolean", boolean.class.getName(), val.getMetaType().getClassName());
+ assertNotNull("property port value is not null", ((SimpleValue) val).getValue());
+
+ prop = properties.get("fixedHostName");
+ assertNotNull("Missing property fixedHostName", prop);
+ val = prop.getValue();
+ assertNotNull("property port has no value", val);
+ assertTrue("property port value is SimpleValue", val instanceof SimpleValue);
+ assertNotNull("property port value is not null", ((SimpleValue) val).getValue());
+ assertEquals("type of port value isn't boolean", boolean.class.getName(), val.getMetaType().getClassName());
+ assertNotNull("property port value is not null", ((SimpleValue) val).getValue());
}
}
Modified: branches/Branch_5_x/varia/src/main/org/jboss/services/binding/ServiceBinding.java
===================================================================
--- branches/Branch_5_x/varia/src/main/org/jboss/services/binding/ServiceBinding.java 2009-04-29 15:46:01 UTC (rev 88011)
+++ branches/Branch_5_x/varia/src/main/org/jboss/services/binding/ServiceBinding.java 2009-04-29 16:14:25 UTC (rev 88012)
@@ -26,13 +26,6 @@
import java.security.AccessController;
import java.security.PrivilegedExceptionAction;
-import org.jboss.managed.api.annotation.ManagementComponent;
-import org.jboss.managed.api.annotation.ManagementObject;
-import org.jboss.managed.api.annotation.ManagementObjectID;
-import org.jboss.managed.api.annotation.ManagementProperties;
-import org.jboss.managed.api.annotation.ManagementProperty;
-import org.jboss.managed.api.annotation.ViewUse;
-
/**
* A ServiceBinding is a {name,virtualHost,port,interfaceAddress}
* quad specifying a named binding for a service.
@@ -41,8 +34,6 @@
* @author Scott.Stark at jboss.org
* @version $Revision$
*/
- at ManagementObject(componentType=@ManagementComponent(type="MCBean", subtype="ServiceBinding"),
- properties=ManagementProperties.EXPLICIT)
public class ServiceBinding implements Comparable<ServiceBinding>
{
@@ -187,7 +178,6 @@
*
* @return the name. Will not be <code>null</code>.
*/
- @ManagementProperty(description="the name of the service to which this binding applies")
public String getServiceName()
{
return serviceName;
@@ -200,8 +190,6 @@
* @return the name, or <code>null</code> if this is an unnamed default binding
* for the service.
*/
- @ManagementProperty(description="a qualifier identifying which particular " +
- "binding within the service this is")
public String getBindingName()
{
return this.bindingName;
@@ -213,8 +201,6 @@
* @return the {@link #getServiceName() serviceName}:{@link #getBindingName() bindingName} or
* just the service name if the binding name is <code>null</code>.
*/
- @ManagementProperty(description="the fully qualified binding name")
- @ManagementObjectID(type="ServiceBinding")
public String getFullyQualifiedName()
{
return fullyQualifiedName;
@@ -225,8 +211,6 @@
*
* @return the hostname or address
*/
- @ManagementProperty(use={ViewUse.STATISTIC}, description="the host name or " +
- "string notation IP address to use for the binding")
public String getHostName()
{
return this.hostName;
@@ -237,7 +221,6 @@
*
* @return The port
*/
- @ManagementProperty(use={ViewUse.STATISTIC}, description="the port to use for the binding")
public int getPort()
{
return this.port;
@@ -248,8 +231,6 @@
*
* @return The binding address
*/
- @ManagementProperty(use={ViewUse.STATISTIC}, description="the InetAddress of " +
- "the interface to use for the binding")
public InetAddress getBindAddress()
{
return this.bindAddress;
@@ -260,7 +241,6 @@
*
* @return the description, or <code>null</code> if there isn't one
*/
- @ManagementProperty(use={ViewUse.STATISTIC}, description="description of the binding")
public String getDescription()
{
return description;
Modified: branches/Branch_5_x/varia/src/main/org/jboss/services/binding/ServiceBindingManager.java
===================================================================
--- branches/Branch_5_x/varia/src/main/org/jboss/services/binding/ServiceBindingManager.java 2009-04-29 15:46:01 UTC (rev 88011)
+++ branches/Branch_5_x/varia/src/main/org/jboss/services/binding/ServiceBindingManager.java 2009-04-29 16:14:25 UTC (rev 88012)
@@ -29,10 +29,10 @@
import org.jboss.managed.api.annotation.ManagementComponent;
import org.jboss.managed.api.annotation.ManagementObject;
-import org.jboss.managed.api.annotation.ManagementObjectID;
import org.jboss.managed.api.annotation.ManagementProperties;
import org.jboss.managed.api.annotation.ManagementProperty;
import org.jboss.managed.api.annotation.ViewUse;
+import org.jboss.metatype.api.annotations.MetaMapping;
import org.jboss.services.binding.impl.SimpleServiceBindingValueSourceImpl;
import org.jboss.services.binding.impl.StringReplacementServiceBindingValueSourceImpl;
import org.jboss.services.binding.impl.Util;
@@ -56,8 +56,9 @@
* @jmx:mbean
*/
@ManagementObject(name="ServiceBindingManager",
- componentType=@ManagementComponent(type="MCBean", subtype="ServiceBindingManager"),
- properties=ManagementProperties.EXPLICIT)
+ componentType=@ManagementComponent(type="MCBean", subtype="ServiceBindingManager"),
+ properties=ManagementProperties.EXPLICIT,
+ description="The ServiceBindingManager enables the centralized management of ports, by service.")
public class ServiceBindingManager
implements ServiceBindingManagerMBean
{
@@ -160,6 +161,7 @@
@ManagementProperty(description="the set of service binding configurations associated with this instance",
use={ViewUse.STATISTIC})
+ @MetaMapping(value=ServiceBindingMapper.class)
public Set<ServiceBinding> getServiceBindings()
{
return this.store.getServiceBindings(this.serverName);
Added: branches/Branch_5_x/varia/src/main/org/jboss/services/binding/ServiceBindingMapper.java
===================================================================
--- branches/Branch_5_x/varia/src/main/org/jboss/services/binding/ServiceBindingMapper.java (rev 0)
+++ branches/Branch_5_x/varia/src/main/org/jboss/services/binding/ServiceBindingMapper.java 2009-04-29 16:14:25 UTC (rev 88012)
@@ -0,0 +1,177 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.services.binding;
+
+import java.lang.reflect.Type;
+import java.net.InetAddress;
+import java.util.Comparator;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.jboss.logging.Logger;
+import org.jboss.metatype.api.types.ArrayMetaType;
+import org.jboss.metatype.api.types.CollectionMetaType;
+import org.jboss.metatype.api.types.CompositeMetaType;
+import org.jboss.metatype.api.types.ImmutableCompositeMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.ArrayValueSupport;
+import org.jboss.metatype.api.values.CollectionValueSupport;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.MapCompositeValueSupport;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.metatype.spi.values.MetaMapper;
+
+/**
+ * {@link MetaMapper} for a set of {@link ServiceBindings}.
+ *
+ * @author Brian Stansberry
+ */
+public class ServiceBindingMapper extends MetaMapper<Set<ServiceBinding>>
+{
+ private static final Logger log = Logger.getLogger(ServiceBindingMapper.class);
+ public static final CollectionMetaType TYPE;
+ public static final CompositeMetaType SERVICE_BINDING_TYPE;
+
+ static
+ {
+ String[] itemNames = {
+ "serviceName",
+ "bindingName",
+ "fullyQualifiedName",
+ "description",
+ "hostName",
+ "bindAddress",
+ "port"
+ };
+ String[] itemDescriptions = {
+ "the name of the service to which this binding applies",
+ "a qualifier identifying which particular binding within the service this is",
+ "the fully qualified binding name",
+ "description of the binding",
+ "the host name or string notation IP address to use for the binding",
+ "byte[] representing the InetAddress of the interface to use for the binding",
+ "the port to use for the binding",
+ };
+ MetaType[] itemTypes = {
+ SimpleMetaType.STRING,
+ SimpleMetaType.STRING,
+ SimpleMetaType.STRING,
+ SimpleMetaType.STRING,
+ SimpleMetaType.STRING,
+ ArrayMetaType.getPrimitiveArrayType(byte[].class),
+ SimpleMetaType.INTEGER_PRIMITIVE
+ };
+ SERVICE_BINDING_TYPE = new ImmutableCompositeMetaType("org.jboss.services.binding.ServiceBinding",
+ "Service Binding",
+ itemNames, itemDescriptions, itemTypes);
+ TYPE = new CollectionMetaType("java.util.Set", SERVICE_BINDING_TYPE);
+ }
+
+ @Override
+ public MetaType getMetaType()
+ {
+ return TYPE;
+ }
+
+ @Override
+ public Type mapToType()
+ {
+ return Set.class;
+ }
+
+ @Override
+ public MetaValue createMetaValue(MetaType metaType, Set<ServiceBinding> object)
+ {
+ Set<CompositeValue> tmp = new TreeSet<CompositeValue>(new FullyQualifiedNameComparator());
+ for (ServiceBinding b : object)
+ {
+ try
+ {
+ MapCompositeValueSupport cvs = new MapCompositeValueSupport(SERVICE_BINDING_TYPE);
+ cvs.put("serviceName", SimpleValueSupport.wrap(b.getServiceName()));
+ cvs.put("bindingName", SimpleValueSupport.wrap(b.getBindingName()));
+ cvs.put("fullyQualifiedName", SimpleValueSupport.wrap(b.getFullyQualifiedName()));
+ cvs.put("description", SimpleValueSupport.wrap(b.getDescription()));
+ cvs.put("hostName", SimpleValueSupport.wrap(b.getHostName()));
+ InetAddress inet = b.getBindAddress();
+ if (inet != null)
+ {
+ ArrayValueSupport avs = new ArrayValueSupport(ArrayMetaType.getPrimitiveArrayType(byte[].class));
+ avs.setValue(inet.getAddress());
+ cvs.put("bindAddress", avs);
+ }
+ else
+ {
+ cvs.put("bindAddress", null);
+ }
+ cvs.put("port", SimpleValueSupport.wrap(b.getPort()));
+ tmp.add(cvs);
+ }
+ catch(Exception e)
+ {
+ log.warn("Skipping binding: "+ b, e);
+ }
+
+ }
+ MetaValue[] elements = tmp.toArray(new MetaValue[tmp.size()]);
+ CollectionValueSupport bindings = new CollectionValueSupport(TYPE, elements);
+ return bindings;
+ }
+
+ /**
+ * This always returns null as ServiceBindings cannot be created from a meta value
+ */
+ @Override
+ public Set<ServiceBinding> unwrapMetaValue(MetaValue metaValue)
+ {
+ return null;
+ }
+
+ /** Used to order CompositeValues by the fullyQualifiedName key */
+ private static class FullyQualifiedNameComparator implements Comparator<CompositeValue>
+ {
+
+ public int compare(CompositeValue o1, CompositeValue o2)
+ {
+ SimpleValue sv1 = (SimpleValue) o1.get("fullyQualifiedName");
+ if (sv1 == null)
+ {
+ throw new IllegalStateException(o1 + " has no fullyQualifiedName");
+ }
+ SimpleValue sv2 = (SimpleValue) o2.get("fullyQualifiedName");
+ if (sv2 == null)
+ {
+ throw new IllegalStateException(o2 + " has no fullyQualifiedName");
+ }
+
+ String name1 = (String) sv1.getValue();
+ String name2 = (String) sv2.getValue();
+ return name1.compareTo(name2);
+ }
+
+ }
+
+}
Property changes on: branches/Branch_5_x/varia/src/main/org/jboss/services/binding/ServiceBindingMapper.java
___________________________________________________________________
Name: svn:keywords
+
Modified: branches/Branch_5_x/varia/src/main/org/jboss/services/binding/ServiceBindingMetadata.java
===================================================================
--- branches/Branch_5_x/varia/src/main/org/jboss/services/binding/ServiceBindingMetadata.java 2009-04-29 15:46:01 UTC (rev 88011)
+++ branches/Branch_5_x/varia/src/main/org/jboss/services/binding/ServiceBindingMetadata.java 2009-04-29 16:14:25 UTC (rev 88012)
@@ -442,7 +442,10 @@
* object must be respected; <code>false</code> if it can be
* altered.
*/
- public boolean isFixedPort()
+ @ManagementProperty(description="whether bindings created from this metadata can" +
+ "alter the port value based on the server on which the binding is used",
+ use={ViewUse.CONFIGURATION})
+ public boolean isFixedPort()
{
return fixedPort;
}
@@ -470,6 +473,9 @@
* object must be respected; <code>false</code> if it can be
* altered.
*/
+ @ManagementProperty(description="whether bindings created from this metadata can" +
+ "alter the host name value based on the server on which the binding is used",
+ use={ViewUse.CONFIGURATION})
public boolean isFixedHostName()
{
return (this.fixedHostName == null ? this.hostName != null : this.fixedHostName.booleanValue());
More information about the jboss-cvs-commits
mailing list