[jboss-cvs] JBossAS SVN: r89765 - in trunk: server/src/etc/conf/all and 8 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jun 3 16:14:46 EDT 2009
Author: bstansberry at jboss.com
Date: 2009-06-03 16:14:46 -0400 (Wed, 03 Jun 2009)
New Revision: 89765
Added:
trunk/server/src/etc/conf/all/bindingservice.beans/
trunk/server/src/etc/conf/minimal/bindingservice.beans/
trunk/testsuite/src/main/org/jboss/test/profileservice/override/restart/test/ServiceBindingManagedObjectsTestCase.java
trunk/testsuite/src/main/org/jboss/test/profileservice/override/test/ServiceBindingManagedObjectsTestCase.java
trunk/varia/src/main/org/jboss/services/binding/managed/
Removed:
trunk/server/src/etc/conf/all/bindings-jboss-beans.xml
trunk/server/src/etc/conf/minimal/bindings-jboss-beans.xml
trunk/varia/src/main/org/jboss/services/binding/ServiceBindingMapper.java
Modified:
trunk/build/build.xml
trunk/server/src/etc/conf/all/bootstrap/profile.xml
trunk/server/src/etc/conf/default/bootstrap/profile.xml
trunk/testsuite/src/main/org/jboss/test/profileservice/test/ServiceBindingManagedObjectsTestCase.java
trunk/varia/src/main/org/jboss/services/binding/ServiceBindingManager.java
trunk/varia/src/main/org/jboss/services/binding/ServiceBindingMetadata.java
trunk/varia/src/main/org/jboss/services/binding/impl/PojoServiceBindingStore.java
trunk/varia/src/main/org/jboss/services/binding/impl/ServiceBindingSet.java
Log:
[JBAS-6259] Port from Branch_5_x
Modified: trunk/build/build.xml
===================================================================
--- trunk/build/build.xml 2009-06-03 20:07:08 UTC (rev 89764)
+++ trunk/build/build.xml 2009-06-03 20:14:46 UTC (rev 89765)
@@ -1351,13 +1351,16 @@
<include name="jboss-as-varia-hsqldb-plugin.jar"/>
<include name="jboss-as-varia-autonumber-plugin.jar"/>
<include name="jboss-as-varia-properties-plugin.jar"/>
- <include name="jboss-as-varia-jboss-bindingservice.jar"/>
<include name="jboss-as-varia-jboss-monitoring.jar"/>
<include name="jboss-as-varia-jboss-srp.jar"/>
</fileset>
<mapper type="glob" from="jboss-as-varia-*.jar" to="*.jar"/>
</copy>
+ <!-- copy the service binding manager jar to it's deployment -->
+ <copy file="${varia.module.output}/jboss-as-varia-jboss-bindingservice.jar"
+ tofile="${install.all.conf}/bindingservice.beans/jboss-bindingservice.jar"/>
+
<!-- Copy to docs/examples -->
<mkdir dir="${install.examples.varia}"/>
<copy todir="${install.examples.varia}" filtering="no">
Deleted: trunk/server/src/etc/conf/all/bindings-jboss-beans.xml
===================================================================
--- trunk/server/src/etc/conf/all/bindings-jboss-beans.xml 2009-06-03 20:07:08 UTC (rev 89764)
+++ trunk/server/src/etc/conf/all/bindings-jboss-beans.xml 2009-06-03 20:14:46 UTC (rev 89765)
@@ -1,481 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<deployment xmlns="urn:jboss:bean-deployer:2.0">
-
- <classloader><inject bean="bindings-classloader:0.0.0"/></classloader>
-
- <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>
-
- <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>
-
- <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 -->
- <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>
- </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>
- <!-- The name of the set -->
- <parameter>ports-default</parameter>
- <!-- Default host name -->
- <parameter>${jboss.bind.address}</parameter>
- <!-- The port offset -->
- <parameter>0</parameter>
- <!-- Set of bindings to which the "offset by X" approach can't be applied -->
- <parameter><null/></parameter>
- </constructor>
- </bean>
-
- <!-- The ports-01 bindings are obtained by taking the base bindings and adding 100 to each port value -->
- <bean name="Ports01Bindings" class="org.jboss.services.binding.impl.ServiceBindingSet">
- <constructor>
- <!-- The name of the set -->
- <parameter>ports-01</parameter>
- <!-- Default host name -->
- <parameter>${jboss.bind.address}</parameter>
- <!-- The port offset -->
- <parameter>100</parameter>
- <!-- Set of bindings to which the "offset by X" approach can't be applied -->
- <parameter><null/></parameter>
- </constructor>
- </bean>
-
- <!-- The ports-02 bindings are obtained by taking ports-default and adding 200 to each port value -->
- <bean name="Ports02Bindings" class="org.jboss.services.binding.impl.ServiceBindingSet">
- <constructor>
- <!-- The name of the set -->
- <parameter>ports-02</parameter>
- <!-- Default host name -->
- <parameter>${jboss.bind.address}</parameter>
- <!-- The port offset -->
- <parameter>200</parameter>
- <!-- Set of bindings to which the "offset by X" approach can't be applied -->
- <parameter><null/></parameter>
- </constructor>
- </bean>
-
- <!-- The ports-03 bindings are obtained by taking ports-default and adding 300 to each port value -->
- <bean name="Ports03Bindings" class="org.jboss.services.binding.impl.ServiceBindingSet">
- <constructor>
- <!-- The name of the set -->
- <parameter>ports-03</parameter>
- <!-- Default host name -->
- <parameter>${jboss.bind.address}</parameter>
- <!-- The port offset -->
- <parameter>300</parameter>
- <!-- Set of bindings to which the "offset by X" approach can't be applied -->
- <parameter><null/></parameter>
- </constructor>
- </bean>
-
- <!-- Base binding metadata that ServiceBindingStore uses to create bindings for each set -->
- <bean name="StandardBindings" class="java.util.HashSet">
- <constructor>
- <parameter class="java.util.Collection">
- <set elementClass="org.jboss.services.binding.ServiceBindingMetadata">
- <!-- ********************* conf/jboss-service.xml ****************** -->
-
- <!-- Naming Service -->
- <bean class="org.jboss.services.binding.ServiceBindingMetadata">
- <property name="serviceName">jboss:service=Naming</property>
- <property name="bindingName">Port</property>
- <property name="port">1099</property>
- <property name="description">The listening socket for the Naming service</property>
- </bean>
-
- <bean class="org.jboss.services.binding.ServiceBindingMetadata">
- <property name="serviceName">jboss:service=Naming</property>
- <property name="bindingName">RmiPort</property>
- <property name="port">1098</property>
- <property name="description">Socket Naming service uses to receive RMI requests from client proxies</property>
- </bean>
-
- <!-- Remote classloading service -->
- <bean class="org.jboss.services.binding.ServiceBindingMetadata">
- <property name="serviceName">jboss:service=WebService</property>
- <property name="port">8083</property>
- <property name="description">Socket for dynamic class and resource loading</property>
- </bean>
-
- <!-- Remoting Connector -->
- <bean class="org.jboss.services.binding.ServiceBindingMetadata">
- <property name="serviceName">UnifiedInvokerConnector</property>
- <property name="port">4446</property>
- <property name="description">Socket for JBoss Remoting Connector used by UnifiedInvoker</property>
- </bean>
-
- <!-- Used to create a multihome Remoting server. See -->
- <!-- deploy/remoting-jboss-beans.xml for more details. -->
- <!--bean class="org.jboss.services.binding.ServiceBindingMetadata">
- <property name="serviceName">UnifiedInvokerConnector:bindingHome1</property>
- <parameter>192.168.2.2</property>
- <property name="port">7777</property>
- <property name="description">Socket for JBoss Remoting Connector used by UnifiedInvoker on a multihome server</property>
- </bean-->
-
- <!-- Used to create a multihome Remoting server. See -->
- <!-- deploy/remoting-jboss-beans.xml for more details. -->
- <!--bean class="org.jboss.services.binding.ServiceBindingMetadata">
- <property name="serviceName">UnifiedInvokerConnector:bindingHome2</property>
- <parameter>10.11.12.238</property>
- <property name="port">8888</property>
- <property name="description">Socket for JBoss Remoting Connector used by UnifiedInvoker on a multihome server</property>
- </bean-->
-
- <!-- ********************* deploy/legacy-invokers-service.xml ****************** -->
-
- <!-- RMI/JRMP invoker -->
- <bean class="org.jboss.services.binding.ServiceBindingMetadata">
- <property name="serviceName">jboss:service=invoker,type=jrmp</property>
- <property name="port">4444</property>
- <property name="description">Socket for the legacy RMI/JRMP invoker</property>
- </bean>
-
- <!-- Pooled invoker -->
- <bean class="org.jboss.services.binding.ServiceBindingMetadata">
- <property name="serviceName">jboss:service=invoker,type=pooled</property>
- <property name="port">4445</property>
- <property name="description">Socket for the legacy Pooled invoker</property>
- </bean>
-
- <!-- ********************* deploy/cluster/hajndi-service.xml ****************** -->
-
- <bean class="org.jboss.services.binding.ServiceBindingMetadata">
- <property name="serviceName">jboss:service=HAJNDI</property>
- <property name="bindingName">Port</property>
- <property name="port">1100</property>
- <property name="description">The listening socket for the HA-JNDI service</property>
- </bean>
-
- <bean class="org.jboss.services.binding.ServiceBindingMetadata">
- <property name="serviceName">jboss:service=HAJNDI</property>
- <property name="bindingName">RmiPort</property>
- <property name="port">1101</property>
- <property name="description">Socket HA-JNDI service uses to receive RMI requests from client proxies</property>
- </bean>
-
- <bean class="org.jboss.services.binding.ServiceBindingMetadata">
- <property name="serviceName">jboss:service=HAJNDI</property>
- <property name="bindingName">AutoDiscovery</property>
- <property name="hostName">${jboss.partition.udpGroup:230.0.0.4}</property>
- <property name="port">1102</property>
- <property name="description">Multicast socket on which HA-JNDI listens for auto-discovery requests from clients</property>
- <!-- This address should not be changed between different
- binding sets; all nodes need to listen on the same
- multicast address -->
- <property name="fixedHostName">true</property>
- <!-- This port should not be changed between different
- binding sets; all nodes need to listen on the same port -->
- <property name="fixedPort">true</property>
- </bean>
-
- <bean class="org.jboss.services.binding.ServiceBindingMetadata">
- <property name="serviceName">jboss:service=HAJNDI</property>
- <property name="bindingName">AutoDiscoveryInterface</property>
- <property name="hostName">${jboss.bind.address}</property>
- <property name="description">Interface for multicast socket on which HA-JNDI listens for auto-discovery requests from clients</property>
- </bean>
-
- <!-- ********************* deploy/cluster/ha-legacy-service.xml ****************** -->
-
- <!-- HA RMI/JRMP invoker -->
- <bean class="org.jboss.services.binding.ServiceBindingMetadata">
- <property name="serviceName">jboss:service=invoker,type=jrmpha</property>
- <property name="port">4447</property>
- <property name="description">Socket for high availability version of the legacy RMI/JRMP invoker</property>
- </bean>
-
- <!-- HA Pooled invoker -->
- <bean class="org.jboss.services.binding.ServiceBindingMetadata">
- <property name="serviceName">jboss:service=invoker,type=pooledha</property>
- <property name="port">4448</property>
- <property name="description">Socket for high availability version of the legacy Pooled invoker</property>
- </bean>
-
- <!-- ********************* deploy/iiop-service.xml ****************** -->
-
- <bean class="org.jboss.services.binding.ServiceBindingMetadata">
- <property name="serviceName">jboss:service=CorbaORB</property>
- <property name="port">3528</property>
- <property name="description">IIOP socket for the Corba ORB</property>
- </bean>
-
- <!-- ********************* deploy/snmp-adaptor.sar **************** -->
-
- <!-- Trap receiver that acts as an SNMP Manager -->
- <bean class="org.jboss.services.binding.ServiceBindingMetadata">
- <property name="serviceName">jboss.jmx:name=SnmpAgent,service=trapd,type=logger</property>
- <property name="port">1162</property>
- <property name="description">Socket for the SNMP trap receiver</property>
- </bean>
-
- <!-- The SNMP adaptor MBean -->
- <bean class="org.jboss.services.binding.ServiceBindingMetadata">
- <property name="serviceName">jboss.jmx:name=SnmpAgent,service=snmp,type=adaptor</property>
- <property name="port">1161</property>
- <property name="description">Socket for the SNMP adaptor MBean</property>
- </bean>
-
- <!-- ********************* deploy/jmx-remoting.sar **************** -->
-
- <bean class="org.jboss.services.binding.ServiceBindingMetadata">
- <property name="serviceName">jboss.remoting:service=JMXConnectorServer,protocol=rmi</property>
- <property name="port">1090</property>
- <property name="description">RMI/JRMP socket for connecting to the JMX MBeanServer</property>
- </bean>
-
- <!-- ********************* deploy/ejb3-connectors-service.xml **************** -->
-
- <!-- EJB3 wants to have the service create its own ServiceBinding object
- dynamically. See the value-factory usage in deploy/ejb3-connectors-service.xml -->
-
-
- <!-- ********************* deploy/jbossweb.sar **************** -->
- <!-- ********************* deploy/httpha-invoker.sar **************** -->
-
- <!--
- JBoss Web server.xml configuration.
-
- Same binding config can be used by the following services, or really
- anything else that needs to point to the JBoss Web HTTP connector
- but doesn't need an XSL Transform
-
- jboss:service=invoker,type=http
- jboss:service=invoker,type=http,target=Naming
- jboss:service=invoker,type=http,target=Naming,readonly=true
- jboss:service=invoker,type=httpHA
- jboss:service=invoker,type=http,target=HAJNDI
- jboss.ws:service=ServiceEndpointManager
- -->
- <bean class="org.jboss.services.binding.ServiceBindingMetadata">
- <property name="serviceName">jboss.web:service=WebServer</property>
- <property name="port">8080</property>
- <property name="description">JBoss Web HTTP connector socket; also drives the values for the HTTPS and AJP sockets</property>
-
- <!--
- Inject a XSLT transform configuration (see below) that describes
- how to transform server.xml
- If the binding value request doesn't require an XSL Transform, this config
- will be ignored.
- -->
- <property name="serviceBindingValueSourceConfig"><inject bean="JBossWebConnectorXSLTConfig"/></property>
- </bean>
-
- <!-- For services like those listed above that need to know the
- port of the HTTPS connector -->
- <bean class="org.jboss.services.binding.ServiceBindingMetadata">
- <property name="serviceName">jboss.web:service=WebServer</property>
- <property name="bindingName">HttpsConnector</property>
- <property name="port">8443</property>
- <property name="description">JBoss Web HTTPS connector socket</property>
- </bean>
-
- <!-- ********************* deploy/messaging/remoting-bisocket-service.xml ********************** -->
-
- <!-- Standard JBM bisocket connector -->
- <bean class="org.jboss.services.binding.ServiceBindingMetadata">
- <property name="serviceName">jboss.messaging:service=Connector,transport=bisocket</property>
- <property name="port">4457</property>
- <property name="description">Socket for JBoss Messaging 1.x</property>
- </bean>
-
- <!-- ********************* JBoss Messaging 2 **************** -->
-
- <bean class="org.jboss.services.binding.ServiceBindingMetadata">
- <property name="serviceName">JBM2</property>
- <property name="bindingName">netty-port</property>
- <property name="port">5445</property>
- <property name="description">Socket for JBoss Messaging 2.x</property>
- </bean>
-
- <bean class="org.jboss.services.binding.ServiceBindingMetadata">
- <property name="serviceName">JBM2</property>
- <property name="bindingName">netty-ssl-port</property>
- <property name="port">5446</property>
- <property name="description">SSL socket for JBoss Messaging 2.x</property>
- </bean>
-
- <!-- ********************* deploy/transaction-jboss-beans.xml ********************** -->
-
- <!-- JBossTS Recovery Manager -->
- <bean class="org.jboss.services.binding.ServiceBindingMetadata">
- <property name="serviceName">TransactionManager</property>
- <property name="bindingName">recoveryManager</property>
- <property name="port">4712</property>
- <property name="description">Socket for JBossTS Recovery Manager</property>
- </bean>
-
- <!-- JBossTS Transaction Status Manager -->
- <bean class="org.jboss.services.binding.ServiceBindingMetadata">
- <property name="serviceName">TransactionManager</property>
- <property name="bindingName">transactionStatusManager</property>
- <property name="port">4713</property>
- <property name="description">Socket for JBossTS Transaction Status Manager</property>
- </bean>
-
- <!-- JBossTS SocketProcessId. The address part is ignored,
- it will always use localhost/127.0.0.1. -->
- <bean class="org.jboss.services.binding.ServiceBindingMetadata">
- <property name="serviceName">TransactionManager</property>
- <property name="bindingName">socketProcessId</property>
- <property name="port">4714</property>
- <property name="description">Socket used to provide unique process id for JBossTS. The address configuration is ignored; will always use localhost/127.0.0.1</property>
- </bean>
-
- <!-- ********************* deploy/hsqldb-ds.xml **************** -->
-
- <!-- Commented out as tcp/ip access to Hypersonic is not enabled by default -->
- <!--
- <bean class="org.jboss.services.binding.ServiceBindingMetadata">
- <property name="serviceName">jboss:service=Hypersonic</property>
- <property name="port">1701</property>
- <property name="description">TCP/IP socket for remote connection to Hypersonic database</property>
- </bean>
- -->
-
- <!-- ********************* JBoss MQ **************** -->
-
- <!-- Commented out as JBoss MQ is not installed by default
- If you uncomment this and also use jboss.mq:service=InvocationLayer,type=HTTP,
- configure the http invocation layer using the jboss.web:service=WebServer binding above
- -->
- <!--
- <bean class="org.jboss.services.binding.ServiceBindingMetadata">
- <property name="serviceName">jboss.mq:service=InvocationLayer,type=UIL2</property>
- <property name="port">8093</property>
- <property name="description">UIL2 socket for JBossMQ</property>
- </bean>
- -->
- </set>
- </parameter>
- </constructor>
- </bean>
-
- <!-- Conversion of selected bindings into system properties -->
- <bean name="SystemPropertyBinder" class="org.jboss.services.binding.SystemPropertyBinder">
-
- <constructor>
- <parameter>
- <set>
- <!-- JBM's remoting connector -->
- <bean class="org.jboss.services.binding.SystemPropertyBinding">
- <constructor>
- <parameter>jboss.messaging.connector.bisocket.port</parameter>
- <parameter class="int">
- <value-factory bean="ServiceBindingManager" method="getIntBinding"
- parameter="jboss.messaging:service=Connector,transport=bisocket"/>
- </parameter>
- </constructor>
- </bean>
- <!-- JBM2 netty connector -->
- <bean class="org.jboss.services.binding.SystemPropertyBinding">
- <constructor>
- <parameter>jbm.remoting.netty.port</parameter>
- <parameter class="int">
- <value-factory bean="ServiceBindingManager" method="getIntBinding">
- <parameter>JBM2</parameter>
- <parameter>netty-port</parameter>
- </value-factory>
- </parameter>
- </constructor>
- </bean>
- <!-- JBM2 netty ssl connector -->
- <bean class="org.jboss.services.binding.SystemPropertyBinding">
- <constructor>
- <parameter>jbm.remoting.netty.ssl.port</parameter>
- <parameter class="int">
- <value-factory bean="ServiceBindingManager" method="getIntBinding">
- <parameter>JBM2</parameter>
- <parameter>netty-ssl-port</parameter>
- </value-factory>
- </parameter>
- </constructor>
- </bean>
- </set>
- </parameter>
- </constructor>
-
- </bean>
-
- <!-- XSL Transform to apply to server.xml -->
- <bean name="JBossWebConnectorXSLTConfig"
- class="org.jboss.services.binding.impl.XSLTServiceBindingValueSourceConfig">
-
- <constructor>
- <parameter><![CDATA[
- <xsl:stylesheet
- xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
-
- <xsl:output method="xml" />
- <xsl:param name="port"/>
-
- <xsl:variable name="portAJP" select="$port - 71"/>
- <xsl:variable name="portHttps" select="$port + 363"/>
-
- <xsl:template match="/">
- <xsl:apply-templates/>
- </xsl:template>
-
- <xsl:template match = "Connector">
- <Connector>
- <xsl:for-each select="@*">
- <xsl:choose>
- <xsl:when test="(name() = 'port' and . = '8080')">
- <xsl:attribute name="port"><xsl:value-of select="$port" /></xsl:attribute>
- </xsl:when>
- <xsl:when test="(name() = 'port' and . = '8009')">
- <xsl:attribute name="port"><xsl:value-of select="$portAJP" /></xsl:attribute>
- </xsl:when>
- <xsl:when test="(name() = 'redirectPort')">
- <xsl:attribute name="redirectPort"><xsl:value-of select="$portHttps" /></xsl:attribute>
- </xsl:when>
- <xsl:when test="(name() = 'port' and . = '8443')">
- <xsl:attribute name="port"><xsl:value-of select="$portHttps" /></xsl:attribute>
- </xsl:when>
- <xsl:otherwise>
- <xsl:attribute name="{name()}"><xsl:value-of select="." /></xsl:attribute>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:for-each>
- <xsl:apply-templates/>
- </Connector>
- </xsl:template>
-
- <xsl:template match="*|@*">
- <xsl:copy>
- <xsl:apply-templates select="@*|node()"/>
- </xsl:copy>
- </xsl:template>
- </xsl:stylesheet>
- ]]>
- </parameter>
- </constructor>
- </bean>
-
-</deployment>
Copied: trunk/server/src/etc/conf/all/bindingservice.beans (from rev 89704, branches/Branch_5_x/server/src/etc/conf/all/bindingservice.beans)
Modified: trunk/server/src/etc/conf/all/bootstrap/profile.xml
===================================================================
--- trunk/server/src/etc/conf/all/bootstrap/profile.xml 2009-06-03 20:07:08 UTC (rev 89764)
+++ trunk/server/src/etc/conf/all/bootstrap/profile.xml 2009-06-03 20:14:46 UTC (rev 89765)
@@ -19,7 +19,7 @@
The uri to the deployers folder.
A list of uris to deploy folders. -->
<bean name="BootstrapProfileFactory" class="org.jboss.system.server.profileservice.StaticClusteredProfileFactory">
- <property name="bindingsURI">${jboss.server.home.url}conf/bindings-jboss-beans.xml</property>
+ <property name="bindingsURI">${jboss.server.home.url}conf/bindingservice.beans</property>
<property name="bootstrapURI">${jboss.server.home.url}conf/jboss-service.xml</property>
<property name="deployersURI">${jboss.server.home.url}deployers</property>
<property name="applicationURIs">
Modified: trunk/server/src/etc/conf/default/bootstrap/profile.xml
===================================================================
--- trunk/server/src/etc/conf/default/bootstrap/profile.xml 2009-06-03 20:07:08 UTC (rev 89764)
+++ trunk/server/src/etc/conf/default/bootstrap/profile.xml 2009-06-03 20:14:46 UTC (rev 89765)
@@ -19,7 +19,7 @@
The uri to the deployers folder.
A list of uris to deploy folders. -->
<bean name="BootstrapProfileFactory" class="org.jboss.system.server.profileservice.repository.StaticProfileFactory">
- <property name="bindingsURI">${jboss.server.home.url}conf/bindings-jboss-beans.xml</property>
+ <property name="bindingsURI">${jboss.server.home.url}conf/bindingservice.beans</property>
<property name="bootstrapURI">${jboss.server.home.url}conf/jboss-service.xml</property>
<property name="deployersURI">${jboss.server.home.url}deployers</property>
<property name="applicationURIs">
Deleted: trunk/server/src/etc/conf/minimal/bindings-jboss-beans.xml
===================================================================
--- trunk/server/src/etc/conf/minimal/bindings-jboss-beans.xml 2009-06-03 20:07:08 UTC (rev 89764)
+++ trunk/server/src/etc/conf/minimal/bindings-jboss-beans.xml 2009-06-03 20:14:46 UTC (rev 89765)
@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<deployment xmlns="urn:jboss:bean-deployer:2.0">
-
- <!-- In the minimal config, bindings-jboss-beans.xml is just a placeholder
- we use to avoid having to exclude it from conf/profile.xml -->
-
-</deployment>
Copied: trunk/server/src/etc/conf/minimal/bindingservice.beans (from rev 89734, branches/Branch_5_x/server/src/etc/conf/minimal/bindingservice.beans)
Copied: trunk/testsuite/src/main/org/jboss/test/profileservice/override/restart/test/ServiceBindingManagedObjectsTestCase.java (from rev 89702, branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/override/restart/test/ServiceBindingManagedObjectsTestCase.java)
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/profileservice/override/restart/test/ServiceBindingManagedObjectsTestCase.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/profileservice/override/restart/test/ServiceBindingManagedObjectsTestCase.java 2009-06-03 20:14:46 UTC (rev 89765)
@@ -0,0 +1,631 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt 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.profileservice.override.restart.test;
+
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+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.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.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.services.binding.ServiceBindingMetadata;
+import org.jboss.services.binding.impl.ServiceBindingSet;
+import org.jboss.services.binding.managed.ServiceBindingMetadataMapper;
+import org.jboss.test.profileservice.test.AbstractProfileServiceTest;
+
+/**
+ * <p>
+ * Profile service ServiceBindingManager persistent update tests.
+ * </p>
+ *
+ * @see org.jboss.test.profileservice.override.test.ServiceBindingManagedObjectsTestCase
+ * for the tests that add and update the service binding metadata.
+ *
+ * @author Brian Stansberry
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 88921 $
+ */
+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.
+ * </p>
+ *
+ * @param name a {@code String} representing the name of this {@code TestCase}.
+ */
+ public ServiceBindingManagedObjectsTestCase(String name)
+ {
+ super(name);
+ }
+
+
+ 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;
+
+ MetaValue metaval = compValue.get("serviceName");
+ assertNotNull("has serviceName", metaval);
+ assertTrue(metaval instanceof SimpleValue);
+ assertTrue(((SimpleValue) metaval).getValue() instanceof String);
+
+ metaval = compValue.get("bindingName");
+ if (metaval != null)
+ {
+ assertTrue(metaval instanceof SimpleValue);
+ Object val = ((SimpleValue) metaval).getValue();
+ assertTrue(val instanceof String);
+ }
+
+ metaval = compValue.get("fullyQualifiedName");
+ assertNotNull("has fullyQualifiedName", metaval);
+ assertTrue(metaval instanceof SimpleValue);
+ assertTrue(((SimpleValue) metaval).getValue() instanceof String);
+
+ metaval = compValue.get("description");
+ if (metaval != null)
+ {
+ assertTrue(metaval instanceof SimpleValue);
+ Object val = ((SimpleValue) metaval).getValue();
+ assertTrue(val instanceof String);
+ }
+
+ metaval = compValue.get("hostName");
+ assertNotNull("has hostName", metaval);
+ assertTrue(metaval instanceof SimpleValue);
+ assertTrue(((SimpleValue) metaval).getValue() instanceof String);
+
+ metaval = compValue.get("bindAddress");
+ assertNotNull("has bindAddress", metaval);
+ assertTrue(metaval instanceof ArrayValue);
+ Object val = ((ArrayValue) metaval).getValue();
+ assertTrue(val instanceof byte[]);
+
+ metaval = compValue.get("port");
+ assertNotNull("has port", metaval);
+ assertTrue(metaval instanceof SimpleValue);
+ assertEquals("type of port value isn't int", int.class.getName(), metaval.getMetaType().getClassName());
+ }
+
+ private void serviceBindingSetTest(MetaValue metaValue, Map<String, Integer> offsets) throws Exception
+ {
+ 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 testUpdatedStandardBindings() throws Exception
+ {
+ ManagedComponent component = getServiceBindingManagerManagedComponent();
+
+ logHierarchy(component);
+
+ Map<String, ManagedProperty> properties = component.getProperties();
+ assertNotNull(properties);
+
+ ManagedProperty prop = properties.get("standardBindings");
+
+ // 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);
+ 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);
+
+ // C) Validate update from B)
+
+ component = getServiceBindingManagerManagedComponent();
+ properties = component.getProperties();
+
+ 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));
+ }
+ IndexedArray indexedArray = checkAddedBinding(properties, 25, 23456, offsets, hosts);
+
+ }
+
+ private IndexedArray checkAddedBinding(Map<String, ManagedProperty> properties, int bindingCount, int basePort, Map<String, Integer> offsets, Map<String, String> hosts)
+ {
+ // 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 testUpdatedServiceBindingSets() throws Exception
+ {
+ ManagedComponent component = getServiceBindingManagerManagedComponent();
+
+ logHierarchy(component);
+
+ Map<String, ManagedProperty> properties = component.getProperties();
+ assertNotNull(properties);
+
+
+ // 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>();
+ 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[] elements = ((CollectionValue) val).getElements();
+ assertNotNull("property standardBindings value has elements", elements);
+ for (MetaValue mv : elements)
+ {
+ standardBindings.put(getSimpleValue(mv, "fullyQualifiedName", String.class), mv);
+ }
+
+ // B) Validate the addition from A) took effect and then UPDATE the added binding set
+ IndexedArray indexedArray = checkAddedBindingSet(properties, 5, 400, 43210, standardBindings);
+ }
+
+ private IndexedArray checkAddedBindingSet(Map<String, ManagedProperty> properties, int numSets, int portOffset, int overrideBindingPort,
+ Map<String, MetaValue> standardBindings)
+ {
+ IndexedArray result = new IndexedArray();
+
+ // 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++)
+ {
+ 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;
+ }
+ }
+ 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))
+ {
+ 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"));
+ }
+ else
+ {
+ 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"));
+ }
+ }
+
+ 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;
+ }
+}
Copied: trunk/testsuite/src/main/org/jboss/test/profileservice/override/test/ServiceBindingManagedObjectsTestCase.java (from rev 89702, branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/override/test/ServiceBindingManagedObjectsTestCase.java)
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/profileservice/override/test/ServiceBindingManagedObjectsTestCase.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/profileservice/override/test/ServiceBindingManagedObjectsTestCase.java 2009-06-03 20:14:46 UTC (rev 89765)
@@ -0,0 +1,607 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt 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.profileservice.override.test;
+
+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.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>
+ * Profile service ServiceBindingManager update tests.
+ * </p>
+ * @see org.jboss.test.profileservice.override.restart.test.ServiceBindingManagedObjectsTestCase
+ * for the tests of the persisted updates.
+ *
+ * @author Brian Stansberry
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 88921 $
+ */
+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.
+ * </p>
+ *
+ * @param name a {@code String} representing the name of this {@code TestCase}.
+ */
+ public ServiceBindingManagedObjectsTestCase(String name)
+ {
+ super(name);
+ }
+
+ private ManagedComponent getServiceBindingManagerManagedComponent() throws Exception
+ {
+ ManagementView managementView = getManagementView();
+ ComponentType type = new ComponentType("MCBean", "ServiceBindingManager");
+ ManagedComponent component = managementView.getComponent("ServiceBindingManager", type);
+ assertNotNull(component);
+ return component;
+ }
+
+ public void testUpdateServiceBindingSets() throws Exception
+ {
+ ManagedComponent component = getServiceBindingManagerManagedComponent();
+
+ logHierarchy(component);
+
+ Map<String, ManagedProperty> properties = component.getProperties();
+ assertNotNull(properties);
+
+ // A) ADD a new binding set
+
+ 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[] origElements = ((CollectionValue) val).getElements();
+ assertNotNull(origElements);
+ 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("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 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);
+ }
+
+ 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 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));
+
+ 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
+
+ component = getServiceBindingManagerManagedComponent();
+ properties = component.getProperties();
+ assertNotNull(properties);
+
+ indexedArray = checkAddedBindingSet(properties, newElements.length, 400, 43210, standardBindings);
+ }
+
+
+ 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);
+ 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);
+ 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);
+ }
+
+ private IndexedArray checkAddedBindingSet(Map<String, ManagedProperty> properties, int numSets, int portOffset, int overrideBindingPort,
+ Map<String, MetaValue> standardBindings)
+ {
+ IndexedArray result = new IndexedArray();
+
+ // 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++)
+ {
+ 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;
+ }
+ }
+ 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))
+ {
+ 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"));
+ }
+ else
+ {
+ 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"));
+ }
+ }
+
+ return result;
+ }
+
+ private IndexedArray checkAddedBinding(Map<String, ManagedProperty> properties, int bindingCount, int basePort, Map<String, Integer> offsets, Map<String, String> hosts)
+ {
+ // 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;
+ }
+
+ 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 IndexedArray
+ {
+ int index;
+ MetaValue[] array;
+ }
+}
Modified: trunk/testsuite/src/main/org/jboss/test/profileservice/test/ServiceBindingManagedObjectsTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/profileservice/test/ServiceBindingManagedObjectsTestCase.java 2009-06-03 20:07:08 UTC (rev 89764)
+++ trunk/testsuite/src/main/org/jboss/test/profileservice/test/ServiceBindingManagedObjectsTestCase.java 2009-06-03 20:14:46 UTC (rev 89765)
@@ -22,29 +22,115 @@
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.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.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.services.binding.ServiceBindingMetadata;
+import org.jboss.services.binding.impl.ServiceBindingSet;
+import org.jboss.services.binding.managed.ServiceBindingMetadataMapper;
/**
* <p>
* Profile service ServiceBindingManager tests.
* </p>
*
+ * @see org.jboss.test.profileservice.override.test.ServiceBindingManagedObjectsTestCase
+ * for tests of updating the metadata
+ *
* @author Brian Stansberry
* @version $Revision$
*/
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 +144,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 +164,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,203 +285,312 @@
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
- {
- ManagementView managementView = super.getManagementView();
- ComponentType type = new ComponentType("MCBean", "ServiceBindingStore");
- ManagedComponent component = managementView.getComponent("PojoServiceBindingStore", type);
- assertNotNull(component);
-
- // verify that the component has the expected properties.
- 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());
-
- 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());
- }
- public void testPortsDefault() throws Exception
+ private void serviceBindingSetTest(MetaValue metaValue, Map<String, Integer> offsets) throws Exception
{
- serviceBindingSetTest("ports-default", 0);
- }
-
- public void testPorts01() throws Exception
- {
- serviceBindingSetTest("ports-01", 100);
- }
-
- public void testPorts02() 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.
- Map<String, ManagedProperty> properties = component.getProperties();
- assertNotNull(properties);
+ assertTrue(metaValue instanceof CompositeValue);
+ CompositeValue bindingSet = (CompositeValue) metaValue;
- ManagedProperty prop = properties.get("name");
- assertNotNull("Missing property name", prop);
- getLog().debug("name: " + prop);
- MetaValue val = prop.getValue();
+ MetaValue val = bindingSet.get("name");
assertNotNull("property name has no value", val);
assertTrue("property name value is SimpleValue", val instanceof SimpleValue);
- assertEquals(name, ((SimpleValue) val).getValue());
+ Object simpleVal = ((SimpleValue) val).getValue();
+ assertTrue(simpleVal instanceof String);
+ String name = (String) simpleVal;
- prop = properties.get("defaultHostName");
- assertNotNull("Missing property defaultHostName", prop);
- getLog().debug("defaultHostName: " + prop);
- val = prop.getValue();
+ 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()));
- prop = properties.get("portOffset");
- assertNotNull("Missing property portOffset", prop);
- getLog().debug("portOffset: " + prop);
- val = prop.getValue();
+ val = bindingSet.get("portOffset");
assertNotNull("property portOffset has no value", val);
assertTrue("property portOffset value is SimpleValue", val instanceof SimpleValue);
- assertEquals(Integer.valueOf(offset), ((SimpleValue) val).getValue());
+ simpleVal = ((SimpleValue) val).getValue();
+ assertTrue(simpleVal instanceof Integer);
+ assertTrue(((Integer) simpleVal).intValue() > -1);
+ offsets.put(name, (Integer) simpleVal);
- 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());
+ 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);
+ }
}
- 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 Checked serviceBindingMetadataTest(MetaValue metaValue)
+ {
+ assertTrue(metaValue instanceof CompositeValue);
+ CompositeValue bindingMetadata = (CompositeValue) metaValue;
- // 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)
+ 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)
{
- if (checkedBindingName && checkedHostName)
+ 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;
+ }
+
+// // FIXME: disabled as we don't want to change to name of a server that
+// // the testsuite later restarts. Move this somewhere else where we can do it
+// 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());
+// }
+
+
+ private IndexedArray checkAddedBindingSet(Map<String, ManagedProperty> properties, int numSets, int portOffset, int overrideBindingPort,
+ Map<String, MetaValue> standardBindings)
+ {
+ IndexedArray result = new IndexedArray();
+
+ // 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++)
+ {
+ 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: trunk/varia/src/main/org/jboss/services/binding/ServiceBindingManager.java
===================================================================
--- trunk/varia/src/main/org/jboss/services/binding/ServiceBindingManager.java 2009-06-03 20:07:08 UTC (rev 89764)
+++ trunk/varia/src/main/org/jboss/services/binding/ServiceBindingManager.java 2009-06-03 20:14:46 UTC (rev 89765)
@@ -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: trunk/varia/src/main/org/jboss/services/binding/ServiceBindingMapper.java
===================================================================
--- trunk/varia/src/main/org/jboss/services/binding/ServiceBindingMapper.java 2009-06-03 20:07:08 UTC (rev 89764)
+++ trunk/varia/src/main/org/jboss/services/binding/ServiceBindingMapper.java 2009-06-03 20:14:46 UTC (rev 89765)
@@ -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: trunk/varia/src/main/org/jboss/services/binding/ServiceBindingMetadata.java
===================================================================
--- trunk/varia/src/main/org/jboss/services/binding/ServiceBindingMetadata.java 2009-06-03 20:07:08 UTC (rev 89764)
+++ trunk/varia/src/main/org/jboss/services/binding/ServiceBindingMetadata.java 2009-06-03 20:14:46 UTC (rev 89765)
@@ -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: trunk/varia/src/main/org/jboss/services/binding/impl/PojoServiceBindingStore.java
===================================================================
--- trunk/varia/src/main/org/jboss/services/binding/impl/PojoServiceBindingStore.java 2009-06-03 20:07:08 UTC (rev 89764)
+++ trunk/varia/src/main/org/jboss/services/binding/impl/PojoServiceBindingStore.java 2009-06-03 20:14:46 UTC (rev 89765)
@@ -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: trunk/varia/src/main/org/jboss/services/binding/impl/ServiceBindingSet.java
===================================================================
--- trunk/varia/src/main/org/jboss/services/binding/impl/ServiceBindingSet.java 2009-06-03 20:07:08 UTC (rev 89764)
+++ trunk/varia/src/main/org/jboss/services/binding/impl/ServiceBindingSet.java 2009-06-03 20:14:46 UTC (rev 89765)
@@ -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")
Copied: trunk/varia/src/main/org/jboss/services/binding/managed (from rev 89698, branches/Branch_5_x/varia/src/main/org/jboss/services/binding/managed)
More information about the jboss-cvs-commits
mailing list