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 by CounterService to provide a distributed atomic counter
Since:
3.0.0
  • Field Details

    • REQUEST_ID_GENERATOR

      private static final AtomicLong REQUEST_ID_GENERATOR
    • REQUEST_TYPES_CACHED

      private static final COUNTER.RequestType[] REQUEST_TYPES_CACHED
    • RESPONSE_TYPES_CACHED

      private static final COUNTER.ResponseType[] RESPONSE_TYPES_CACHED
    • 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 List<Address> backup_coords
      Backup coordinators. Only created if num_backups > 0 and coord=true
    • reconciliation_task_future

      protected Future<?> reconciliation_task_future
    • reconciliation_task

      protected COUNTER.ReconciliationTask reconciliation_task
    • counters

      protected final Map<String,COUNTER.VersionedValue> counters
    • pending_requests

      protected final Map<Owner,COUNTER.RequestCompletableFuture<?>> pending_requests
    • REQUEST

      protected static final byte REQUEST
      See Also:
    • RESPONSE

      protected static final byte RESPONSE
      See Also:
    • transport

      private TP transport
  • Constructor Details

    • COUNTER

      public COUNTER()
  • Method Details

    • getBypassBundling

      public boolean getBypassBundling()
    • setBypassBundling

      public COUNTER setBypassBundling(boolean bypass_bundling)
    • getNumberOfBackups

      public int getNumberOfBackups()
    • setNumberOfBackups

      public COUNTER setNumberOfBackups(int num_backups)
    • getView

      public String getView()
    • getBackupCoords

      public String getBackupCoords()
    • init

      public void init() throws Exception
      Description copied from class: Protocol
      Called 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.
      Specified by:
      init in interface Lifecycle
      Overrides:
      init in class Protocol
      Throws:
      Exception - Thrown if protocol cannot be initialized successfully. This will cause the ProtocolStack to fail, so the the channel constructor will throw an exception
    • getOrCreateCounter

      @Deprecated public Counter getOrCreateCounter(String name, long initial_value)
      Deprecated.
    • getOrCreateAsyncCounter

      public CompletionStage<AsyncCounter> getOrCreateAsyncCounter(String name, long initial_value)
    • doGetOrCreateCounter

      private CompletionStage<COUNTER.CounterImpl> doGetOrCreateCounter(String name, long initial_value)
    • deleteCounter

      public void deleteCounter(String name)
      Sent asynchronously - we don't wait for an ack
    • down

      public 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 using down_prot.down().
      Overrides:
      down in class Protocol
    • up

      public 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 using down_prot.down() or c) the event (or another event) is sent up the stack using up_prot.up().
      Overrides:
      up in class Protocol
    • up

      public 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.
      Overrides:
      up in class Protocol
    • getCounter

      protected COUNTER.VersionedValue getCounter(String name)
    • handleResponse

      protected void handleResponse(COUNTER.Response rsp, Address sender)
    • handleReconcileResponse

      private void handleReconcileResponse(COUNTER.ReconcileResponse rsp, Address sender)
    • printCounters

      public String printCounters()
    • dumpPendingRequests

      public String dumpPendingRequests()
    • handleView

      protected void handleView(View view)
    • getOwner

      protected Owner getOwner()
    • updateBackups

      protected void updateBackups(String name, long[] versionedValue)
    • sendRequest

      protected void sendRequest(Address dest, COUNTER.Request req)
    • sendResponse

      protected void sendResponse(Address dest, COUNTER.Response<?> rsp)
    • send

      protected void send(Address dest, ByteArray buffer)
    • logSending

      private void logSending(Address dst, Object data)
    • sendCounterNotFoundExceptionResponse

      protected void sendCounterNotFoundExceptionResponse(Address dest, Owner owner, String counter_name)
    • updateCounter

      private <T> T updateCounter(COUNTER.ResponseData<T> responseData)
    • requestToBuffer

      protected static ByteArray requestToBuffer(COUNTER.Request req) throws Exception
      Throws:
      Exception
    • responseToBuffer

      protected static ByteArray responseToBuffer(COUNTER.Response<?> rsp) throws Exception
      Throws:
      Exception
    • streamableToBuffer

      protected static ByteArray streamableToBuffer(byte req_or_rsp, byte type, Streamable obj) throws Exception
      Throws:
      Exception
    • requestFromDataInput

      protected static COUNTER.Request requestFromDataInput(DataInput in) throws Exception
      Throws:
      Exception
    • responseFromDataInput

      protected static COUNTER.Response<?> responseFromDataInput(DataInput in) throws Exception
      Throws:
      Exception
    • startReconciliationTask

      protected void startReconciliationTask()
    • stopReconciliationTask

      protected void stopReconciliationTask()
    • writeReconciliation

      protected static void writeReconciliation(DataOutput out, String[] names, long[] values, long[] versions) throws IOException
      Throws:
      IOException
    • readReconciliationNames

      protected static String[] readReconciliationNames(DataInput in, int len) throws IOException
      Throws:
      IOException
    • readReconciliationLongs

      protected static long[] readReconciliationLongs(DataInput in, int len) throws IOException
      Throws:
      IOException
    • dump

      protected static String dump(String[] names, long[] values, long[] versions)
    • sendRequestToCoordinator

      private <T> CompletableFuture<T> sendRequestToCoordinator(Owner owner, COUNTER.Request request)
    • skipRequest

      private boolean skipRequest()
    • traceResending

      private void traceResending(COUNTER.Request request)