org.jgroups.blocks

Class Link

Implemented Interfaces:
Runnable

public class Link
extends java.lang.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

static interface
Link.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, long timeout, long hb_interval, Link.Receiver r)
Link(String local_addr, int local_port, String remote_addr, int remote_port, Link.Receiver r)

Method Summary

boolean
equals(Object other)
boolean
established()
InetAddress
getLocalAddress()
int
getLocalPort()
InetAddress
getRemoteAddress()
int
getRemotePort()
int
hashCode()
static void
main(String[] args)
void
run()
Receiver thread main loop.
boolean
send(byte[] buf)
Tries to send buffer across out socket.
void
setReceiver(Link.Receiver r)
void
setTrace(boolean t)
void
start()
void
stop()
String
toString()

Constructor Details

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,
            long timeout,
            long hb_interval,
            Link.Receiver r)

Link

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

Method Details

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()
            throws Exception

stop

public void stop()

toString

public String toString()

Copyright B) 1998-2005 Bela Ban. All Rights Reserved.