[jboss-cvs] JBoss Messaging SVN: r3502 - in trunk: src/main/org/jboss/jms/client/delegate and 11 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Dec 14 09:25:45 EST 2007


Author: jmesnil
Date: 2007-12-14 09:25:44 -0500 (Fri, 14 Dec 2007)
New Revision: 3502

Added:
   trunk/src/main/org/jboss/messaging/core/remoting/ConnectorRegistry.java
   trunk/src/main/org/jboss/messaging/core/remoting/ServerLocator.java
   trunk/tests/src/org/jboss/messaging/core/remoting/test/unit/ConnectorRegistryTest.java
   trunk/tests/src/org/jboss/messaging/core/remoting/test/unit/ServerLocatorTest.java
Modified:
   trunk/src/etc/server/default/deploy/jbm-beans.xml
   trunk/src/main/org/jboss/jms/client/delegate/ClientClusteredConnectionFactoryDelegate.java
   trunk/src/main/org/jboss/jms/client/delegate/ClientConnectionFactoryDelegate.java
   trunk/src/main/org/jboss/jms/client/remoting/JMSRemotingConnection.java
   trunk/src/main/org/jboss/jms/server/ConnectionFactoryManager.java
   trunk/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactory.java
   trunk/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactoryJNDIMapper.java
   trunk/src/main/org/jboss/messaging/core/remoting/Client.java
   trunk/src/main/org/jboss/messaging/core/remoting/NIOConnector.java
   trunk/src/main/org/jboss/messaging/core/remoting/TransportType.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/invm/INVMConnector.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/FilterChainSupport.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MinaConnector.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MinaService.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/PacketCodecFactory.java
   trunk/tests/src/org/jboss/messaging/core/remoting/impl/ClientTestBase.java
   trunk/tests/src/org/jboss/messaging/core/remoting/impl/invm/test/unit/INVMClientTest.java
   trunk/tests/src/org/jboss/messaging/core/remoting/impl/mina/integration/test/MinaClientTest.java
   trunk/tests/src/org/jboss/messaging/core/remoting/test/unit/ClientTest.java
   trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/PacketTypeTest.java
Log:
http://jira.jboss.org/jira/browse/JBMESSAGING-1195 Optimize in-vm communication
* added a ConnectorRegistry to check if a server and a client are in the same VM.
  if it the case, use a INVMConnector regardless of the transport type defined
  for the MinaService in jbm-beans.xml

Modified: trunk/src/etc/server/default/deploy/jbm-beans.xml
===================================================================
--- trunk/src/etc/server/default/deploy/jbm-beans.xml	2007-12-13 15:54:58 UTC (rev 3501)
+++ trunk/src/etc/server/default/deploy/jbm-beans.xml	2007-12-14 14:25:44 UTC (rev 3502)
@@ -348,6 +348,7 @@
 
    <bean name="MinaService" class="org.jboss.messaging.core.remoting.impl.mina.MinaService">
       <constructor>
+         <parameter>tcp</parameter>      
          <parameter>localhost</parameter>      
          <parameter>
             <inject bean="Configuration" property="remotingBindAddress"/>

