com.cloudtran.replicator.localStore
Class CacheLocalStoreImpl

java.lang.Object
  extended by com.cloudtran.replicator.localStore.CacheLocalStoreImpl
All Implemented Interfaces:
LocalStore

public class CacheLocalStoreImpl
extends Object
implements LocalStore

This class implements the backup storage purely with a cache. This might be good enough if an elastic cache can be used, with the two replicator nodes being enabled for the storage.


Field Summary
 String OUTBOUND_CACHENAME
           
 
Fields inherited from interface com.cloudtran.replicator.localStore.LocalStore
GREEN_ZONE, RED_ZONE, YELLOW_ZONE
 
Constructor Summary
CacheLocalStoreImpl()
           
 
Method Summary
 boolean releaseOutbound(long txSeqNum)
          Releases the ReplicatorPacket stored under the txSeqNum.
 Long[] resync()
          Call this on each isolator instance when initializing replicator to set up the local store.
 ReplicatorPacket retrieveOutbound(long txSeqNum)
          After a resync() is called, any un-replicated packets must be sent to the remote DC.
 String storeOutbound(AtomicLong txSeqNumAL, ReplicatorOutboundRequest ror)
          We get passed a single packet.
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

OUTBOUND_CACHENAME

public final String OUTBOUND_CACHENAME
See Also:
Constant Field Values
Constructor Detail

CacheLocalStoreImpl

public CacheLocalStoreImpl()
Method Detail

resync

public Long[] resync()
Description copied from interface: LocalStore
Call this on each isolator instance when initializing replicator to set up the local store.

Specified by:
resync in interface LocalStore
Returns:
a Long array containing (a) the first TxSeqNum to resend to the peer (b) the number of transactions to resend to the peer. Once complete, the first TxSeqNum in the new run will be the sum of these two.

storeOutbound

public String storeOutbound(AtomicLong txSeqNumAL,
                            ReplicatorOutboundRequest ror)
We get passed a single packet. We just whack it into the cache. The caller must provide a lock around this method to ensure things happen sequentially.

Specified by:
storeOutbound in interface LocalStore
Parameters:
txSeqNumAL - the AtomicLong counter to generate the sequence number to store for the transaction. This number starts @ 0 after a drive/directory reformat and is then incremented as packets are sent. (This numbering sequence is continued across runs: it only gets reset by a reformat of the SSD drives.) The AtomicLong passed here belongs to the DCConnection. On input, it will be the highest previous txSeqNum set by this replicator. Therefore, the first packet sent will be (input txSeqNum + 1) etc. **NB** This method must set the sequenceNumber for this packet into the ror.packets[i].myTxSeqNum.
ror - ReplicatorOutboundRequest holding the packets to store. The packets include the local data center's internalTxId field for the transaction. **NB** This method must release ReplicatorOutboundRequest.finishOutboundRequestSem before returning.
Returns:
returns the String for the zone - GREEEN_ZONE, YELLOW_ZONE, RED_ZONE. If the RED_ZONE is returned, the caller must retry. Otherwise, the ReplicatorOutboundRequest has been restored. **NB** Just before returning, this method must release ror.finishOutboundRequestSem unless the RED_ZONE is returned.

releaseOutbound

public boolean releaseOutbound(long txSeqNum)
Description copied from interface: LocalStore
Releases the ReplicatorPacket stored under the txSeqNum.

Specified by:
releaseOutbound in interface LocalStore
Parameters:
txSeqNum - the transaction sequence number, as passed in storeOutbound.
Returns:
returns true if the packet was correctly stored. If false is returned the caller should retry.

toString

public String toString()
Overrides:
toString in class Object

retrieveOutbound

public ReplicatorPacket retrieveOutbound(long txSeqNum)
Description copied from interface: LocalStore
After a resync() is called, any un-replicated packets must be sent to the remote DC. This call assumes that the resync() has been called before any further storeOutbound()/releaseOutbound() calls.

Specified by:
retrieveOutbound in interface LocalStore
Parameters:
txSeqNum - the (replicator's) sequence number of the packet to retrieve.
Returns:
the ReplicatorPacket for the given txSeqNum.