org.jgroups.blocks
Class Link
java.lang.Object
org.jgroups.blocks.Link
- All Implemented Interfaces:
- java.lang.Runnable
- public class Link
- extends java.lang.Object
- implements java.lang.Runnable
Implements a physical link between 2 parties (point-to-point connection). For incoming traffic,
a server socket is created (bound to a given local address and port). The receiver thread does the
following: it accepts a new connection from the server socket and (on the same thread) reads messages
until the connection breaks. Then it goes back to accept(). This is done in 2 nested while-loops.
The outgoing connection is established when started. If this fails, the link is marked as not established.
This means that there is not outgoing socket.
A heartbeat will be exchanged between the 2 peers periodically as long as the connection is established
(outgoing socket is okay). When the connection breaks, the heartbeat will stop and a connection establisher
thread will be started. It periodically tries to re-establish connection to the peer. When this happens
it will stop and the heartbeat thread will resume.
For details see Link.txt
- Author:
- Bela Ban, June 2000
Constructor Summary |
Link(java.lang.String local_addr,
int local_port,
java.lang.String remote_addr,
int remote_port)
|
Link(java.lang.String local_addr,
int local_port,
java.lang.String remote_addr,
int remote_port,
Link.Receiver r)
|
Link(java.lang.String local_addr,
int local_port,
java.lang.String remote_addr,
int remote_port,
long timeout,
long hb_interval,
Link.Receiver r)
|
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Link
public Link(java.lang.String local_addr,
int local_port,
java.lang.String remote_addr,
int remote_port)
Link
public Link(java.lang.String local_addr,
int local_port,
java.lang.String remote_addr,
int remote_port,
Link.Receiver r)
Link
public Link(java.lang.String local_addr,
int local_port,
java.lang.String remote_addr,
int remote_port,
long timeout,
long hb_interval,
Link.Receiver r)
setTrace
public void setTrace(boolean t)
setReceiver
public void setReceiver(Link.Receiver r)
established
public boolean established()
getLocalAddress
public java.net.InetAddress getLocalAddress()
getRemoteAddress
public java.net.InetAddress getRemoteAddress()
getLocalPort
public int getLocalPort()
getRemotePort
public int getRemotePort()
start
public void start()
throws java.lang.Exception
- Throws:
java.lang.Exception
stop
public void stop()
send
public boolean send(byte[] buf)
- Tries to send buffer across out socket. Tries to establish connection if not yet connected.
run
public void run()
- Receiver thread main loop. Accept a connection and then read on it until the connection
breaks. Only then is the next connection handled. The reason is that there is only supposed
to be 1 connection to this server socket at the same time.
- Specified by:
run
in interface java.lang.Runnable
toString
public java.lang.String toString()
equals
public boolean equals(java.lang.Object other)
hashCode
public int hashCode()
main
public static void main(java.lang.String[] args)
Copyright ? 2001,2002 www.jgroups.com . All Rights Reserved.