JBoss Remoting SVN: r4654 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/registry.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-11-08 15:19:22 -0500 (Sat, 08 Nov 2008)
New Revision: 4654
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/registry/InvokerRegistryRaceTestCase.java
Log:
JBREM-1056: New unit test.
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/registry/InvokerRegistryRaceTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/registry/InvokerRegistryRaceTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/registry/InvokerRegistryRaceTestCase.java 2008-11-08 20:19:22 UTC (rev 4654)
@@ -0,0 +1,303 @@
+package org.jboss.test.remoting.registry;
+
+import java.net.InetAddress;
+import java.net.MalformedURLException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.InvokerRegistry;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.Callback;
+import org.jboss.remoting.callback.HandleCallbackException;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+import org.jboss.remoting.transport.bisocket.Bisocket;
+
+import EDU.oswego.cs.dl.util.concurrent.Rendezvous;
+
+
+/**
+ * Unit test for JBREM-1056.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ *
+ * <p>
+ * Copyright Nov 8, 2008
+ * </p>
+ */
+public class InvokerRegistryRaceTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(InvokerRegistryRaceTestCase.class);
+
+ private static boolean firstTime = true;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(Level.INFO);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+ }
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testRaceCondition() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ int THREADS = 20;
+ int LOOPS = 1000;
+ Rendezvous barrier = new Rendezvous(THREADS * 2 + 1);
+ CreateCallbackThread[] createCallbackThreads = new CreateCallbackThread[THREADS];
+ InvokerLocatorUpdateThread[] invokerLocatorUpdateThreads = new InvokerLocatorUpdateThread[THREADS];
+ for (int i = 0; i < THREADS; i++)
+ {
+ createCallbackThreads[i] = new CreateCallbackThread(i, client, barrier, LOOPS);
+ invokerLocatorUpdateThreads[i] = new InvokerLocatorUpdateThread(i, barrier, LOOPS * 100);
+ createCallbackThreads[i].start();
+ invokerLocatorUpdateThreads[i].start();
+ }
+ log.info("main thread going to rendezvous");
+ barrier.rendezvous(null);
+ barrier.rendezvous(null);
+ log.info("main thread leaving second rendezvous");
+
+ client.disconnect();
+ shutdownServer();
+
+ for (int i = 0; i < THREADS; i++)
+ {
+ assertTrue(createCallbackThreads[i].ok);
+ assertTrue(invokerLocatorUpdateThreads[i].ok);
+ }
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "bisocket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer() throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ String metadata = System.getProperty("remoting.metadata");
+ if (metadata != null)
+ {
+ locatorURI += "/?" + metadata;
+ }
+ serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ invocationHandler = new TestInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+ connector.start();
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+
+
+ static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ public void addListener(InvokerCallbackHandler callbackHandler) {}
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ return invocation.getParameter();
+ }
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+
+
+ static class TestCallbackHandler implements InvokerCallbackHandler
+ {
+ public void handleCallback(Callback callback) throws HandleCallbackException
+ {
+ log.info("received callback");
+ }
+ }
+
+ static class CreateCallbackThread extends Thread
+ {
+ int id;
+ Client client;
+ Rendezvous barrier;
+ int counter;
+ public boolean ok = true;
+
+ public CreateCallbackThread(int id, Client client, Rendezvous barrier, int counter)
+ {
+ this.id = id;
+ this.client = client;
+ this.barrier = barrier;
+ this.counter = counter;
+ setName("CreateCallbackThread:" + id);
+ }
+
+ public void run()
+ {
+ HashMap metadata = new HashMap();
+ metadata.put(Client.CALLBACK_SERVER_PORT, "8888888" + id);
+ metadata.put(Bisocket.IS_CALLBACK_SERVER, "true");
+ TestCallbackHandler callbackHandler = new TestCallbackHandler();
+ rendezvous();
+ log.info(this + " passed barrier");
+ for (int i = 0; i < counter; i++)
+ {
+ try
+ {
+ if ((i + 1) % (counter / 5) == 0)
+ {
+ log.info(this + " adding listener: " + (i + 1));
+ }
+ client.addListener(callbackHandler, metadata, null, true);
+ if ((i + 1) % (counter / 5) == 0)
+ {
+ log.info(this + " added listener: " + (i + 1));
+ }
+ client.removeListener(callbackHandler);
+ if ((i + 1) % (counter / 5) == 0)
+ {
+ log.info(this + " removed listener: " + (i + 1));
+ }
+ }
+ catch (Throwable t)
+ {
+ log.error("unable to register callback handler", t);
+ ok = false;
+ }
+ }
+ log.info(this + " entering final rendezvous");
+ rendezvous();
+ }
+
+ private void rendezvous()
+ {
+ try
+ {
+ barrier.rendezvous(null);
+ }
+ catch (Exception e)
+ {
+ log.error("error in rendezvous", e);
+ }
+ }
+ }
+
+ static class InvokerLocatorUpdateThread extends Thread
+ {
+ int id;
+ InvokerLocator locator;
+ Rendezvous barrier;
+ int counter;
+ boolean ok = true;
+
+ public InvokerLocatorUpdateThread(int id, Rendezvous barrier, int counter) throws MalformedURLException
+ {
+ this.id = id;
+ this.barrier = barrier;
+ this.counter = counter;
+ setName("InvokerLocatorUpdateThread:" + id);
+ locator = new InvokerLocator("socket://localhost:8888");
+ }
+
+ public void run()
+ {
+ rendezvous();
+ log.info(this + " passed barrier");
+ for (int i = 0; i < counter; i++)
+ {
+ try
+ {
+ InvokerRegistry.updateServerInvokerLocator(locator, locator);
+ if ((i + 1) % (counter / 5) == 0)
+ {
+ log.info(this + " updated locator: " + (i + 1));
+ }
+ }
+ catch (Exception e)
+ {
+ ok = false;
+ log.error("error updated locator", e);
+ }
+ }
+ log.info(this + " entering final rendezvous");
+ rendezvous();
+ }
+ private void rendezvous()
+ {
+ try
+ {
+ barrier.rendezvous(null);
+ }
+ catch (Exception e)
+ {
+ log.error("error in rendezvous", e);
+ }
+ }
+ }
+}
\ No newline at end of file
16 years
JBoss Remoting SVN: r4653 - remoting2/branches/2.x/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-11-08 15:18:51 -0500 (Sat, 08 Nov 2008)
New Revision: 4653
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/InvokerRegistry.java
Log:
JBREM-1056: Removed unused imports.
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 20:17:37 UTC (rev 4652)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/InvokerRegistry.java 2008-11-08 20:18:51 UTC (rev 4653)
@@ -33,9 +33,6 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.security.AccessController;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
16 years
JBoss Remoting SVN: r4652 - remoting2/branches/2.x/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
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);
16 years
JBoss Remoting SVN: r4651 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/registry.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-11-08 05:09:19 -0500 (Sat, 08 Nov 2008)
New Revision: 4651
Added:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/registry/InvokerRegistryRaceTestCase.java
Log:
JBREM-1056: New unit test.
Added: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/registry/InvokerRegistryRaceTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/registry/InvokerRegistryRaceTestCase.java (rev 0)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/registry/InvokerRegistryRaceTestCase.java 2008-11-08 10:09:19 UTC (rev 4651)
@@ -0,0 +1,304 @@
+package org.jboss.test.remoting.registry;
+
+import java.net.InetAddress;
+import java.net.MalformedURLException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.logging.XLevel;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.InvokerRegistry;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.Callback;
+import org.jboss.remoting.callback.HandleCallbackException;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+import org.jboss.remoting.transport.bisocket.Bisocket;
+
+import EDU.oswego.cs.dl.util.concurrent.Rendezvous;
+
+
+/**
+ * Unit test for JBREM-1056.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ *
+ * <p>
+ * Copyright Nov 8, 2008
+ * </p>
+ */
+public class InvokerRegistryRaceTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(InvokerRegistryRaceTestCase.class);
+
+ private static boolean firstTime = true;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+ }
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testRaceCondition() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ int THREADS = 20;
+ int LOOPS = 1000;
+ Rendezvous barrier = new Rendezvous(THREADS * 2 + 1);
+ CreateCallbackThread[] createCallbackThreads = new CreateCallbackThread[THREADS];
+ InvokerLocatorUpdateThread[] invokerLocatorUpdateThreads = new InvokerLocatorUpdateThread[THREADS];
+ for (int i = 0; i < THREADS; i++)
+ {
+ createCallbackThreads[i] = new CreateCallbackThread(i, client, barrier, LOOPS);
+ invokerLocatorUpdateThreads[i] = new InvokerLocatorUpdateThread(i, barrier, LOOPS * 100);
+ createCallbackThreads[i].start();
+ invokerLocatorUpdateThreads[i].start();
+ }
+ log.info("main thread going to rendezvous");
+ barrier.rendezvous(null);
+ barrier.rendezvous(null);
+ log.info("main thread leaving second rendezvous");
+
+ client.disconnect();
+ shutdownServer();
+
+ for (int i = 0; i < THREADS; i++)
+ {
+ assertTrue(createCallbackThreads[i].ok);
+ assertTrue(invokerLocatorUpdateThreads[i].ok);
+ }
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "bisocket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer() throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ String metadata = System.getProperty("remoting.metadata");
+ if (metadata != null)
+ {
+ locatorURI += "/?" + metadata;
+ }
+ serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ invocationHandler = new TestInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+ connector.start();
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+
+
+ static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ public void addListener(InvokerCallbackHandler callbackHandler) {}
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ return invocation.getParameter();
+ }
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+
+
+ static class TestCallbackHandler implements InvokerCallbackHandler
+ {
+ public void handleCallback(Callback callback) throws HandleCallbackException
+ {
+ log.info("received callback");
+ }
+ }
+
+ static class CreateCallbackThread extends Thread
+ {
+ int id;
+ Client client;
+ Rendezvous barrier;
+ int counter;
+ public boolean ok = true;
+
+ public CreateCallbackThread(int id, Client client, Rendezvous barrier, int counter)
+ {
+ this.id = id;
+ this.client = client;
+ this.barrier = barrier;
+ this.counter = counter;
+ setName("CreateCallbackThread:" + id);
+ }
+
+ public void run()
+ {
+ HashMap metadata = new HashMap();
+ metadata.put(Client.CALLBACK_SERVER_PORT, "8888888" + id);
+ metadata.put(Bisocket.IS_CALLBACK_SERVER, "true");
+ TestCallbackHandler callbackHandler = new TestCallbackHandler();
+ rendezvous();
+ log.info(this + " passed barrier");
+ for (int i = 0; i < counter; i++)
+ {
+ try
+ {
+ if ((i + 1) % (counter / 5) == 0)
+ {
+ log.info(this + " adding listener: " + (i + 1));
+ }
+ client.addListener(callbackHandler, metadata, null, true);
+ if ((i + 1) % (counter / 5) == 0)
+ {
+ log.info(this + " added listener: " + (i + 1));
+ }
+ client.removeListener(callbackHandler);
+ if ((i + 1) % (counter / 5) == 0)
+ {
+ log.info(this + " removed listener: " + (i + 1));
+ }
+ }
+ catch (Throwable t)
+ {
+ log.error("unable to register callback handler", t);
+ ok = false;
+ }
+ }
+ log.info(this + " entering final rendezvous");
+ rendezvous();
+ }
+
+ private void rendezvous()
+ {
+ try
+ {
+ barrier.rendezvous(null);
+ }
+ catch (Exception e)
+ {
+ log.error("error in rendezvous", e);
+ }
+ }
+ }
+
+ static class InvokerLocatorUpdateThread extends Thread
+ {
+ int id;
+ InvokerLocator locator;
+ Rendezvous barrier;
+ int counter;
+ boolean ok = true;
+
+ public InvokerLocatorUpdateThread(int id, Rendezvous barrier, int counter) throws MalformedURLException
+ {
+ this.id = id;
+ this.barrier = barrier;
+ this.counter = counter;
+ setName("InvokerLocatorUpdateThread:" + id);
+ locator = new InvokerLocator("socket://localhost:8888");
+ }
+
+ public void run()
+ {
+ rendezvous();
+ log.info(this + " passed barrier");
+ for (int i = 0; i < counter; i++)
+ {
+ try
+ {
+ InvokerRegistry.updateServerInvokerLocator(locator, locator);
+ if ((i + 1) % (counter / 5) == 0)
+ {
+ log.info(this + " updated locator: " + (i + 1));
+ }
+ }
+ catch (Exception e)
+ {
+ ok = false;
+ log.error("error updated locator", e);
+ }
+ }
+ log.info(this + " entering final rendezvous");
+ rendezvous();
+ }
+ private void rendezvous()
+ {
+ try
+ {
+ barrier.rendezvous(null);
+ }
+ catch (Exception e)
+ {
+ log.error("error in rendezvous", e);
+ }
+ }
+ }
+}
\ No newline at end of file
16 years
JBoss Remoting SVN: r4650 - remoting2/branches/2.2/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
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);
16 years
JBoss Remoting SVN: r4649 - in remoting3/trunk: core/src/main/java/org/jboss/remoting/core and 1 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-11-06 16:26:46 -0500 (Thu, 06 Nov 2008)
New Revision: 4649
Modified:
remoting3/trunk/api/src/main/java/org/jboss/remoting/ServiceListener.java
remoting3/trunk/core/src/main/java/org/jboss/remoting/core/EndpointImpl.java
remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MultiplexProtocol.java
Log:
More flexible and future-proof service registration listener API
Modified: remoting3/trunk/api/src/main/java/org/jboss/remoting/ServiceListener.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/remoting/ServiceListener.java 2008-11-05 09:49:49 UTC (rev 4648)
+++ remoting3/trunk/api/src/main/java/org/jboss/remoting/ServiceListener.java 2008-11-06 21:26:46 UTC (rev 4649)
@@ -30,27 +30,79 @@
public interface ServiceListener {
/**
- * Receive notification that a local service was added. To receive a notification when it is closed, register a
- * close handler on the provided {@code requestHandlerSource} parameter.
+ * Receive notification that a service was registered.
*
* @param listenerHandle the handle to this listener
- * @param serviceType the service type string
- * @param groupName the group name string
- * @param requestHandlerSource the request handler source
+ * @param info the servce information
*/
- void localServiceCreated(SimpleCloseable listenerHandle, String serviceType, String groupName, RequestHandlerSource requestHandlerSource);
+ void serviceRegistered(SimpleCloseable listenerHandle, ServiceInfo info);
/**
- * Receive notification that a remote service was registered. To receive a notification when it is unregistered, register a
- * close handler on the provided {@code handle} parameter.
- *
- * @param listenerHandle the handle to this listener
- * @param endpointName the remote endpoint name
- * @param serviceType the service type string
- * @param groupName the group name string
- * @param metric the metric value
- * @param requestHandlerSource the request handler source
- * @param handle the handle to the registration
+ *
*/
- void remoteServiceRegistered(SimpleCloseable listenerHandle, String endpointName, String serviceType, String groupName, int metric, RequestHandlerSource requestHandlerSource, SimpleCloseable handle);
+ final class ServiceInfo {
+ private String endpointName;
+ private String serviceType;
+ private String groupName;
+ private boolean remote;
+ private int metric;
+ private RequestHandlerSource requestHandlerSource;
+ private SimpleCloseable registrationHandle;
+
+ public String getServiceType() {
+ return serviceType;
+ }
+
+ public void setServiceType(final String serviceType) {
+ this.serviceType = serviceType;
+ }
+
+ public String getGroupName() {
+ return groupName;
+ }
+
+ public void setGroupName(final String groupName) {
+ this.groupName = groupName;
+ }
+
+ public int getMetric() {
+ return metric;
+ }
+
+ public void setMetric(final int metric) {
+ this.metric = metric;
+ }
+
+ public RequestHandlerSource getRequestHandlerSource() {
+ return requestHandlerSource;
+ }
+
+ public void setRequestHandlerSource(final RequestHandlerSource requestHandlerSource) {
+ this.requestHandlerSource = requestHandlerSource;
+ }
+
+ public SimpleCloseable getRegistrationHandle() {
+ return registrationHandle;
+ }
+
+ public void setRegistrationHandle(final SimpleCloseable registrationHandle) {
+ this.registrationHandle = registrationHandle;
+ }
+
+ public String getEndpointName() {
+ return endpointName;
+ }
+
+ public void setEndpointName(final String endpointName) {
+ this.endpointName = endpointName;
+ }
+
+ public boolean isRemote() {
+ return remote;
+ }
+
+ public void setRemote(final boolean remote) {
+ this.remote = remote;
+ }
+ }
}
Modified: remoting3/trunk/core/src/main/java/org/jboss/remoting/core/EndpointImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/remoting/core/EndpointImpl.java 2008-11-05 09:49:49 UTC (rev 4648)
+++ remoting3/trunk/core/src/main/java/org/jboss/remoting/core/EndpointImpl.java 2008-11-06 21:26:46 UTC (rev 4649)
@@ -203,7 +203,15 @@
for (final ServiceListenerRegistration slr : serviceListenerMap.values()) {
final ServiceListener listener = slr.getServiceListener();
try {
- listener.localServiceCreated(slr.handle, serviceType, groupName, localRequestHandlerSource);
+ final ServiceListener.ServiceInfo serviceInfo = new ServiceListener.ServiceInfo();
+ serviceInfo.setEndpointName(name);
+ serviceInfo.setGroupName(groupName);
+ serviceInfo.setServiceType(serviceType);
+ serviceInfo.setMetric(metric);
+ serviceInfo.setRegistrationHandle(newHandle);
+ serviceInfo.setRemote(false);
+ serviceInfo.setRequestHandlerSource(localRequestHandlerSource);
+ listener.serviceRegistered(slr.handle, serviceInfo);
} catch (Throwable t) {
logListenerError(t);
}
@@ -287,12 +295,11 @@
if (size == 0) {
final FutureClientSource<I, O> futureClientSource = new FutureClientSource<I, O>();
final SimpleCloseable listenerHandle = addServiceListener(new ServiceListener() {
-
- public void localServiceCreated(final SimpleCloseable listenerHandle, final String addedServiceType, final String addedGroupName, final RequestHandlerSource requestHandlerSource) {
- remoteServiceRegistered(listenerHandle, name, addedServiceType, addedGroupName, 0, requestHandlerSource, null);
- }
-
- public void remoteServiceRegistered(final SimpleCloseable listenerHandle, final String addedEndpointName, final String addedServiceType, final String addedGroupName, final int metric, final RequestHandlerSource requestHandlerSource, final SimpleCloseable handle) {
+ public void serviceRegistered(final SimpleCloseable listenerHandle, final ServiceInfo info) {
+ final String addedEndpointName = info.getEndpointName();
+ final String addedServiceType = info.getServiceType();
+ final String addedGroupName = info.getGroupName();
+ final RequestHandlerSource requestHandlerSource = info.getRequestHandlerSource();
if (endpointName != null && endpointName.length() > 0 && !endpointName.equals(addedEndpointName)) {
// no match
return;
@@ -385,7 +392,15 @@
for (final ServiceListenerRegistration slr : serviceListenerMap.values()) {
final ServiceListener listener = slr.getServiceListener();
try {
- listener.remoteServiceRegistered(slr.handle, endpointName, serviceType, groupName, metric, handlerSource, newHandle);
+ final ServiceListener.ServiceInfo info = new ServiceListener.ServiceInfo();
+ info.setEndpointName(endpointName);
+ info.setGroupName(groupName);
+ info.setMetric(metric);
+ info.setRegistrationHandle(newHandle);
+ info.setRemote(true);
+ info.setRequestHandlerSource(handlerSource);
+ info.setServiceType(serviceType);
+ listener.serviceRegistered(slr.handle, info);
} catch (Throwable t) {
logListenerError(t);
}
@@ -414,11 +429,15 @@
if (! onlyNew) {
for (final ServiceRegistration reg : serviceRegistrations) {
try {
- if (reg.isRemote()) { // x is remote
- serviceListener.remoteServiceRegistered(handle, reg.getEndpointName(), reg.getServiceType(), reg.getGroupName(), reg.getMetric(), reg.getHandlerSource(), reg.getHandle());
- } else { // x is local
- serviceListener.localServiceCreated(handle, reg.getServiceType(), reg.getGroupName(), reg.getHandlerSource());
- }
+ final ServiceListener.ServiceInfo info = new ServiceListener.ServiceInfo();
+ info.setEndpointName(reg.getEndpointName());
+ info.setGroupName(reg.getGroupName());
+ info.setMetric(reg.getMetric());
+ info.setRegistrationHandle(reg.getHandle());
+ info.setRemote(reg.isRemote());
+ info.setRequestHandlerSource(reg.getHandlerSource());
+ info.setServiceType(reg.getServiceType());
+ serviceListener.serviceRegistered(handle, info);
} catch (Throwable t) {
logListenerError(t);
}
Modified: remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MultiplexProtocol.java
===================================================================
--- remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MultiplexProtocol.java 2008-11-05 09:49:49 UTC (rev 4648)
+++ remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MultiplexProtocol.java 2008-11-06 21:26:46 UTC (rev 4649)
@@ -65,7 +65,7 @@
*
* @param endpoint the endpoint
* @param configuration the configuration
- * @param channelSource the XNIO channel source to use to establish the connection @param allocator the buffer allocator to use
+ * @param channelSource the XNIO channel source to use to establish the connection
* @return a handle which may be used to close the connection
* @throws IOException if an error occurs
*/
16 years
JBoss Remoting SVN: r4648 - in remoting3/trunk: api/src/test/java/org/jboss/remoting/spi and 4 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: trustin
Date: 2008-11-05 04:49:49 -0500 (Wed, 05 Nov 2008)
New Revision: 4648
Modified:
remoting3/trunk/api/src/main/java/org/jboss/remoting/spi/AbstractHandleableCloseable.java
remoting3/trunk/api/src/test/java/org/jboss/remoting/spi/CloseableTestCase.java
remoting3/trunk/core/src/main/java/org/jboss/remoting/core/RequestListenerExecutor.java
remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MultiplexProtocol.java
remoting3/trunk/protocol/multiplex/src/test/java/org/jboss/remoting/protocol/multiplex/ConnectionTestCase.java
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/CollectionUtil.java
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/SynchronizedQueue.java
remoting3/trunk/util/src/main/java/org/jboss/remoting/util/WeakHashSet.java
Log:
* Fixed warnings related with generic
* Removed unused imports
* Added a to-do marker for an unused method and a unused local variable
Modified: remoting3/trunk/api/src/main/java/org/jboss/remoting/spi/AbstractHandleableCloseable.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/remoting/spi/AbstractHandleableCloseable.java 2008-11-05 09:40:43 UTC (rev 4647)
+++ remoting3/trunk/api/src/main/java/org/jboss/remoting/spi/AbstractHandleableCloseable.java 2008-11-05 09:49:49 UTC (rev 4648)
@@ -108,7 +108,6 @@
for (final CloseHandler<? super T> handler : closeHandlers) {
try {
executor.execute(new Runnable() {
- @SuppressWarnings({ "unchecked" })
public void run() {
SpiUtils.safeHandleClose(handler, (T) AbstractHandleableCloseable.this);
}
Modified: remoting3/trunk/api/src/test/java/org/jboss/remoting/spi/CloseableTestCase.java
===================================================================
--- remoting3/trunk/api/src/test/java/org/jboss/remoting/spi/CloseableTestCase.java 2008-11-05 09:40:43 UTC (rev 4647)
+++ remoting3/trunk/api/src/test/java/org/jboss/remoting/spi/CloseableTestCase.java 2008-11-05 09:49:49 UTC (rev 4648)
@@ -187,7 +187,7 @@
};
final Handle<Object> rootHandle = closeable.getHandle();
try {
-
+ // todo - something with that rootHandle
} finally {
IoUtils.safeClose(closeable);
}
Modified: remoting3/trunk/core/src/main/java/org/jboss/remoting/core/RequestListenerExecutor.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/remoting/core/RequestListenerExecutor.java 2008-11-05 09:40:43 UTC (rev 4647)
+++ remoting3/trunk/core/src/main/java/org/jboss/remoting/core/RequestListenerExecutor.java 2008-11-05 09:49:49 UTC (rev 4648)
@@ -33,9 +33,9 @@
private final Set<Task> tasks = CollectionUtil.synchronizedHashSet();
private final Executor executor;
- private final RequestContextImpl requestContext;
+ private final RequestContextImpl<?> requestContext;
- public RequestListenerExecutor(final Executor executor, final RequestContextImpl context) {
+ public RequestListenerExecutor(final Executor executor, final RequestContextImpl<?> context) {
this.executor = executor;
requestContext = context;
}
Modified: remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MultiplexProtocol.java
===================================================================
--- remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MultiplexProtocol.java 2008-11-05 09:40:43 UTC (rev 4647)
+++ remoting3/trunk/protocol/multiplex/src/main/java/org/jboss/remoting/protocol/multiplex/MultiplexProtocol.java 2008-11-05 09:49:49 UTC (rev 4648)
@@ -75,6 +75,7 @@
return new AbstractConvertingIoFuture<SimpleCloseable, AllocatedMessageChannel>(futureChannel) {
protected SimpleCloseable convert(final AllocatedMessageChannel channel) throws RemotingException {
return new AbstractConnection(configuration.getExecutor()) {
+ // todo - this method is not called by anyone?
public Handle<RequestHandlerSource> getServiceForId(final int id) throws IOException {
return multiplexHandler.getRemoteService(id).getHandle();
}
Modified: remoting3/trunk/protocol/multiplex/src/test/java/org/jboss/remoting/protocol/multiplex/ConnectionTestCase.java
===================================================================
--- remoting3/trunk/protocol/multiplex/src/test/java/org/jboss/remoting/protocol/multiplex/ConnectionTestCase.java 2008-11-05 09:40:43 UTC (rev 4647)
+++ remoting3/trunk/protocol/multiplex/src/test/java/org/jboss/remoting/protocol/multiplex/ConnectionTestCase.java 2008-11-05 09:49:49 UTC (rev 4648)
@@ -48,7 +48,6 @@
import org.jboss.xnio.Xnio;
import org.jboss.xnio.CloseableExecutor;
import org.jboss.xnio.ChannelSource;
-import org.jboss.xnio.IoHandler;
import org.jboss.xnio.IoHandlerFactory;
import org.jboss.xnio.IoFuture;
import org.jboss.xnio.Buffers;
Modified: remoting3/trunk/util/src/main/java/org/jboss/remoting/util/CollectionUtil.java
===================================================================
--- remoting3/trunk/util/src/main/java/org/jboss/remoting/util/CollectionUtil.java 2008-11-05 09:40:43 UTC (rev 4647)
+++ remoting3/trunk/util/src/main/java/org/jboss/remoting/util/CollectionUtil.java 2008-11-05 09:49:49 UTC (rev 4648)
@@ -504,7 +504,7 @@
private static final Iterator<?> EMPTY_ITERATOR = new EmptyIterator();
- private static final class EmptyIterator implements Iterator {
+ private static final class EmptyIterator implements Iterator<Object> {
public boolean hasNext() {
return false;
Modified: remoting3/trunk/util/src/main/java/org/jboss/remoting/util/SynchronizedQueue.java
===================================================================
--- remoting3/trunk/util/src/main/java/org/jboss/remoting/util/SynchronizedQueue.java 2008-11-05 09:40:43 UTC (rev 4647)
+++ remoting3/trunk/util/src/main/java/org/jboss/remoting/util/SynchronizedQueue.java 2008-11-05 09:49:49 UTC (rev 4648)
@@ -83,7 +83,7 @@
}
}
- public <T> T[] toArray(final T[] a) {
+ public <U> U[] toArray(final U[] a) {
synchronized(monitor) {
//noinspection SuspiciousToArrayCall
return delegate.toArray(a);
Modified: remoting3/trunk/util/src/main/java/org/jboss/remoting/util/WeakHashSet.java
===================================================================
--- remoting3/trunk/util/src/main/java/org/jboss/remoting/util/WeakHashSet.java 2008-11-05 09:40:43 UTC (rev 4647)
+++ remoting3/trunk/util/src/main/java/org/jboss/remoting/util/WeakHashSet.java 2008-11-05 09:49:49 UTC (rev 4648)
@@ -31,7 +31,7 @@
return map.keySet().toArray();
}
- public <T> T[] toArray(final T[] a) {
+ public <U> U[] toArray(final U[] a) {
return map.keySet().toArray(a);
}
16 years
JBoss Remoting SVN: r4647 - remoting3/trunk.
by jboss-remoting-commits@lists.jboss.org
Author: trustin
Date: 2008-11-05 04:40:43 -0500 (Wed, 05 Nov 2008)
New Revision: 4647
Modified:
remoting3/trunk/
Log:
Added IDE-specific files to svn:ignore
Property changes on: remoting3/trunk
___________________________________________________________________
Name: svn:ignore
- *.ipr
*.iws
build.properties.local
jboss-remoting-*.jar
+ *.ipr
*.iws
build.properties.local
jboss-remoting-*.jar
.project
.classpath
.settings
16 years
JBoss Remoting SVN: r4646 - remoting3/trunk/protocol/multiplex/src/test/java/org/jboss/remoting/protocol/multiplex.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-11-04 12:50:07 -0500 (Tue, 04 Nov 2008)
New Revision: 4646
Modified:
remoting3/trunk/protocol/multiplex/src/test/java/org/jboss/remoting/protocol/multiplex/ConnectionTestCase.java
Log:
Make this into a real test (even if it fails)
Modified: remoting3/trunk/protocol/multiplex/src/test/java/org/jboss/remoting/protocol/multiplex/ConnectionTestCase.java
===================================================================
--- remoting3/trunk/protocol/multiplex/src/test/java/org/jboss/remoting/protocol/multiplex/ConnectionTestCase.java 2008-11-04 09:15:17 UTC (rev 4645)
+++ remoting3/trunk/protocol/multiplex/src/test/java/org/jboss/remoting/protocol/multiplex/ConnectionTestCase.java 2008-11-04 17:50:07 UTC (rev 4646)
@@ -28,14 +28,36 @@
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.CountDownLatch;
+import java.net.URI;
+import java.io.IOException;
import junit.framework.TestCase;
import org.jboss.remoting.core.EndpointImpl;
import org.jboss.remoting.test.support.LoggingHelper;
+import org.jboss.remoting.SimpleCloseable;
+import org.jboss.remoting.LocalServiceConfiguration;
+import org.jboss.remoting.RequestListener;
+import org.jboss.remoting.ClientContext;
+import org.jboss.remoting.ServiceContext;
+import org.jboss.remoting.RequestContext;
+import org.jboss.remoting.RemoteExecutionException;
+import org.jboss.remoting.ClientSource;
+import org.jboss.remoting.Client;
import org.jboss.xnio.BufferAllocator;
import org.jboss.xnio.IoUtils;
import org.jboss.xnio.Xnio;
import org.jboss.xnio.CloseableExecutor;
+import org.jboss.xnio.ChannelSource;
+import org.jboss.xnio.IoHandler;
+import org.jboss.xnio.IoHandlerFactory;
+import org.jboss.xnio.IoFuture;
+import org.jboss.xnio.Buffers;
+import org.jboss.xnio.log.Logger;
+import org.jboss.xnio.channels.AllocatedMessageChannel;
+import org.jboss.xnio.channels.Channels;
import org.jboss.xnio.nio.NioXnio;
+import org.jboss.river.RiverMarshallerFactory;
+import org.jboss.marshalling.MarshallingConfiguration;
/**
*
@@ -45,28 +67,79 @@
LoggingHelper.init();
}
+ public static final Logger log = Logger.getLogger(ConnectionTestCase.class);
+
public void testConnection() throws Throwable {
final String REQUEST = "request";
final String REPLY = "reply";
final List<Throwable> problems = Collections.synchronizedList(new LinkedList<Throwable>());
final CloseableExecutor closeableExecutor = IoUtils.closeableExecutor(Executors.newCachedThreadPool(), 500L, TimeUnit.MILLISECONDS);
try {
- final BufferAllocator<ByteBuffer> allocator = new BufferAllocator<ByteBuffer>() {
- public ByteBuffer allocate() {
- return ByteBuffer.allocate(1024);
- }
-
- public void free(final ByteBuffer buffer) {
- }
- };
+ final BufferAllocator<ByteBuffer> allocator = Buffers.createHeapByteBufferAllocator(1024);
final Xnio xnio = NioXnio.create();
try {
- final EndpointImpl endpoint = new EndpointImpl();
- endpoint.setExecutor(closeableExecutor);
- endpoint.start();
+ final EndpointImpl remoteEndpoint = new EndpointImpl();
+ remoteEndpoint.setExecutor(closeableExecutor);
+ remoteEndpoint.start();
try {
+ final EndpointImpl endpoint = new EndpointImpl();
+ endpoint.setExecutor(closeableExecutor);
+ endpoint.start();
+ try {
+ final CountDownLatch latch = new CountDownLatch(1);
+ final MultiplexConfiguration configuration = new MultiplexConfiguration();
+ configuration.setAllocator(allocator);
+ configuration.setExecutor(closeableExecutor);
+ configuration.setLinkMetric(10);
+ configuration.setMarshallerFactory(new RiverMarshallerFactory());
+ final MarshallingConfiguration marshallingConfiguration = new MarshallingConfiguration();
+ configuration.setMarshallingConfiguration(marshallingConfiguration);
+ final IoHandlerFactory<AllocatedMessageChannel> handlerFactory = MultiplexProtocol.createServer(remoteEndpoint, configuration);
+ final ChannelSource<AllocatedMessageChannel> channelSource = Channels.convertStreamToAllocatedMessage(xnio.createPipeServer(Channels.convertStreamToAllocatedMessage(handlerFactory, 16384, 16384)), 16384, 16384);
+ final IoFuture<SimpleCloseable> future = MultiplexProtocol.connect(endpoint, configuration, channelSource);
+ future.get();
+ final LocalServiceConfiguration<Object, Object> localServiceConfiguration = new LocalServiceConfiguration<Object, Object>(new RequestListener<Object, Object>() {
+ public void handleClientOpen(final ClientContext context) {
+ log.debug("Client open");
+ }
+
+ public void handleServiceOpen(final ServiceContext context) {
+ }
+
+ public void handleRequest(final RequestContext<Object> context, final Object request) throws RemoteExecutionException {
+ try {
+ context.sendReply(REPLY);
+ } catch (IOException e) {
+ log.error(e, "Failed to send reply");
+ problems.add(e);
+ }
+ }
+
+ public void handleServiceClose(final ServiceContext context) {
+ }
+
+ public void handleClientClose(final ClientContext context) {
+ log.debug("Client closed");
+ latch.countDown();
+ }
+ }, Object.class, Object.class);
+ localServiceConfiguration.setServiceType("connection.test");
+ localServiceConfiguration.setGroupName("testgroup");
+ localServiceConfiguration.setMetric(10);
+ remoteEndpoint.registerService(localServiceConfiguration);
+ final IoFuture<ClientSource<Object,Object>> futureClientSource = endpoint.locateService(new URI("jrs:connection.test::"), Object.class, Object.class);
+ assertEquals(IoFuture.Status.DONE, futureClientSource.await(1L, TimeUnit.SECONDS));
+ final ClientSource<Object, Object> clientSource = futureClientSource.get();
+ final Client<Object,Object> client = clientSource.createClient();
+ final IoFuture<Object> futureReply = client.send(REQUEST);
+ assertEquals(IoFuture.Status.DONE, futureReply.await(1L, TimeUnit.SECONDS));
+ assertEquals(REPLY, futureReply.get());
+ assertTrue(latch.await(1L, TimeUnit.SECONDS));
+ } finally {
+ endpoint.stop();
+ }
} finally {
- endpoint.stop();
+ remoteEndpoint.stop();
}
} finally {
IoUtils.safeClose(xnio);
16 years
JBoss Remoting SVN: r4645 - in remoting2/branches/2.x: .settings and 1 other directory.
by jboss-remoting-commits@lists.jboss.org
Author: trustin
Date: 2008-11-04 04:15:17 -0500 (Tue, 04 Nov 2008)
New Revision: 4645
Added:
remoting2/branches/2.x/.settings/
remoting2/branches/2.x/.settings/org.eclipse.jdt.core.prefs
Log:
Made sure compiler version is 1.4 in Eclipse
Added: remoting2/branches/2.x/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- remoting2/branches/2.x/.settings/org.eclipse.jdt.core.prefs (rev 0)
+++ remoting2/branches/2.x/.settings/org.eclipse.jdt.core.prefs 2008-11-04 09:15:17 UTC (rev 4645)
@@ -0,0 +1,12 @@
+#Tue Nov 04 18:17:28 KST 2008
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.4
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
+org.eclipse.jdt.core.compiler.source=1.3
16 years