com.cloudtran.replicator.isolator
Class DCConnection

java.lang.Object
  extended by com.cloudtran.replicator.isolator.DCConnection

public class DCConnection
extends Object

 Overview of DCConnection.

 This is in support of the Replicator service in the Isolator instance.
 There will typically be up to three Isolator instances at each end.

 LinkListener
    implemented by the calling object - so typically 'this' on the init() call below
    connectionClosed() - callback; connection to the other replicator instance has been lost.
          This callback is not used when the caller uses DCConnectionManager.disconnect().

 DCConnectionManager - the single point for sending to the other end.
                     The caller should instantiate one of these at start of day.
                     It organises the logical connection to a remote replicator service.
     init( Object[], LinkListener )
         startofday initialisation.  The objects in the passed array are
         protocol-specific end-points, for use by the underlying comms package.
         If there are three isolator instances at the remote data center, there should
           be three objects in the Object[] array.
         This call constructs the Link objects below but then returns quickly.

     LinkedBlockingQueue[4] connect()
         An isolator instance calls this when it is elected as "the one" for the replicator service
         This should be called at start of day, to find "the [first] one",
         or after a link goes down, to find "the [next] one".
         When this is successfully connected, it returns four LinkedBlockingQueues in this order:
           [0] receiveDataQueue;    // data for us to backup in our grid comes in here
           [1] dccOutboundAckQueue; // when we have committed backup data, we send the ACK here
           [2] sendPacketQueue;     // we send data to the other DC here
           [3] inboundAckQueue;     // when the remote end has dealt with the data, he sends an
                                    // ACK which ends up here
         The caller then interacts directly with these queues for normal work:
         there are no more calls require until the logical link is disconnected().

         The user of the DCConnectionManager doesn't have to worry about which Link is in use.

 Link - the path to one remote instance.
      The Manager starts a new thread to run each Link object.
      When one of the Links successfully connects, the threads calling into the other
         Links are destroyed.
      This reflects the overall design that there is only one Isolator instance
      elected to provider the replicator service.

      connectionClosed()
         This is a callback from the LinkSingleConnection to say that the connection closed.

      disconnect() - I don't think we need to do this.  The other end will signal when it is down.
         We normally keep the replicator up for the lifetime of the grid.

 LinkSingleConnection
     provides a wire connection to the other end.
     The particular connection technology must implement this.
     THIS MUST SUPPORT TWO CHANNELS, with data flowing in each direction on both channels.

     The LinkSingleConnection is established once at start of day.

     LinkedBlockingQueue[4] connect( Object connectionDetails, Link caller ) - connect to the other end.
        The returned LBQ's are the same as for DCConnectionManager.
        If no connection is available, the method can throw an exception or just hang.
        Only one of all the remote links will connect - because only one Isolator at a time
        is elected to run the replicator service.
        The caller object is passed in.  When the link goes down, the LinkSingleConnection
        calls to the connectionClosed() method.

 ================================================

 DCConnectionManager class proves the public API to a group of DCConnectionManagers.

 Each Link instance on a given isolator instance tries to connect to all the
 isolators in the remote data center.

 At start of day, the configure() method is called with the array of Links representing the available links.
 


Nested Class Summary
 class DCConnection.LinkProviderReceiveThread
           
 
Field Summary
static boolean dcIsPassive
           
static DCConnState desiredState
           
static boolean left
           
static HashMap<Integer,Prod> mapMsgtypeToProd
           
static int MAX_PACKETS_PER_R2M_INVOCATION
           
static int maxUnackedPackets
           
 AtomicLong myTxSeqNum_LastSent
           
 AtomicLong myTxSeqNum_LastSentToSSD
           
static int NPRODS
           
 LinkedBlockingQueue<ReplicatorPacket[]> outboundRequestQueue
           
static Prod prod_cmdL2Connect
           
static Prod prod_cmdL2Down
           
static Prod prod_cmdPause
           
static Prod prod_cmdResynch
           
static Prod prod_cmdStop
           
static Prod prod_L2DataErr
           
static Prod prod_L2Down
           
static Prod prod_L2UP
           
static Prod prod_msgDATAFLOW
           
static Prod prod_msgPAUSED
           
static Prod prod_msgREPLICATORPACKET
           
static Prod prod_msgRESYNCHPREPARE
           
static Prod prod_msgRESYNCHREADY
           
static Prod prod_msgSTOPPED
           
static Prod prod_msgZPACKET
           
 LinkedBlockingQueue<ReplicatorPacket> sendFromLocalStoreQueue
           
static DCConnState state_DataFlow
           
static DCLinkState state_L2Down
          Overview: 1.
static DCConnState state_Paused
           
static DCLinkState state_ResynchWait
           
static DCConnState state_Stopped
           
static int toManagerThreadCount
           
 Long txSeqNum_BeforeRunningDownSendQueue
           
 boolean txToBuffer_goingUp
           
static int txToBuffer_HighWaterMark
           
static int txToBuffer_LowWaterMark
           
 
Method Summary
 DCBaseState FSM(Prod prod)
          To make a recursive call into the FSM, use FSMInner - because spinlocks are already held
 DCBaseState FSM(Prod prod, Object extraData)
           
