public class CounterContext
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
CounterContext.ContextState
Helper class to work on contexts (works by iterating over them).
|
static class |
CounterContext.Relationship |
Constructor and Description |
---|
CounterContext() |
Modifier and Type | Method and Description |
---|---|
<V> V |
clearAllLocal(V context,
ValueAccessor<V> accessor) |
java.nio.ByteBuffer |
createGlobal(CounterId id,
long clock,
long count)
Creates a counter context with a single global, 2.1+ shard (a result of increment).
|
java.nio.ByteBuffer |
createLocal(long count)
Creates a counter context with a single local shard.
|
java.nio.ByteBuffer |
createRemote(CounterId id,
long clock,
long count)
Creates a counter context with a single remote shard.
|
java.nio.ByteBuffer |
createUpdate(long count)
Creates a counter context with a single local shard with clock id of UPDATE_CLOCK_ID.
|
CounterContext.Relationship |
diff(java.nio.ByteBuffer left,
java.nio.ByteBuffer right)
Determine the count relationship between two contexts.
|
int |
findPositionOf(java.nio.ByteBuffer context,
CounterId id)
Finds the position of a shard with the given id within the context (via binary search).
|
ClockAndCount |
getClockAndCountOf(java.nio.ByteBuffer context,
CounterId id)
Returns the clock and the count associated with the given counter id, or (0, 0) if no such shard is present.
|
ClockAndCount |
getLocalClockAndCount(java.nio.ByteBuffer context)
Returns the clock and the count associated with the local counter id, or (0, 0) if no such shard is present.
|
long |
getLocalCount(java.nio.ByteBuffer context)
Returns the count associated with the local counter id, or 0 if no such shard is present.
|
<V> boolean |
hasLegacyShards(V context,
ValueAccessor<V> accessor)
Detects whether or not the context has any legacy (local or remote) shards in it.
|
static <V> int |
headerLength(V context,
ValueAccessor<V> accessor) |
static CounterContext |
instance() |
boolean |
isUpdate(java.nio.ByteBuffer context)
Checks if a context is an update (see createUpdate() for justification).
|
java.nio.ByteBuffer |
markLocalToBeCleared(java.nio.ByteBuffer context)
Mark context to delete local references afterward.
|
java.nio.ByteBuffer |
merge(java.nio.ByteBuffer left,
java.nio.ByteBuffer right)
Return a context w/ an aggregated count for each counter id.
|
<V> boolean |
shouldClearLocal(V context,
ValueAccessor<V> accessor) |
java.lang.String |
toString(java.nio.ByteBuffer context)
Human-readable String from context.
|
<V> long |
total(Cell<V> cell) |
<V> long |
total(V context,
ValueAccessor<V> accessor)
Returns the aggregated count across all counter ids.
|
<V> void |
validateContext(V context,
ValueAccessor<V> accessor) |
public static CounterContext instance()
public java.nio.ByteBuffer createUpdate(long count)
public boolean isUpdate(java.nio.ByteBuffer context)
public java.nio.ByteBuffer createGlobal(CounterId id, long clock, long count)
public java.nio.ByteBuffer createLocal(long count)
public java.nio.ByteBuffer createRemote(CounterId id, long clock, long count)
public static <V> int headerLength(V context, ValueAccessor<V> accessor)
public CounterContext.Relationship diff(java.nio.ByteBuffer left, java.nio.ByteBuffer right)
left
- counter context.right
- counter context.public java.nio.ByteBuffer merge(java.nio.ByteBuffer left, java.nio.ByteBuffer right)
left
- counter context.right
- counter context.public java.lang.String toString(java.nio.ByteBuffer context)
context
- counter context.public <V> long total(V context, ValueAccessor<V> accessor)
context
- a counter contextcontext
public <V> long total(Cell<V> cell)
public <V> boolean shouldClearLocal(V context, ValueAccessor<V> accessor)
public <V> boolean hasLegacyShards(V context, ValueAccessor<V> accessor)
public java.nio.ByteBuffer markLocalToBeCleared(java.nio.ByteBuffer context)
context
- a counter contextpublic <V> V clearAllLocal(V context, ValueAccessor<V> accessor)
public <V> void validateContext(V context, ValueAccessor<V> accessor) throws MarshalException
MarshalException
public ClockAndCount getLocalClockAndCount(java.nio.ByteBuffer context)
public long getLocalCount(java.nio.ByteBuffer context)
public ClockAndCount getClockAndCountOf(java.nio.ByteBuffer context, CounterId id)
public int findPositionOf(java.nio.ByteBuffer context, CounterId id)
Copyright © 2009-2022 The Apache Software Foundation