CVS update: JGroups/src/org/jgroups/protocols STOMP.java

"Bela Ban" <[email protected]> Wed, 27 Oct 2010 10:52:07 +0000
Newsgroups gmane.comp.java.javagroups.cvs
Message-ID <[email protected]>
  User: belaban 
  Date: 10/10/27 10:52:07

  Modified:    src/org/jgroups/protocols STOMP.java
  Log:
  added bind_addr
  
  Revision  Changes    Path
  1.21      +19 -9     JGroups/src/org/jgroups/protocols/STOMP.java
  
  Index: STOMP.java
  ===================================================================
  RCS file: /cvsroot/javagroups/JGroups/src/org/jgroups/protocols/STOMP.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- STOMP.java	27 Oct 2010 09:25:02 -0000	1.20
  +++ STOMP.java	27 Oct 2010 10:52:07 -0000	1.21
  @@ -10,10 +10,7 @@
   import java.io.DataOutputStream;
   import java.io.EOFException;
   import java.io.IOException;
  -import java.net.InetAddress;
  -import java.net.ServerSocket;
  -import java.net.Socket;
  -import java.net.SocketException;
  +import java.net.*;
   import java.nio.ByteBuffer;
   import java.util.*;
   import java.util.concurrent.ConcurrentMap;
  @@ -29,14 +26,22 @@
    * todo: add PING to test health of client connections
    * <p/> 
    * @author Bela Ban
  - * @version $Id: STOMP.java,v 1.20 2010/10/27 09:25:02 belaban Exp $
  + * @version $Id: STOMP.java,v 1.21 2010/10/27 10:52:07 belaban Exp $
    * @since 2.11
    */
  -@MBean
  +@MBean(description="Server side STOPM protocol, STOMP clients can connect to it")
   @Experimental @Unsupported
   public class STOMP extends Protocol implements Runnable {
   
       /* -----------------------------------------    Properties     ----------------------------------------------- */
  +
  +    @Property(name="bind_addr",
  +              description="The bind address which should be used by the server socket. The following special values " +
  +                      "are also recognized: GLOBAL, SITE_LOCAL, LINK_LOCAL and NON_LOOPBACK",
  +              defaultValueIPv4="0.0.0.0", defaultValueIPv6="::",
  +              systemProperty={Global.STOMP_BIND_ADDR},writable=false)
  +    protected InetAddress bind_addr=null;
  +
       @Property(description="Port on which the STOMP protocol listens for requests",writable=false)
       protected int port=8787;
   
  @@ -90,7 +95,7 @@
   
       public void start() throws Exception {
           super.start();
  -        srv_sock=Util.createServerSocket(getSocketFactory(), Global.STOMP_SRV_SOCK, port);
  +        srv_sock=Util.createServerSocket(getSocketFactory(), Global.STOMP_SRV_SOCK, bind_addr, port);
           if(log.isDebugEnabled())
               log.debug("server socket listening on " + srv_sock.getLocalSocketAddress());
   
  @@ -100,7 +105,7 @@
               acceptor.start();
           }
   
  -        endpoint=getAddress(srv_sock.getLocalPort());
  +        endpoint=getAddress();
       }
   
   
  @@ -290,7 +295,12 @@
           }
       }
   
  -    private static String getAddress(int port) {
  +    private String getAddress() {
  +        InetSocketAddress saddr=(InetSocketAddress)srv_sock.getLocalSocketAddress();
  +        InetAddress tmp=saddr.getAddress();
  +        if(!tmp.isAnyLocalAddress())
  +            return tmp.getHostAddress() + ":" + srv_sock.getLocalPort();
  +
           for(Util.AddressScope scope: Util.AddressScope.values()) {
               try {
                   InetAddress addr=Util.getAddress(scope);
  
  
  

------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store 
http://p.sf.net/sfu/nokia-dev2dev