Author: ron.sigal(a)jboss.com
Date: 2011-01-28 18:38:19 -0500 (Fri, 28 Jan 2011)
New Revision: 6228
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transporter/TransporterClient.java
Log:
JBREM-1246: Created versions of each of the constructors and each of the factory methods
that takes a metadata map, which is passed to Client.invoke().
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transporter/TransporterClient.java
===================================================================
---
remoting2/branches/2.x/src/main/org/jboss/remoting/transporter/TransporterClient.java 2011-01-28
21:23:20 UTC (rev 6227)
+++
remoting2/branches/2.x/src/main/org/jboss/remoting/transporter/TransporterClient.java 2011-01-28
23:38:19 UTC (rev 6228)
@@ -46,6 +46,7 @@
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
+import java.util.Map;
/**
* Class to be used as a factory via static method calls to get
@@ -64,6 +65,8 @@
private final Logger log = Logger.getLogger(TransporterClient.class);
private static final long serialVersionUID = 7418567482011657189L;
+
+ private Map metadata;
/**
* Creates the remoting client to server POJO.
@@ -80,6 +83,20 @@
/**
* Creates the remoting client to server POJO.
+ * Is not clustered.
+ *
+ * @param locator
+ * @throws Exception
+ */
+ private TransporterClient(InvokerLocator locator, Map metadata) throws Exception
+ {
+ remotingClient = new Client(locator);
+ remotingClient.connect();
+ this.metadata = metadata;
+ }
+
+ /**
+ * Creates the remoting client to server POJO.
* Is clustered
*
* @param locator
@@ -100,6 +117,23 @@
*
* @param locator
* @param targetSubsystem
+ * @throws Exception
+ */
+ private TransporterClient(InvokerLocator locator, String targetSubsystem, Map
metadata) throws Exception
+ {
+ remotingClient = new Client(locator, targetSubsystem);
+ remotingClient.connect();
+ this.isClustered = true;
+ this.subSystem = targetSubsystem;
+ this.metadata = metadata;
+ }
+
+ /**
+ * Creates the remoting client to server POJO.
+ * Is clustered
+ *
+ * @param locator
+ * @param targetSubsystem
* @param loadbalancer policy
* @throws Exception
*/
@@ -113,6 +147,25 @@
}
/**
+ * Creates the remoting client to server POJO.
+ * Is clustered
+ *
+ * @param locator
+ * @param targetSubsystem
+ * @param loadbalancer policy
+ * @throws Exception
+ */
+ private TransporterClient(InvokerLocator locator, String targetSubsystem, LoadBalancer
loadbalancer, Map metadata) throws Exception
+ {
+ this.loadBalancer = loadbalancer;
+ remotingClient = new Client(locator, targetSubsystem);
+ remotingClient.connect();
+ this.isClustered = true;
+ this.subSystem = targetSubsystem;
+ this.metadata = metadata;
+ }
+
+ /**
* Disconnects the remoting client
*/
private void disconnect()
@@ -206,6 +259,42 @@
*
* @param locatorURI - the remoting locator uri to the target server where the target
POJO exists.
* @param targetClass - the interface class of the POJO will be calling upon.
+ * @param clustered - true will cause the transporter to look for other remoting
serves that have the POJO running
+ * and include it in the client's target list. If a call on
first target fails, will seamlessly fail over to one
+ * of the other discovered targets.
+ * @return dynamic remote proxy typed to the interface specified by the targetClass
param.
+ * @throws Exception
+ */
+ public static Object createTransporterClient(String locatorURI, Class targetClass,
boolean clustered, Map metadata) throws Exception
+ {
+ if (!clustered)
+ {
+ return createTransporterClient(locatorURI, targetClass, metadata);
+ }
+ else
+ {
+ if (InternalTransporterServices.getInstance().getNetworkRegistry() == null)
+ {
+ setupDetector();
+ }
+ InvokerLocator locator = new InvokerLocator(locatorURI);
+ TransporterClient client = new TransporterClient(locator,
targetClass.getName());
+ ClassLoader tcl = (ClassLoader) AccessController.doPrivileged( new
PrivilegedAction()
+ {
+ public Object run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ return Proxy.newProxyInstance(tcl, new Class[]{targetClass}, client);
+ }
+ }
+
+ /**
+ * Create a remote proxy to a POJO on a remote server.
+ *
+ * @param locatorURI - the remoting locator uri to the target server where the target
POJO exists.
+ * @param targetClass - the interface class of the POJO will be calling upon.
* @param loadBalancer - policy for selecting which target server to use from list of
available servers.
* @return dynamic remote proxy typed to the interface specified by the targetClass
param.
* @throws Exception
@@ -233,18 +322,60 @@
*
* @param locatorURI - the remoting locator uri to the target server where the target
POJO exists.
* @param targetClass - the interface class of the POJO will be calling upon.
+ * @param loadBalancer - policy for selecting which target server to use from list of
available servers.
* @return dynamic remote proxy typed to the interface specified by the targetClass
param.
* @throws Exception
*/
+ public static Object createTransporterClient(String locatorURI, Class targetClass,
LoadBalancer loadBalancer, Map metadata) throws Exception
+ {
+ if (InternalTransporterServices.getInstance().getNetworkRegistry() == null)
+ {
+ setupDetector();
+ }
+ InvokerLocator locator = new InvokerLocator(locatorURI);
+ TransporterClient client = new TransporterClient(locator, targetClass.getName(),
loadBalancer, metadata);
+ ClassLoader tcl = (ClassLoader) AccessController.doPrivileged( new
PrivilegedAction()
+ {
+ public Object run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ return Proxy.newProxyInstance(tcl, new Class[]{targetClass}, client);
+ }
+
+ /**
+ * Create a remote proxy to a POJO on a remote server.
+ *
+ * @param locatorURI - the remoting locator uri to the target server where the target
POJO exists.
+ * @param targetClass - the interface class of the POJO will be calling upon.
+ * @return dynamic remote proxy typed to the interface specified by the targetClass
param.
+ * @throws Exception
+ */
public static Object createTransporterClient(String locatorURI, Class targetClass)
throws Exception
{
InvokerLocator locator = new InvokerLocator(locatorURI);
return createTransporterClient(locator, targetClass);
}
+
/**
* Create a remote proxy to a POJO on a remote server.
*
+ * @param locatorURI - the remoting locator uri to the target server where the target
POJO exists.
+ * @param targetClass - the interface class of the POJO will be calling upon.
+ * @return dynamic remote proxy typed to the interface specified by the targetClass
param.
+ * @throws Exception
+ */
+ public static Object createTransporterClient(String locatorURI, Class targetClass, Map
metadata) throws Exception
+ {
+ InvokerLocator locator = new InvokerLocator(locatorURI);
+ return createTransporterClient(locator, targetClass, metadata);
+ }
+
+ /**
+ * Create a remote proxy to a POJO on a remote server.
+ *
* @param locator - the remoting locator to the target server where the target
POJO exists.
* @param targetClass - the interface class of the POJO will be calling upon.
* @return dynamic remote proxy typed to the interface specified by the targetClass
param.
@@ -264,6 +395,27 @@
}
/**
+ * Create a remote proxy to a POJO on a remote server.
+ *
+ * @param locator - the remoting locator to the target server where the target
POJO exists.
+ * @param targetClass - the interface class of the POJO will be calling upon.
+ * @return dynamic remote proxy typed to the interface specified by the targetClass
param.
+ * @throws Exception
+ */
+ public static Object createTransporterClient(InvokerLocator locator, Class
targetClass, Map metadata) throws Exception
+ {
+ TransporterClient client = new TransporterClient(locator, targetClass.getName(),
metadata);
+ ClassLoader tcl = (ClassLoader) AccessController.doPrivileged( new
PrivilegedAction()
+ {
+ public Object run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ return Proxy.newProxyInstance(tcl, new Class[]{targetClass}, client);
+ }
+
+ /**
* Needs to be called by user when no longer need to make calls on remote POJO.
Otherwise will
* maintain remote connection until this is called.
*
@@ -318,7 +470,14 @@
try
{
failOver = false;
- response = remotingClient.invoke(request);
+ if (metadata != null)
+ {
+ response = remotingClient.invoke(request, metadata);
+ }
+ else
+ {
+ response = remotingClient.invoke(request);
+ }
}
catch (CannotConnectException cnc)
{