[jboss-cvs] JBossAS SVN: r88905 - in branches/Branch_5_x: testsuite/src/main/org/jboss/test/profileservice/test and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu May 14 16:42:36 EDT 2009
Author: bstansberry at jboss.com
Date: 2009-05-14 16:42:36 -0400 (Thu, 14 May 2009)
New Revision: 88905
Added:
branches/Branch_5_x/varia/src/main/org/jboss/services/binding/managed/
branches/Branch_5_x/varia/src/main/org/jboss/services/binding/managed/ServiceBindingManagementObject.java
branches/Branch_5_x/varia/src/main/org/jboss/services/binding/managed/ServiceBindingMapper.java
branches/Branch_5_x/varia/src/main/org/jboss/services/binding/managed/ServiceBindingMetadataMapper.java
branches/Branch_5_x/varia/src/main/org/jboss/services/binding/managed/ServiceBindingSetMapper.java
branches/Branch_5_x/varia/src/main/org/jboss/services/binding/managed/Util.java
branches/Branch_5_x/varia/src/tests/org/jboss/test/services/binding/test/ServiceBindingMetadataMapperTestCase.java
branches/Branch_5_x/varia/src/tests/org/jboss/test/services/binding/test/ServiceBindingSetMapperTestCase.java
Removed:
branches/Branch_5_x/varia/src/main/org/jboss/services/binding/ServiceBindingMapper.java
Modified:
branches/Branch_5_x/server/src/etc/conf/all/bindings-jboss-beans.xml
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/DuplicateServiceException.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
branches/Branch_5_x/varia/src/main/org/jboss/services/binding/impl/PojoServiceBindingStore.java
branches/Branch_5_x/varia/src/main/org/jboss/services/binding/impl/ServiceBindingSet.java
branches/Branch_5_x/varia/src/tests/org/jboss/test/services/binding/test/PojoServiceBindingStoreUnitTestCase.java
branches/Branch_5_x/varia/src/tests/org/jboss/test/services/binding/test/ServiceBindingMetadataTestCase.java
branches/Branch_5_x/varia/src/tests/org/jboss/test/services/binding/test/ServiceBindingTestBase.java
Log:
[JBAS-6259] Management interface for the ServiceBindingManager
Modified: branches/Branch_5_x/server/src/etc/conf/all/bindings-jboss-beans.xml
===================================================================
--- branches/Branch_5_x/server/src/etc/conf/all/bindings-jboss-beans.xml 2009-05-14 20:42:20 UTC (rev 88904)
+++ branches/Branch_5_x/server/src/etc/conf/all/bindings-jboss-beans.xml 2009-05-14 20:42:36 UTC (rev 88905)
@@ -7,37 +7,45 @@
<classloader name="bindings-classloader" xmlns="urn:jboss:classloader:1.0" export-all="NON_EMPTY" import-all="true">
<root>${jboss.common.lib.url}jboss-bindingservice.jar</root>
</classloader>
-
+
+ <!-- The actual SBM from which services obtain binding information -->
<bean name="ServiceBindingManager" class="org.jboss.services.binding.ServiceBindingManager">
<annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.system:service=ServiceBindingManager", exposedInterface=org.jboss.services.binding.ServiceBindingManagerMBean.class, registerDirectly=true)</annotation>
-
+
+ <!-- Here we use the ServiceBindingManagementObject as a factory to create the SBM -->
+ <constructor factoryMethod="getServiceBindingManager">
+ <factory bean="ServiceBindingManagementObject"/>
+ </constructor>
+
+ </bean>
+
+ <!-- Provides management tools with a ProfileService ManagementView
+ interface to the SBM and its components -->
+ <bean name="ServiceBindingManagementObject"
+ class="org.jboss.services.binding.managed.ServiceBindingManagementObject">
+
<constructor>
<!-- The name of the set of bindings to use for this server -->
<parameter>${jboss.service.binding.set:ports-default}</parameter>
-
- <!-- The named sets of bindings -->
+
+ <!-- The binding sets -->
<parameter>
- <bean name="ServiceBindingStore" class="org.jboss.services.binding.impl.PojoServiceBindingStore">
-
- <!-- Base bindings that are used to create bindings for each set -->
- <property name="standardBindings"><inject bean="StandardBindings"/></property>
-
- <!-- The sets of bindings -->
- <property name="serviceBindingSets">
- <set>
- <inject bean="PortsDefaultBindings"/>
- <inject bean="Ports01Bindings"/>
- <inject bean="Ports02Bindings"/>
- <inject bean="Ports03Bindings"/>
- </set>
- </property>
- </bean>
+ <set>
+ <inject bean="PortsDefaultBindings"/>
+ <inject bean="Ports01Bindings"/>
+ <inject bean="Ports02Bindings"/>
+ <inject bean="Ports03Bindings"/>
+ </set>
</parameter>
+
+ <!-- Base binding metadata that is used to create bindings for each set -->
+ <parameter><inject bean="StandardBindings"/></parameter>
+
</constructor>
-
</bean>
-
+
+
<!-- The ports-default bindings are obtained by taking the base bindings and adding 0 to each port value -->
<bean name="PortsDefaultBindings" class="org.jboss.services.binding.impl.ServiceBindingSet">
<constructor>
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-05-14 20:42:20 UTC (rev 88904)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ServiceBindingManagedObjectsTestCase.java 2009-05-14 20:42:36 UTC (rev 88905)
@@ -22,18 +22,31 @@
package org.jboss.test.profileservice.test;
import java.net.InetAddress;
+import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.jboss.deployers.spi.management.ManagementView;
import org.jboss.managed.api.ComponentType;
+import org.jboss.managed.api.ManagedCommon;
import org.jboss.managed.api.ManagedComponent;
import org.jboss.managed.api.ManagedProperty;
+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.ArrayValue;
import org.jboss.metatype.api.values.CollectionValue;
+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.services.binding.ServiceBindingMetadata;
+import org.jboss.services.binding.impl.ServiceBindingSet;
+import org.jboss.services.binding.managed.ServiceBindingMetadataMapper;
/**
* <p>
@@ -45,6 +58,80 @@
*/
public class ServiceBindingManagedObjectsTestCase extends AbstractProfileServiceTest
{
+ public static final CompositeMetaType SERVICE_BINDING_METADATA_TYPE;
+ public static final CompositeMetaType SERVICE_BINDING_SET_TYPE;
+
+ static
+ {
+ String[] itemNames = {
+ "bindingSetName",
+ "serviceName",
+ "bindingName",
+ "fullyQualifiedName",
+ "description",
+ "hostName",
+ "port",
+ "fixedHostName",
+ "fixedPort"//,
+// "serviceBindingValueSourceClassName",
+// "serviceBindingValueSourceConfig"
+ };
+ String[] itemDescriptions = {
+ "binding set to which this binding applies, or null for all sets",
+ "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",
+ "the port to use for the binding",
+ "whether the host name should remain fixed in all binding sets",
+ "whether the port should remain fixed in all binding sets"//,
+// "fully qualified classname of specialized object used to process binding results",
+// ""
+ };
+ MetaType[] itemTypes = {
+ SimpleMetaType.STRING,
+ SimpleMetaType.STRING,
+ SimpleMetaType.STRING,
+ SimpleMetaType.STRING,
+ SimpleMetaType.STRING,
+ SimpleMetaType.STRING,
+ SimpleMetaType.INTEGER_PRIMITIVE,
+ SimpleMetaType.BOOLEAN_PRIMITIVE,
+ SimpleMetaType.BOOLEAN_PRIMITIVE//,
+// SimpleMetaType.STRING,
+// new GenericMetaType(ManagedObject)
+ };
+ SERVICE_BINDING_METADATA_TYPE = new ImmutableCompositeMetaType(ServiceBindingMetadata.class.getName(),
+ "Service Binding Metadata",
+ itemNames, itemDescriptions, itemTypes);
+
+
+ String[] itemNames2 = {
+ "name",
+ "defaultHostName",
+ "portOffset",
+ "overrideBindings"
+ };
+ String[] itemDescriptions2 = {
+ "the name of the binding set",
+ "the host name that should be used for all bindings whose configuration " +
+ "does not specify fixedHostName=\"true\"",
+ "value to add to the port configuration for a standard binding to " +
+ "derive the port to use in this binding set",
+ "binding configurations that apply only to this binding set, either " +
+ "non-standard bindings or ones that override standard binding configurations",
+ };
+ MetaType[] itemTypes2 = {
+ SimpleMetaType.STRING,
+ SimpleMetaType.STRING,
+ SimpleMetaType.INTEGER_PRIMITIVE,
+ ServiceBindingMetadataMapper.TYPE
+ };
+ SERVICE_BINDING_SET_TYPE = new ImmutableCompositeMetaType(ServiceBindingSet.class.getName(),
+ "Service Binding Set", itemNames2, itemDescriptions2, itemTypes2);
+ }
+
/**
* <p>
* Creates an instance of {@code SecurityManagedObjectsTestCase} with the specified name.
@@ -58,19 +145,16 @@
}
/**
- * <p>
* Validates at the {@code ServiceBindingManager} managed component.
- * </p>
*
* @throws Exception if an error occurs while running the test.
*/
- public void testServiceBindingManager() throws Exception
+ public void testValidateSBMContent() throws Exception
{
- ManagementView managementView = getManagementView();
- ComponentType type = new ComponentType("MCBean", "ServiceBindingManager");
- ManagedComponent component = managementView.getComponent("ServiceBindingManager", type);
- assertNotNull(component);
+ ManagedComponent component = getServiceBindingManagerManagedComponent();
+ logHierarchy(component);
+
// verify that the component has the expected properties.
Map<String, ManagedProperty> properties = component.getProperties();
assertNotNull(properties);
@@ -81,33 +165,81 @@
getLog().debug(entry.getKey() + " = " + entry.getValue());
}
- ManagedProperty prop = properties.get("serverName");
- assertNotNull("Missing property serverName", prop);
+ ManagedProperty prop = properties.get("activeBindingSetName");
+ assertNotNull("Missing property activeBindingSetName", prop);
MetaValue val = prop.getValue();
- assertNotNull("property serverName has no value", val);
- assertTrue("property serverName value is SimpleValue", val instanceof SimpleValue);
- assertEquals("incorrect serverName value", "ports-default", ((SimpleValue) val).getValue());
+ assertNotNull("property activeBindingSetName has no value", val);
+ assertTrue("property activeBindingSetName value is SimpleValue", val instanceof SimpleValue);
+ assertEquals("incorrect activeBindingSetName value", "ports-default", ((SimpleValue) val).getValue());
+ prop = properties.get("standardBindings");
+ assertNotNull("Missing property standardBindings", prop);
+ val = prop.getValue();
+ assertNotNull("property standardBindings has no value", val);
+ assertTrue("property standardBindings value is CollectionValue", val instanceof CollectionValue);
+ MetaValue[] elements = ((CollectionValue) val).getElements();
+ assertNotNull(elements);
+ for (MetaValue mv : elements)
+ {
+ getLog().info(mv);
+ serviceBindingMetadataTest(mv);
+ }
+
+ prop = properties.get("bindingSets");
+ assertNotNull("Missing property bindingSets", prop);
+ val = prop.getValue();
+ assertNotNull("property bindingSets has no value", val);
+ assertTrue("property bindingSets value is CollectionValue", val instanceof CollectionValue);
+ elements = ((CollectionValue) val).getElements();
+ assertNotNull("property bindingSets value has elements", elements);
+ Map<String, Integer> offsets = new HashMap<String, Integer>();
+ for (MetaValue mv : elements)
+ {
+ getLog().info(mv);
+ serviceBindingSetTest(mv, offsets);
+ }
+ assertEquals(Integer.valueOf(0), offsets.get("ports-default"));
+ assertEquals(Integer.valueOf(100), offsets.get("ports-01"));
+ assertEquals(Integer.valueOf(200), offsets.get("ports-02"));
+ assertEquals(Integer.valueOf(300), offsets.get("ports-03"));
+
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);
- CollectionValue colVal = (CollectionValue) val;
- getLog().info(colVal.getElements());
- for (MetaValue element : colVal.getElements())
+ assertTrue("property serviceBindings value is CompositeValue", val instanceof CompositeValue);
+ CompositeValue compVal = (CompositeValue) val;
+ assertEquals("correct number of sets of actual bindings", offsets.size(), compVal.values().size());
+ for (String bindingSetName : offsets.keySet())
{
- serviceBindingTest(element);
+ MetaValue mv = compVal.get(bindingSetName);
+ assertTrue(mv instanceof CollectionValue);
+ CollectionValue colVal = (CollectionValue) mv;
+ getLog().info(colVal.getElements());
+ for (MetaValue element : colVal.getElements())
+ {
+ serviceBindingTest(element);
+ }
}
boolean hasState = properties.get("state") != null;
- assertEquals("Unexpected number of properties", hasState ? 3 : 2, properties.size());
+ assertEquals("Unexpected number of properties", hasState ? 5 : 4, properties.size());
}
+ private ManagedComponent getServiceBindingManagerManagedComponent() throws Exception
+ {
+ ManagementView managementView = getManagementView();
+ ComponentType type = new ComponentType("MCBean", "ServiceBindingManager");
+ ManagedComponent component = managementView.getComponent("ServiceBindingManager", type);
+ assertNotNull(component);
+ return component;
+ }
+
private void serviceBindingTest(MetaValue element)
{
+ getLog().info(element);
+
assertTrue(element instanceof CompositeValue);
CompositeValue compValue = (CompositeValue) element;
@@ -154,204 +286,698 @@
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.
- * </p>
- *
- * @throws Exception if an error occurs while running the test.
- */
- public void testServiceBindingStore() throws Exception
+
+ private void serviceBindingSetTest(MetaValue metaValue, Map<String, Integer> offsets) throws Exception
{
- ManagementView managementView = super.getManagementView();
- ComponentType type = new ComponentType("MCBean", "ServiceBindingStore");
- ManagedComponent component = managementView.getComponent("PojoServiceBindingStore", type);
+ assertTrue(metaValue instanceof CompositeValue);
+ CompositeValue bindingSet = (CompositeValue) metaValue;
+
+ MetaValue val = bindingSet.get("name");
+ assertNotNull("property name has no value", val);
+ assertTrue("property name value is SimpleValue", val instanceof SimpleValue);
+ Object simpleVal = ((SimpleValue) val).getValue();
+ assertTrue(simpleVal instanceof String);
+ String name = (String) simpleVal;
+
+ val = bindingSet.get("defaultHostName");
+ assertNotNull("property defaultHostName has no value", val);
+ assertEquals("type of defaultHostName value isn't String", String.class.getName(), val.getMetaType().getClassName());
+ assertTrue("property defaultHostName value is SimpleValue", val instanceof SimpleValue);
+ assertEquals(InetAddress.getByName(getServerHost()), InetAddress.getByName((String) ((SimpleValue) val).getValue()));
+
+ val = bindingSet.get("portOffset");
+ assertNotNull("property portOffset has no value", val);
+ assertTrue("property portOffset value is SimpleValue", val instanceof SimpleValue);
+ simpleVal = ((SimpleValue) val).getValue();
+ assertTrue(simpleVal instanceof Integer);
+ assertTrue(((Integer) simpleVal).intValue() > -1);
+ offsets.put(name, (Integer) simpleVal);
+
+ val = bindingSet.get("overrideBindings");
+ assertNotNull("property overrideBindings has no value", val);
+ assertTrue("property overrideBindings value is CollectionValue", val instanceof CollectionValue);
+ MetaValue[] elements = ((CollectionValue) val).getElements();
+ getLog().info(elements);
+ for (MetaValue element : elements)
+ {
+ serviceBindingMetadataTest(element);
+ }
+
+ }
+
+ private Checked serviceBindingMetadataTest(MetaValue metaValue)
+ {
+ assertTrue(metaValue instanceof CompositeValue);
+ CompositeValue bindingMetadata = (CompositeValue) metaValue;
+
+ Checked result = new Checked();
+
+ MetaValue val = bindingMetadata.get("fullyQualifiedName");
+ assertNotNull("property fullyQualifiedName has no value", val);
+ assertTrue("property fullyQualifiedName value is SimpleValue", val instanceof SimpleValue);
+ assertNotNull("property fullyQualifiedName value is not null", ((SimpleValue) val).getValue());
+
+ val = bindingMetadata.get("serviceName");
+ assertNotNull("property serviceName has no value", val);
+ assertTrue("property serviceName value is SimpleValue", val instanceof SimpleValue);
+ assertNotNull("property serviceName value is not null", ((SimpleValue) val).getValue());
+
+ val = bindingMetadata.get("bindingName");
+ if (val != null)
+ {
+ result.bindingName = true;
+ assertNotNull("property bindingName has no value", val);
+ assertTrue("property bindingName value is SimpleValue", val instanceof SimpleValue);
+ assertEquals("type of bindingName value isn't String", String.class.getName(), val.getMetaType().getClassName());
+ }
+
+ val = bindingMetadata.get("bindingSetName");
+ if (val != null)
+ {
+ assertNotNull("property bindingSetName has no value", val);
+ assertTrue("property bindingSetName value is SimpleValue", val instanceof SimpleValue);
+ assertEquals("type of bindingSetName value isn't String", String.class.getName(), val.getMetaType().getClassName());
+ }
+
+ val = bindingMetadata.get("hostName");
+ if (val != null)
+ {
+ result.hostname = true;
+ assertTrue("property hostName value is SimpleValue", val instanceof SimpleValue);
+ assertEquals("type of hostName value isn't String", String.class.getName(), val.getMetaType().getClassName());
+ }
+
+ val = bindingMetadata.get("port");
+ 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 int", int.class.getName(), val.getMetaType().getClassName());
+ assertNotNull("property port value is not null", ((SimpleValue) val).getValue());
+
+ val = bindingMetadata.get("description");
+ if (val != null)
+ {
+ result.hostname = true;
+ assertNotNull("property hostName has no value", val);
+ assertTrue("property description value is SimpleValue", val instanceof SimpleValue);
+ assertEquals("type of description value isn't String", String.class.getName(), val.getMetaType().getClassName());
+ }
+
+ val = bindingMetadata.get("fixedPort");
+ assertNotNull("property bindingName has no value", val);
+ assertTrue("property bindingName value is SimpleValue", val instanceof SimpleValue);
+ assertNotNull("property bindingName value is not null", ((SimpleValue) val).getValue());
+ assertEquals("type of bindingName value isn't boolean", boolean.class.getName(), val.getMetaType().getClassName());
+ assertNotNull("property bindingName value is not null", ((SimpleValue) val).getValue());
+
+ val = bindingMetadata.get("fixedHostName");
+ assertNotNull("property bindingName has no value", val);
+ assertTrue("property bindingName value is SimpleValue", val instanceof SimpleValue);
+ assertNotNull("property bindingName value is not null", ((SimpleValue) val).getValue());
+ assertEquals("type of bindingName value isn't boolean", boolean.class.getName(), val.getMetaType().getClassName());
+ assertNotNull("property bindingName value is not null", ((SimpleValue) val).getValue());
+
+ return result;
+ }
+
+ public void testUpdateActiveBindingSetName() throws Exception
+ {
+ ManagedComponent component = getServiceBindingManagerManagedComponent();
+
+ ManagedProperty property = component.getProperty("activeBindingSetName");
+ assertNotNull(property);
+
+ property.setValue(SimpleValueSupport.wrap("ports-01"));
+
+ getManagementView().updateComponent(component);
+ log.debug("updated component " + component);
+
+ component = getServiceBindingManagerManagedComponent();
assertNotNull(component);
+ log.debug("re-acquired component " + component);
+
+ property = component.getProperty("activeBindingSetName");
+ assertNotNull(property);
+
+ SimpleValue val = (SimpleValue) property.getValue();
+ assertEquals("ports-01", val.getValue());
+ }
- // verify that the component has the expected properties.
+
+ public void testUpdateStandardBindings() throws Exception
+ {
+ ManagedComponent component = getServiceBindingManagerManagedComponent();
+
+ logHierarchy(component);
+
Map<String, ManagedProperty> properties = component.getProperties();
assertNotNull(properties);
ManagedProperty prop = properties.get("standardBindings");
assertNotNull("Missing property standardBindings", prop);
- // FIXME not sure why this doesn't work
-// MetaValue val = prop.getValue();
-// assertNotNull("property standardBindings has no value", val);
-// assertTrue("property standardBindings value is CollectionValue", val instanceof CollectionValue);
-// getLog().info(((CollectionValue) val).getElements());
+ MetaValue val = prop.getValue();
+ assertNotNull("property standardBindings has no value", val);
+ assertTrue("property standardBindings value is CollectionValue", val instanceof CollectionValue);
+ MetaValue[] origElements = ((CollectionValue) val).getElements();
+ assertNotNull(origElements);
+
+ // A) ADD a new element to "standardBindings"
+
+ MetaValue[] newElements = new MetaValue[origElements.length + 1];
+ System.arraycopy(origElements, 0, newElements, 0, origElements.length);
+
+ Map<String, MetaValue> map = new HashMap<String, MetaValue>();
+ map.put("serviceName", SimpleValueSupport.wrap("AddedStandardBinding"));
+ map.put("bindingName", SimpleValueSupport.wrap("bindingName"));
+ map.put("description", SimpleValueSupport.wrap("description"));
+ map.put("port", SimpleValueSupport.wrap(12345));
+ map.put("fixedHostName", SimpleValueSupport.wrap(false));
+ map.put("fixedPort", SimpleValueSupport.wrap(false));
+ MapCompositeValueSupport newElement = new MapCompositeValueSupport(map, SERVICE_BINDING_METADATA_TYPE);
+ newElements[newElements.length - 1] = newElement;
+
+ CollectionValue newVal = new CollectionValueSupport((CollectionMetaType) val.getMetaType(), newElements);
+ prop.setValue(newVal);
+
+ // Before passing the updated component back, store some info about
+ // the binding sets so we can use it later
prop = properties.get("bindingSets");
assertNotNull("Missing property bindingSets", prop);
- // FIXME not sure why this doesn't work
-// val = prop.getValue();
-// assertNotNull("property bindingSets has no value", val);
-// assertTrue("property bindingSets value is CollectionValue", val instanceof CollectionValue);
-// getLog().info(((CollectionValue) val).getElements());
- managementView.updateComponent(component);
+ val = prop.getValue();
+ assertNotNull("property bindingSets has no value", val);
+ assertTrue("property bindingSets value is CollectionValue", val instanceof CollectionValue);
+ MetaValue[] elements = ((CollectionValue) val).getElements();
+ assertNotNull(elements);
+
+ // Two maps we'll use
+ Map<String, Integer> offsets = new HashMap<String, Integer>();
+ Map<String, String> hosts = new HashMap<String, String>();
+ for (MetaValue mv : elements)
+ {
+ String name = getSimpleValue(mv, "name", String.class);
+ offsets.put(name, getSimpleValue(mv, "portOffset", Integer.class));
+ hosts.put(name, getSimpleValue(mv, "defaultHostName", String.class));
+ }
+
+ try
+ {
+ getManagementView().updateComponent(component);
+ }
+ catch (Exception e)
+ {
+ log.error("Failed updating " + component, e);
+ throw e;
+ }
+
+ // B) Validate the result of A) and MODIFY the element we added in A
+
+ component = getServiceBindingManagerManagedComponent();
+ properties = component.getProperties();
+
+ IndexedArray indexedArray = checkAddedBinding(properties, newElements.length, 12345, offsets, hosts);
+ // We'll update the component again using this MetaValue[]
+ newElements = new MetaValue[indexedArray.array.length];
+ System.arraycopy(indexedArray.array, 0, newElements, 0, newElements.length);
+
+ MapCompositeValueSupport update = cloneCompositeValue((CompositeValue) indexedArray.array[indexedArray.index]);
+ update.put("port", SimpleValueSupport.wrap(23456));
+ newElements[indexedArray.index] = update;
+
+ newVal = new CollectionValueSupport((CollectionMetaType) val.getMetaType(), newElements);
+ properties.get("standardBindings").setValue(newVal);
+
+ // OK, now update
+ try
+ {
+ getManagementView().updateComponent(component);
+ }
+ catch (Exception e)
+ {
+ log.error("Failed updating " + component, e);
+ throw e;
+ }
+
+ // C) Validate update from B) plus REMOVE the element we added
+
+ component = getServiceBindingManagerManagedComponent();
+ properties = component.getProperties();
+
+ indexedArray = checkAddedBinding(properties, newElements.length, 23456, offsets, hosts);
+
+ // We'll update the component again using this MetaValue[]
+ newElements = new MetaValue[indexedArray.array.length - 1];
+ int j = 0;
+ System.arraycopy(indexedArray.array, 0, newElements, 0, indexedArray.index);
+ System.arraycopy(indexedArray.array, indexedArray.index + 1, newElements, indexedArray.index, indexedArray.array.length - indexedArray.index -1);
+
+ newVal = new CollectionValueSupport((CollectionMetaType) val.getMetaType(), newElements);
+ properties.get("standardBindings").setValue(newVal);
+
+ // OK, now update
+ try
+ {
+ getManagementView().updateComponent(component);
+ }
+ catch (Exception e)
+ {
+ log.error("Failed updating " + component, e);
+ throw e;
+ }
+
+ // D) Removal from C) took effect
+
+ component = getServiceBindingManagerManagedComponent();
+ properties = component.getProperties();
+
+ prop = properties.get("standardBindings");
+ assertNotNull("Missing property standardBindings", prop);
+ val = prop.getValue();
+ assertNotNull("property standardBindings has no value", val);
+ assertTrue("property standardBindings value is CollectionValue", val instanceof CollectionValue);
+
+ MetaValue[] finalElements = ((CollectionValue) val).getElements();
+ assertNotNull(finalElements);
+ assertEquals(origElements.length, finalElements.length);
+ for (MetaValue mv : finalElements)
+ {
+ assertFalse("AddedStandardBinding".equals(getSimpleValue(mv, "serviceName")));
+ }
+
+ prop = properties.get("serviceBindings");
+ assertNotNull("Missing property serviceBindings", prop);
+ log.info("serviceBindings: " + prop);
+ val = prop.getValue();
+ assertNotNull("property serviceBindings has no value", val);
+ assertTrue("property serviceBindings value is CompositeValue", val instanceof CompositeValue);
+ CompositeValue compVal = (CompositeValue) val;
+ assertEquals(offsets.size(), compVal.values().size());
+ for (String bindingSetName : offsets.keySet())
+ {
+ MetaValue mv = compVal.get(bindingSetName);
+ assertTrue(mv instanceof CollectionValue);
+ CollectionValue colVal = (CollectionValue) mv;
+ for (MetaValue element : colVal.getElements())
+ {
+ assertFalse("AddedStandardBinding".equals(getSimpleValue(element, "serviceName")));
+ }
+ }
}
- public void testPortsDefault() throws Exception
+ private IndexedArray checkAddedBinding(Map<String, ManagedProperty> properties, int bindingCount, int basePort, Map<String, Integer> offsets, Map<String, String> hosts)
{
- serviceBindingSetTest("ports-default", 0);
+ // Return the array of standard bindings + the pos of the added binding
+ IndexedArray result = new IndexedArray();
+
+ // Scan for the standard binding
+
+ ManagedProperty prop = properties.get("standardBindings");
+ assertNotNull("Missing property standardBindings", prop);
+ MetaValue val = prop.getValue();
+ assertNotNull("property standardBindings has no value", val);
+ assertTrue("property standardBindings value is CollectionValue", val instanceof CollectionValue);
+ MetaValue[] refreshedElements = ((CollectionValue) val).getElements();
+ assertEquals(bindingCount, refreshedElements.length);
+ result.array = refreshedElements; // pass back to caller
+ boolean sawAdded = false;
+ for (int i = 0; i < refreshedElements.length; i++)
+ {
+ MetaValue mv = refreshedElements[i];
+ if ("AddedStandardBinding".equals(getSimpleValue(mv, "serviceName")))
+ {
+ sawAdded = true;
+ assertEquals("correct bindingName in standard binding", "bindingName", getSimpleValue(mv, "bindingName"));
+ assertEquals("correct description in standard binding", "description", getSimpleValue(mv, "description"));
+ assertNull("correct hostName in standardBinding", getSimpleValue(mv, "hostName"));
+ assertEquals("correct port in standard binding", basePort, getSimpleValue(mv, "port", Integer.class).intValue());
+ assertFalse("correct fixedPort in standard binding", getSimpleValue(mv, "fixedPort", Boolean.class).booleanValue());
+ assertFalse("correct fixedHostName in standard binding", getSimpleValue(mv, "fixedHostName", Boolean.class).booleanValue());
+
+ result.index = i; // tell caller which pos has the added binding
+ break;
+ }
+ }
+ assertTrue("saw standard binding", sawAdded);
+
+ // Check that our standard binding metadata generated the expected actual bindings
+
+ prop = properties.get("serviceBindings");
+ assertNotNull("Missing property serviceBindings", prop);
+ log.info("serviceBindings: " + prop);
+ val = prop.getValue();
+ assertNotNull("property serviceBindings has no value", val);
+ assertTrue("property serviceBindings value is CompositeValue", val instanceof CompositeValue);
+ CompositeValue compVal = (CompositeValue) val;
+ assertEquals("correct number of standard bindings", offsets.size(), compVal.values().size());
+ for (String bindingSetName : offsets.keySet())
+ {
+ MetaValue mv = compVal.get(bindingSetName);
+ assertTrue(mv instanceof CollectionValue);
+ CollectionValue colVal = (CollectionValue) mv;
+ sawAdded = false;
+ for (MetaValue element : colVal.getElements())
+ {
+ if ("AddedStandardBinding".equals(getSimpleValue(element, "serviceName")))
+ {
+ sawAdded = true;
+ assertEquals("correct bindingName in set " + bindingSetName,
+ "bindingName", getSimpleValue(element, "bindingName"));
+ assertEquals("correct description in set " + bindingSetName,
+ "description", getSimpleValue(element, "description"));
+ assertEquals("correct hostName in set " + bindingSetName,
+ hosts.get(bindingSetName), getSimpleValue(element, "hostName"));
+ assertEquals("correct port in set " + bindingSetName,
+ basePort + offsets.get(bindingSetName).intValue(),
+ getSimpleValue(element, "port", Integer.class).intValue());
+ break;
+ }
+ }
+ assertTrue("saw AddedStandardBinding in set " + bindingSetName, sawAdded);
+ }
+
+ return result;
}
-
- public void testPorts01() throws Exception
- {
- serviceBindingSetTest("ports-01", 100);
- }
- public void testPorts02() throws Exception
+ public void testUpdateServiceBindingSets() throws Exception
{
- serviceBindingSetTest("ports-02", 200);
- }
-
- public void testPorts03() throws Exception
- {
- serviceBindingSetTest("ports-03", 300);
- }
-
- private void serviceBindingSetTest(String name, int offset) throws Exception
- {
- ManagementView managementView = super.getManagementView();
- ComponentType type = new ComponentType("MCBean", "ServiceBindingSet");
- ManagedComponent component = managementView.getComponent(name, type);
- assertNotNull(component);
-
- // verify that the component has the expected properties.
+ ManagedComponent component = getServiceBindingManagerManagedComponent();
+
+ logHierarchy(component);
+
Map<String, ManagedProperty> properties = component.getProperties();
assertNotNull(properties);
- ManagedProperty prop = properties.get("name");
- assertNotNull("Missing property name", prop);
- getLog().debug("name: " + prop);
+ // A) ADD a new binding set
+
+ ManagedProperty prop = properties.get("bindingSets");
+ assertNotNull("Missing property bindingSets", prop);
MetaValue val = prop.getValue();
- assertNotNull("property name has no value", val);
- assertTrue("property name value is SimpleValue", val instanceof SimpleValue);
- assertEquals(name, ((SimpleValue) val).getValue());
+ assertNotNull("property bindingSets has no value", val);
+ assertTrue("property bindingSets value is CollectionValue", val instanceof CollectionValue);
+ MetaValue[] origElements = ((CollectionValue) val).getElements();
+ assertNotNull(origElements);
+ MetaValue[] newElements = new MetaValue[origElements.length + 1];
+ System.arraycopy(origElements, 0, newElements, 0, origElements.length);
- prop = properties.get("defaultHostName");
- assertNotNull("Missing property defaultHostName", prop);
- getLog().debug("defaultHostName: " + prop);
+
+ Map<String, MetaValue> map = new HashMap<String, MetaValue>();
+ map.put("name", SimpleValueSupport.wrap("ports-test"));
+ map.put("defaultHostName", SimpleValueSupport.wrap("localhost"));
+ map.put("portOffset", SimpleValueSupport.wrap(500));
+
+ Map<String, MetaValue> metadata = new HashMap<String, MetaValue>();
+ metadata.put("serviceName", SimpleValueSupport.wrap("AddedOverrideBinding"));
+ metadata.put("description", SimpleValueSupport.wrap("description"));
+ metadata.put("port", SimpleValueSupport.wrap(54321));
+ MapCompositeValueSupport newMetadata = new MapCompositeValueSupport(metadata, SERVICE_BINDING_METADATA_TYPE);
+ CollectionValue overrides = new CollectionValueSupport(new CollectionMetaType(Set.class.getName(), SERVICE_BINDING_METADATA_TYPE), new MetaValue[]{newMetadata});
+
+ map.put("overrideBindings", overrides);
+ MapCompositeValueSupport newElement = new MapCompositeValueSupport(map, SERVICE_BINDING_SET_TYPE);
+ newElements[newElements.length - 1] = newElement;
+ CollectionValue newVal = new CollectionValueSupport(new CollectionMetaType(Set.class.getName(), SERVICE_BINDING_SET_TYPE), newElements);
+ prop.setValue(newVal);
+
+ // Before updating get a ref to the standard bindings so we can use it
+ // in later validation
+ Map<String, MetaValue> standardBindings = new HashMap<String, MetaValue>();
+ prop = properties.get("standardBindings");
+ assertNotNull("Missing property standardBindings", 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());
- assertTrue("property defaultHostName value is SimpleValue", val instanceof SimpleValue);
- assertEquals(InetAddress.getByName(getServerHost()), InetAddress.getByName((String) ((SimpleValue) val).getValue()));
+ assertNotNull("property standardBindings has no value", val);
+ assertTrue("property standardBindings value is CollectionValue", val instanceof CollectionValue);
+ MetaValue[] elements = ((CollectionValue) val).getElements();
+ assertNotNull("property standardBindings value has elements", elements);
+ for (MetaValue mv : elements)
+ {
+ standardBindings.put(getSimpleValue(mv, "fullyQualifiedName", String.class), mv);
+ }
- prop = properties.get("portOffset");
- assertNotNull("Missing property portOffset", prop);
- getLog().debug("portOffset: " + prop);
+ try
+ {
+ getManagementView().updateComponent(component);
+ }
+ catch (Exception e)
+ {
+ log.error("Failed updating " + component, e);
+ throw e;
+ }
+
+ // B) Validate the addition from A) took effect and then UPDATE the added binding set
+
+ component = getServiceBindingManagerManagedComponent();
+ properties = component.getProperties();
+ assertNotNull(properties);
+
+ IndexedArray indexedArray = checkAddedBindingSet(properties, newElements.length, 500, 54321, standardBindings);
+
+ prop = properties.get("bindingSets");
+ assertNotNull("Missing property bindingSets", prop);
val = prop.getValue();
- assertNotNull("property portOffset has no value", val);
- assertTrue("property portOffset value is SimpleValue", val instanceof SimpleValue);
- assertEquals(Integer.valueOf(offset), ((SimpleValue) val).getValue());
+ assertNotNull("property bindingSets has no value", val);
+ assertTrue("property bindingSets value is CollectionValue", val instanceof CollectionValue);
+ MetaValue[] updated = newElements.clone();
+ MapCompositeValueSupport updatedBindingSet = cloneCompositeValue((CompositeValue) updated[indexedArray.index]);
+ updatedBindingSet.put("portOffset", SimpleValueSupport.wrap(400));
- 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);
-// assertTrue("property overrideBindings value is CollectionValue", val instanceof CollectionValue);
-// getLog().info(((CollectionValue) val).getElements());
+ MetaValue[] updatedOverrides = ((CollectionValue) updatedBindingSet.get("overrideBindings")).getElements();
+ assertEquals("single override binding", 1, updatedOverrides.length);
+ MapCompositeValueSupport updatedOverride = cloneCompositeValue((CompositeValue) updatedOverrides[0]);
+ updatedOverride.put("port", SimpleValueSupport.wrap(43210));
+ updatedBindingSet.put("overrideBindings", new CollectionValueSupport(new CollectionMetaType(Set.class.getName(), SERVICE_BINDING_METADATA_TYPE), new MetaValue[]{updatedOverride}));
+ updated[indexedArray.index] = updatedBindingSet;
+ newVal = new CollectionValueSupport(new CollectionMetaType(Set.class.getName(), SERVICE_BINDING_SET_TYPE), updated);
+ prop.setValue(newVal);
+
+ try
+ {
+ getManagementView().updateComponent(component);
+ }
+ catch (Exception e)
+ {
+ log.error("Failed updating " + component, e);
+ throw e;
+ }
+
+ // C) Validate the update from B) took effect and then REMOVE the added binding set
+
+ component = getServiceBindingManagerManagedComponent();
+ properties = component.getProperties();
+ assertNotNull(properties);
+
+ indexedArray = checkAddedBindingSet(properties, newElements.length, 400, 43210, standardBindings);
+
+ // We'll update the component again using this MetaValue[]
+ newElements = new MetaValue[indexedArray.array.length - 1];
+ System.arraycopy(indexedArray.array, 0, newElements, 0, indexedArray.index);
+ System.arraycopy(indexedArray.array, indexedArray.index + 1, newElements, indexedArray.index, indexedArray.array.length - indexedArray.index -1);
+
+ newVal = new CollectionValueSupport((CollectionMetaType) val.getMetaType(), newElements);
+ properties.get("bindingSets").setValue(newVal);
+
+ try
+ {
+ getManagementView().updateComponent(component);
+ }
+ catch (Exception e)
+ {
+ log.error("Failed updating " + component, e);
+ throw e;
+ }
+
+ // D) Confirm the added binding set is now gone
+
+ component = getServiceBindingManagerManagedComponent();
+ properties = component.getProperties();
+ assertNotNull(properties);
+
+ prop = properties.get("bindingSets");
+ assertNotNull("Missing property bindingSets", prop);
+ val = prop.getValue();
+ assertNotNull("property bindingSets has no value", val);
+ assertTrue("property bindingSets value is CollectionValue", val instanceof CollectionValue);
+ MetaValue[] finalElements = ((CollectionValue) val).getElements();
+ assertNotNull("property bindingSets value has elements", finalElements);
+ assertEquals("correct number of binding sets after removal",
+ origElements.length, finalElements.length);
+ for (MetaValue mv : finalElements)
+ {
+ assertFalse("ports-test".equals(getSimpleValue(mv, "name")));
+ }
+ prop = properties.get("serviceBindings");
+ assertNotNull("Missing property serviceBindings", prop);
+ val = prop.getValue();
+ assertTrue(val instanceof CompositeValue);
+ assertNull("no actual bindings for ports-test", ((CompositeValue) val).get("ports-test"));
}
- public void testServiceBindingMetadata() throws Exception
- {
- ManagementView managementView = getManagementView();
- ComponentType type = new ComponentType("MCBean", "ServiceBindingMetadata");
- Set<ManagedComponent> mcs = managementView.getComponentsForType(type);
- assertTrue("There are ServiceBindingMetadata components", mcs.size() > 0);
- getLog().debug("ServiceBindingMetadata components: " + mcs);
+ private IndexedArray checkAddedBindingSet(Map<String, ManagedProperty> properties, int numSets, int portOffset, int overrideBindingPort,
+ Map<String, MetaValue> standardBindings)
+ {
+ IndexedArray result = new IndexedArray();
- // Not all bindings have a val for bindingName or hostName,
- // so check until we find one that does
- boolean checkedBindingName = false;
- boolean checkedHostName = false;
- for (ManagedComponent component : mcs)
+ // First confirm the expected binding set is there
+
+ ManagedProperty prop = properties.get("bindingSets");
+ assertNotNull("Missing property bindingSets", prop);
+ MetaValue val = prop.getValue();
+ assertNotNull("property bindingSets has no value", val);
+ assertTrue("property bindingSets value is CollectionValue", val instanceof CollectionValue);
+ MetaValue[] elements = ((CollectionValue) val).getElements();
+ assertNotNull(elements);
+ assertEquals(numSets, elements.length);
+ result.array = elements;
+ boolean sawAdded = false;
+ for (int i = 0; i < elements.length; i++)
{
- if (checkedBindingName && checkedHostName)
+ MetaValue mv = elements[i];
+ if ("ports-test".equals(getSimpleValue(mv, "name")))
+ {
+ sawAdded = true;
+ assertEquals("added binding set has correct defaultHostName",
+ "localhost", getSimpleValue(mv, "defaultHostName"));
+ assertEquals("added binding set has correct portOffset",
+ portOffset, getSimpleValue(mv, "portOffset", Integer.class).intValue());
+ MetaValue overVal = ((CompositeValue) mv).get("overrideBindings");
+ assertTrue(overVal instanceof CollectionValue);
+ MetaValue[] overrides = ((CollectionValue) overVal).getElements();
+ assertNotNull("added binding set has overrides", overrides);
+ assertEquals("added binding set has correct # of overrides", 1, overrides.length);
+ mv = overrides[0];
+ assertEquals("added binding set has AddedOverrideBinding",
+ "AddedOverrideBinding", getSimpleValue(mv, "serviceName"));
+ assertNull("AddedOverrideBinding has null bindingName",
+ getSimpleValue(mv, "bindingName"));
+ assertEquals("AddedOverrideBinding has correct description",
+ "description", getSimpleValue(mv, "description"));
+ assertNull("AddedOverrideBinding has null hostName",
+ getSimpleValue(mv, "hostName"));
+ assertEquals("AddedOverrideBinding has correct port",
+ overrideBindingPort, getSimpleValue(mv, "port", Integer.class).intValue());
+ assertFalse("AddedOverrideBinding has correct fixedHostName",
+ getSimpleValue(mv, "fixedHostName", Boolean.class).booleanValue());
+ assertFalse("AddedOverrideBinding has correct fixedPort",
+ getSimpleValue(mv, "fixedPort", Boolean.class).booleanValue());
+ result.index = i;
break;
-
- // verify that the component has the expected properties.
- Map<String, ManagedProperty> properties = component.getProperties();
- assertNotNull(properties);
-
- ManagedProperty prop = properties.get("fullyQualifiedName");
- assertNotNull("Missing property fullyQualifiedName", prop);
- MetaValue val = prop.getValue();
- assertNotNull("property fullyQualifiedName has no value", val);
- assertTrue("property fullyQualifiedName value is SimpleValue", val instanceof SimpleValue);
- assertNotNull("property fullyQualifiedName value is not null", ((SimpleValue) val).getValue());
-
- prop = properties.get("serviceName");
- assertNotNull("Missing property serviceName", prop);
- val = prop.getValue();
- assertNotNull("property serviceName has no value", val);
- assertTrue("property serviceName value is SimpleValue", val instanceof SimpleValue);
- assertNotNull("property serviceName value is not null", ((SimpleValue) val).getValue());
-
- prop = properties.get("bindingName");
- assertNotNull("Missing property bindingName", prop);
- val = prop.getValue();
- if (val != null)
- {
- checkedBindingName = true;
- assertNotNull("property bindingName has no value", val);
- assertTrue("property bindingName value is SimpleValue", val instanceof SimpleValue);
- assertEquals("type of bindingName value isn't String", String.class.getName(), val.getMetaType().getClassName());
}
-
- prop = properties.get("hostName");
- assertNotNull("Missing property hostName", prop);
- val = prop.getValue();
- if (val != null)
+ }
+ assertTrue(sawAdded);
+
+ // Next validate the expected actual bindings are there
+ prop = properties.get("serviceBindings");
+ assertNotNull("Missing property serviceBindings", prop);
+ val = prop.getValue();
+ assertNotNull("property serviceBindings has no value", val);
+ assertTrue("property serviceBindings value is Composite", val instanceof CompositeValue);
+ val = ((CompositeValue) val).get("ports-test");
+ assertNotNull(val);
+ assertTrue("property serviceBindings value is CollectionValue", val instanceof CollectionValue);
+ elements = ((CollectionValue) val).getElements();
+ assertNotNull("property serviceBindings value has elements", elements);
+ assertEquals("property serviceBindings value has correct # of elements",
+ standardBindings.size() + 1, elements.length);
+ for (MetaValue mv : elements)
+ {
+ String fqn = getSimpleValue(mv, "fullyQualifiedName", String.class);
+ if ("AddedOverrideBinding".equals(fqn))
{
- checkedHostName = true;
- assertTrue("property hostName value is SimpleValue", val instanceof SimpleValue);
- assertEquals("type of hostName value isn't String", String.class.getName(), val.getMetaType().getClassName());
+ assertEquals("actual AddedOverrideBinding has correct serviceName",
+ "AddedOverrideBinding", getSimpleValue(mv, "serviceName"));
+ assertNull("actual AddedOverrideBinding has null bindingName",
+ getSimpleValue(mv, "bindingName"));
+ assertEquals("actual AddedOverrideBinding has correct description",
+ "description", getSimpleValue(mv, "description"));
+ assertEquals("actual AddedOverrideBinding has correct port",
+ overrideBindingPort + portOffset, getSimpleValue(mv, "port", Integer.class).intValue());
+ assertEquals("actual AddedOverrideBinding has correct hostName",
+ "localhost", getSimpleValue(mv, "hostName"));
}
-
- prop = properties.get("port");
- assertNotNull("Missing property port", 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 int", int.class.getName(), val.getMetaType().getClassName());
- assertNotNull("property port value is not null", ((SimpleValue) val).getValue());
-
- prop = properties.get("description");
- assertNotNull("Missing property 'description'", prop);
- val = prop.getValue();
- if (val != null)
+ else
{
- checkedHostName = true;
- assertNotNull("property hostName has no value", val);
- assertTrue("property description value is SimpleValue", val instanceof SimpleValue);
- assertEquals("type of description value isn't String", String.class.getName(), val.getMetaType().getClassName());
+ MetaValue standard = standardBindings.get(fqn);
+ assertNotNull(standard);
+ assertEquals("standardBinding " + fqn + " has correct serviceName",
+ getSimpleValue(standard, "serviceName"), getSimpleValue(mv, "serviceName"));
+ assertEquals("standardBinding " + fqn + " has correct bindingName",
+ getSimpleValue(standard, "bindingName"), getSimpleValue(mv, "bindingName"));
+ assertEquals("standardBinding " + fqn + " has correct description",
+ getSimpleValue(standard, "description"), getSimpleValue(mv, "description"));
+ int offset = getSimpleValue(standard, "fixedPort", Boolean.class).booleanValue() ? 0 : portOffset;
+ assertEquals("standardBinding " + fqn + " has correct port",
+ getSimpleValue(standard, "port", Integer.class).intValue() + offset,
+ getSimpleValue(mv, "port", Integer.class).intValue());
+ String host = getSimpleValue(standard, "fixedHostName", Boolean.class).booleanValue()
+ ? getSimpleValue(standard, "hostName", String.class)
+ : "localhost";
+ assertEquals("standardBinding " + fqn + " has correct hostName",
+ host, getSimpleValue(mv, "hostName"));
}
-
- 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());
}
+ return result;
}
+
+ private void logHierarchy(ManagedComponent mc)
+ {
+ ManagedCommon child = mc;
+ ManagedCommon mcom = mc.getParent();
+ while (mcom != null)
+ {
+ log.debug("parent of " + child.getName() + " is " + mcom.getName());
+ child = mcom;
+ mcom = mcom.getParent();
+ }
+ }
+
+ private Object getSimpleValue(MetaValue val, String key)
+ {
+ return getSimpleValue(val, key, Object.class);
+ }
+
+ private <T> T getSimpleValue(MetaValue val, String key, Class<T> type)
+ {
+ T result = null;
+ assertTrue(val instanceof CompositeValue);
+ CompositeValue cval = (CompositeValue) val;
+ MetaValue mv = cval.get(key);
+ if (mv != null)
+ {
+ assertTrue(mv instanceof SimpleValue);
+ Object obj = ((SimpleValue) mv).getValue();
+ result = type.cast(obj);
+ }
+ return result;
+ }
+
+ private static MapCompositeValueSupport cloneCompositeValue(CompositeValue toClone)
+ {
+ if (toClone instanceof MapCompositeValueSupport)
+ {
+ return (MapCompositeValueSupport) toClone.clone();
+ }
+ else
+ {
+ CompositeMetaType type = toClone.getMetaType();
+ Map<String, MetaValue> map = new HashMap<String, MetaValue>();
+ for (String key : type.keySet())
+ {
+ map.put(key, toClone.get(key));
+ }
+ return new MapCompositeValueSupport(map, type);
+ }
+ }
+
+ private class Checked
+ {
+ private boolean hostname;
+ private boolean bindingName;
+ }
+
+ private class IndexedArray
+ {
+ int index;
+ MetaValue[] array;
+ }
}
Modified: branches/Branch_5_x/varia/src/main/org/jboss/services/binding/DuplicateServiceException.java
===================================================================
--- branches/Branch_5_x/varia/src/main/org/jboss/services/binding/DuplicateServiceException.java 2009-05-14 20:42:20 UTC (rev 88904)
+++ branches/Branch_5_x/varia/src/main/org/jboss/services/binding/DuplicateServiceException.java 2009-05-14 20:42:36 UTC (rev 88905)
@@ -45,7 +45,7 @@
public DuplicateServiceException(String serverName, String serviceName, String bindingName)
{
- this("No binding " + bindingName + " found for service " + serviceName + " in set " + serverName);
+ this("Duplicate binding " + bindingName + " found for service " + serviceName + " in set " + serverName);
}
/**
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-05-14 20:42:20 UTC (rev 88904)
+++ branches/Branch_5_x/varia/src/main/org/jboss/services/binding/ServiceBindingManager.java 2009-05-14 20:42:36 UTC (rev 88905)
@@ -27,12 +27,6 @@
import java.net.UnknownHostException;
import java.util.Set;
-import org.jboss.managed.api.annotation.ManagementComponent;
-import org.jboss.managed.api.annotation.ManagementObject;
-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;
@@ -55,10 +49,6 @@
*
* @jmx:mbean
*/
- at ManagementObject(name="ServiceBindingManager",
- 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
{
@@ -68,12 +58,12 @@
public enum BindingType { INT, INETADDRESS, STRING, ELEMENT, URL, RESOURCE, GENERIC };
/**
- * Algorithm for obtaining a ServiceBindingValueSource given a particular
+ * Algorithm for obtaining a {@link ServiceBindingValueSource} given a particular
* binding and binding type.
*
* @param binding the binding
* @param bindingType the binding type
- * @return the appropriate ServiceBindingValueSource. Will not return <code>null</code>.
+ * @return the appropriate {@link ServiceBindingValueSource}. Will not return <code>null</code>.
*
* @throws ClassNotFoundException if any {@link ServiceBinding#getServiceBindingValueSourceClassName()} cannot be found
* @throws InstantiationException if any {@link ServiceBinding#getServiceBindingValueSourceClassName()} cannot be instantiated
@@ -120,12 +110,11 @@
/**
* The name of the config set this manager is associated with. This is a
- * logical name used to lookup ServiceConfigs from the ServiceBindingStore.
+ * logical name used to lookup ServiceBindings from the ServiceBindingStore.
*/
private String serverName;
- /** The ServiceConfig store instance
- */
+ /** The ServiceBindingStore instance */
private final ServiceBindingStore store;
// ----------------------------------------------------------- Constructors
@@ -149,10 +138,9 @@
* {@link ServiceBindingStore#getServiceBinding(String, String, String) requesting bindings}.
*
* @return name of the set of bindings this server uses
+ *
+ * @jmx:attribute
*/
- @ManagementProperty(description="the value of the serverName param this " +
- "instance should pass to ServiceBindingStore when requesting bindings",
- use={ViewUse.CONFIGURATION}, readOnly=false)
public String getServerName()
{
return this.serverName;
@@ -163,16 +151,19 @@
* to <code>ServiceBindingStore</code> when
* {@link ServiceBindingStore#getServiceBinding(String, String, String) requesting bindings}.
*
- * @return name of the set of bindings this server uses
+ * @return name of the set of bindings this server uses. Cannot be <code>null</code>
+ *
+ * @throws IllegalArgumentException if <code>serverName</code> is <code>null</code>
*/
public void setServerName(String serverName)
{
+ if (serverName == null)
+ {
+ throw new IllegalArgumentException("serverName is null");
+ }
this.serverName = serverName;
}
- @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);
Deleted: 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 2009-05-14 20:42:20 UTC (rev 88904)
+++ branches/Branch_5_x/varia/src/main/org/jboss/services/binding/ServiceBindingMapper.java 2009-05-14 20:42:36 UTC (rev 88905)
@@ -1,177 +0,0 @@
-/*
- * 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);
- }
-
- }
-
-}
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-05-14 20:42:20 UTC (rev 88904)
+++ branches/Branch_5_x/varia/src/main/org/jboss/services/binding/ServiceBindingMetadata.java 2009-05-14 20:42:36 UTC (rev 88905)
@@ -25,13 +25,6 @@
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
-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;
-
/**
* Metadata about a {@link ServiceBinding} that management tools can use. Does
* not represent the runtime binding information, but rather the metadata
@@ -39,8 +32,6 @@
*
* @author Brian Stansberry
*/
- at ManagementObject(componentType=@ManagementComponent(type="MCBean", subtype="ServiceBindingMetadata"),
- properties=ManagementProperties.EXPLICIT)
public class ServiceBindingMetadata implements Comparable<ServiceBindingMetadata>
{
/**
@@ -224,6 +215,23 @@
setServiceBindingValueSourceConfig(binding.getServiceBindingValueSourceConfig());
}
+ /**
+ * Copy constructor.
+ *
+ * @param binding the metadata to copy. Cannot be <code>null</code>
+ */
+ public ServiceBindingMetadata(ServiceBindingMetadata binding)
+ {
+ this(binding.getServiceName(), binding.getBindingName(),
+ binding.getHostName(), binding.getPort(), binding.isFixedHostName(), binding.isFixedPort());
+ setServiceBindingValueSource(binding.getServiceBindingValueSource());
+ if (this.serviceBindingValueSourceClassName == null)
+ {
+ setServiceBindingValueSourceClassName(binding.getServiceBindingValueSourceClassName());
+ }
+ setServiceBindingValueSourceConfig(binding.getServiceBindingValueSourceConfig());
+ }
+
// ------------------------------------------------------------ Properties
/**
@@ -231,7 +239,6 @@
*
* @return the name.
*/
- @ManagementProperty(description="the name of the service to which this binding applies")
public String getServiceName()
{
return serviceName;
@@ -260,8 +267,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;
@@ -277,8 +282,8 @@
public void setBindingName(String bindingName)
{
this.bindingName = bindingName;
- }
-
+ }
+
/**
* Gets the fully qualified binding name.
*
@@ -287,15 +292,27 @@
*
* @throws IllegalStateException if {@link #getServiceName() serviceName} is <code>null</code>
*/
- @ManagementProperty(description="the fully qualified binding name")
- @ManagementObjectID(type="ServiceBindingMetadata")
public String getFullyQualifiedName()
{
if (this.serviceName == null)
{
throw new IllegalStateException("Must set serviceName");
}
- return (this.bindingName == null ? this.serviceName : (this.serviceName + ":" + this.bindingName));
+ else if (this.bindingName == null)
+ {
+ return this.serviceName;
+ }
+ else
+ {
+ StringBuilder sb = new StringBuilder(this.serviceName);
+ if (this.bindingName != null)
+ {
+ sb.append(':');
+ sb.append(this.bindingName);
+ }
+
+ return sb.toString();
+ }
}
/**
@@ -303,9 +320,6 @@
*
* @return the hostname or address. May be <code>null</code>
*/
- @ManagementProperty(description="the host name or " +
- "string notation IP address to use for the binding",
- use={ViewUse.CONFIGURATION}) // overrides superclass annotation's use attribute
public String getHostName()
{
return hostName;
@@ -326,8 +340,6 @@
}
}
- @ManagementProperty(description="the port to use for the binding",
- use={ViewUse.CONFIGURATION}) // overrides superclass annotation's use attribute
public int getPort()
{
return port;
@@ -348,7 +360,6 @@
*
* @return the description, or <code>null</code> if there isn't one
*/
- @ManagementProperty(use={ViewUse.CONFIGURATION}, description="description of the binding")
public String getDescription()
{
return description;
@@ -442,10 +453,7 @@
* object must be respected; <code>false</code> if it can be
* altered.
*/
- @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()
+ public boolean isFixedPort()
{
return fixedPort;
}
@@ -473,9 +481,6 @@
* 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());
@@ -516,7 +521,8 @@
if (obj instanceof ServiceBindingMetadata)
{
ServiceBindingMetadata other = (ServiceBindingMetadata) obj;
- return (safeEquals(this.getFullyQualifiedName(), other.getFullyQualifiedName()));
+ return (this.serviceName != null && this.serviceName.equals(other.serviceName)
+ && safeEquals(this.bindingName, other.bindingName));
}
return false;
@@ -529,7 +535,8 @@
public int hashCode()
{
int result = 19;
- result += 29 * this.getFullyQualifiedName().hashCode();
+ result += 29 * this.serviceName.hashCode();
+ result += 29 * (this.bindingName == null ? 0 : this.bindingName.hashCode());
return result;
}
Modified: branches/Branch_5_x/varia/src/main/org/jboss/services/binding/impl/PojoServiceBindingStore.java
===================================================================
--- branches/Branch_5_x/varia/src/main/org/jboss/services/binding/impl/PojoServiceBindingStore.java 2009-05-14 20:42:20 UTC (rev 88904)
+++ branches/Branch_5_x/varia/src/main/org/jboss/services/binding/impl/PojoServiceBindingStore.java 2009-05-14 20:42:36 UTC (rev 88905)
@@ -29,13 +29,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
-import org.jboss.managed.api.ManagedOperation.Impact;
-import org.jboss.managed.api.annotation.ManagementComponent;
-import org.jboss.managed.api.annotation.ManagementObject;
-import org.jboss.managed.api.annotation.ManagementOperation;
-import org.jboss.managed.api.annotation.ManagementParameter;
-import org.jboss.managed.api.annotation.ManagementProperties;
-import org.jboss.managed.api.annotation.ManagementProperty;
+import org.jboss.logging.Logger;
import org.jboss.services.binding.DuplicateServiceException;
import org.jboss.services.binding.NoSuchBindingException;
import org.jboss.services.binding.ServiceBinding;
@@ -48,11 +42,11 @@
* @author Brian Stansberry
* @version $Revision$
*/
- at ManagementObject(name="PojoServiceBindingStore", type="ServiceBindingStore",
- componentType=@ManagementComponent(type="MCBean", subtype="ServiceBindingStore"),
- properties=ManagementProperties.EXPLICIT)
-public class PojoServiceBindingStore implements ServiceBindingStore
+public class PojoServiceBindingStore
+ implements ServiceBindingStore
{
+ private static final Logger log = Logger.getLogger(PojoServiceBindingStore.class);
+
/** Dummy value to make ConcurrentHashMap act like a Set */
private static final Object VALUE = new Object();
@@ -71,7 +65,7 @@
new ConcurrentHashMap<ServiceBindingMetadata, Object>(16, (float) .75, 2);
private boolean started;
-
+
// ------------------------------------------------------------ Constructors
/**
@@ -79,27 +73,23 @@
*/
public PojoServiceBindingStore() {}
+ public PojoServiceBindingStore(Set<ServiceBindingSet> bindingSets, Set<ServiceBindingMetadata> standardBindings)
+ {
+ setServiceBindingSetsInternal(bindingSets);
+ setStandardBindingsInternal(standardBindings);
+ }
+
// ----------------------------------------------------- ServiceBindingStore
- public void addServiceBinding(String serverName, ServiceBindingMetadata metadata)
+ public synchronized void addServiceBinding(String serverName, ServiceBindingMetadata metadata)
throws DuplicateServiceException, UnknownHostException
{
- validateServerName(serverName);
- ServiceBindingSet bindingSet = bindingSets.get(serverName);
- ServiceBinding binding = new ServiceBinding(metadata, bindingSet.getDefaultHostName(), bindingSet.getPortOffset());
- ServiceBinding oldBinding = bindings.putIfAbsent(new ServiceBindingKey(serverName, metadata), binding);
- if (oldBinding != null &&
- (safeEquals(oldBinding.getHostName(), binding.getHostName()) == false
- || oldBinding.getPort() != binding.getPort()))
- {
- throw new DuplicateServiceException(serverName, binding);
- }
+ addServiceBindingInternal(serverName, metadata, true);
- // For management purposes, treat this as an override
- bindingSet.getOverrideBindings().add(metadata);
+ log.debug("added binding " + metadata.getFullyQualifiedName() + " to " + serverName);
}
- public ServiceBinding getServiceBinding(String serverName, String serviceName, String bindingName)
+ public synchronized ServiceBinding getServiceBinding(String serverName, String serviceName, String bindingName)
throws NoSuchBindingException
{
ServiceBinding binding = bindings.get(new ServiceBindingKey(serverName, serviceName, bindingName));
@@ -110,7 +100,7 @@
return binding;
}
- public Set<ServiceBinding> getServiceBindings(String serverName)
+ public synchronized Set<ServiceBinding> getServiceBindings(String serverName)
{
validateServerName(serverName);
@@ -126,7 +116,7 @@
return result;
}
- public void removeServiceBinding(String serverName, ServiceBindingMetadata metadata)
+ public synchronized void removeServiceBinding(String serverName, ServiceBindingMetadata metadata)
{
validateServerName(serverName);
bindings.remove(new ServiceBindingKey(serverName, metadata));
@@ -136,13 +126,13 @@
bindingSet.getOverrideBindings().remove(metadata);
}
- public String getDefaultHostName(String serverName)
+ public synchronized String getDefaultHostName(String serverName)
{
validateServerName(serverName);
return bindingSets.get(serverName).getDefaultHostName();
}
- public int getDefaultPortOffset(String serverName)
+ public synchronized int getDefaultPortOffset(String serverName)
{
validateServerName(serverName);
return bindingSets.get(serverName).getPortOffset();
@@ -155,42 +145,51 @@
* adjusted to conform to the binding set's defaultHostName and offset.
*
* @param bindings the set of base bindings. May be <code>null</code>
+ * @throws DuplicateServiceException
+ * @throws UnknownHostException
*
* @throws IllegalStateException if invoked after {@link #start()}
*/
- public void setStandardBindings(Set<ServiceBindingMetadata> bindings)
- {
+ public synchronized void setStandardBindings(Set<ServiceBindingMetadata> bindings) throws UnknownHostException, DuplicateServiceException
+ {
+ setStandardBindingsInternal(bindings);
+
if (started)
{
- throw new IllegalStateException("Cannot call setPortOffsetBindings() after start()");
- }
- standardBindings.clear();
- if (bindings != null)
- {
- for (ServiceBindingMetadata binding : bindings)
+ log.debug("updated standard bindings injected");
+ if (log.isTraceEnabled())
{
- standardBindings.put(binding, VALUE);
+ for (ServiceBindingMetadata sbm : bindings)
+ {
+ log.trace(sbm.getFullyQualifiedName() + " port is " + sbm.getPort() + " " + sbm.isFixedHostName() + "/" + sbm.isFixedPort());
+ }
}
+
+ establishBindings();
}
}
- public void setServiceBindingSets(Set<ServiceBindingSet> sets)
- {
+ public synchronized void setServiceBindingSets(Set<ServiceBindingSet> sets) throws UnknownHostException, DuplicateServiceException
+ {
+ setServiceBindingSetsInternal(sets);
+
if (started)
{
- throw new IllegalStateException("Cannot call setServiceBindingSets() after start()");
- }
-
- this.bindingSets.clear();
-
- if (sets != null)
- {
- for (ServiceBindingSet bindingSet : sets)
+ log.debug("updated ServiceBindingSets injected");
+ if (log.isTraceEnabled())
{
- this.bindingSets.put(bindingSet.getName(), bindingSet);
+ for (ServiceBindingSet set : sets)
+ {
+ log.trace(set.getName() + " offset is " + set.getPortOffset() + " defaultHostName is " + set.getDefaultHostName());
+ java.util.Set<ServiceBindingMetadata> ovr = set.getOverrideBindings();
+ for (ServiceBindingMetadata sbm : ovr)
+ {
+ log.trace(sbm.getFullyQualifiedName() + " port is " + sbm.getPort() + " " + sbm.isFixedHostName() + "/" + sbm.isFixedPort());
+ }
+ }
}
+ establishBindings();
}
-
}
/**
@@ -202,41 +201,15 @@
*/
public void start() throws DuplicateServiceException, UnknownHostException
{
- // Establish the override bindings first, so when we add the
- // fixed and portOffset, we get DuplicateServiceException
- for (ServiceBindingSet bindingSet : bindingSets.values())
- {
- for (ServiceBindingMetadata binding : bindingSet.getOverrideBindings())
- {
- addServiceBinding(bindingSet.getName(), binding);
- }
- }
+ establishBindings();
- // Establish the standard bindings
- for (ServiceBindingMetadata metadata : standardBindings.keySet())
- {
- for (ServiceBindingSet bindingSet : bindingSets.values())
- {
- try
- {
- addServiceBinding(bindingSet.getName(), metadata);
- }
- catch (DuplicateServiceException e)
- {
- if (bindingSet.getOverrideBindings().contains(metadata) == false)
- {
- throw e;
- }
- }
- }
- }
-
this.started = true;
}
public void stop()
{
this.bindings.clear();
+
this.started = false;
}
@@ -249,16 +222,30 @@
*
* @return the set of base bindings
*/
- @ManagementProperty(description="the base set of bindings that should be associated " +
- "with each binding set")
public Set<ServiceBindingMetadata> getStandardBindings()
{
return new HashSet<ServiceBindingMetadata>(standardBindings.keySet());
}
- @ManagementProperty(description="the named binding sets")
+ /**
+ * See {@link #getServiceBindingSets()}
+ *
+ * @return the binding sets
+ *
+ * @deprecated use {@link #getServiceBindingSets()}
+ */
public Set<ServiceBindingSet> getBindingSets()
{
+ return getServiceBindingSets();
+ }
+
+ /**
+ * Gets the {@link ServiceBindingSet}s associated with this store.
+ *
+ * @return the binding sets. Will not return <code>null</code>
+ */
+ public Set<ServiceBindingSet> getServiceBindingSets()
+ {
return new HashSet<ServiceBindingSet>(bindingSets.values());
}
@@ -278,17 +265,14 @@
* @throws DuplicateServiceException thrown if a configuration for the
* <serverName, serviceName> pair already exists.
*/
- @ManagementOperation(description="adds a service binding", impact=Impact.WriteOnly,
- params={@ManagementParameter(name="binding"),
- @ManagementParameter(name="fixed")})
- public void addServiceBinding(ServiceBindingMetadata metadata) throws DuplicateServiceException
+ public synchronized void addServiceBinding(ServiceBindingMetadata metadata) throws DuplicateServiceException
{
// Add to the runtime objects
for (ServiceBindingSet bindingSet : bindingSets.values())
{
try
{
- addServiceBinding(bindingSet.getName(), metadata);
+ addServiceBindingInternal(bindingSet.getName(), metadata, false);
}
catch (UnknownHostException e)
{
@@ -319,21 +303,45 @@
* @throws DuplicateServiceException thrown if a configuration for the
* <serverName, serviceName> pair already exists.
*/
- @ManagementOperation(description="adds a service binding", impact=Impact.WriteOnly,
- params={@ManagementParameter(name="serviceName"),
- @ManagementParameter(name="bindingName"),
- @ManagementParameter(name="hostName"),
- @ManagementParameter(name="port"),
- @ManagementParameter(name="fixedPort")})
- public void addServiceBinding(String serviceName, String bindingName, String hostName, int port, boolean fixedPort)
+ public synchronized void addServiceBinding(String serviceName, String bindingName, String hostName, int port, boolean fixedPort)
throws DuplicateServiceException, UnknownHostException
{
+ addServiceBinding(serviceName, bindingName, null, hostName, port, false, fixedPort);
+ }
+
+ /**
+ * Creates a new {@link ServiceBindingMetadata} from the given params
+ * and calls {@link #addServiceBinding(ServiceBindingMetadata)}.
+ *
+ * @param serviceName the name of the service. Cannot be <code>null</code>
+ * @param bindingName name qualifier for the binding within the service.
+ * May be <code>null</code>
+ * @param description helpful description of the binding; may be <code>null</code>
+ * @param hostName hostname or IP address to which the binding should be
+ * bound. Often <code>null</code> since the host name typically
+ * comes from the default host name for each binding set
+ * @param port port the binding should use
+ * @param fixedHostName <code>true</code> if the binding's <code>hostName</code>
+ * should remain fixed when added to each binding set;
+ * <code>false</code> if it should be changed to the binding set's
+ * default host name
+ * @param fixedPort <code>true</code> if the binding's port should remain fixed
+ * when added to each binding set; <code>false</code> if it
+ * should be offset by the binding set's port offset
+ *
+ * @throws DuplicateServiceException thrown if a configuration for the
+ * <serverName, serviceName> pair already exists.
+ */
+ public synchronized void addServiceBinding(String serviceName, String bindingName, String description, String hostName, int port, boolean fixedHostName, boolean fixedPort)
+ throws DuplicateServiceException, UnknownHostException
+ {
ServiceBindingMetadata metadata = new ServiceBindingMetadata();
metadata.setServiceName(serviceName);
metadata.setBindingName(bindingName);
metadata.setHostName(hostName);
metadata.setPort(port);
metadata.setFixedPort(fixedPort);
+
addServiceBinding(metadata);
}
@@ -342,9 +350,7 @@
*
* @param metadata the binding
*/
- @ManagementOperation(description="removes a service binding", impact=Impact.WriteOnly,
- params={@ManagementParameter(name="binding")})
- public void removeServiceBinding(ServiceBindingMetadata metadata)
+ public synchronized void removeServiceBinding(ServiceBindingMetadata metadata)
{
// Remove from runtime sets
for (String serverName : bindingSets.keySet())
@@ -353,18 +359,17 @@
}
// Remove from managed set
- standardBindings.remove(metadata);
+ standardBindings.remove(metadata);
}
/**
* Remove a service configuration from all binding sets in the store.
*
- * @param serviceBinding the binding
+ * @param serviceName the name of the service. Cannot be <code>null</code>
+ * @param bindingName name qualifier for the binding within the service.
+ * May be <code>null</code>
*/
- @ManagementOperation(description="removes a service binding", impact=Impact.WriteOnly,
- params={@ManagementParameter(name="serviceName"),
- @ManagementParameter(name="bindingName")})
- public void removeServiceBinding(String serviceName, String bindingName)
+ public synchronized void removeServiceBinding(String serviceName, String bindingName)
{
ServiceBindingMetadata metadata = new ServiceBindingMetadata(serviceName, bindingName);
removeServiceBinding(metadata);
@@ -383,6 +388,89 @@
throw new IllegalArgumentException("unknown serverName " +serverName);
}
+ private void setServiceBindingSetsInternal(Set<ServiceBindingSet> sets)
+ {
+ this.bindingSets.clear();
+
+ if (sets != null)
+ {
+ for (ServiceBindingSet bindingSet : sets)
+ {
+ this.bindingSets.put(bindingSet.getName(), bindingSet);
+ }
+ }
+ }
+
+ private void setStandardBindingsInternal(Set<ServiceBindingMetadata> bindings)
+ {
+ standardBindings.clear();
+ if (bindings != null)
+ {
+ for (ServiceBindingMetadata binding : bindings)
+ {
+ standardBindings.put(binding, VALUE);
+ }
+ }
+ }
+
+ private void establishBindings() throws UnknownHostException, DuplicateServiceException
+ {
+ synchronized (this)
+ {
+ this.bindings.clear();
+
+ // Establish the override bindings first, so when we add the
+ // fixed and portOffset, we get DuplicateServiceException
+ for (ServiceBindingSet bindingSet : bindingSets.values())
+ {
+ for (ServiceBindingMetadata binding : bindingSet.getOverrideBindings())
+ {
+ addServiceBindingInternal(bindingSet.getName(), binding, false);
+ }
+ }
+
+ // Establish the standard bindings
+ for (ServiceBindingMetadata metadata : standardBindings.keySet())
+ {
+ for (ServiceBindingSet bindingSet : bindingSets.values())
+ {
+ try
+ {
+ addServiceBindingInternal(bindingSet.getName(), metadata, false);
+ }
+ catch (DuplicateServiceException e)
+ {
+ if (bindingSet.getOverrideBindings().contains(metadata) == false)
+ {
+ throw e;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private void addServiceBindingInternal(String serverName, ServiceBindingMetadata metadata, boolean addToBindingSet)
+ throws DuplicateServiceException, UnknownHostException
+ {
+ validateServerName(serverName);
+ ServiceBindingSet bindingSet = bindingSets.get(serverName);
+ ServiceBinding binding = new ServiceBinding(metadata, bindingSet.getDefaultHostName(), bindingSet.getPortOffset());
+ ServiceBinding oldBinding = bindings.putIfAbsent(new ServiceBindingKey(serverName, metadata), binding);
+ if (oldBinding != null &&
+ (safeEquals(oldBinding.getHostName(), binding.getHostName()) == false
+ || oldBinding.getPort() != binding.getPort()))
+ {
+ throw new DuplicateServiceException(serverName, binding);
+ }
+
+ if (addToBindingSet)
+ {
+ // For management purposes, treat this as an override
+ bindingSet.getOverrideBindings().add(metadata);
+ }
+ }
+
private static class ServiceBindingKey
{
private final String serverName;
Modified: branches/Branch_5_x/varia/src/main/org/jboss/services/binding/impl/ServiceBindingSet.java
===================================================================
--- branches/Branch_5_x/varia/src/main/org/jboss/services/binding/impl/ServiceBindingSet.java 2009-05-14 20:42:20 UTC (rev 88904)
+++ branches/Branch_5_x/varia/src/main/org/jboss/services/binding/impl/ServiceBindingSet.java 2009-05-14 20:42:36 UTC (rev 88905)
@@ -26,11 +26,6 @@
import java.util.HashSet;
import java.util.Set;
-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.services.binding.ServiceBindingMetadata;
/**
@@ -39,8 +34,6 @@
* @author Brian Stansberry
* @version $Revision$
*/
- at ManagementObject(componentType=@ManagementComponent(type="MCBean", subtype="ServiceBindingSet"),
- properties=ManagementProperties.EXPLICIT)
public class ServiceBindingSet
{
/** The serialVersionUID */
@@ -49,7 +42,7 @@
private final String bindingSetName;
private String defaultHostName;
private int portOffset;
- private final Set<ServiceBindingMetadata> overrides;
+ private final Set<ServiceBindingMetadata> overrides = new HashSet<ServiceBindingMetadata>(0);
// ------------------------------------------------------------ Constructors
@@ -105,24 +98,26 @@
throw new IllegalArgumentException("name is null");
}
- this.overrides = overrides == null ? new HashSet<ServiceBindingMetadata>(0) : overrides;
-
this.bindingSetName = name;
this.defaultHostName = defaultHostName;
this.portOffset = offset;
+
+ if (overrides != null)
+ {
+ for (ServiceBindingMetadata sbm : overrides)
+ {
+ this.overrides.add(sbm);
+ }
+ }
}
// -------------------------------------------------------------- Properties
- @ManagementProperty(description="the name of the set")
- @ManagementObjectID(type="ServiceBindingSet")
public String getName()
{
return bindingSetName;
}
- @ManagementProperty(description="the host name bindings associated with this " +
- "set should use not configured in the binding itself")
public String getDefaultHostName()
{
return defaultHostName;
@@ -133,8 +128,6 @@
this.defaultHostName = defaultHostName;
}
- @ManagementProperty(description="offset that should be applied to non-fixed-port" +
- "bindings associated with this set")
public int getPortOffset()
{
return portOffset;
@@ -145,8 +138,6 @@
this.portOffset = portOffset;
}
- @ManagementProperty(description="bindings that either override or are additions " +
- "to the base bindings configured in the ServiceBindingStore")
public Set<ServiceBindingMetadata> getOverrideBindings()
{
@SuppressWarnings("unchecked")
Added: branches/Branch_5_x/varia/src/main/org/jboss/services/binding/managed/ServiceBindingManagementObject.java
===================================================================
--- branches/Branch_5_x/varia/src/main/org/jboss/services/binding/managed/ServiceBindingManagementObject.java (rev 0)
+++ branches/Branch_5_x/varia/src/main/org/jboss/services/binding/managed/ServiceBindingManagementObject.java 2009-05-14 20:42:36 UTC (rev 88905)
@@ -0,0 +1,331 @@
+/*
+ * 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.managed;
+
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.managed.api.annotation.ManagementComponent;
+import org.jboss.managed.api.annotation.ManagementObject;
+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.DuplicateServiceException;
+import org.jboss.services.binding.ServiceBinding;
+import org.jboss.services.binding.ServiceBindingManager;
+import org.jboss.services.binding.ServiceBindingMetadata;
+import org.jboss.services.binding.ServiceBindingStore;
+import org.jboss.services.binding.ServiceBindingValueSource;
+import org.jboss.services.binding.impl.PojoServiceBindingStore;
+import org.jboss.services.binding.impl.ServiceBindingSet;
+
+/**
+ * Provide a management interface to the overall {@link ServiceBindingManager} system.
+ *
+ * @author Brian Stansberry
+ *
+ * @version $Revision: $
+ */
+ at ManagementObject(name="ServiceBindingManager",
+ componentType=@ManagementComponent(type="MCBean", subtype="ServiceBindingManager"),
+ properties=ManagementProperties.EXPLICIT,
+ description="The ServiceBindingManager enables the centralized management of ports, by service.")
+public class ServiceBindingManagementObject
+{
+ private final ServiceBindingManager bindingManager;
+ private final PojoServiceBindingStore bindingStore;
+
+ /**
+ * Create a new ServiceBindingManager.
+ *
+ * @param serverName
+ * @param bindingSets
+ * @param standardBindings
+ */
+ public ServiceBindingManagementObject(String serverName, Set<ServiceBindingSet> bindingSets,
+ Set<ServiceBindingMetadata> standardBindings)
+ {
+ bindingStore = new PojoServiceBindingStore(bindingSets, standardBindings);
+ bindingManager = new ServiceBindingManager(serverName, bindingStore);
+ }
+
+ public ServiceBindingManager getServiceBindingManager()
+ {
+ return bindingManager;
+ }
+
+ /**
+ * Gets the value of the <code>serverName</code> param the <code>ServiceBindingManager</code>
+ * should pass to <code>ServiceBindingStore</code> when
+ * {@link ServiceBindingStore#getServiceBinding(String, String, String) requesting bindings}.
+ *
+ * @return name of the set of bindings this server uses
+ */
+ @ManagementProperty(description="the name of the binding set the " +
+ "ServiceBindingManager should use when resolving bindings",
+ use={ViewUse.CONFIGURATION}, readOnly=false)
+ public String getActiveBindingSetName()
+ {
+ return bindingManager.getServerName();
+ }
+
+ /**
+ * Sets the value of the <code>serverName</code> param the <code>ServiceBindingManager</code>
+ * should pass to <code>ServiceBindingStore</code> when
+ * {@link ServiceBindingStore#getServiceBinding(String, String, String) requesting bindings}.
+ *
+ * param name name of the set of bindings this server uses
+ */
+ public void setActiveBindingSetName(String name)
+ {
+ bindingManager.setServerName(name);
+ }
+
+ @ManagementProperty(description="the set of service binding configurations associated with this instance",
+ use={ViewUse.STATISTIC}, readOnly=true)
+ @MetaMapping(value=ServiceBindingMapper.class)
+ public Map<String, Set<ServiceBinding>> getServiceBindings()
+ {
+ Map<String, Set<ServiceBinding>> result = new HashMap<String, Set<ServiceBinding>>();
+ for (ServiceBindingSet set : getBindingSets())
+ {
+ String name = set.getName();
+ result.put(name, bindingStore.getServiceBindings(name));
+ }
+ return result;
+ }
+
+ /**
+ * Gets the available {@link ServiceBindingSet}s.
+ *
+ * @return the binding sets. Will not return <code>null</code>
+ */
+ @ManagementProperty(description="the named binding sets")
+ @MetaMapping(ServiceBindingSetMapper.class)
+ public Set<ServiceBindingSet> getBindingSets()
+ {
+ return bindingStore.getServiceBindingSets();
+ }
+
+ /**
+ * Sets the available {@link ServiceBindingSet}s.
+ *
+ * @param bindingSets the binding sets
+ * @throws DuplicateServiceException
+ * @throws UnknownHostException
+ */
+ public void setBindingSets(Set<ServiceBindingSet> bindingSets) throws UnknownHostException, DuplicateServiceException
+ {
+ // The managed objects don't handle any configure value sources, so we need
+ // to restore any existing ones
+ restoreOverrideBindingValueSources(bindingSets);
+
+ bindingStore.setServiceBindingSets(bindingSets);
+ }
+
+ /**
+ * Gets the base set of bindings that should be associated with each binding set,
+ * but with that binding set's {@link ServiceBindingSet#getPortOffset() port offset}
+ * applied to the port value.
+ *
+ * @return the set of base bindings
+ */
+ @ManagementProperty(description="the base set of bindings that should be associated " +
+ "with each binding set")
+ @MetaMapping(ServiceBindingMetadataMapper.class)
+ public Set<ServiceBindingMetadata> getStandardBindings()
+ {
+ return bindingStore.getStandardBindings();
+ }
+
+ /**
+ * Sets the base set of bindings that should be associated with each binding set,
+ * but with that binding set's {@link ServiceBindingSet#getPortOffset() port offset}
+ * applied to the port value.
+ *
+ * @param bindings the set of base bindings
+ * @throws DuplicateServiceException
+ * @throws UnknownHostException
+ */
+ public void setStandardBindings(Set<ServiceBindingMetadata> bindings) throws UnknownHostException, DuplicateServiceException
+ {
+ // The managed objects don't handle any configure value sources, so we need
+ // to restore any existing ones
+ restoreStandardBindingValueSources(bindings);
+
+ bindingStore.setStandardBindings(bindings);
+ }
+
+
+ private void restoreStandardBindingValueSources(Set<ServiceBindingMetadata> bindings)
+ {
+ if (bindings != null)
+ {
+ Set<ServiceBindingMetadata> existing = bindingStore.getStandardBindings();
+ restoreServiceBindingValueSources(bindings, existing);
+ }
+ }
+
+
+ private void restoreOverrideBindingValueSources(Set<ServiceBindingSet> bindingSets)
+ {
+ if (bindingSets != null)
+ {
+ Set<ServiceBindingSet> existingSets = bindingStore.getServiceBindingSets();
+ Map<String, Set<ServiceBindingMetadata>> byName = new HashMap<String, Set<ServiceBindingMetadata>>();
+ for (ServiceBindingSet set : existingSets)
+ {
+ byName.put(set.getName(), set.getOverrideBindings());
+ }
+
+ for (ServiceBindingSet set : bindingSets)
+ {
+ restoreServiceBindingValueSources(set.getOverrideBindings(), byName.get(set.getName()));
+ }
+ }
+ }
+
+ private void restoreServiceBindingValueSources(Set<ServiceBindingMetadata> bindings,
+ Set<ServiceBindingMetadata> existing)
+ {
+ if (bindings != null && existing != null)
+ {
+ Map<String, ServiceBindingMetadata> byFQN = new HashMap<String, ServiceBindingMetadata>();
+ for (ServiceBindingMetadata md : existing)
+ {
+ byFQN.put(md.getFullyQualifiedName(), md);
+ }
+
+ for (ServiceBindingMetadata newMD : bindings)
+ {
+ ServiceBindingMetadata old = byFQN.get(newMD.getFullyQualifiedName());
+ if (old != null)
+ {
+ ServiceBindingValueSource source = old.getServiceBindingValueSource();
+ if (source != null)
+ {
+ newMD.setServiceBindingValueSource(source);
+ }
+ else
+ {
+ String sourceClass = old.getServiceBindingValueSourceClassName();
+ if (sourceClass != null)
+ {
+ newMD.setServiceBindingValueSourceClassName(sourceClass);
+ }
+ }
+
+ newMD.setServiceBindingValueSourceConfig(old.getServiceBindingValueSourceConfig());
+ }
+ }
+ }
+ }
+
+// /**
+// * Add a ServiceBinding to all binding sets in the store. For each binding
+// * set, a new ServiceBinding is added whose serviceName and bindingName
+// * properties match the passed binding. If <the given <code>binding</code>'s
+// * <code>fixeHostName</code> property is <code>false</code>, the new binding's
+// * hostName matches the target set's {@link #getDefaultHostName(String) default host name}.
+// * If <code>binding</code>'s <code>fixedPort</code> property is <code>false</code>,
+// * the new binding's port is derived by taking the port from the passed binding
+// * and incrementing it by the target set's
+// * {@link #getDefaultPortOffset(String) default port offset}.
+// *
+// * @param serviceName the name of the service. Cannot be <code>null</code>
+// * @param bindingName name qualifier for the binding within the service.
+// * May be <code>null</code>
+// * @param description helpful description of the binding; may be <code>null</code>
+// * @param hostName hostname or IP address to which the binding should be
+// * bound. Often <code>null</code> since the host name typically
+// * comes from the default host name for each binding set
+// * @param port port the binding should use
+// * @param fixedHostName <code>true</code> if the binding's <code>hostName</code>
+// * should remain fixed when added to each binding set;
+// * <code>false</code> if it should be changed to the binding set's
+// * default host name
+// * @param fixedPort <code>true</code> if the binding's port should remain fixed
+// * when added to each binding set; <code>false</code> if it
+// * should be offset by the binding set's port offset
+// *
+// * @throws DuplicateServiceException thrown if a configuration for the
+// * <serverName, serviceName> pair already exists.
+// */
+// @ManagementOperation(description="adds a service binding to all binding sets in the store", impact=Impact.WriteOnly,
+// params={@ManagementParameter(name="serviceName",
+// description="the name of the service; cannot be null"),
+// @ManagementParameter(name="bindingName",
+// description="name qualifier for the binding within the service; may be null"),
+// @ManagementParameter(name="description",
+// description="helpful description of the binding; may be null"),
+// @ManagementParameter(name="hostName",
+// description="hostname or IP address designating " +
+// "the interface to which the binding " +
+// "should be bound; Often null since the host name " +
+// "typically comes from the default host name for each binding set"),
+// @ManagementParameter(name="port",
+// description="port the binding should use"),
+// @ManagementParameter(name="fixedHostName",
+// description="true if the value of the hostName " +
+// "param must be respected; false if it " +
+// "can be altered to the default value " +
+// "for each binding set"),
+// @ManagementParameter(name="fixedPort",
+// description="true if the the binding's port " +
+// "should remain fixed when added to each " +
+// "binding set; false if it should be " +
+// "offset by the binding set's port offset")})
+// public void addStandardBinding(String serviceName, String bindingName, String description, String hostName, int port, boolean fixedHostName, boolean fixedPort)
+// throws DuplicateServiceException, UnknownHostException
+// {
+// bindingStore.addServiceBinding(serviceName, bindingName, description, hostName, port, fixedHostName, fixedPort);
+// }
+//
+// /**
+// * Remove a service configuration from all binding sets in the store.
+// *
+// * @param serviceName the name of the service. Cannot be <code>null</code>
+// * @param bindingName name qualifier for the binding within the service.
+// * May be <code>null</code>
+// */
+// @ManagementOperation(description="removes a service binding", impact=Impact.WriteOnly,
+// params={@ManagementParameter(name="serviceName"),
+// @ManagementParameter(name="bindingName")})
+// public void removeStandardBinding(String serviceName, String bindingName)
+// {
+// bindingStore.removeServiceBinding(serviceName, bindingName);
+// }
+
+ public void start() throws Exception
+ {
+ bindingStore.start();
+ }
+
+ public void stop() throws Exception
+ {
+ bindingStore.stop();
+ }
+}
Property changes on: branches/Branch_5_x/varia/src/main/org/jboss/services/binding/managed/ServiceBindingManagementObject.java
___________________________________________________________________
Name: svn:keywords
+
Copied: branches/Branch_5_x/varia/src/main/org/jboss/services/binding/managed/ServiceBindingMapper.java (from rev 88764, branches/Branch_5_x/varia/src/main/org/jboss/services/binding/ServiceBindingMapper.java)
===================================================================
--- branches/Branch_5_x/varia/src/main/org/jboss/services/binding/managed/ServiceBindingMapper.java (rev 0)
+++ branches/Branch_5_x/varia/src/main/org/jboss/services/binding/managed/ServiceBindingMapper.java 2009-05-14 20:42:36 UTC (rev 88905)
@@ -0,0 +1,191 @@
+/*
+ * 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.managed;
+
+import java.lang.reflect.Type;
+import java.net.InetAddress;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Map;
+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.MapCompositeMetaType;
+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;
+import org.jboss.services.binding.ServiceBinding;
+
+/**
+ * {@link MetaMapper} for a map of all {@link ServiceBinding}s available,
+ * where keys are the name of a {@link ServiceBindingSet} and the values are
+ * the set of {@link ServiceBinding}s associated with that binding set.
+ *
+ * @author Brian Stansberry
+ */
+public class ServiceBindingMapper extends MetaMapper<Map<String, Set<ServiceBinding>>>
+{
+ private static final Logger log = Logger.getLogger(ServiceBindingMapper.class);
+ public static final MapCompositeMetaType TYPE;
+ public static final CompositeMetaType SERVICE_BINDING_TYPE;
+ public static final CollectionMetaType MAP_VALUE_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(ServiceBinding.class.getName(),
+ "Service Binding",
+ itemNames, itemDescriptions, itemTypes);
+ MAP_VALUE_TYPE = new CollectionMetaType(Set.class.getName(), SERVICE_BINDING_TYPE);
+ TYPE = new MapCompositeMetaType(MAP_VALUE_TYPE);
+ }
+
+ @Override
+ public MetaType getMetaType()
+ {
+ return TYPE;
+ }
+
+ @Override
+ public Type mapToType()
+ {
+ return Map.class;
+ }
+
+ @Override
+ public MetaValue createMetaValue(MetaType metaType, Map<String, Set<ServiceBinding>> object)
+ {
+ Map<String, MetaValue> map = new HashMap<String, MetaValue>();
+ for (Map.Entry<String, Set<ServiceBinding>> mapEntry: object.entrySet())
+ {
+ Set<CompositeValue> tmp = new TreeSet<CompositeValue>(new FullyQualifiedNameComparator());
+ for (ServiceBinding b : mapEntry.getValue())
+ {
+ 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 bindingSet = new CollectionValueSupport(MAP_VALUE_TYPE, elements);
+
+ map.put(mapEntry.getKey(), bindingSet);
+ }
+
+ return new MapCompositeValueSupport(map, MAP_VALUE_TYPE);
+ }
+
+ /**
+ * This always returns null as ServiceBindings cannot be created from a meta value
+ */
+ @Override
+ public Map<String, 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/managed/ServiceBindingMapper.java
___________________________________________________________________
Name: svn:keywords
+
Name: svn:mergeinfo
+
Added: branches/Branch_5_x/varia/src/main/org/jboss/services/binding/managed/ServiceBindingMetadataMapper.java
===================================================================
--- branches/Branch_5_x/varia/src/main/org/jboss/services/binding/managed/ServiceBindingMetadataMapper.java (rev 0)
+++ branches/Branch_5_x/varia/src/main/org/jboss/services/binding/managed/ServiceBindingMetadataMapper.java 2009-05-14 20:42:36 UTC (rev 88905)
@@ -0,0 +1,229 @@
+/*
+ * 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.managed;
+
+import java.lang.reflect.Type;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.jboss.logging.Logger;
+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.CollectionValue;
+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;
+import org.jboss.services.binding.ServiceBindingMetadata;
+
+/**
+ * {@link MetaMapper} for a set of {@link ServiceBindingMetadata}.
+ *
+ * @author Brian Stansberry
+ */
+public class ServiceBindingMetadataMapper extends MetaMapper<Set<ServiceBindingMetadata>>
+{
+ private static final Logger log = Logger.getLogger(ServiceBindingMetadataMapper.class);
+ public static final CollectionMetaType TYPE;
+ public static final CompositeMetaType SERVICE_BINDING_METADATA_TYPE;
+
+ static
+ {
+ String[] itemNames = {
+ "serviceName",
+ "bindingName",
+ "fullyQualifiedName",
+ "description",
+ "hostName",
+ "port",
+ "fixedHostName",
+ "fixedPort"//,
+// "serviceBindingValueSourceClassName",
+// "serviceBindingValueSourceConfig"
+ };
+ 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",
+ "the port to use for the binding",
+ "whether the host name should remain fixed in all binding sets",
+ "whether the port should remain fixed in all binding sets"//,
+// "fully qualified classname of specialized object used to process binding results",
+// ""
+ };
+ MetaType[] itemTypes = {
+ SimpleMetaType.STRING,
+ SimpleMetaType.STRING,
+ SimpleMetaType.STRING,
+ SimpleMetaType.STRING,
+ SimpleMetaType.STRING,
+ SimpleMetaType.INTEGER_PRIMITIVE,
+ SimpleMetaType.BOOLEAN_PRIMITIVE,
+ SimpleMetaType.BOOLEAN_PRIMITIVE//,
+// SimpleMetaType.STRING,
+// new GenericMetaType(ManagedObject)
+ };
+ SERVICE_BINDING_METADATA_TYPE = new ImmutableCompositeMetaType(ServiceBindingMetadata.class.getName(),
+ "Service Binding Metadata",
+ itemNames, itemDescriptions, itemTypes);
+ TYPE = new CollectionMetaType(Set.class.getName(), SERVICE_BINDING_METADATA_TYPE);
+ }
+
+ public ServiceBindingMetadataMapper()
+ {
+ super();
+ }
+
+ @Override
+ public MetaType getMetaType()
+ {
+ return TYPE;
+ }
+
+ @Override
+ public Type mapToType()
+ {
+ return Set.class;
+ }
+
+ @Override
+ public MetaValue createMetaValue(MetaType metaType, Set<ServiceBindingMetadata> object)
+ {
+ Set<CompositeValue> tmp = new TreeSet<CompositeValue>(new FullyQualifiedNameComparator());
+ for (ServiceBindingMetadata b : object)
+ {
+ try
+ {
+ MapCompositeValueSupport cvs = new MapCompositeValueSupport(SERVICE_BINDING_METADATA_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()));
+ cvs.put("port", SimpleValueSupport.wrap(b.getPort()));
+ cvs.put("fixedHostName", SimpleValueSupport.wrap(b.isFixedHostName()));
+ cvs.put("fixedPort", SimpleValueSupport.wrap(b.isFixedPort()));
+ 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;
+ }
+
+ /**
+ * Converts the {@link CollectionValue} <code>metaValue</code> into a set
+ * of {@link ServiceBindingMetadata}.
+ *
+ * {@inheritDoc}
+ *
+ * @throws IllegalArgumentException if <code>metaValue</code> is not a
+ * {@link CollectionValue} or if any element is not a {@link CompositeValue}
+ */
+ @Override
+ public Set<ServiceBindingMetadata> unwrapMetaValue(MetaValue metaValue)
+ {
+ if (metaValue == null)
+ {
+ return null;
+ }
+
+ if ((metaValue instanceof CollectionValue) == false)
+ {
+ throw new IllegalArgumentException(metaValue + " is not a " + CollectionValue.class.getSimpleName());
+ }
+ CollectionValue collValue = (CollectionValue) metaValue;
+ MetaValue[] elements = collValue.getElements();
+ Set<ServiceBindingMetadata> result = new HashSet<ServiceBindingMetadata>(elements.length);
+ for (MetaValue element : elements)
+ {
+
+ if ((element instanceof CompositeValue) == false)
+ {
+ throw new IllegalArgumentException(element + " is not a " + CompositeValue.class.getSimpleName());
+ }
+ CompositeValue compValue = (CompositeValue) element;
+ String bindingSetName = Util.getValueFromComposite(compValue, "bindingSetName", String.class);
+ String serviceName = Util.getValueFromComposite(compValue, "serviceName", String.class);
+ String bindingName = Util.getValueFromComposite(compValue, "bindingName", String.class);
+ String description = Util.getValueFromComposite(compValue, "description", String.class);
+ String hostName = Util.getValueFromComposite(compValue, "hostName", String.class);
+ Integer port = Util.getValueFromComposite(compValue, "port", Integer.class);
+ if (port == null)
+ {
+ throw new IllegalStateException(element + " has no value for key 'port'");
+ }
+ Boolean fixedHostName = Util.getValueFromComposite(compValue, "fixedHostName", Boolean.class);
+ Boolean fixedPort = Util.getValueFromComposite(compValue, "fixedPort", Boolean.class);
+// String serviceBindingValueSourceClassName = getValueFromComposite(compValue, "serviceBindingValueSourceClassName", String.class);
+ ServiceBindingMetadata sbm =
+ new ServiceBindingMetadata(serviceName, bindingName, hostName, port.intValue(),
+ fixedHostName == null ? false : fixedHostName.booleanValue(),
+ fixedPort == null ? false : fixedPort.booleanValue());
+ sbm.setDescription(description);
+// sbm.setServiceBindingValueSourceClassName(serviceBindingValueSourceClassName);
+ result.add(sbm);
+ }
+ return result;
+ }
+
+ /** 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/managed/ServiceBindingMetadataMapper.java
___________________________________________________________________
Name: svn:keywords
+
Added: branches/Branch_5_x/varia/src/main/org/jboss/services/binding/managed/ServiceBindingSetMapper.java
===================================================================
--- branches/Branch_5_x/varia/src/main/org/jboss/services/binding/managed/ServiceBindingSetMapper.java (rev 0)
+++ branches/Branch_5_x/varia/src/main/org/jboss/services/binding/managed/ServiceBindingSetMapper.java 2009-05-14 20:42:36 UTC (rev 88905)
@@ -0,0 +1,204 @@
+/*
+ * 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.managed;
+
+import java.lang.reflect.Type;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.jboss.logging.Logger;
+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.CollectionValue;
+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;
+import org.jboss.services.binding.ServiceBinding;
+import org.jboss.services.binding.ServiceBindingMetadata;
+import org.jboss.services.binding.impl.ServiceBindingSet;
+
+/**
+ * {@link MetaMapper} for a set of {@link ServiceBindingSet}s.
+ *
+ * @author Brian Stansberry
+ */
+public class ServiceBindingSetMapper extends MetaMapper<Set<ServiceBindingSet>>
+{
+ private static final Logger log = Logger.getLogger(ServiceBindingSetMapper.class);
+ public static final CollectionMetaType TYPE;
+ public static final CompositeMetaType SERVICE_BINDING_SET_TYPE;
+
+ static
+ {
+ String[] itemNames = {
+ "name",
+ "defaultHostName",
+ "portOffset",
+ "overrideBindings"
+ };
+ String[] itemDescriptions = {
+ "the name of the binding set",
+ "the host name that should be used for all bindings whose configuration " +
+ "does not specify fixedHostName=\"true\"",
+ "value to add to the port configuration for a standard binding to " +
+ "derive the port to use in this binding set",
+ "binding configurations that apply only to this binding set, either " +
+ "non-standard bindings or ones that override standard binding configurations",
+ };
+ MetaType[] itemTypes = {
+ SimpleMetaType.STRING,
+ SimpleMetaType.STRING,
+ SimpleMetaType.INTEGER_PRIMITIVE,
+ ServiceBindingMetadataMapper.TYPE
+ };
+ SERVICE_BINDING_SET_TYPE = new ImmutableCompositeMetaType(ServiceBindingSet.class.getName(),
+ "Service Binding Set",
+ itemNames, itemDescriptions, itemTypes);
+ TYPE = new CollectionMetaType(Set.class.getName(), SERVICE_BINDING_SET_TYPE);
+ }
+
+ @Override
+ public MetaType getMetaType()
+ {
+ return TYPE;
+ }
+
+ @Override
+ public Type mapToType()
+ {
+ return Set.class;
+ }
+
+ @Override
+ public MetaValue createMetaValue(MetaType metaType, Set<ServiceBindingSet> object)
+ {
+ ServiceBindingMetadataMapper mapper = new ServiceBindingMetadataMapper();
+ Set<CompositeValue> tmp = new TreeSet<CompositeValue>(new NameComparator());
+ for (ServiceBindingSet b : object)
+ {
+ try
+ {
+ MapCompositeValueSupport cvs = new MapCompositeValueSupport(SERVICE_BINDING_SET_TYPE);
+ cvs.put("name", SimpleValueSupport.wrap(b.getName()));
+ cvs.put("defaultHostName", SimpleValueSupport.wrap(b.getDefaultHostName()));
+ cvs.put("portOffset", SimpleValueSupport.wrap(b.getPortOffset()));
+ Set<ServiceBindingMetadata> metadata = b.getOverrideBindings();
+ if (metadata != null)
+ {
+ cvs.put("overrideBindings", mapper.createMetaValue(mapper.getMetaType(), metadata));
+ }
+ 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;
+ }
+
+ /**
+ * Converts the {@link CollectionValue} <code>metaValue</code> into a set
+ * of {@link ServiceBindingMetadata}.
+ *
+ * {@inheritDoc}
+ *
+ * @throws IllegalArgumentException if <code>metaValue</code> is not a
+ * {@link CollectionValue} or if any element is not a {@link CompositeValue}
+ */
+ @Override
+ public Set<ServiceBindingSet> unwrapMetaValue(MetaValue metaValue)
+ {
+ if (metaValue == null)
+ {
+ return null;
+ }
+
+ if ((metaValue instanceof CollectionValue) == false)
+ {
+ throw new IllegalArgumentException(metaValue + " is not a " + CollectionValue.class.getSimpleName());
+ }
+ CollectionValue collValue = (CollectionValue) metaValue;
+ MetaValue[] elements = collValue.getElements();
+
+ ServiceBindingMetadataMapper mapper = new ServiceBindingMetadataMapper();
+
+ Set<ServiceBindingSet> result = new HashSet<ServiceBindingSet>(elements.length);
+ for (MetaValue element : elements)
+ {
+
+ if ((element instanceof CompositeValue) == false)
+ {
+ throw new IllegalArgumentException(element + " is not a " + CompositeValue.class.getSimpleName());
+ }
+ CompositeValue compValue = (CompositeValue) element;
+ String name = Util.getValueFromComposite(compValue, "name", String.class);
+ String defaultHostName = Util.getValueFromComposite(compValue, "defaultHostName", String.class);
+ Integer portOffset = Util.getValueFromComposite(compValue, "portOffset", Integer.class);
+ if (portOffset == null)
+ {
+ throw new IllegalStateException(element + " has no value for key 'port'");
+ }
+ Set<ServiceBindingMetadata> overrides = mapper.unwrapMetaValue(compValue.get("overrideBindings"));
+ ServiceBindingSet sbs = new ServiceBindingSet(name, defaultHostName, portOffset.intValue(), overrides);
+ result.add(sbs);
+ }
+ return result;
+ }
+
+ /** Used to order CompositeValues by the name key */
+ private static class NameComparator implements Comparator<CompositeValue>
+ {
+
+ public int compare(CompositeValue o1, CompositeValue o2)
+ {
+ SimpleValue sv1 = (SimpleValue) o1.get("name");
+ if (sv1 == null)
+ {
+ throw new IllegalStateException(o1 + " has no name");
+ }
+ SimpleValue sv2 = (SimpleValue) o2.get("name");
+ if (sv2 == null)
+ {
+ throw new IllegalStateException(o2 + " has no name");
+ }
+
+ 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/managed/ServiceBindingSetMapper.java
___________________________________________________________________
Name: svn:keywords
+
Added: branches/Branch_5_x/varia/src/main/org/jboss/services/binding/managed/Util.java
===================================================================
--- branches/Branch_5_x/varia/src/main/org/jboss/services/binding/managed/Util.java (rev 0)
+++ branches/Branch_5_x/varia/src/main/org/jboss/services/binding/managed/Util.java 2009-05-14 20:42:36 UTC (rev 88905)
@@ -0,0 +1,57 @@
+/*
+ * 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.managed;
+
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.SimpleValue;
+
+/**
+ * Utility methods
+ *
+ * @author Brian Stansberry
+ *
+ * @version $Revision: $
+ */
+public class Util
+{
+
+ public static <T> T getValueFromComposite(CompositeValue composite, String key, Class<T> type)
+ {
+ T result = null;
+ SimpleValue sv = (SimpleValue) composite.get(key);
+ if (sv != null)
+ {
+ Object val = sv.getValue();
+ result = type.cast(val);
+ }
+ return result;
+ }
+
+ /**
+ * Prevent instantiation.
+ */
+ private Util()
+ {
+ }
+
+}
Property changes on: branches/Branch_5_x/varia/src/main/org/jboss/services/binding/managed/Util.java
___________________________________________________________________
Name: svn:keywords
+
Modified: branches/Branch_5_x/varia/src/tests/org/jboss/test/services/binding/test/PojoServiceBindingStoreUnitTestCase.java
===================================================================
--- branches/Branch_5_x/varia/src/tests/org/jboss/test/services/binding/test/PojoServiceBindingStoreUnitTestCase.java 2009-05-14 20:42:20 UTC (rev 88904)
+++ branches/Branch_5_x/varia/src/tests/org/jboss/test/services/binding/test/PojoServiceBindingStoreUnitTestCase.java 2009-05-14 20:42:36 UTC (rev 88905)
@@ -25,15 +25,17 @@
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
import junit.framework.TestCase;
import org.jboss.services.binding.DuplicateServiceException;
-import org.jboss.services.binding.ServiceBindingMetadata;
import org.jboss.services.binding.NoSuchBindingException;
import org.jboss.services.binding.ServiceBinding;
+import org.jboss.services.binding.ServiceBindingMetadata;
import org.jboss.services.binding.impl.PojoServiceBindingStore;
import org.jboss.services.binding.impl.ServiceBindingSet;
@@ -418,5 +420,190 @@
}
}
+ public void testSetStandardBindings() throws Exception
+ {
+ Set<ServiceBindingMetadata> set = new HashSet<ServiceBindingMetadata>();
+ set.addAll(Arrays.asList(AA, AB, Anull));
+
+ Set<ServiceBindingSet> sbs = new HashSet<ServiceBindingSet>();
+ ServiceBindingSet setB = new ServiceBindingSet(B, "localhost", 20);
+ sbs.add(setB);
+ ServiceBindingSet setC = new ServiceBindingSet(C, "192.168.0.10", 30);
+ sbs.add(setC);
+
+ PojoServiceBindingStore store = new PojoServiceBindingStore(sbs, set);
+ store.start();
+
+ Set<ServiceBindingMetadata> updatedSet =
+ new HashSet<ServiceBindingMetadata>(store.getStandardBindings());
+ assertEquals(3, updatedSet.size());
+ ServiceBindingMetadata updated = new ServiceBindingMetadata(AA);
+ updated.setPort(9999);
+ updated.setDescription("updated");
+ updatedSet.remove(AA);
+ updatedSet.add(updated);
+ updatedSet.add(BA);
+ assertEquals(4, updatedSet.size());
+
+ store.setStandardBindings(updatedSet);
+
+ Set<ServiceBindingMetadata> result = store.getStandardBindings();
+ assertNotNull(result);
+ assertTrue("has updated", result.contains(updated));
+ assertTrue("has AB", result.contains(AB));
+ assertTrue("has Anull", result.contains(Anull));
+ assertTrue("has BA", result.contains(BA));
+
+ for (ServiceBindingSet bindingSet : sbs)
+ {
+ String setName = bindingSet.getName();
+ Set<ServiceBinding> bindings = store.getServiceBindings(setName);
+ assertNotNull(bindings);
+ assertEquals(4, bindings.size());
+ Map<String, ServiceBinding> byFQN = new HashMap<String, ServiceBinding>();
+ for (ServiceBinding binding : bindings)
+ {
+ byFQN.put(binding.getFullyQualifiedName(), binding);
+ }
+
+ ServiceBinding aa = byFQN.get(updated.getFullyQualifiedName());
+ assertNotNull(aa);
+ assertEquals(setName + "/updated/serviceName", updated.getServiceName(), aa.getServiceName());
+ assertEquals(setName + "/updated/bindingName", updated.getBindingName(), aa.getBindingName());
+ assertEquals(setName + "/updated/description", updated.getDescription(), aa.getDescription());
+ assertEquals(setName + "/updated/hostName", bindingSet.getDefaultHostName(), aa.getHostName());
+ assertEquals(setName + "/updated/port", updated.getPort() + bindingSet.getPortOffset(), aa.getPort());
+
+ ServiceBinding ab = byFQN.get(AB.getFullyQualifiedName());
+ assertNotNull(aa);
+ assertEquals(setName + "/AB/serviceName", AB.getServiceName(), ab.getServiceName());
+ assertEquals(setName + "/AB/bindingName", AB.getBindingName(), ab.getBindingName());
+ assertEquals(setName + "/AB/description", AB.getDescription(), ab.getDescription());
+ assertEquals(setName + "/AB/hostName", bindingSet.getDefaultHostName(), ab.getHostName());
+ assertEquals(setName + "/AB/port", AB.getPort() + bindingSet.getPortOffset(), ab.getPort());
+
+ ServiceBinding anull = byFQN.get(Anull.getFullyQualifiedName());
+ assertNotNull(anull);
+ assertEquals(setName + "/Anull/serviceName", Anull.getServiceName(), anull.getServiceName());
+ assertEquals(setName + "/Anull/bindingName", Anull.getBindingName(), anull.getBindingName());
+ assertEquals(setName + "/Anull/description", Anull.getDescription(), anull.getDescription());
+ assertEquals(setName + "/Anull/hostName", bindingSet.getDefaultHostName(), anull.getHostName());
+ assertEquals(setName + "/Anull/port", Anull.getPort() + bindingSet.getPortOffset(), anull.getPort());
+
+ ServiceBinding newOne = byFQN.get(BA.getFullyQualifiedName());
+ assertNotNull(newOne);
+ assertEquals(setName + "/BA/serviceName", BA.getServiceName(), newOne.getServiceName());
+ assertEquals(setName + "/BA/bindingName", BA.getBindingName(), newOne.getBindingName());
+ assertEquals(setName + "/BA/description", BA.getDescription(), newOne.getDescription());
+ assertEquals(setName + "/BA/hostName", bindingSet.getDefaultHostName(), newOne.getHostName());
+ assertEquals(setName + "/BA/port", BA.getPort() + bindingSet.getPortOffset(), newOne.getPort());
+ }
+ }
+
+ public void testSetServiceBindingSets() throws Exception
+ {
+ Set<ServiceBindingMetadata> set = new HashSet<ServiceBindingMetadata>();
+ set.addAll(Arrays.asList(AA, AB, Anull));
+
+ Set<ServiceBindingSet> sbs = new HashSet<ServiceBindingSet>();
+ ServiceBindingSet setA = new ServiceBindingSet(A, null, 10);
+ sbs.add(setA);
+ ServiceBindingSet setB = new ServiceBindingSet(B, "localhost", 20);
+ sbs.add(setB);
+
+ PojoServiceBindingStore store = new PojoServiceBindingStore(sbs, set);
+ store.start();
+
+ Set<ServiceBindingSet> updated = new HashSet<ServiceBindingSet>(store.getServiceBindingSets());
+
+ Set<ServiceBindingMetadata> overrides = new HashSet<ServiceBindingMetadata>();
+ overrides.add(BA);
+ ServiceBindingSet newSet = new ServiceBindingSet(C, "192.168.0.10", 30, overrides);
+ updated.add(newSet);
+ ServiceBindingSet replaced = new ServiceBindingSet(B, "localhost", 50);
+ updated.remove(setB);
+ updated.add(replaced);
+ assertEquals(3, updated.size());
+
+ store.setServiceBindingSets(updated);
+
+ Set<ServiceBindingSet> result = store.getServiceBindingSets();
+ assertNotNull(result);
+ assertTrue("has setA", result.contains(setA));
+ assertTrue("has setB", result.contains(replaced));
+ assertTrue("has newSet", result.contains(newSet));
+
+ Set<ServiceBinding> bindings = store.getServiceBindings(C);
+ assertNotNull(bindings);
+ Map<String, ServiceBinding> byFQN = new HashMap<String, ServiceBinding>();
+ for (ServiceBinding binding : bindings)
+ {
+ byFQN.put(binding.getFullyQualifiedName(), binding);
+ }
+
+ ServiceBinding aa = byFQN.get(AA.getFullyQualifiedName());
+ assertNotNull(aa);
+ assertEquals(AA.getServiceName(), aa.getServiceName());
+ assertEquals(AA.getBindingName(), aa.getBindingName());
+ assertEquals(AA.getDescription(), aa.getDescription());
+ assertEquals("192.168.0.10", aa.getHostName());
+ assertEquals(AA.getPort() + 30, aa.getPort());
+
+ ServiceBinding ab = byFQN.get(AB.getFullyQualifiedName());
+ assertNotNull(aa);
+ assertEquals(AB.getServiceName(), ab.getServiceName());
+ assertEquals(AB.getBindingName(), ab.getBindingName());
+ assertEquals(AB.getDescription(), ab.getDescription());
+ assertEquals("192.168.0.10", ab.getHostName());
+ assertEquals(AB.getPort() + 30, ab.getPort());
+
+ ServiceBinding anull = byFQN.get(Anull.getFullyQualifiedName());
+ assertNotNull(anull);
+ assertEquals(Anull.getServiceName(), anull.getServiceName());
+ assertEquals(Anull.getBindingName(), anull.getBindingName());
+ assertEquals(Anull.getDescription(), anull.getDescription());
+ assertEquals("192.168.0.10", anull.getHostName());
+ assertEquals(Anull.getPort() + 30, anull.getPort());
+
+ ServiceBinding newOne = byFQN.get(BA.getFullyQualifiedName());
+ assertNotNull(newOne);
+ assertEquals(BA.getServiceName(), newOne.getServiceName());
+ assertEquals(BA.getBindingName(), newOne.getBindingName());
+ assertEquals(BA.getDescription(), newOne.getDescription());
+ assertEquals("192.168.0.10", newOne.getHostName());
+ assertEquals(BA.getPort() + 30, newOne.getPort());
+
+ bindings = store.getServiceBindings(B);
+ assertNotNull(bindings);
+ byFQN = new HashMap<String, ServiceBinding>();
+ for (ServiceBinding binding : bindings)
+ {
+ byFQN.put(binding.getFullyQualifiedName(), binding);
+ }
+
+ aa = byFQN.get(AA.getFullyQualifiedName());
+ assertNotNull(aa);
+ assertEquals(AA.getServiceName(), aa.getServiceName());
+ assertEquals(AA.getBindingName(), aa.getBindingName());
+ assertEquals(AA.getDescription(), aa.getDescription());
+ assertEquals("localhost", aa.getHostName());
+ assertEquals(AA.getPort() + 50, aa.getPort());
+
+ ab = byFQN.get(AB.getFullyQualifiedName());
+ assertNotNull(aa);
+ assertEquals(AB.getServiceName(), ab.getServiceName());
+ assertEquals(AB.getBindingName(), ab.getBindingName());
+ assertEquals(AB.getDescription(), ab.getDescription());
+ assertEquals("localhost", ab.getHostName());
+ assertEquals(AB.getPort() + 50, ab.getPort());
+
+ anull = byFQN.get(Anull.getFullyQualifiedName());
+ assertNotNull(anull);
+ assertEquals(Anull.getServiceName(), anull.getServiceName());
+ assertEquals(Anull.getBindingName(), anull.getBindingName());
+ assertEquals(Anull.getDescription(), anull.getDescription());
+ assertEquals("localhost", anull.getHostName());
+ assertEquals(Anull.getPort() + 50, anull.getPort());
+ }
}
Added: branches/Branch_5_x/varia/src/tests/org/jboss/test/services/binding/test/ServiceBindingMetadataMapperTestCase.java
===================================================================
--- branches/Branch_5_x/varia/src/tests/org/jboss/test/services/binding/test/ServiceBindingMetadataMapperTestCase.java (rev 0)
+++ branches/Branch_5_x/varia/src/tests/org/jboss/test/services/binding/test/ServiceBindingMetadataMapperTestCase.java 2009-05-14 20:42:36 UTC (rev 88905)
@@ -0,0 +1,106 @@
+/*
+ * 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.test.services.binding.test;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.services.binding.ServiceBindingMetadata;
+import org.jboss.services.binding.impl.StringReplacementServiceBindingValueSourceConfig;
+import org.jboss.services.binding.impl.StringReplacementServiceBindingValueSourceImpl;
+import org.jboss.services.binding.managed.ServiceBindingMetadataMapper;
+
+/**
+ * Unit test of {@link ServiceBindingMetadataMapper}.
+ *
+ * @author Brian Stansberry
+ *
+ */
+public class ServiceBindingMetadataMapperTestCase extends TestCase
+{
+
+ /**
+ * Create a new ServiceBindingMetadataMapperTestCase.
+ *
+ * @param name
+ */
+ public ServiceBindingMetadataMapperTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testRoundTrip() throws Exception
+ {
+ Set<ServiceBindingMetadata> input = new HashSet<ServiceBindingMetadata>();
+ ServiceBindingMetadata complete = new ServiceBindingMetadata("complete", "binding", "host", 10, true, true);
+ complete.setDescription("desc");
+ complete.setServiceBindingValueSource(new StringReplacementServiceBindingValueSourceImpl());
+ complete.setServiceBindingValueSourceConfig(new StringReplacementServiceBindingValueSourceConfig());
+ input.add(complete);
+
+ ServiceBindingMetadata nulls = new ServiceBindingMetadata("nulls", null, null, 20);
+ input.add(nulls);
+
+ ServiceBindingMetadataMapper mapper = new ServiceBindingMetadataMapper();
+ MetaValue wrapped = mapper.createMetaValue(null, input);
+ Set<ServiceBindingMetadata> output = mapper.unwrapMetaValue(wrapped);
+
+ assertEquals(input, output);
+ for (ServiceBindingMetadata md : output)
+ {
+ if ("complete".equals(md.getServiceName()))
+ {
+ assertEquals(complete.getFullyQualifiedName(), md.getFullyQualifiedName());
+ assertEquals(complete.getBindingName(), md.getBindingName());
+ assertEquals(complete.getDescription(), md.getDescription());
+ assertEquals(complete.getHostName(), md.getHostName());
+ assertEquals(complete.getPort(), md.getPort());
+ assertEquals(complete.isFixedHostName(), md.isFixedHostName());
+ assertEquals(complete.isFixedPort(), md.isFixedPort());
+ // We expect null for the following, but if the impl changes these can change
+ assertNull(md.getServiceBindingValueSourceClassName());
+ assertNull(md.getServiceBindingValueSourceConfig());
+ }
+ else if ("nulls".equals(md.getServiceName()))
+ {
+ assertEquals(nulls.getFullyQualifiedName(), md.getFullyQualifiedName());
+ assertNull(md.getBindingName());
+ assertNull(md.getDescription());
+ assertNull(md.getHostName());
+ assertEquals(nulls.getPort(), md.getPort());
+ assertFalse(md.isFixedHostName());
+ assertFalse(md.isFixedPort());
+ assertNull(md.getServiceBindingValueSourceClassName());
+ assertNull(md.getServiceBindingValueSourceConfig());
+
+ }
+ else
+ {
+ fail("Unexpected member " + md.getFullyQualifiedName());
+ }
+ }
+ }
+}
Property changes on: branches/Branch_5_x/varia/src/tests/org/jboss/test/services/binding/test/ServiceBindingMetadataMapperTestCase.java
___________________________________________________________________
Name: svn:keywords
+
Modified: branches/Branch_5_x/varia/src/tests/org/jboss/test/services/binding/test/ServiceBindingMetadataTestCase.java
===================================================================
--- branches/Branch_5_x/varia/src/tests/org/jboss/test/services/binding/test/ServiceBindingMetadataTestCase.java 2009-05-14 20:42:20 UTC (rev 88904)
+++ branches/Branch_5_x/varia/src/tests/org/jboss/test/services/binding/test/ServiceBindingMetadataTestCase.java 2009-05-14 20:42:36 UTC (rev 88905)
@@ -273,12 +273,7 @@
{
ServiceBindingMetadata md1 = new ServiceBindingMetadata();
ServiceBindingMetadata md2 = new ServiceBindingMetadata();
- try
- {
- md1.equals(md2);
- fail("equals should fail with unset serviceName");
- }
- catch (IllegalStateException good) {}
+ assertFalse(md1.equals(md2));
md1 = new ServiceBindingMetadata(S, B);
md2 = new ServiceBindingMetadata(S, null);
Added: branches/Branch_5_x/varia/src/tests/org/jboss/test/services/binding/test/ServiceBindingSetMapperTestCase.java
===================================================================
--- branches/Branch_5_x/varia/src/tests/org/jboss/test/services/binding/test/ServiceBindingSetMapperTestCase.java (rev 0)
+++ branches/Branch_5_x/varia/src/tests/org/jboss/test/services/binding/test/ServiceBindingSetMapperTestCase.java 2009-05-14 20:42:36 UTC (rev 88905)
@@ -0,0 +1,136 @@
+/*
+ * 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.test.services.binding.test;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.services.binding.ServiceBindingMetadata;
+import org.jboss.services.binding.impl.ServiceBindingSet;
+import org.jboss.services.binding.impl.StringReplacementServiceBindingValueSourceConfig;
+import org.jboss.services.binding.impl.StringReplacementServiceBindingValueSourceImpl;
+import org.jboss.services.binding.managed.ServiceBindingMetadataMapper;
+import org.jboss.services.binding.managed.ServiceBindingSetMapper;
+
+/**
+ * Unit test of {@link ServiceBindingMetadataMapper}.
+ *
+ * @author Brian Stansberry
+ *
+ */
+public class ServiceBindingSetMapperTestCase extends TestCase
+{
+
+ /**
+ * Create a new ServiceBindingMetadataMapperTestCase.
+ *
+ * @param name
+ */
+ public ServiceBindingSetMapperTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testRoundTrip() throws Exception
+ {
+ Set<ServiceBindingSet> input = new HashSet<ServiceBindingSet>();
+
+ Set<ServiceBindingMetadata> overrideInput = new HashSet<ServiceBindingMetadata>();
+ ServiceBindingMetadata complete = new ServiceBindingMetadata("complete", "binding", "host", 10, true, true);
+ complete.setDescription("desc");
+ complete.setServiceBindingValueSource(new StringReplacementServiceBindingValueSourceImpl());
+ complete.setServiceBindingValueSourceConfig(new StringReplacementServiceBindingValueSourceConfig());
+ overrideInput.add(complete);
+
+ ServiceBindingMetadata nulls = new ServiceBindingMetadata("nulls", null, null, 20);
+ overrideInput.add(nulls);
+
+ ServiceBindingSet withOverride = new ServiceBindingSet("withOverride", "localhost", 1000, overrideInput);
+ input.add(withOverride);
+
+ ServiceBindingSet noOverride = new ServiceBindingSet("noOverride", "localhost", 900);
+ input.add(noOverride);
+
+ ServiceBindingSetMapper mapper = new ServiceBindingSetMapper();
+ MetaValue wrapped = mapper.createMetaValue(null, input);
+ Set<ServiceBindingSet> output = mapper.unwrapMetaValue(wrapped);
+
+ for (ServiceBindingSet outputSet : output)
+ {
+ if ("withOverride".equals(outputSet.getName()))
+ {
+ Set<ServiceBindingMetadata> overrideOutput = outputSet.getOverrideBindings();
+ assertNotNull("has overrideOutput", overrideOutput);
+ assertEquals("localhost", outputSet.getDefaultHostName());
+ assertEquals(1000, outputSet.getPortOffset());
+
+ for (ServiceBindingMetadata md : overrideOutput)
+ {
+ if ("complete".equals(md.getServiceName()))
+ {
+ assertEquals(complete.getFullyQualifiedName(), md.getFullyQualifiedName());
+ assertEquals(complete.getBindingName(), md.getBindingName());
+ assertEquals(complete.getDescription(), md.getDescription());
+ assertEquals(complete.getHostName(), md.getHostName());
+ assertEquals(complete.getPort(), md.getPort());
+ assertEquals(complete.isFixedHostName(), md.isFixedHostName());
+ assertEquals(complete.isFixedPort(), md.isFixedPort());
+ // We expect null for the following, but if the impl changes these can change
+ assertNull(md.getServiceBindingValueSourceClassName());
+ assertNull(md.getServiceBindingValueSourceConfig());
+ }
+ else if ("nulls".equals(md.getServiceName()))
+ {
+ assertEquals(nulls.getFullyQualifiedName(), md.getFullyQualifiedName());
+ assertNull(md.getBindingName());
+ assertNull(md.getDescription());
+ assertNull(md.getHostName());
+ assertEquals(nulls.getPort(), md.getPort());
+ assertFalse(md.isFixedHostName());
+ assertFalse(md.isFixedPort());
+ assertNull(md.getServiceBindingValueSourceClassName());
+ assertNull(md.getServiceBindingValueSourceConfig());
+
+ }
+ else
+ {
+ fail("Unexpected member " + md.getFullyQualifiedName());
+ }
+ }
+ }
+ else if ("noOverride".equals(outputSet.getName()))
+ {
+ assertEquals("localhost", outputSet.getDefaultHostName());
+ assertEquals(900, outputSet.getPortOffset());
+ assertNotNull("has no overrideOutput", outputSet.getOverrideBindings());
+ }
+ else
+ {
+ fail("Unexpected member " + outputSet.getName());
+ }
+ }
+ }
+}
Property changes on: branches/Branch_5_x/varia/src/tests/org/jboss/test/services/binding/test/ServiceBindingSetMapperTestCase.java
___________________________________________________________________
Name: svn:keywords
+
Modified: branches/Branch_5_x/varia/src/tests/org/jboss/test/services/binding/test/ServiceBindingTestBase.java
===================================================================
--- branches/Branch_5_x/varia/src/tests/org/jboss/test/services/binding/test/ServiceBindingTestBase.java 2009-05-14 20:42:20 UTC (rev 88904)
+++ branches/Branch_5_x/varia/src/tests/org/jboss/test/services/binding/test/ServiceBindingTestBase.java 2009-05-14 20:42:36 UTC (rev 88905)
@@ -38,7 +38,6 @@
import junit.framework.Assert;
import junit.framework.TestCase;
-import org.jboss.bootstrap.spi.ServerConfig;
import org.jboss.services.binding.ServiceBinding;
import org.jboss.services.binding.ServiceBindingMetadata;
import org.jboss.services.binding.impl.XSLTServiceBindingValueSourceConfig;
@@ -68,6 +67,8 @@
protected static final String OTHER_PARAM = "other";
protected static final String OTHER_VALUE = "ABC";
protected static final String XSL_INPUT = getFullyQualifiedResourceName("xslt_input.xml");
+
+ private static final String SERVER_TEMP_DIR_PROPERTY = "jboss.server.temp.dir";
protected ServiceBindingMetadata bindingMetadata;
protected ServiceBinding binding;
@@ -94,9 +95,9 @@
if (existingElementEditor == null)
PropertyEditorManager.registerEditor(Element.class, ElementEditor.class);
- serverTempDir = System.getProperty(ServerConfig.SERVER_TEMP_DIR);
+ serverTempDir = System.getProperty(SERVER_TEMP_DIR_PROPERTY);
if (serverTempDir == null)
- System.setProperty(ServerConfig.SERVER_TEMP_DIR, System.getProperty("java.io.tmpdir"));
+ System.setProperty(SERVER_TEMP_DIR_PROPERTY, System.getProperty("java.io.tmpdir"));
bindingMetadata = new ServiceBindingMetadata(SVC_NAME, BINDING_NAME, HOST, PORT, false, false);
binding = new ServiceBinding(bindingMetadata, HOST, 0);
@@ -108,7 +109,7 @@
if (existingElementEditor == null)
PropertyEditorManager.registerEditor(Element.class, null);
if (serverTempDir == null)
- System.clearProperty(ServerConfig.SERVER_TEMP_DIR);
+ System.clearProperty(SERVER_TEMP_DIR_PROPERTY);
super.tearDown();
}
More information about the jboss-cvs-commits
mailing list