directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r160253 - in directory/network/trunk/src: examples/org/apache/mina/examples/registry/Main.java java/org/apache/mina/registry/Service.java java/org/apache/mina/registry/SimpleServiceRegistry.java
Date Wed, 06 Apr 2005 05:18:33 GMT
Author: trustin
Date: Tue Apr  5 22:18:31 2005
New Revision: 160253

URL: http://svn.apache.org/viewcvs?view=rev&rev=160253
Log:
Fixed: Users cannot specify the interface to bind on to ServiceRegistry.

Modified:
    directory/network/trunk/src/examples/org/apache/mina/examples/registry/Main.java
    directory/network/trunk/src/java/org/apache/mina/registry/Service.java
    directory/network/trunk/src/java/org/apache/mina/registry/SimpleServiceRegistry.java

Modified: directory/network/trunk/src/examples/org/apache/mina/examples/registry/Main.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/registry/Main.java?view=diff&r1=160252&r2=160253
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/registry/Main.java (original)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/registry/Main.java Tue Apr
 5 22:18:31 2005
@@ -3,9 +3,12 @@
  */
 package org.apache.mina.examples.registry;
 
+import java.net.InetSocketAddress;
+
 import org.apache.mina.common.TransportType;
 import org.apache.mina.examples.echoserver.EchoProtocolHandler;
 import org.apache.mina.examples.reverser.ReverseProtocolProvider;
+import org.apache.mina.protocol.vmpipe.VmPipeAddress;
 import org.apache.mina.registry.Service;
 import org.apache.mina.registry.ServiceRegistry;
 import org.apache.mina.registry.SimpleServiceRegistry;
@@ -26,20 +29,27 @@
         ServiceRegistry registry = new SimpleServiceRegistry();
 
         // Register echo service
-        registry.bind( new Service( "echo", TransportType.SOCKET, 8080 ),
-                new EchoProtocolHandler() );
-        registry.bind( new Service( "echo", TransportType.DATAGRAM, 8080 ),
-                new EchoProtocolHandler() );
+        registry.bind( new Service( "echo", TransportType.SOCKET,
+                                    new InetSocketAddress( 8080 ) ),
+                       new EchoProtocolHandler() );
+
+        registry.bind( new Service( "echo", TransportType.DATAGRAM,
+                                    new InetSocketAddress( 8080 ) ),
+                       new EchoProtocolHandler() );
 
         // Register reverse service
-        registry.bind( new Service( "reverse", TransportType.SOCKET, 8081 ),
-                new ReverseProtocolProvider() );
-        registry.bind(
-                new Service( "reverse", TransportType.DATAGRAM, 8081 ),
-                new ReverseProtocolProvider() );
-        registry.bind( new Service( "reverse", TransportType.VM_PIPE, 8081 ),
-                new ReverseProtocolProvider() );
+        registry.bind( new Service( "reverse", TransportType.SOCKET,
+                                    new InetSocketAddress( 8081 ) ),
+                       new ReverseProtocolProvider() );
+
+        registry.bind( new Service( "reverse", TransportType.DATAGRAM,
+                                    new InetSocketAddress( 8081 ) ),
+                       new ReverseProtocolProvider() );
+
+        registry.bind( new Service( "reverse", TransportType.VM_PIPE,
+                                    new VmPipeAddress( 8081 ) ),
+                       new ReverseProtocolProvider() );
         
-        System.out.println(registry.getAllServices());
+        System.out.println( registry.getAllServices() );
     }
 }

Modified: directory/network/trunk/src/java/org/apache/mina/registry/Service.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/registry/Service.java?view=diff&r1=160252&r2=160253
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/registry/Service.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/registry/Service.java Tue Apr  5 22:18:31
2005
@@ -19,8 +19,10 @@
 package org.apache.mina.registry;
 
 import java.io.Serializable;
+import java.net.SocketAddress;
 
 import org.apache.mina.common.TransportType;
+import org.apache.mina.protocol.vmpipe.VmPipeAddress;
 
 /**
  * Represents a service that is registered to {@link ServiceRegistry}.
@@ -36,24 +38,31 @@
 
     private final TransportType transportType;
 
-    private final int port;
+    private final SocketAddress address;
 
     /**
      * Creates a new instance with the specified protocol name, transport type,
-     * and port number.
+     * and socket address to be bound.
      */
