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 |
---|---|
java.nio.ByteBuffer |
clearAllLocal(java.nio.ByteBuffer context)
Remove all the local of a context (but keep global).
|
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.
|
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.
|
boolean |
hasLegacyShards(java.nio.ByteBuffer context)
Detects whether or not the context has any legacy (local or remote) shards in it.
|
static CounterContext |
instance() |
boolean |
isLocal(java.nio.ByteBuffer context)
Checks if a context is local
|
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.
|
boolean |
shouldClearLocal(java.nio.ByteBuffer context) |
java.lang.String |
toString(java.nio.ByteBuffer context)
Human-readable String from context.
|
long |
total(java.nio.ByteBuffer context)
Returns the aggregated count across all counter ids.
|
void |
updateDigest(java.security.MessageDigest message,
java.nio.ByteBuffer context)
Update a MessageDigest with the content of a context.
|
void |
validateContext(java.nio.ByteBuffer context) |
public static CounterContext instance()
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 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 long total(java.nio.ByteBuffer context)
context
- a counter contextcontext
public boolean shouldClearLocal(java.nio.ByteBuffer context)
public boolean hasLegacyShards(java.nio.ByteBuffer context)
public java.nio.ByteBuffer markLocalToBeCleared(java.nio.ByteBuffer context)
context
- a counter contextpublic java.nio.ByteBuffer clearAllLocal(java.nio.ByteBuffer context)
context
- a counter contextcontext
where no shards are local.public void validateContext(java.nio.ByteBuffer context) throws MarshalException
MarshalException
public void updateDigest(java.security.MessageDigest message, java.nio.ByteBuffer context)
public ClockAndCount getLocalClockAndCount(java.nio.ByteBuffer context)
public long getLocalCount(java.nio.ByteBuffer context)
public boolean isLocal(java.nio.ByteBuffer context)
public ClockAndCount getClockAndCountOf(java.nio.ByteBuffer context, CounterId id)
public int findPositionOf(java.nio.ByteBuffer context, CounterId id)
Copyright © 2015 The Apache Software Foundation