com.cloudtran.replicator.link
Class LoopbackProvider

java.lang.Object
  extended by com.cloudtran.replicator.link.AbstractLinkProvider
      extended by com.cloudtran.replicator.link.LoopbackProvider
All Implemented Interfaces:
LinkProvider

public class LoopbackProvider
extends AbstractLinkProvider

This class is never going to run for real. All it does is allow us to test the path from the MEL event back to putting into the grid. It will run on the same box and then just duplicate the puts into the grid and the persistence (which will happen twice). It is possible to have multiple LoopbackProviders across different DCConnections, but it doesn't make sense to have more than one LoopbackProvider per DCConnection.


Constructor Summary
LoopbackProvider()
           
 
Method Summary
 void connect()
          This call is issued at start of day or after a crash on the other side causes our link to go down.
static byte[] copy(byte[] src, int offset)
          Copies bytes from a source byte array into a new byte array.
static byte[] copy(byte[] src, int offset, int length)
          Copies bytes from a source byte array into a new byte array.
static void copy(byte[] src, int srcOffset, int length, byte[] dst, int dstOffset)
          Copies a part of a byte array into another byte array.
 void receiveBytes(byte[] array, int offset, int len)
          This is a request to read 'len' bytes bytes.
 void reset()
          This method resets the link, i.e.
 void sendBytes(byte[] array, int offset, int len)
          The sendBytes method writes out from a byte array.
 String toString()
           
 
Methods inherited from class com.cloudtran.replicator.link.AbstractLinkProvider
deserialize, getLocalDataCentreName, getRemoteDataCentreName, serialize, setLink, signalL2Connected, test
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LoopbackProvider

public LoopbackProvider()
Method Detail

toString

public String toString()
Overrides:
toString in class Object

reset

public void reset()
Description copied from interface: LinkProvider
This method resets the link, i.e. disconnects. It is issued at start of day, when the link is signalled down, when another Link in the DcConnection connects, or after a crash on the other side. ... Or when the connection is reopened, so it needs to handle redundant calls. This method is called from the DCConnection; it shouldn't be called by the LinkProvider implementer.


connect

public void connect()
Description copied from interface: LinkProvider
This call is issued at start of day or after a crash on the other side causes our link to go down. This is executed synchronously by the DCConnection. The LinkProvider should normally poll the connection on an asynchronous thread, because the connection establishment at one end must wait for the other data center to start. When the link is connected, the provider signals back to the link's signalL2Connected() method, which the sends 'prod_L2UP' into the DCconnection FSM.


sendBytes

public void sendBytes(byte[] array,
                      int offset,
                      int len)
Description copied from interface: LinkProvider
The sendBytes method writes out from a byte array. It must be thread-safe: if necessary, add 'synchronized' on the implementation If the link is down or there is a problem with the underlying connection, the IOException is thrown. The caller should call FSM(prod_L2Down) to reset the link and the FSM. (This method cannot do that itself, because it may be called inside an FSM action itself and would deadlock on the FSM synchronization.)


receiveBytes

public void receiveBytes(byte[] array,
                         int offset,
                         int len)
This is a request to read 'len' bytes bytes. There must be enough space in array to hold the data - assert( array.length >= (offset+len) )


copy

public static void copy(byte[] src,
                        int srcOffset,
                        int length,
                        byte[] dst,
                        int dstOffset)
Copies a part of a byte array into another byte array.

Parameters:
src - The source byte array.
srcOffset - Offset in the source byte array.
length - The number of bytes to copy.
dst - The destination byte array.
dstOffset - Offset in the destination byte array.

copy

public static byte[] copy(byte[] src,
                          int offset,
                          int length)
Copies bytes from a source byte array into a new byte array.

Parameters:
src - Copy from this byte array.
offset - Start copying here.
length - Copy this many bytes.
Returns:
The new byte array. Its length is number of copied bytes.

copy

public static byte[] copy(byte[] src,
                          int offset)
Copies bytes from a source byte array into a new byte array.

Parameters:
src - Copy from this byte array.
offset - Start copying here.
Returns:
The new byte array. Its length is number of copied bytes.