org.jgroups.stack
Class RouterStub

java.lang.Object
  extended byorg.jgroups.stack.RouterStub

public class RouterStub
extends java.lang.Object


Field Summary
protected static org.apache.commons.logging.Log log
           
 
Constructor Summary
RouterStub(java.lang.String router_host, int router_port)
          Creates a stub for a remote Router object.
 
Method Summary
 Address connect()
          Establishes a connection to the router.
 void disconnect()
          Closes the socket and the input and output streams associated with it
 List get(java.lang.String groupname)
          Retrieves the membership (list of Addresses) for a given group.
 boolean isConnected()
           
static void main(java.lang.String[] args)
           
 Message receive()
          Receives a message from the router (blocking mode).
 boolean reconnect()
           
 boolean reconnect(int max_attempts)
          Tries to establish connection to router.
 boolean register(java.lang.String groupname)
          Register this process with the router under groupname.
 boolean send(Message msg, java.lang.String groupname)
          Sends a message to the router.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final org.apache.commons.logging.Log log
Constructor Detail

RouterStub

public RouterStub(java.lang.String router_host,
                  int router_port)
Creates a stub for a remote Router object.

Parameters:
router_host - The name of the router's host
router_port - The router's port
Method Detail

isConnected

public boolean isConnected()

connect

public Address connect()
                throws java.lang.Exception
Establishes a connection to the router. The router will send my address (its peer address) back as an Address, which is subsequently returned to the caller. The reason for not using InetAddress.getLocalHost() or sock.getLocalAddress() is that this may not be permitted with certain security managers (e.g if this code runs in an applet). Also, some network address translation (NAT) (e.g IP Masquerading) may return the wrong address.

Throws:
java.lang.Exception

disconnect

public void disconnect()
Closes the socket and the input and output streams associated with it


register

public boolean register(java.lang.String groupname)
Register this process with the router under groupname.

Parameters:
groupname - The name of the group under which to register
Returns:
boolean False if connection down, true if registration successful.

get

public List get(java.lang.String groupname)
Retrieves the membership (list of Addresses) for a given group. This is mainly used by the PING protocol to obtain its initial membership. This is used infrequently, so don't maintain socket for the entire time, but create/delete it on demand.


send

public boolean send(Message msg,
                    java.lang.String groupname)
Sends a message to the router. Returns false if message cannot be sent (e.g. no connection to router, true otherwise.


receive

public Message receive()
Receives a message from the router (blocking mode). If the connection is down, false is returned, otherwise true


reconnect

public boolean reconnect(int max_attempts)
Tries to establish connection to router. Tries until router is up again.


reconnect

public boolean reconnect()

main

public static void main(java.lang.String[] args)


Copyright ? 1998-2005 Bela Ban. All Rights Reserved.