Package org.jgroups.protocols
Class COUNTER
- java.lang.Object
-
- org.jgroups.stack.Protocol
-
- org.jgroups.protocols.COUNTER
-
public class COUNTER extends Protocol
Protocol which is used byCounterService
to provide a distributed atomic counter- Since:
- 3.0.0
- Author:
- Bela Ban
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
COUNTER.AddAndGetRequest
protected static class
COUNTER.BooleanResponse
protected static class
COUNTER.CompareAndSetRequest
static class
COUNTER.CounterHeader
protected class
COUNTER.CounterImpl
protected static class
COUNTER.DeleteRequest
protected static class
COUNTER.ExceptionResponse
protected static class
COUNTER.GetOrCreateRequest
protected static class
COUNTER.GetOrCreateResponse
protected static class
COUNTER.ReconcileRequest
protected static class
COUNTER.ReconcileResponse
protected class
COUNTER.ReconciliationTask
protected static interface
COUNTER.Request
protected static class
COUNTER.RequestType
protected static class
COUNTER.ResendPendingRequests
protected static interface
COUNTER.Response
protected static class
COUNTER.ResponseType
protected static class
COUNTER.SetRequest
protected static class
COUNTER.SimpleRequest
protected static class
COUNTER.SimpleResponse
Response without dataprotected static class
COUNTER.UpdateRequest
protected static class
COUNTER.ValueResponse
protected static class
COUNTER.VersionedValue
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<Address>
backup_coords
Backup coordinators.protected boolean
bypass_bundling
protected Address
coord
The address of the cluster coordinator.protected java.util.concurrent.ConcurrentMap<java.lang.String,COUNTER.VersionedValue>
counters
protected boolean
discard_requests
Set to true during reconciliation process, will cause all requests to be discardedprotected Address
local_addr
protected int
num_backups
protected java.util.Map<Owner,Tuple<COUNTER.Request,Promise>>
pending_requests
protected COUNTER.ReconciliationTask
reconciliation_task
protected java.util.concurrent.Future<?>
reconciliation_task_future
protected long
reconciliation_timeout
protected static byte
REQUEST
protected static byte
RESPONSE
protected long
timeout
protected View
view
-
Fields inherited from class org.jgroups.stack.Protocol
after_creation_hook, down_prot, ergonomics, id, log, stack, stats, up_prot
-
-
Constructor Summary
Constructors Constructor Description COUNTER()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static COUNTER.Request
createRequest(COUNTER.RequestType type)
protected static COUNTER.Response
createResponse(COUNTER.ResponseType type)
void
deleteCounter(java.lang.String name)
Sent asynchronously - we don't wait for an ackjava.lang.Object
down(Event evt)
An event is to be sent down the stack.protected static java.lang.String
dump(java.lang.String[] names, long[] values, long[] versions)
java.lang.String
dumpPendingRequests()
java.lang.String
getAddress()
java.lang.String
getBackupCoords()
boolean
getBypassBundling()
protected COUNTER.VersionedValue
getCounter(java.lang.String name)
Counter
getOrCreateCounter(java.lang.String name, long initial_value)
protected Owner
getOwner()
java.lang.String
getView()
protected void
handleRequest(COUNTER.Request req, Address sender)
protected void
handleResponse(COUNTER.Response rsp, Address sender)
protected void
handleView(View view)
java.lang.String
printCounters()
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.Request
requestFromBuffer(byte[] buf, int offset, int length)
protected static Buffer
requestToBuffer(COUNTER.Request req)
protected static COUNTER.RequestType
requestToRequestType(COUNTER.Request req)
protected static COUNTER.Response
responseFromBuffer(byte[] buf, int offset, int length)
protected static Buffer
responseToBuffer(COUNTER.Response rsp)
protected static COUNTER.ResponseType
responseToResponseType(COUNTER.Response rsp)
protected void
send(Address dest, Buffer buffer)
protected void
sendCounterNotFoundExceptionResponse(Address dest, Owner owner, java.lang.String counter_name)
protected void
sendRequest(Address dest, COUNTER.Request req)
protected void
sendResponse(Address dest, COUNTER.Response rsp)
void
setBypassBundling(boolean bypass_bundling)
protected void
startReconciliationTask()
protected void
stopReconciliationTask()
protected static Streamable
streamableFromBuffer(byte[] buf, int offset, int length)
protected static Buffer
streamableToBuffer(byte req_or_rsp, byte type, Streamable obj)
java.lang.Object
up(Event evt)
An event was received from the protocol below.java.lang.Object
up(Message msg)
A single message was received.protected void
updateBackups(java.lang.String name, long value, long version)
protected static void
writeReconciliation(java.io.DataOutput out, java.lang.String[] names, long[] values, long[] versions)
-
Methods inherited from class org.jgroups.stack.Protocol
accept, afterCreationHook, destroy, down, enableStats, getConfigurableObjects, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getLog, getName, getProtocolStack, getSocketFactory, getThreadFactory, getTransport, getUpProtocol, getUpServices, getValue, init, isErgonomics, level, parse, providedDownServices, providedUpServices, requiredDownServices, requiredUpServices, resetStatistics, resetStats, setDownProtocol, setErgonomics, setId, setLevel, setProtocolStack, setSocketFactory, setUpProtocol, setValue, start, statsEnabled, stop, 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
-
local_addr
protected Address local_addr
-
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.concurrent.ConcurrentMap<java.lang.String,COUNTER.VersionedValue> counters
-
pending_requests
protected final java.util.Map<Owner,Tuple<COUNTER.Request,Promise>> 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
-
requestToRequestType
protected static COUNTER.RequestType requestToRequestType(COUNTER.Request req)
-
responseToResponseType
protected static COUNTER.ResponseType responseToResponseType(COUNTER.Response rsp)
-
getBypassBundling
public boolean getBypassBundling()
-
setBypassBundling
public void setBypassBundling(boolean bypass_bundling)
-
getAddress
public java.lang.String getAddress()
-
getView
public java.lang.String getView()
-
getBackupCoords
public java.lang.String getBackupCoords()
-
getOrCreateCounter
public Counter getOrCreateCounter(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:Protocol
An 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:Protocol
An 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:Protocol
A single message was received. Protocols may examine the message and do something (e.g. add a header) with it before passing it up.
-
handleRequest
protected void handleRequest(COUNTER.Request req, Address sender)
-
getCounter
protected COUNTER.VersionedValue getCounter(java.lang.String name)
-
handleResponse
protected void handleResponse(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()
-
sendRequest
protected void sendRequest(Address dest, COUNTER.Request req)
-
sendResponse
protected void sendResponse(Address dest, COUNTER.Response rsp)
-
updateBackups
protected void updateBackups(java.lang.String name, long value, long version)
-
sendCounterNotFoundExceptionResponse
protected void sendCounterNotFoundExceptionResponse(Address dest, Owner owner, java.lang.String counter_name)
-
requestToBuffer
protected static Buffer requestToBuffer(COUNTER.Request req) throws java.lang.Exception
- Throws:
java.lang.Exception
-
responseToBuffer
protected static Buffer responseToBuffer(COUNTER.Response rsp) throws java.lang.Exception
- Throws:
java.lang.Exception
-
streamableToBuffer
protected static Buffer streamableToBuffer(byte req_or_rsp, byte type, Streamable obj) throws java.lang.Exception
- Throws:
java.lang.Exception
-
streamableFromBuffer
protected static Streamable streamableFromBuffer(byte[] buf, int offset, int length) throws java.lang.Exception
- Throws:
java.lang.Exception
-
requestFromBuffer
protected static final COUNTER.Request requestFromBuffer(byte[] buf, int offset, int length) throws java.lang.Exception
- Throws:
java.lang.Exception
-
createRequest
protected static COUNTER.Request createRequest(COUNTER.RequestType type)
-
responseFromBuffer
protected static final COUNTER.Response responseFromBuffer(byte[] buf, int offset, int length) throws java.lang.Exception
- Throws:
java.lang.Exception
-
createResponse
protected static COUNTER.Response createResponse(COUNTER.ResponseType type)
-
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)
-
-