Author: ron.sigal(a)jboss.com
Date: 2008-11-08 15:17:37 -0500 (Sat, 08 Nov 2008)
New Revision: 4652
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/InvokerRegistry.java
Log:
JBREM-1056: Reorganized synchronization.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/InvokerRegistry.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/InvokerRegistry.java 2008-11-08
10:09:19 UTC (rev 4651)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/InvokerRegistry.java 2008-11-08
20:17:37 UTC (rev 4652)
@@ -73,9 +73,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()]);
+ }
}
/**
@@ -84,19 +87,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;
}
/**
@@ -166,11 +172,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);
+ }
}
/**
@@ -178,16 +189,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);
+ }
}
/**
@@ -302,18 +322,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)
@@ -618,13 +646,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);
+ }
}
/**
@@ -642,7 +673,10 @@
Class transportFactoryClass = null;
try
{
- transportFactoryClass = getTransportClientFactory(transport);
+ synchronized (clientLock)
+ {
+ transportFactoryClass = getTransportClientFactory(transport);
+ }
ClientFactory clientFactory =
(ClientFactory)transportFactoryClass.newInstance();
Method meth = SecurityUtility.getMethod(transportFactoryClass,
"supportsSSL", new Class[]{});
Boolean boolVal = (Boolean)meth.invoke(clientFactory, null);
Show replies by date