Package org.jgroups.protocols
Class COUNTER
- java.lang.Object
-
- org.jgroups.stack.Protocol
-
- org.jgroups.protocols.COUNTER
-
- All Implemented Interfaces:
Lifecycle
public class COUNTER extends Protocol
Protocol which is used byCounterServiceto provide a distributed atomic counter- Since:
- 3.0.0
- Author:
- Bela Ban
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classCOUNTER.AddAndGetRequestprotected static classCOUNTER.CompareAndSetRequeststatic classCOUNTER.CounterHeaderprotected classCOUNTER.CounterImplprotected static classCOUNTER.DeleteRequestprotected static classCOUNTER.ExceptionResponseprotected static classCOUNTER.GetOrCreateRequestprotected static classCOUNTER.ReconcileRequestprotected static classCOUNTER.ReconcileResponseprotected classCOUNTER.ReconciliationTaskprotected static interfaceCOUNTER.Requestprotected static classCOUNTER.RequestTypeprotected static classCOUNTER.ResendPendingRequestsprotected static classCOUNTER.ResponseTypeprotected static classCOUNTER.SetRequestprotected static classCOUNTER.SimpleRequestprotected static classCOUNTER.UpdateRequestprotected static classCOUNTER.ValueResponseprotected static classCOUNTER.VersionedValue
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<Address>backup_coordsBackup coordinators.protected booleanbypass_bundlingprotected AddresscoordThe address of the cluster coordinator.protected java.util.Map<java.lang.String,COUNTER.VersionedValue>countersprotected booleandiscard_requestsSet to true during reconciliation process, will cause all requests to be discardedprotected intnum_backupsprotected java.util.Map<Owner,org.jgroups.protocols.COUNTER.RequestCompletableFuture<?>>pending_requestsprotected COUNTER.ReconciliationTaskreconciliation_taskprotected java.util.concurrent.Future<?>reconciliation_task_futureprotected longreconciliation_timeoutprotected static byteREQUESTprotected static byteRESPONSEprotected longtimeoutprotected Viewview-
Fields inherited from class org.jgroups.stack.Protocol
after_creation_hook, down_prot, ergonomics, id, local_addr, log, policies, stack, stats, up_prot
-
-
Constructor Summary
Constructors Constructor Description COUNTER()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voiddeleteCounter(java.lang.String name)Sent asynchronously - we don't wait for an ackjava.lang.Objectdown(Event evt)An event is to be sent down the stack.protected static java.lang.Stringdump(java.lang.String[] names, long[] values, long[] versions)java.lang.StringdumpPendingRequests()java.lang.StringgetBackupCoords()booleangetBypassBundling()protected COUNTER.VersionedValuegetCounter(java.lang.String name)intgetNumberOfBackups()java.util.concurrent.CompletionStage<AsyncCounter>getOrCreateAsyncCounter(java.lang.String name, long initial_value)CountergetOrCreateCounter(java.lang.String name, long initial_value)Deprecated.protected OwnergetOwner()java.lang.StringgetView()protected voidhandleResponse(org.jgroups.protocols.COUNTER.Response rsp, Address sender)protected voidhandleView(View view)voidinit()Called after a protocol has been created and before the protocol is started.java.lang.StringprintCounters()protected static long[]readReconciliationLongs(java.io.DataInput in, int len)protected static java.lang.String[]readReconciliationNames(java.io.DataInput in, int len)protected static COUNTER.RequestrequestFromDataInput(java.io.DataInput in)protected static ByteArrayrequestToBuffer(COUNTER.Request req)protected static org.jgroups.protocols.COUNTER.Response<?>responseFromDataInput(java.io.DataInput in)protected static ByteArrayresponseToBuffer(org.jgroups.protocols.COUNTER.Response<?> rsp)protected voidsend(Address dest, ByteArray buffer)protected voidsendCounterNotFoundExceptionResponse(Address dest, Owner owner, java.lang.String counter_name)protected voidsendRequest(Address dest, COUNTER.Request req)protected voidsendResponse(Address dest, org.jgroups.protocols.COUNTER.Response<?> rsp)COUNTERsetBypassBundling(boolean bypass_bundling)COUNTERsetNumberOfBackups(int num_backups)protected voidstartReconciliationTask()protected voidstopReconciliationTask()protected static ByteArraystreamableToBuffer(byte req_or_rsp, byte type, Streamable obj)java.lang.Objectup(Event evt)An event was received from the protocol below.java.lang.Objectup(Message msg)A single message was received.protected voidupdateBackups(java.lang.String name, long[] versionedValue)protected static voidwriteReconciliation(java.io.DataOutput out, java.lang.String[] names, long[] values, long[] versions)-
Methods inherited from class org.jgroups.stack.Protocol
accept, addPolicy, addr, addr, afterCreationHook, destroy, down, down, enableStats, getAddress, getComponents, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getLog, getName, getPolicies, getProtocolStack, getSocketFactory, getThreadFactory, getTransport, getUpProtocol, getUpServices, getValue, isErgonomics, level, parse, policies, providedDownServices, providedUpServices, removePolicy, requiredDownServices, requiredUpServices, resetStatistics, resetStats, setAddress, setDownProtocol, setErgonomics, setId, setLevel, setPolicies, setProtocolStack, setSocketFactory, setUpProtocol, setValue, start, statsEnabled, stop, toString, up
-
-
-
-
Field Detail
-
bypass_bundling
protected boolean bypass_bundling
-
timeout
protected long timeout
-
reconciliation_timeout
protected long reconciliation_timeout
-
num_backups
protected int num_backups
-
discard_requests
protected boolean discard_requests
Set to true during reconciliation process, will cause all requests to be discarded
-
view
protected View view
-
coord
protected Address coord
The address of the cluster coordinator. Updated on view changes
-
backup_coords
protected java.util.List<Address> backup_coords
Backup coordinators. Only created if num_backups > 0 and coord=true
-
reconciliation_task_future
protected java.util.concurrent.Future<?> reconciliation_task_future
-
reconciliation_task
protected COUNTER.ReconciliationTask reconciliation_task
-
counters
protected final java.util.Map<java.lang.String,COUNTER.VersionedValue> counters
-
pending_requests
protected final java.util.Map<Owner,org.jgroups.protocols.COUNTER.RequestCompletableFuture<?>> pending_requests
-
REQUEST
protected static final byte REQUEST
- See Also:
- Constant Field Values
-
RESPONSE
protected static final byte RESPONSE
- See Also:
- Constant Field Values
-
-
Method Detail
-
getBypassBundling
public boolean getBypassBundling()
-
setBypassBundling
public COUNTER setBypassBundling(boolean bypass_bundling)
-
getNumberOfBackups
public int getNumberOfBackups()
-
setNumberOfBackups
public COUNTER setNumberOfBackups(int num_backups)
-
getView
public java.lang.String getView()
-
getBackupCoords
public java.lang.String getBackupCoords()
-
init
public void init() throws java.lang.ExceptionDescription copied from class:ProtocolCalled after a protocol has been created and before the protocol is started. Attributes are already set. Other protocols are not yet connected and events cannot yet be sent.
-
getOrCreateCounter
@Deprecated public Counter getOrCreateCounter(java.lang.String name, long initial_value)
Deprecated.
-
getOrCreateAsyncCounter
public java.util.concurrent.CompletionStage<AsyncCounter> getOrCreateAsyncCounter(java.lang.String name, long initial_value)
-
deleteCounter
public void deleteCounter(java.lang.String name)
Sent asynchronously - we don't wait for an ack
-
down
public java.lang.Object down(Event evt)
Description copied from class:ProtocolAn event is to be sent down the stack. A protocol may want to examine its type and perform some action on it, depending on the event's type. If the event is a message MSG, then the protocol may need to add a header to it (or do nothing at all) before sending it down the stack usingdown_prot.down().
-
up
public java.lang.Object up(Event evt)
Description copied from class:ProtocolAn event was received from the protocol below. Usually the current protocol will want to examine the event type and - depending on its type - perform some computation (e.g. removing headers from a MSG event type, or updating the internal membership list when receiving a VIEW_CHANGE event). Finally, the event is either a) discarded, or b) an event is sent down the stack usingdown_prot.down()or c) the event (or another event) is sent up the stack usingup_prot.up().
-
up
public java.lang.Object up(Message msg)
Description copied from class:ProtocolA single message was received. Protocols may examine the message and do something (e.g. add a header) with it before passing it up.
-
getCounter
protected COUNTER.VersionedValue getCounter(java.lang.String name)
-
handleResponse
protected void handleResponse(org.jgroups.protocols.COUNTER.Response rsp, Address sender)
-
printCounters
public java.lang.String printCounters()
-
dumpPendingRequests
public java.lang.String dumpPendingRequests()
-
handleView
protected void handleView(View view)
-
getOwner
protected Owner getOwner()
-
updateBackups
protected void updateBackups(java.lang.String name, long[] versionedValue)
-
sendRequest
protected void sendRequest(Address dest, COUNTER.Request req)
-
sendResponse
protected void sendResponse(Address dest, org.jgroups.protocols.COUNTER.Response<?> rsp)
-
sendCounterNotFoundExceptionResponse
protected void sendCounterNotFoundExceptionResponse(Address dest, Owner owner, java.lang.String counter_name)
-
requestToBuffer
protected static ByteArray requestToBuffer(COUNTER.Request req) throws java.lang.Exception
- Throws:
java.lang.Exception
-
responseToBuffer
protected static ByteArray responseToBuffer(org.jgroups.protocols.COUNTER.Response<?> rsp) throws java.lang.Exception
- Throws:
java.lang.Exception
-
streamableToBuffer
protected static ByteArray streamableToBuffer(byte req_or_rsp, byte type, Streamable obj) throws java.lang.Exception
- Throws:
java.lang.Exception
-
requestFromDataInput
protected static COUNTER.Request requestFromDataInput(java.io.DataInput in) throws java.lang.Exception
- Throws:
java.lang.Exception
-
responseFromDataInput
protected static org.jgroups.protocols.COUNTER.Response<?> responseFromDataInput(java.io.DataInput in) throws java.lang.Exception- Throws:
java.lang.Exception
-
startReconciliationTask
protected void startReconciliationTask()
-
stopReconciliationTask
protected void stopReconciliationTask()
-
writeReconciliation
protected static void writeReconciliation(java.io.DataOutput out, java.lang.String[] names, long[] values, long[] versions) throws java.io.IOException- Throws:
java.io.IOException
-
readReconciliationNames
protected static java.lang.String[] readReconciliationNames(java.io.DataInput in, int len) throws java.io.IOException- Throws:
java.io.IOException
-
readReconciliationLongs
protected static long[] readReconciliationLongs(java.io.DataInput in, int len) throws java.io.IOException- Throws:
java.io.IOException
-
dump
protected static java.lang.String dump(java.lang.String[] names, long[] values, long[] versions)
-
-