-    public Service( String name, TransportType transportType, int port )
+    public Service( String name, TransportType transportType, SocketAddress address )
     {
         if( name == null )
             throw new NullPointerException( "name" );
         if( transportType == null )
             throw new NullPointerException( "transportType" );
-        if( port < 0 || port > 65535 )
-            throw new IllegalArgumentException( "port: " + port );
+        if( address == null )
+            throw new NullPointerException( "address" );
+
+        if( transportType == TransportType.VM_PIPE &&
+            !( address instanceof VmPipeAddress ) )
+        {
+            throw new IllegalArgumentException(
+                    "VM_PIPE transport type accepts only VmPipeAddress: " + address.getClass()
);
+        }
 
         this.name = name;
         this.transportType = transportType;
-        this.port = port;
+        this.address = address;
     }
 
     /**
@@ -73,17 +82,17 @@
     }
 
     /**
-     * Returns the port number this service is bound on.
+     * Returns the socket address this service is bound on.
      */
-    public int getPort()
+    public SocketAddress getAddress()
     {
-        return port;
+        return address;
     }
 
     public int hashCode()
     {
         return ( ( name.hashCode() * 37 ) ^ transportType.hashCode() * 37 )
-                ^ port;
+                ^ address.hashCode();
     }
 
     public boolean equals( Object o )
@@ -98,7 +107,7 @@
         Service that = ( Service ) o;
         return this.name.equals( that.name )
                 && this.transportType == that.transportType
-                && this.port == that.port;
+                && this.address.equals( that.address );
     }
 
     public Object clone()
@@ -114,6 +123,6 @@
     }
     
     public String toString() {
-        return "(" + transportType + ", " + name + ", " + port + ')';
+        return "(" + transportType + ", " + name + ", " + address + ')';
     }
 }

Modified: directory/network/trunk/src/java/org/apache/mina/registry/SimpleServiceRegistry.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/registry/SimpleServiceRegistry.java?view=diff&r1=160252&r2=160253
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/registry/SimpleServiceRegistry.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/registry/SimpleServiceRegistry.java Tue
Apr  5 22:18:31 2005
@@ -5,6 +5,7 @@
 
 import java.io.IOException;
 import java.net.InetSocketAddress;
+import java.net.SocketAddress;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
@@ -66,7 +67,7 @@
             throws IOException
     {
         IoAcceptor acceptor = findIoAcceptor( service.getTransportType() );
-        acceptor.bind( new InetSocketAddress( service.getPort() ), ioHandler );
+        acceptor.bind( service.getAddress(), ioHandler );
         startThreadPools();
         services.add( service );
     }
@@ -77,16 +78,7 @@
     {
         ProtocolAcceptor acceptor = findProtocolAcceptor( service
                 .getTransportType() );
-        if( acceptor instanceof VmPipeAcceptor )
-        {
-            acceptor.bind( new VmPipeAddress( service.getPort() ),
-                    protocolProvider );
-        }
-        else
-        {
-            acceptor.bind( new InetSocketAddress( service.getPort() ),
-                    protocolProvider );
-        }
+        acceptor.bind( service.getAddress(), protocolProvider );
         startThreadPools();
         services.add( service );
     }
@@ -97,7 +89,7 @@
                 .getTransportType() );
         try
         {
-            acceptor.unbind( new InetSocketAddress( service.getPort() ) );
+            acceptor.unbind( service.getAddress() );
         }
         catch( Exception e )
         {
@@ -106,7 +98,7 @@
         
         try
         {
-            acceptor.unbind( new VmPipeAddress( service.getPort() ) );
+            acceptor.unbind( service.getAddress() );
         }
         catch( Exception e )
         {
@@ -167,7 +159,23 @@
         while( it.hasNext() )
         {
             Service s = ( Service ) it.next();
-            if( s.getPort() == port )
+            SocketAddress addr = ( SocketAddress ) s.getAddress();
+            int servicePort;
+            
+            if( addr instanceof InetSocketAddress )
+            {
+                servicePort = ( ( InetSocketAddress ) addr ).getPort();
+            }
+            else if( addr instanceof VmPipeAddress )
+            {
+                servicePort = ( ( VmPipeAddress ) addr ).getPort();
+            }
+            else
+            {
+                servicePort = -1; // this cannot happen 
+            }
+            
+            if( servicePort == port )
             {
                 result.add( s );
             }



Mime
View raw message