org.jgroups.blocks

Class Link

public class Link extends Object implements 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

Nested Class Summary
interfaceLink.Receiver
Constructor Summary
Link(String local_addr, int local_port, String remote_addr, int remote_port)
Link(String local_addr, int local_port, String remote_addr, int remote_port, Link.Receiver r)
Link(String local_addr, int local_port, String remote_addr, int remote_port, long timeout, long hb_interval, Link.Receiver r)
Method Summary
booleanequals(Object other)
booleanestablished()
InetAddressgetLocalAddress()
intgetLocalPort()
InetAddressgetRemoteAddress()
intgetRemotePort()
inthashCode()
static voidmain(String[] args)
voidrun()
Receiver thread main loop.
booleansend(byte[] buf)
Tries to send buffer across out socket.
voidsetReceiver(Link.Receiver r)
voidsetTrace(boolean t)
voidstart()
voidstop()
StringtoString()
This piece of code would only accept connections from the peer address defined above.

Constructor Detail

Link

public Link(String local_addr, int local_port, String remote_addr, int remote_port)

Link

public Link(String local_addr, int local_port, String remote_addr, int remote_port, Link.Receiver r)

Link

public Link(String local_addr, int local_port, String remote_addr, int remote_port, long timeout, long hb_interval, Link.Receiver r)

Method Detail

equals

public boolean equals(Object other)

established

public boolean established()

getLocalAddress

public InetAddress getLocalAddress()

getLocalPort

public int getLocalPort()

getRemoteAddress

public InetAddress getRemoteAddress()

getRemotePort

public int getRemotePort()

hashCode

public int hashCode()

main

public static void main(String[] args)

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.

send

public boolean send(byte[] buf)
Tries to send buffer across out socket. Tries to establish connection if not yet connected.

setReceiver

public void setReceiver(Link.Receiver r)

setTrace

public void setTrace(boolean t)

start

public void start()

stop

public void stop()

toString

public String toString()
This piece of code would only accept connections from the peer address defined above.
Copyright ? 1998-2005 Bela Ban. All Rights Reserved.