static DCConnection getDefaultDC()
           
static boolean isLessThanUnsigned(long n1, long n2)
           
 void kickStartPacketsFromSSD()
           
 void linkDown(Link link)
          A link owned by this DCConnection has gone down.
 void resynch()
           
 void resynch(String sDesiredState)
           
 void sendControlBufferFromFSM(int messageType)
           
 void sendPackets(ReplicatorOutboundRequest requestFromManager)
           
static DCConnState setDesiredState(String sDesiredState)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dcIsPassive

public static final boolean dcIsPassive

maxUnackedPackets

public static final int maxUnackedPackets

desiredState

public static DCConnState desiredState

left

public static boolean left

outboundRequestQueue

public LinkedBlockingQueue<ReplicatorPacket[]> outboundRequestQueue

sendFromLocalStoreQueue

public LinkedBlockingQueue<ReplicatorPacket> sendFromLocalStoreQueue

txToBuffer_HighWaterMark

public static final int txToBuffer_HighWaterMark

txToBuffer_LowWaterMark

public static final int txToBuffer_LowWaterMark

txToBuffer_goingUp

public boolean txToBuffer_goingUp

txSeqNum_BeforeRunningDownSendQueue

public Long txSeqNum_BeforeRunningDownSendQueue

myTxSeqNum_LastSentToSSD

public AtomicLong myTxSeqNum_LastSentToSSD

myTxSeqNum_LastSent

public AtomicLong myTxSeqNum_LastSent

toManagerThreadCount

public static final int toManagerThreadCount

MAX_PACKETS_PER_R2M_INVOCATION

public static int MAX_PACKETS_PER_R2M_INVOCATION

state_L2Down

public static DCLinkState state_L2Down
Overview: 1. Link is initially L2Down. 2. Link comes up. 3. New state is resynching. 4. First message in resynching state is the msgRESYNCHDETAILS, containing my firstTxIdSeqNum and nPackets (to transmit). 5. Subsequent messages in resynching state are dataflow, till each side has resynched. 6. Each side sends the ResynchComplete message when it has sent everything it wants and received everything it is expecting. 7. The next state depends on the scenario: For a passive DC, the next state will be IPaused. For an active DC, it will be DataFlow. You will also be able to stop. 8. Until we reach IPaused or DataFlow, the Managers will signal 'busy', so no outside requests will be allowed. Exchange ResyncReq, startTxSeqNum and nPackets to resynch.


state_ResynchWait

public static DCLinkState state_ResynchWait

state_DataFlow

public static DCConnState state_DataFlow

state_Paused

public static DCConnState state_Paused

state_Stopped

public static DCConnState state_Stopped

prod_cmdL2Down

public static Prod prod_cmdL2Down

prod_L2Down

public static Prod prod_L2Down

prod_cmdL2Connect

public static Prod prod_cmdL2Connect

prod_L2UP

public static Prod prod_L2UP

prod_cmdResynch

public static Prod prod_cmdResynch

prod_msgRESYNCHPREPARE

public static Prod prod_msgRESYNCHPREPARE

prod_msgRESYNCHREADY

public static Prod prod_msgRESYNCHREADY

prod_msgDATAFLOW

public static Prod prod_msgDATAFLOW

prod_cmdPause

public static Prod prod_cmdPause

prod_msgPAUSED

public static Prod prod_msgPAUSED

prod_cmdStop

public static Prod prod_cmdStop

prod_msgSTOPPED

public static Prod prod_msgSTOPPED

prod_L2DataErr

public static Prod prod_L2DataErr

prod_msgREPLICATORPACKET

public static Prod prod_msgREPLICATORPACKET

prod_msgZPACKET

public static Prod prod_msgZPACKET

NPRODS

public static final int NPRODS
See Also:
Constant Field Values

mapMsgtypeToProd

public static HashMap<Integer,Prod> mapMsgtypeToProd
Method Detail

FSM

public DCBaseState FSM(Prod prod)
To make a recursive call into the FSM, use FSMInner - because spinlocks are already held


FSM

public DCBaseState FSM(Prod prod,
                       Object extraData)

linkDown

public void linkDown(Link link)
A link owned by this DCConnection has gone down. If the DCConnection is still trying to get a link up, it is worth sending it in again. If the link is connected at L2 (i.e. the link is the connectedLink) then we're doomed - signal L2Down Otherwise, we have the connectedLink going, so we can ignore it


sendControlBufferFromFSM

public void sendControlBufferFromFSM(int messageType)

sendPackets

public void sendPackets(ReplicatorOutboundRequest requestFromManager)

kickStartPacketsFromSSD

public void kickStartPacketsFromSSD()

getDefaultDC

public static DCConnection getDefaultDC()

isLessThanUnsigned

public static boolean isLessThanUnsigned(long n1,
                                         long n2)

setDesiredState

public static DCConnState setDesiredState(String sDesiredState)

resynch

public void resynch(String sDesiredState)

resynch

public void resynch()