Modified: trunk/src/main/org/jboss/jms/client/delegate/ClientClusteredConnectionFactoryDelegate.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/delegate/ClientClusteredConnectionFactoryDelegate.java	2007-12-13 15:54:58 UTC (rev 3501)
+++ trunk/src/main/org/jboss/jms/client/delegate/ClientClusteredConnectionFactoryDelegate.java	2007-12-14 14:25:44 UTC (rev 3502)
@@ -100,10 +100,9 @@
          if (trace) log.trace("Trying communication on server(" + server + ")=" + delegates[server].getServerLocatorURI());
          try
          {
-            String serverHost = delegates[server].getServerHost();
-            int serverPort = delegates[server].getServerPort();
+            String serverlocatorURI = delegates[server].getServerLocatorURI();
             
-            remoting = new JMSRemotingConnection(serverHost, serverPort, delegates[server].getStrictTck());
+            remoting = new JMSRemotingConnection(serverlocatorURI, delegates[server].getStrictTck());
             remoting.start();
             currentDelegate = delegates[server];
             if (trace) log.trace("Adding callback");

Modified: trunk/src/main/org/jboss/jms/client/delegate/ClientConnectionFactoryDelegate.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/delegate/ClientConnectionFactoryDelegate.java	2007-12-13 15:54:58 UTC (rev 3501)
+++ trunk/src/main/org/jboss/jms/client/delegate/ClientConnectionFactoryDelegate.java	2007-12-14 14:25:44 UTC (rev 3502)
@@ -21,8 +21,6 @@
  */
 package org.jboss.jms.client.delegate;
 
-import static org.jboss.messaging.core.remoting.TransportType.TCP;
-
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.Serializable;
@@ -36,7 +34,9 @@
 import org.jboss.jms.delegate.TopologyResult;
 import org.jboss.jms.exception.MessagingNetworkFailureException;
 import org.jboss.messaging.core.remoting.Client;
-import org.jboss.messaging.core.remoting.impl.mina.MinaConnector;
+import org.jboss.messaging.core.remoting.ConnectorRegistry;
+import org.jboss.messaging.core.remoting.NIOConnector;
+import org.jboss.messaging.core.remoting.ServerLocator;
 import org.jboss.messaging.core.remoting.wireformat.CreateConnectionRequest;
 import org.jboss.messaging.core.remoting.wireformat.CreateConnectionResponse;
 import org.jboss.messaging.core.remoting.wireformat.GetClientAOPStackRequest;
@@ -67,10 +67,8 @@
 
    private String uniqueName;
 
-   private String serverHost;
+   private String serverLocatorURI;
 
-   private int serverPort;
-
    private Version serverVersion;
  
    private int serverID;
@@ -107,15 +105,14 @@
 
    // Constructors ---------------------------------------------------------------------------------
 
-   public ClientConnectionFactoryDelegate(String uniqueName, String objectID, int serverID, String host,
-                                          int port, Version serverVersion, boolean clientPing, boolean strictTck)
+   public ClientConnectionFactoryDelegate(String uniqueName, String objectID, int serverID, 
+         String serverLocatorURI, Version serverVersion, boolean clientPing, boolean strictTck)
    {
       super(objectID);
 
       this.uniqueName = uniqueName;
       this.serverID = serverID;
-      this.serverHost = host;
-      this.serverPort = port;
+      this.serverLocatorURI = serverLocatorURI;
       this.serverVersion = serverVersion;
       this.clientPing = clientPing;
       this.strictTck = strictTck;
@@ -152,7 +149,7 @@
       
       try
       {
-         remotingConnection = new JMSRemotingConnection(serverHost, serverPort, strictTck);
+         remotingConnection = new JMSRemotingConnection(serverLocatorURI, strictTck);
        
          remotingConnection.start();
          client = remotingConnection.getRemotingClient();
@@ -234,19 +231,9 @@
       return "ConnectionFactoryDelegate[" + id + ", SID=" + serverID + "]";
    }
    
-   public String getServerHost()
-   {
-      return serverHost;
-   }
-   
-   public int getServerPort()
-   {
-      return serverPort;
-   }
-   
    public String getServerLocatorURI()
    {
-      return "tcp://" + serverHost + ":" + serverPort;
+      return serverLocatorURI;
    }
 
    
@@ -289,8 +276,10 @@
       
       try
       {
-         client = new Client(new MinaConnector());
-         client.connect(serverHost, serverPort, TCP);
+         ServerLocator locator = new ServerLocator(serverLocatorURI);
+         NIOConnector connector = ConnectorRegistry.get(locator);
+         client = new Client(connector, locator);
+         client.connect();
       }
       catch (Exception e)
       {
@@ -306,9 +295,7 @@
    {      
       super.read(in);
       
-      serverHost = in.readUTF();
-
-      serverPort = in.readInt();
+      serverLocatorURI = in.readUTF();
       
       serverVersion = new Version();
       
@@ -325,9 +312,7 @@
    {
       super.write(out);
       
-      out.writeUTF(serverHost);
-
-      out.writeInt(serverPort);
+      out.writeUTF(serverLocatorURI);
       
       serverVersion.write(out);
       

Modified: trunk/src/main/org/jboss/jms/client/remoting/JMSRemotingConnection.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/remoting/JMSRemotingConnection.java	2007-12-13 15:54:58 UTC (rev 3501)
+++ trunk/src/main/org/jboss/jms/client/remoting/JMSRemotingConnection.java	2007-12-14 14:25:44 UTC (rev 3502)
@@ -23,8 +23,9 @@
 
 import org.jboss.logging.Logger;
 import org.jboss.messaging.core.remoting.Client;
-import org.jboss.messaging.core.remoting.TransportType;
-import org.jboss.messaging.core.remoting.impl.mina.MinaConnector;
+import org.jboss.messaging.core.remoting.ConnectorRegistry;
+import org.jboss.messaging.core.remoting.NIOConnector;
+import org.jboss.messaging.core.remoting.ServerLocator;
 
 /**
  * Encapsulates the state and behaviour from MINA needed for a JMS connection.
@@ -47,10 +48,8 @@
 
    // Attributes -----------------------------------------------------------------------------------
 
-   private String serverHost;
+   private ServerLocator serverLocator;
 
-   private int serverPort;
-
    private Client client;
 
    private CallbackManager callbackManager;
@@ -63,13 +62,11 @@
    // explicitly remove it from the remoting client
    private ConsolidatedRemotingConnectionListener remotingConnectionListener;
 
-
    // Constructors ---------------------------------------------------------------------------------
 
-   public JMSRemotingConnection(String serverHost, int serverPort, boolean strictTck) throws Exception
+   public JMSRemotingConnection(String serverLocatorURI, boolean strictTck) throws Exception
    {
-      this.serverHost = serverHost;
-      this.serverPort = serverPort;
+      this.serverLocator = new ServerLocator(serverLocatorURI);
       this.strictTck = strictTck;
 
       log.trace(this + " created");
@@ -83,9 +80,13 @@
 
       callbackManager = new CallbackManager();
 
-      client = new Client(new MinaConnector());
-      client.connect(serverHost, serverPort, TransportType.TCP);
+      NIOConnector connector = ConnectorRegistry.get(serverLocator);
+      client = new Client(connector, serverLocator);
+      client.connect();
 
+      if (log.isDebugEnabled())
+         log.debug("Using " + connector.getServerURI() + " to connect to " + serverLocator);
+
       log.trace(this + " started");
    }
 
@@ -181,7 +182,7 @@
 
    public String toString()
    {
-      return "JMSRemotingConnection[" + serverHost + ":" + serverPort + "]";
+      return "JMSRemotingConnection[" + serverLocator.getURI() + "]";
    }
 
    // Package protected ----------------------------------------------------------------------------

Modified: trunk/src/main/org/jboss/jms/server/ConnectionFactoryManager.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/ConnectionFactoryManager.java	2007-12-13 15:54:58 UTC (rev 3501)
+++ trunk/src/main/org/jboss/jms/server/ConnectionFactoryManager.java	2007-12-14 14:25:44 UTC (rev 3502)
@@ -31,8 +31,8 @@
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
  * @author <a href="ataylor at redhat.com">Andy Taylor</a>
  * @version <tt>$Revision$</tt>
- *          <p/>
- *          $Id$
+ * 
+ * $Id$
  */
 public interface ConnectionFactoryManager extends MessagingComponent
 {
@@ -41,7 +41,7 @@
     *        AOP subsystem, but not bound in JNDI.
     */
    void registerConnectionFactory(String uniqueName, String clientID,  List<String> jndiBindings,
-                                 String host, int port, boolean clientPing,
+                                 String serverURI, boolean clientPing,
                                  int prefetchSize,
                                  boolean slowConsumers,
                                  int defaultTempQueueFullSize,

Modified: trunk/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactory.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactory.java	2007-12-13 15:54:58 UTC (rev 3501)
+++ trunk/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactory.java	2007-12-14 14:25:44 UTC (rev 3502)
@@ -15,6 +15,7 @@
 import org.jboss.jms.server.ConnectorManager;
 import org.jboss.jms.server.ServerPeer;
 import org.jboss.logging.Logger;
+import org.jboss.messaging.core.remoting.ServerLocator;
 import org.jboss.messaging.core.remoting.impl.mina.MinaService;
 import org.jboss.messaging.util.ExceptionUtil;
 
@@ -116,8 +117,7 @@
                                                "each Connection Factory");
          }
       
-         String host = minaService.getHost();
-         int port = minaService.getPort();
+         ServerLocator serverLocator = minaService.getLocator();
 
          if (!serverPeer.isSupportsFailover())
          {
@@ -132,17 +132,13 @@
          
          connectionFactoryManager.
             registerConnectionFactory(getName(), clientID, jndiBindings,
-                                      host, port, false, prefetchSize, slowConsumers,
+                                      serverLocator.getURI(), false, prefetchSize, slowConsumers,
                                       defaultTempQueueFullSize, defaultTempQueuePageSize,                                      
                                       defaultTempQueueDownCacheSize, dupsOKBatchSize, supportsFailover, supportsLoadBalancing,
                                       loadBalancingFactory, strictTck);               
          connectorManager.registerConnector(getName());
-         String info = "Connector "  + "mina://" +
-            host + ":" + port;
-                 
-         info += " has lease disabled";
       
-         log.info(info);
+         log.info(serverLocator + " has lease disabled");
          log.info(this + " started");
       }
       catch (Throwable t)

Modified: trunk/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactoryJNDIMapper.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactoryJNDIMapper.java	2007-12-13 15:54:58 UTC (rev 3501)
+++ trunk/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactoryJNDIMapper.java	2007-12-14 14:25:44 UTC (rev 3502)
@@ -105,8 +105,7 @@
    public synchronized void registerConnectionFactory(String uniqueName,
                                                       String clientID,
                                                       List<String> jndiBindings,
-                                                      String host,
-                                                      int port,
+                                                      String serverLocatorURI,
                                                       boolean clientPing,
                                                       int prefetchSize,
                                                       boolean slowConsumers,
@@ -171,7 +170,7 @@
 
       ClientConnectionFactoryDelegate localDelegate =
          new ClientConnectionFactoryDelegate(uniqueName, id, serverPeer.getConfiguration().getServerPeerID(),
-                                             host, port, version, clientPing, useStrict);
+                                             serverLocatorURI, version, clientPing, useStrict);
 
       log.debug(this + " created local delegate " + localDelegate);
 

Modified: trunk/src/main/org/jboss/messaging/core/remoting/Client.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/Client.java	2007-12-13 15:54:58 UTC (rev 3501)
+++ trunk/src/main/org/jboss/messaging/core/remoting/Client.java	2007-12-14 14:25:44 UTC (rev 3502)
@@ -32,6 +32,8 @@
 
    // Attributes ----------------------------------------------------
 
+   private ServerLocator serverLocator;
+
    private final NIOConnector connector;
 
    private NIOSession session;
@@ -44,31 +46,22 @@
 
    // Constructors --------------------------------------------------
 
-   public Client(NIOConnector connector)
+   public Client(NIOConnector connector, ServerLocator locator)
    {
       assert connector != null;
-
+      assert locator != null;
+      
       this.connector = connector;
+      this.serverLocator = locator;
    }
 
    // Public --------------------------------------------------------
 
-   public void connect(String host, int port, TransportType transport)
-         throws Exception
+   public void connect() throws Exception
    {
-      connect(host, port, transport, false);
+      this.session = connector.connect();
    }
 
-   public void connect(String host, int port, TransportType transport,
-         boolean useSSL) throws Exception
-   {
-      assert host != null;
-      assert port > 0;
-      assert transport != null;
-
-      this.session = connector.connect(host, port, transport);
-   }
-
    public boolean disconnect() throws Exception
    {
       session = null;

Added: trunk/src/main/org/jboss/messaging/core/remoting/ConnectorRegistry.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/ConnectorRegistry.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/ConnectorRegistry.java	2007-12-14 14:25:44 UTC (rev 3502)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting;
+
+import static org.jboss.messaging.core.remoting.TransportType.INVM;
+import static org.jboss.messaging.core.remoting.TransportType.TCP;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.messaging.core.remoting.impl.invm.INVMConnector;
+import org.jboss.messaging.core.remoting.impl.mina.MinaConnector;
+import org.jboss.messaging.core.remoting.impl.mina.MinaService;
+
+/**
+ * The ConnectorRegistry keeps track of ServerLocators and NIOConnectors.
+ * 
+ * When a {@link MinaService} is started, it register its {@link ServerLocator}.
+ * 
+ * When a {@link Client} is created, it gets its {@link NIOConnector} from the
+ * ConnectorRegistry using the {@link ServerLocator} corresponding to the server
+ * it wants to connect to. If the ConnectionRegistry contains this locator, it
+ * implies that the Client is in the same VM than the server. In that case, we
+ * optimize by returning a {@link INVMConnector} regardless of the transport
+ * type defined by the locator
+ * 
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ * 
+ */
+public class ConnectorRegistry
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   private static Set<ServerLocator> locators = new HashSet<ServerLocator>();
+
+   public static boolean register(ServerLocator locator)
+   {
+      return locators.add(locator);
+   }
+
+   public static boolean unregister(ServerLocator locator)
+   {
+      return locators.remove(locator);
+   }
+
+   public static NIOConnector get(ServerLocator locator)
+   {
+      assert locator != null;
+
+      // check if the server is in the same vm than the client
+      if (locators.contains(locator))
+      {
+         return new INVMConnector(locator.getHost(), locator.getPort());
+      }
+
+      TransportType transport = locator.getTransport();
+
+      if (transport == TCP)
+      {
+         return new MinaConnector(locator.getTransport(), locator.getHost(),
+               locator.getPort());
+      } else if (transport == INVM)
+      {
+         return new INVMConnector(locator.getHost(), locator.getPort());
+      } else
+      {
+         throw new IllegalArgumentException(
+               "no connector defined for transport " + transport);
+      }
+   }
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}

Modified: trunk/src/main/org/jboss/messaging/core/remoting/NIOConnector.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/NIOConnector.java	2007-12-13 15:54:58 UTC (rev 3501)
+++ trunk/src/main/org/jboss/messaging/core/remoting/NIOConnector.java	2007-12-14 14:25:44 UTC (rev 3502)
@@ -19,8 +19,7 @@
 public interface NIOConnector
 {
 
-   public abstract NIOSession connect(String host, int port,
-         TransportType transport) throws IOException;
+   public abstract NIOSession connect() throws IOException;
 
    public abstract boolean disconnect();
 

Added: trunk/src/main/org/jboss/messaging/core/remoting/ServerLocator.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/ServerLocator.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/ServerLocator.java	2007-12-14 14:25:44 UTC (rev 3502)
@@ -0,0 +1,137 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ * 
+ */
+public class ServerLocator
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   private TransportType transport;
+   private String host;
+   private int port;
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public ServerLocator(String uri) throws URISyntaxException
+   {
+      assert uri != null;
+      assert uri.length() > 0;
+
+      URI u = new URI(uri);
+
+      try
+      {
+         String scheme = u.getScheme().toUpperCase();
+         this.transport = TransportType.valueOf(scheme);
+      } catch (IllegalArgumentException e)
+      {
+         URISyntaxException use = new URISyntaxException(uri, u.getScheme()
+               .toUpperCase()
+               + " transport type is not supported");
+         use.initCause(e);
+         
+         throw use;
+      }
+      this.host = u.getHost();
+      this.port = u.getPort();
+   }
+
+   public ServerLocator(TransportType transport, String host, int port)
+   {
+      this.transport = transport;
+      this.host = host;
+      this.port = port;
+   }
+
+   // Public --------------------------------------------------------
+
+   public TransportType getTransport()
+   {
+      return transport;
+   }
+
+   public String getHost()
+   {
+      return host;
+   }
+
+   public int getPort()
+   {
+      return port;
+   }
+
+   @Override
+   public int hashCode()
+   {
+      final int prime = 31;
+      int result = 1;
+      result = prime * result + ((host == null) ? 0 : host.hashCode());
+      result = prime * result + port;
+      result = prime * result
+            + ((transport == null) ? 0 : transport.hashCode());
+      return result;
+   }
+
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (this == obj)
+         return true;
+      if (obj == null)
+         return false;
+      if (getClass() != obj.getClass())
+         return false;
+      final ServerLocator other = (ServerLocator) obj;
+      if (host == null)
+      {
+         if (other.host != null)
+            return false;
+      } else if (!host.equals(other.host))
+         return false;
+      if (port != other.port)
+         return false;
+      if (transport == null)
+      {
+         if (other.transport != null)
+            return false;
+      } else if (!transport.equals(other.transport))
+         return false;
+      return true;
+   }
+
+   public String getURI()
+   {
+      return transport + "://" + host + ":" + port;
+   }
+
+   @Override
+   public String toString()
+   {
+      return "RemoteServiceLocator[uri=" + getURI() + "]";
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}

Modified: trunk/src/main/org/jboss/messaging/core/remoting/TransportType.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/TransportType.java	2007-12-13 15:54:58 UTC (rev 3501)
+++ trunk/src/main/org/jboss/messaging/core/remoting/TransportType.java	2007-12-14 14:25:44 UTC (rev 3502)
@@ -16,4 +16,10 @@
 public enum TransportType
 {
    TCP, HTTP, INVM;
+   
+   @Override
+   public String toString()
+   {
+      return super.toString().toLowerCase();
+   }
 }

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/invm/INVMConnector.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/invm/INVMConnector.java	2007-12-13 15:54:58 UTC (rev 3501)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/invm/INVMConnector.java	2007-12-14 14:25:44 UTC (rev 3502)
@@ -6,12 +6,13 @@
  */
 package org.jboss.messaging.core.remoting.impl.invm;
 
+import static org.jboss.messaging.core.remoting.TransportType.INVM;
+
 import java.io.IOException;
 
 import org.jboss.jms.client.remoting.ConsolidatedRemotingConnectionListener;
 import org.jboss.messaging.core.remoting.NIOConnector;
 import org.jboss.messaging.core.remoting.NIOSession;
-import org.jboss.messaging.core.remoting.TransportType;
 
 /**
  * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
@@ -27,6 +28,8 @@
 
    private String host;
 
+   private int port;
+
    private INVMSession session;
  
    // Static --------------------------------------------------------
@@ -35,15 +38,19 @@
 
    // Public --------------------------------------------------------
 
+   public INVMConnector(String host, int port)
+   {
+      assert host != null;
+      
+      this.host = host;
+      this.port = port;
+   }
+
    // NIOConnector implementation -----------------------------------
 
-   public NIOSession connect(String host, int port, TransportType transport)
+   public NIOSession connect()
          throws IOException
    {
-      assert host != null;
-      assert transport == TransportType.INVM;
-      
-      this.host = host;
       this.session = new INVMSession();
       return session;
    }
@@ -63,7 +70,7 @@
 
    public String getServerURI()
    {
-      return "invm://" + host;
+      return INVM + "://" + host + ":" + port;
    }
    
    public void removeConnectionListener(

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/FilterChainSupport.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/FilterChainSupport.java	2007-12-13 15:54:58 UTC (rev 3501)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/FilterChainSupport.java	2007-12-14 14:25:44 UTC (rev 3502)
@@ -39,7 +39,6 @@
    // Package protected ---------------------------------------------
 
    static void addCodecFilter(DefaultIoFilterChainBuilder filterChain)
-         throws Exception
    {
       assert filterChain != null;
 
@@ -48,7 +47,6 @@
    }
 
    static void addMDCFilter(DefaultIoFilterChainBuilder filterChain)
-         throws Exception
    {
       assert filterChain != null;
 

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MinaConnector.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MinaConnector.java	2007-12-13 15:54:58 UTC (rev 3501)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MinaConnector.java	2007-12-14 14:25:44 UTC (rev 3502)
@@ -6,6 +6,7 @@
  */
 package org.jboss.messaging.core.remoting.impl.mina;
 
+import static org.jboss.messaging.core.remoting.TransportType.TCP;
 import static org.jboss.messaging.core.remoting.impl.mina.FilterChainSupport.addBlockingRequestResponseFilter;
 import static org.jboss.messaging.core.remoting.impl.mina.FilterChainSupport.addCodecFilter;
 import static org.jboss.messaging.core.remoting.impl.mina.FilterChainSupport.addLoggingFilter;
@@ -46,6 +47,10 @@
 
    // Attributes ----------------------------------------------------
 
+   private String host;
+
+   private int port;
+   
    private NioSocketConnector connector;
 
    private ScheduledExecutorService blockingScheduler;
@@ -54,14 +59,22 @@
 
    private Map<ConsolidatedRemotingConnectionListener, IoServiceListener> listeners = new HashMap<ConsolidatedRemotingConnectionListener, IoServiceListener>();
 
+
    // Static --------------------------------------------------------
 
    // Constructors --------------------------------------------------
 
    // Public --------------------------------------------------------
 
-   public MinaConnector() throws Exception
+   public MinaConnector(TransportType transport, String host, int port)
    {
+      assert transport == TCP;
+      assert host != null;
+      assert port > 0;
+      
+      this.host = host;
+      this.port = port;
+      
       this.connector = new NioSocketConnector();
       DefaultIoFilterChainBuilder filterChain = connector.getFilterChain();
       
@@ -81,11 +94,8 @@
 
    // NIOConnector implementation -----------------------------------
    
-   public NIOSession connect(String host, int port, TransportType transport) throws IOException {
-      assert host != null;
-      assert port > 0;
-      assert transport != null;
-
+   public NIOSession connect() throws IOException {
+   
       InetSocketAddress address = new InetSocketAddress(host, port);
       ConnectFuture future = connector.connect(address);
       connector.setDefaultRemoteAddress(address);
@@ -149,14 +159,14 @@
    {
       if (connector == null)
       {
-         return null;
+         return TCP + "://" + host + ":" + port;
       }
       InetSocketAddress address = connector.getDefaultRemoteAddress();
       if (address != null)
       {
-         return address.toString();
+         return TCP + "://" + address.toString();
       } else {
-         return null;
+         return TCP + "://" + host + ":" + port;
       }
    }
 

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MinaService.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MinaService.java	2007-12-13 15:54:58 UTC (rev 3501)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MinaService.java	2007-12-14 14:25:44 UTC (rev 3502)
@@ -15,7 +15,10 @@
 import org.apache.mina.common.DefaultIoFilterChainBuilder;
 import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
 import org.jboss.logging.Logger;
+import org.jboss.messaging.core.remoting.ConnectorRegistry;
 import org.jboss.messaging.core.remoting.PacketDispatcher;
+import org.jboss.messaging.core.remoting.ServerLocator;
+import org.jboss.messaging.core.remoting.TransportType;
 
 /**
  * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
@@ -37,31 +40,34 @@
    
    private NioSocketAcceptor acceptor;
 
+   private TransportType transport;
+
    // Static --------------------------------------------------------
 
    // Constructors --------------------------------------------------
 
-
-   public MinaService(String host, int port)
+   public MinaService(String transport, String host, int port)
    {
+      this(TransportType.valueOf(transport.toUpperCase()), host, port);
+   }
+   
+   public MinaService(TransportType transport, String host, int port)
+   {
+      assert transport != null;
       assert host !=  null;
       assert port > 0;
       
+      this.transport = transport;
       this.host = host;
       this.port = port;
    }
 
    // Public --------------------------------------------------------
-   
-   public int getPort()
+
+   public ServerLocator getLocator()
    {
-      return port;
+      return new ServerLocator(transport, host, port);
    }
-      
-   public String getHost()
-   {
-     return host;
-   }
    
    public void start() throws Exception
    {
@@ -83,6 +89,8 @@
 
          acceptor.setHandler(new MinaHandler(PacketDispatcher.server));
          acceptor.bind();
+         
+         ConnectorRegistry.register(getLocator());
       } 
    }
 
@@ -93,6 +101,8 @@
          acceptor.unbind();
          acceptor.dispose();
          acceptor = null;
+         
+         ConnectorRegistry.unregister(getLocator());
       }    
    }
    

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/PacketCodecFactory.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/PacketCodecFactory.java	2007-12-13 15:54:58 UTC (rev 3501)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/PacketCodecFactory.java	2007-12-14 14:25:44 UTC (rev 3502)
@@ -9,6 +9,7 @@
 import static org.jboss.messaging.core.remoting.wireformat.PacketType.NULL;
 
 import org.apache.mina.filter.codec.demux.DemuxingProtocolCodecFactory;
+import org.jboss.logging.Logger;
 import org.jboss.messaging.core.remoting.codec.AbstractPacketCodec;
 import org.jboss.messaging.core.remoting.codec.AcknowledgeDeliveriesRequestCodec;
 import org.jboss.messaging.core.remoting.codec.AcknowledgeDeliveryRequestCodec;
@@ -110,6 +111,8 @@
 {
    // Constants -----------------------------------------------------
 
+   private final Logger log = Logger.getLogger(PacketCodecFactory.class);
+
    // Attributes ----------------------------------------------------
 
    // Static --------------------------------------------------------
@@ -117,7 +120,7 @@
    // Constructors --------------------------------------------------
 
    // FIXME: split encoder/decoder required only on client and/or server sides
-   public PacketCodecFactory() throws Exception
+   public PacketCodecFactory()
    {
       addCodecForEmptyPacket(NULL, NullPacket.class);
 
@@ -258,13 +261,18 @@
    // FIXME generics definition should be in term of <P>...
    private void addCodec(
          Class<? extends AbstractPacket> packetClass,
-         Class<? extends AbstractPacketCodec<? extends AbstractPacket>> codecClass) throws Exception
+         Class<? extends AbstractPacketCodec<? extends AbstractPacket>> codecClass)
    {
-      AbstractPacketCodec<? extends AbstractPacket> codec = codecClass
-            .newInstance();
-      MinaPacketCodec<AbstractPacket> minaCodec = new MinaPacketCodec(codec);
-      super.addMessageDecoder(minaCodec);
-      super.addMessageEncoder(packetClass, minaCodec);
+      try
+      {
+         AbstractPacketCodec<? extends AbstractPacket> codec = codecClass.newInstance();
+         MinaPacketCodec<AbstractPacket> minaCodec = new MinaPacketCodec(codec);
+         super.addMessageDecoder(minaCodec);
+         super.addMessageEncoder(packetClass, minaCodec);
+      } catch (Exception e)
+      {
+         log.error("Unable to add codec for packet class " + packetClass.getName(), e);
+      }
    }
 
    private void addCodecForEmptyPacket(PacketType type,

Modified: trunk/tests/src/org/jboss/messaging/core/remoting/impl/ClientTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/remoting/impl/ClientTestBase.java	2007-12-13 15:54:58 UTC (rev 3501)
+++ trunk/tests/src/org/jboss/messaging/core/remoting/impl/ClientTestBase.java	2007-12-14 14:25:44 UTC (rev 3502)
@@ -9,7 +9,6 @@
 import static java.util.concurrent.TimeUnit.MILLISECONDS;
 import static java.util.concurrent.TimeUnit.SECONDS;
 import static org.jboss.messaging.core.remoting.impl.mina.integration.test.TestSupport.MANY_MESSAGES;
-import static org.jboss.messaging.core.remoting.impl.mina.integration.test.TestSupport.PORT;
 import static org.jboss.messaging.core.remoting.impl.mina.integration.test.TestSupport.reverse;
 
 import java.io.IOException;
@@ -18,9 +17,10 @@
 import junit.framework.TestCase;
 
 import org.jboss.messaging.core.remoting.Client;
+import org.jboss.messaging.core.remoting.NIOConnector;
 import org.jboss.messaging.core.remoting.PacketDispatcher;
 import org.jboss.messaging.core.remoting.PacketSender;
-import org.jboss.messaging.core.remoting.TransportType;
+import org.jboss.messaging.core.remoting.ServerLocator;
 import org.jboss.messaging.core.remoting.impl.mina.integration.test.ReversePacketHandler;
 import org.jboss.messaging.core.remoting.test.unit.TestPacketHandler;
 import org.jboss.messaging.core.remoting.wireformat.AbstractPacket;
@@ -49,11 +49,11 @@
 
    public void testConnected() throws Exception
    {
-      Client client = createClient();
+      Client client = new Client(createNIOConnector(), createServerLocator());
       
       assertFalse(client.isConnected());
 
-      client.connect("localhost", PORT, getTransport());
+      client.connect();
       assertTrue(client.isConnected());
 
       assertTrue(client.disconnect());
@@ -197,8 +197,10 @@
    {
       startServer();
       
-      client = createClient();
-      client.connect("localhost", PORT, getTransport());
+      ServerLocator serverLocator = createServerLocator();
+      NIOConnector connector = createNIOConnector();
+      client = new Client(connector, serverLocator);
+      client.connect();
       
       serverPacketHandler = new ReversePacketHandler();
       PacketDispatcher.server.register(serverPacketHandler);
@@ -215,10 +217,10 @@
       client = null;
    }
    
-   protected abstract Client createClient() throws Exception;
+   protected abstract ServerLocator createServerLocator();
    
-   protected abstract TransportType getTransport();
-   
+   protected abstract NIOConnector createNIOConnector();
+
    protected abstract void startServer() throws Exception;
    
    protected abstract void stopServer();

Modified: trunk/tests/src/org/jboss/messaging/core/remoting/impl/invm/test/unit/INVMClientTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/remoting/impl/invm/test/unit/INVMClientTest.java	2007-12-13 15:54:58 UTC (rev 3501)
+++ trunk/tests/src/org/jboss/messaging/core/remoting/impl/invm/test/unit/INVMClientTest.java	2007-12-14 14:25:44 UTC (rev 3502)
@@ -7,9 +7,10 @@
 package org.jboss.messaging.core.remoting.impl.invm.test.unit;
 
 import static org.jboss.messaging.core.remoting.TransportType.INVM;
+import static org.jboss.messaging.core.remoting.impl.mina.integration.test.TestSupport.PORT;
 
-import org.jboss.messaging.core.remoting.Client;
-import org.jboss.messaging.core.remoting.TransportType;
+import org.jboss.messaging.core.remoting.NIOConnector;
+import org.jboss.messaging.core.remoting.ServerLocator;
 import org.jboss.messaging.core.remoting.impl.ClientTestBase;
 import org.jboss.messaging.core.remoting.impl.invm.INVMConnector;
 
@@ -34,15 +35,15 @@
    // ClientTestBase overrides --------------------------------------
    
    @Override
-   protected Client createClient() throws Exception
+   protected NIOConnector createNIOConnector()
    {
-      return new Client(new INVMConnector());
+      return new INVMConnector("localhost", PORT);
    }
    
    @Override
-   protected TransportType getTransport()
+   protected ServerLocator createServerLocator()
    {
-      return INVM;
+      return new ServerLocator(INVM, "localhost", PORT);
    }
    
    @Override

Modified: trunk/tests/src/org/jboss/messaging/core/remoting/impl/mina/integration/test/MinaClientTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/remoting/impl/mina/integration/test/MinaClientTest.java	2007-12-13 15:54:58 UTC (rev 3501)
+++ trunk/tests/src/org/jboss/messaging/core/remoting/impl/mina/integration/test/MinaClientTest.java	2007-12-14 14:25:44 UTC (rev 3502)
@@ -9,8 +9,8 @@
 import static org.jboss.messaging.core.remoting.TransportType.TCP;
 import static org.jboss.messaging.core.remoting.impl.mina.integration.test.TestSupport.PORT;
 
-import org.jboss.messaging.core.remoting.Client;
-import org.jboss.messaging.core.remoting.TransportType;
+import org.jboss.messaging.core.remoting.NIOConnector;
+import org.jboss.messaging.core.remoting.ServerLocator;
 import org.jboss.messaging.core.remoting.impl.ClientTestBase;
 import org.jboss.messaging.core.remoting.impl.mina.MinaConnector;
 import org.jboss.messaging.core.remoting.impl.mina.MinaService;
@@ -39,21 +39,21 @@
    // ClientTestBase overrides --------------------------------------
    
    @Override
-   protected Client createClient() throws Exception
+   protected NIOConnector createNIOConnector()
    {
-      return new Client(new MinaConnector());
+      return new MinaConnector(TCP, "localhost", PORT);
    }
-
+   
    @Override
-   protected TransportType getTransport()
+   protected ServerLocator createServerLocator()
    {
-      return TCP;
+      return new ServerLocator(TCP, "localhost", PORT);
    }
 
    @Override
    protected void startServer() throws Exception
    {
-      service = new MinaService("localhost", PORT);
+      service = new MinaService(TCP, "localhost", PORT);
       service.start();
    }
 

Modified: trunk/tests/src/org/jboss/messaging/core/remoting/test/unit/ClientTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/remoting/test/unit/ClientTest.java	2007-12-13 15:54:58 UTC (rev 3501)
+++ trunk/tests/src/org/jboss/messaging/core/remoting/test/unit/ClientTest.java	2007-12-14 14:25:44 UTC (rev 3502)
@@ -22,6 +22,7 @@
 import org.jboss.messaging.core.remoting.Client;
 import org.jboss.messaging.core.remoting.NIOConnector;
 import org.jboss.messaging.core.remoting.NIOSession;
+import org.jboss.messaging.core.remoting.ServerLocator;
 import org.jboss.messaging.core.remoting.wireformat.NullPacket;
 
 /**
@@ -41,16 +42,18 @@
 
    // Public --------------------------------------------------------
 
+   private ServerLocator serverLocator;
+
    public void testConnected() throws Exception
    {
       NIOConnector connector = createStrictMock(NIOConnector.class);
       NIOSession session1 = createStrictMock(NIOSession.class);
       NIOSession session2 = createStrictMock(NIOSession.class);
       
-      expect(connector.connect("localhost", PORT, TCP)).andReturn(session1);
+      expect(connector.connect()).andReturn(session1);
       expect(connector.disconnect()).andReturn(true);
       
-      expect(connector.connect("localhost", PORT, TCP)).andReturn(session2);
+      expect(connector.connect()).andReturn(session2);
       expect(session2.isConnected()).andReturn(true);
       
       expect(connector.disconnect()).andReturn(true);
@@ -58,12 +61,12 @@
 
       replay(connector, session1, session2);
 
-      Client client = new Client(connector);
-      connector.connect("localhost", PORT, TCP);
+      Client client = new Client(connector, serverLocator);
+      client.connect();
       assertTrue(client.disconnect());
       assertFalse(client.isConnected());
 
-      client.connect("localhost", PORT, TCP);
+      client.connect();
       assertTrue(client.isConnected());
 
       assertTrue(client.disconnect());
@@ -76,15 +79,15 @@
    public void testConnectionFailure() throws Exception
    {
       NIOConnector connector = createStrictMock(NIOConnector.class);
-      expect(connector.connect("localhost", PORT, TCP)).andThrow(new IOException("connection exception"));
+      expect(connector.connect()).andThrow(new IOException("connection exception"));
 
       replay(connector);
 
-      Client client = new Client(connector);
+      Client client = new Client(connector, serverLocator);
       
       try
       {
-         client.connect("localhost", PORT, TCP);
+         client.connect();
          fail("connection must fail");
       } catch (IOException e)
       {
@@ -100,17 +103,17 @@
       NIOConnector connector = createStrictMock(NIOConnector.class);
       NIOSession session = createStrictMock(NIOSession.class);
       
-      expect(connector.connect("localhost", PORT, TCP)).andReturn(session);
+      expect(connector.connect()).andReturn(session);
       expect(session.isConnected()).andReturn(true);
       expect(session.getID()).andReturn(sessionID);
       expect(connector.disconnect()).andReturn(true);
       
       replay(connector, session);
       
-      Client client = new Client(connector);
-
+      Client client = new Client(connector, serverLocator);
+      
       assertNull(client.getSessionID());
-      client.connect("localhost", PORT, TCP);
+      client.connect();
 
       String actualSessionID = client.getSessionID();
       
@@ -128,7 +131,7 @@
       NIOSession session = createStrictMock(NIOSession.class);
       
       expect(connector.getServerURI()).andReturn(null);
-      expect(connector.connect("localhost", PORT, TCP)).andReturn(session);
+      expect(connector.connect()).andReturn(session);
       expect(connector.getServerURI()).andReturn("tcp://localhost:" + PORT);
       expect(connector.disconnect()).andReturn(true);
       expect(connector.getServerURI()).andReturn(null);
@@ -136,10 +139,10 @@
       
       replay(connector, session);
       
-      Client client = new Client(connector);
+      Client client = new Client(connector, serverLocator);
       
       assertNull(client.getURI());
-      client.connect("localhost", PORT, TCP);
+      client.connect();
       assertNotNull(client.getURI());
       client.disconnect();
       assertNull(client.getURI());
@@ -154,7 +157,7 @@
       // connector is not expected to be called at all;
       replay(connector);
       
-      Client client = new Client(connector);
+      Client client = new Client(connector, serverLocator);
       try
       {
          client.sendOneWay(new NullPacket());
@@ -166,4 +169,20 @@
       
       verify(connector);
    }
+   
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      
+      this.serverLocator = new ServerLocator(TCP, "localhost", PORT);
+   }
+   
+   @Override
+   protected void tearDown() throws Exception
+   {
+      serverLocator = null;
+
+      super.tearDown();
+   }
 }

Added: trunk/tests/src/org/jboss/messaging/core/remoting/test/unit/ConnectorRegistryTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/remoting/test/unit/ConnectorRegistryTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/remoting/test/unit/ConnectorRegistryTest.java	2007-12-14 14:25:44 UTC (rev 3502)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.test.unit;
+
+import static org.jboss.messaging.core.remoting.TransportType.INVM;
+import static org.jboss.messaging.core.remoting.TransportType.TCP;
+import static org.jboss.messaging.core.remoting.impl.mina.integration.test.TestSupport.PORT;
+import junit.framework.TestCase;
+
+import org.jboss.messaging.core.remoting.ConnectorRegistry;
+import org.jboss.messaging.core.remoting.NIOConnector;
+import org.jboss.messaging.core.remoting.ServerLocator;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ *
+ * @version <tt>$Revision$</tt>
+ *
+ */
+public class ConnectorRegistryTest extends TestCase
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+   
+   public void testLocatorRegistration() throws Exception
+   {
+      ServerLocator locator = new ServerLocator(TCP, "localhost", PORT);
+      
+      assertTrue(ConnectorRegistry.register(locator));
+      assertFalse(ConnectorRegistry.register(locator));
+      
+      assertTrue(ConnectorRegistry.unregister(locator));
+      assertFalse(ConnectorRegistry.unregister(locator));
+
+      assertTrue(ConnectorRegistry.register(locator));
+      assertTrue(ConnectorRegistry.unregister(locator));
+   }
+   
+   public void testINVMConnectorFromTCPLocator() throws Exception
+   {
+      ServerLocator locator = new ServerLocator(TCP, "localhost", PORT);
+      
+      // locator is registered -> client and server are in the same vm
+      assertTrue(ConnectorRegistry.register(locator));
+      
+      NIOConnector connector = ConnectorRegistry.get(locator);
+      
+      assertTrue(connector.getServerURI().startsWith(INVM.toString()));
+      
+      assertTrue(ConnectorRegistry.unregister(locator));
+   }
+   
+   
+   public void testTCPConnectorFromTCPLocator() throws Exception
+   {
+      ServerLocator locator = new ServerLocator(TCP, "localhost", PORT);
+      
+      // locator is not registered -> client and server are not in the same vm
+      
+      NIOConnector connector = ConnectorRegistry.get(locator);
+      
+      assertNotNull(connector);
+      assertEquals(locator.getURI(), connector.getServerURI());
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}

Added: trunk/tests/src/org/jboss/messaging/core/remoting/test/unit/ServerLocatorTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/remoting/test/unit/ServerLocatorTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/remoting/test/unit/ServerLocatorTest.java	2007-12-14 14:25:44 UTC (rev 3502)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.test.unit;
+
+import static org.jboss.messaging.core.remoting.TransportType.HTTP;
+import static org.jboss.messaging.core.remoting.TransportType.INVM;
+import static org.jboss.messaging.core.remoting.TransportType.TCP;
+
+import java.net.URISyntaxException;
+
+import junit.framework.TestCase;
+
+import org.jboss.messaging.core.remoting.ServerLocator;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ * 
+ */
+public class ServerLocatorTest extends TestCase
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   public void testUnknownTransport() throws Exception
+   {
+      try
+      {
+         new ServerLocator("whatever://localhost:9090");
+         fail("whatever is not a supported transport type");
+      } catch (URISyntaxException e)
+      {
+
+      }
+   }
+
+   public void testTCPTransport() throws Exception
+   {
+      ServerLocator locator = new ServerLocator(
+            "tcp://localhost:9090");
+
+      assertEquals(TCP, locator.getTransport());
+      assertEquals("localhost", locator.getHost());
+      assertEquals(9090, locator.getPort());
+   }
+
+   public void testHTTPTransport() throws Exception
+   {
+      ServerLocator locator = new ServerLocator(
+            "http://localhost:9090");
+
+      assertEquals(HTTP, locator.getTransport());
+      assertEquals("localhost", locator.getHost());
+      assertEquals(9090, locator.getPort());
+   }
+
+   public void testINVMTransport() throws Exception
+   {
+      ServerLocator locator = new ServerLocator(
+            "invm://localhost:9090");
+
+      assertEquals(INVM, locator.getTransport());
+      assertEquals("localhost", locator.getHost());
+      assertEquals(9090, locator.getPort());
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}

Modified: trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/PacketTypeTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/PacketTypeTest.java	2007-12-13 15:54:58 UTC (rev 3501)
+++ trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/PacketTypeTest.java	2007-12-14 14:25:44 UTC (rev 3502)
@@ -542,9 +542,9 @@
       // FIXME should use mock objects with a correct interface
       ClientConnectionFactoryDelegate[] delegates = new ClientConnectionFactoryDelegate[] {
             new ClientConnectionFactoryDelegate(randomString(), randomString(),
-                  23, randomString(), randomInt(), Version.instance(), false, true),
+                  23, randomString(), Version.instance(), false, true),
             new ClientConnectionFactoryDelegate(randomString(), randomString(),
-                  33, randomString(), randomInt(), Version.instance(), true, false) };
+                  33, randomString(), Version.instance(), true, false) };
       TopologyResult topology = new TopologyResult(randomString(), delegates,
             new HashMap());
       GetTopologyResponse response = new GetTopologyResponse(topology);




More information about the jboss-cvs-commits mailing list