Author: ron.sigal(a)jboss.com
Date: 2008-11-08 05:06:39 -0500 (Sat, 08 Nov 2008)
New Revision: 4650
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/InvokerRegistry.java
Log:
JBREM-1056: Reorganized synchronization.
Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/InvokerRegistry.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/InvokerRegistry.java 2008-11-06
21:26:46 UTC (rev 4649)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/InvokerRegistry.java 2008-11-08
10:06:39 UTC (rev 4650)
@@ -69,9 +69,12 @@
/**
* return an array of InvokerLocators that are local to this VM (server invokers)
*/
- public static synchronized final InvokerLocator[] getRegisteredServerLocators()
+ public static final InvokerLocator[] getRegisteredServerLocators()
{
- return (InvokerLocator[]) registeredLocators.toArray(new
InvokerLocator[registeredLocators.size()]);
+ synchronized (serverLock)
+ {
+ return (InvokerLocator[]) registeredLocators.toArray(new
InvokerLocator[registeredLocators.size()]);
+ }
}
/**
@@ -80,19 +83,22 @@
*
* @param remote
*/
- public static synchronized InvokerLocator
getSuitableServerLocatorForRemote(InvokerLocator remote)
+ public static InvokerLocator getSuitableServerLocatorForRemote(InvokerLocator remote)
{
- Iterator iter = registeredLocators.iterator();
- while(iter.hasNext())
+ synchronized (serverLock)
{
- InvokerLocator l = (InvokerLocator) iter.next();
- if(l.getProtocol().equals(remote.getProtocol()))
+ Iterator iter = registeredLocators.iterator();
+ while(iter.hasNext())
{
- // we found a valid transport match
- return l;
+ InvokerLocator l = (InvokerLocator) iter.next();
+ if(l.getProtocol().equals(remote.getProtocol()))
+ {
+ // we found a valid transport match
+ return l;
+ }
}
+ return null;
}
- return null;
}
/**
@@ -162,11 +168,16 @@
* @param clientFactory implementation of org.jboss.remoting.transport.ClientFactory
* @param serverFactory implementation of org.jboss.remoting.transport.ServerFactory
*/
- public static synchronized void registerInvokerFactories(String transport, Class
clientFactory, Class serverFactory)
+ public static void registerInvokerFactories(String transport, Class clientFactory,
Class serverFactory)
{
- transportClientFactoryClasses.put(transport, clientFactory);
- transportServerFactoryClasses.put(transport, serverFactory);
-
+ synchronized (clientLock)
+ {
+ transportClientFactoryClasses.put(transport, clientFactory);
+ }
+ synchronized (serverLock)
+ {
+ transportServerFactoryClasses.put(transport, serverFactory);
+ }
}
/**
@@ -174,16 +185,25 @@
*
* @param transport
*/
- public static synchronized void unregisterInvokerFactories(String transport)
+ public static void unregisterInvokerFactories(String transport)
{
- transportClientFactoryClasses.remove(transport);
- transportServerFactoryClasses.remove(transport);
+ synchronized (clientLock)
+ {
+ transportClientFactoryClasses.remove(transport);
+ }
+ synchronized (serverLock)
+ {
+ transportServerFactoryClasses.remove(transport);
+ }
}
- public static synchronized void unregisterLocator(InvokerLocator locator)
+ public static void unregisterLocator(InvokerLocator locator)
{
- serverLocators.remove(locator);
- registeredLocators.remove(locator);
+ synchronized (serverLock)
+ {
+ serverLocators.remove(locator);
+ registeredLocators.remove(locator);
+ }
}
/**
@@ -298,18 +318,26 @@
// Check to see if server invoker is local
// If in server locators map, then created locally by this class
- ServerInvoker svrInvoker = (ServerInvoker) serverLocators.get(locator);
- if(svrInvoker != null && !isForceRemote)
+ ServerInvoker svrInvoker = null;
+ if (!isForceRemote)
{
- LocalClientInvoker localInvoker = new LocalClientInvoker(locator,
configuration, isPassByValue);
- // have to set reference to local server invoker so client in invoke
directly
- localInvoker.setServerInvoker(svrInvoker);
- invoker = localInvoker;
- InvokerLocator l = invoker.getLocator();
+ synchronized (serverLock)
+ {
+ svrInvoker = (ServerInvoker) serverLocators.get(locator);
+ }
+ if(svrInvoker != null)
+ {
+ LocalClientInvoker localInvoker = new LocalClientInvoker(locator,
configuration, isPassByValue);
+ // have to set reference to local server invoker so client in invoke
directly
+ localInvoker.setServerInvoker(svrInvoker);
+ invoker = localInvoker;
+ InvokerLocator l = invoker.getLocator();
- addRegisteredClientInvoker(invoker, l, configuration);
+ addRegisteredClientInvoker(invoker, l, configuration);
+ }
}
- else //not local
+
+ if (svrInvoker == null) //not local
{
String protocol = locator.getProtocol();
if(protocol == null)
@@ -610,13 +638,16 @@
* @param locator
* @param newLocator
*/
- public static synchronized void updateServerInvokerLocator(InvokerLocator locator,
InvokerLocator newLocator)
+ public static void updateServerInvokerLocator(InvokerLocator locator, InvokerLocator
newLocator)
{
- Object si = serverLocators.get(locator);
- serverLocators.remove(locator);
- registeredLocators.remove(locator);
- serverLocators.put(newLocator, si);
- registeredLocators.add(newLocator);
+ synchronized (serverLock)
+ {
+ Object si = serverLocators.get(locator);
+ serverLocators.remove(locator);
+ registeredLocators.remove(locator);
+ serverLocators.put(newLocator, si);
+ registeredLocators.add(newLocator);
+ }
}
/**
@@ -634,7 +665,10 @@
Class transportFactoryClass = null;
try
{
- transportFactoryClass = getTransportClientFactory(transport);
+ synchronized (clientLock)
+ {
+ transportFactoryClass = getTransportClientFactory(transport);
+ }
ClientFactory clientFactory =
(ClientFactory)transportFactoryClass.newInstance();
Method meth = transportFactoryClass.getMethod("supportsSSL", new
Class[]{});
Boolean boolVal = (Boolean)meth.invoke(clientFactory, null);
Show replies by date