Skip to content

Commit

Permalink
Add basic core API documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
kuujo committed Jul 27, 2015
1 parent aa5fbf0 commit bb66192
Show file tree
Hide file tree
Showing 18 changed files with 179 additions and 110 deletions.
44 changes: 22 additions & 22 deletions atomic/src/main/java/net/kuujo/copycat/atomic/AsyncReference.java
Expand Up @@ -17,7 +17,7 @@


import net.kuujo.copycat.Listener; import net.kuujo.copycat.Listener;
import net.kuujo.copycat.ListenerContext; import net.kuujo.copycat.ListenerContext;
import net.kuujo.copycat.Mode; import net.kuujo.copycat.PersistenceLevel;
import net.kuujo.copycat.raft.ConsistencyLevel; import net.kuujo.copycat.raft.ConsistencyLevel;


import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -97,34 +97,34 @@ public interface AsyncReference<T> {
CompletableFuture<Void> set(T value, long ttl, TimeUnit unit); CompletableFuture<Void> set(T value, long ttl, TimeUnit unit);


/** /**
* Sets the value with a write mode. * Sets the value with a write persistence.
* *
* @param value The value to set. * @param value The value to set.
* @param mode The write mode. * @param persistence The write persistence.
* @return A completable future to be completed once the value has been set. * @return A completable future to be completed once the value has been set.
*/ */
CompletableFuture<Void> set(T value, Mode mode); CompletableFuture<Void> set(T value, PersistenceLevel persistence);


/** /**
* Sets the value with a write mode. * Sets the value with a write persistence.
* *
* @param value The value to set. * @param value The value to set.
* @param ttl The time after which to expire the value. * @param ttl The time after which to expire the value.
* @param mode The write mode. * @param persistence The write persistence.
* @return A completable future to be completed once the value has been set. * @return A completable future to be completed once the value has been set.
*/ */
CompletableFuture<Void> set(T value, long ttl, Mode mode); CompletableFuture<Void> set(T value, long ttl, PersistenceLevel persistence);


/** /**
* Sets the value with a write mode. * Sets the value with a write persistence.
* *
* @param value The value to set. * @param value The value to set.
* @param ttl The time after which to expire the value. * @param ttl The time after which to expire the value.
* @param unit The expiration time unit. * @param unit The expiration time unit.
* @param mode The write mode. * @param persistence The write persistence.
* @return A completable future to be completed once the value has been set. * @return A completable future to be completed once the value has been set.
*/ */
CompletableFuture<Void> set(T value, long ttl, TimeUnit unit, Mode mode); CompletableFuture<Void> set(T value, long ttl, TimeUnit unit, PersistenceLevel persistence);


/** /**
* Gets the current value and updates it. * Gets the current value and updates it.
Expand Down Expand Up @@ -157,31 +157,31 @@ public interface AsyncReference<T> {
* Gets the current value and updates it. * Gets the current value and updates it.
* *
* @param value The updated value. * @param value The updated value.
* @param mode The write mode. * @param persistence The write persistence.
* @return A completable future to be completed with the previous value. * @return A completable future to be completed with the previous value.
*/ */
CompletableFuture<T> getAndSet(T value, Mode mode); CompletableFuture<T> getAndSet(T value, PersistenceLevel persistence);


/** /**
* Gets the current value and updates it. * Gets the current value and updates it.
* *
* @param value The updated value. * @param value The updated value.
* @param ttl The time after which to expire the value. * @param ttl The time after which to expire the value.
* @param mode The write mode. * @param persistence The write persistence.
* @return A completable future to be completed with the previous value. * @return A completable future to be completed with the previous value.
*/ */
CompletableFuture<T> getAndSet(T value, long ttl, Mode mode); CompletableFuture<T> getAndSet(T value, long ttl, PersistenceLevel persistence);


/** /**
* Gets the current value and updates it. * Gets the current value and updates it.
* *
* @param value The updated value. * @param value The updated value.
* @param ttl The time after which to expire the value. * @param ttl The time after which to expire the value.
* @param unit The expiration time unit. * @param unit The expiration time unit.
* @param mode The write mode. * @param persistence The write persistence.
* @return A completable future to be completed with the previous value. * @return A completable future to be completed with the previous value.
*/ */
CompletableFuture<T> getAndSet(T value, long ttl, TimeUnit unit, Mode mode); CompletableFuture<T> getAndSet(T value, long ttl, TimeUnit unit, PersistenceLevel persistence);


/** /**
* Compares the current value and updated it if expected value == the current value. * Compares the current value and updated it if expected value == the current value.
Expand Down Expand Up @@ -218,21 +218,21 @@ public interface AsyncReference<T> {
* *
* @param expect The expected value. * @param expect The expected value.
* @param update The updated value. * @param update The updated value.
* @param mode The write mode. * @param persistence The write persistence.
* @return A completable future to be completed with a boolean value indicating whether the value was updated. * @return A completable future to be completed with a boolean value indicating whether the value was updated.
*/ */
CompletableFuture<Boolean> compareAndSet(T expect, T update, Mode mode); CompletableFuture<Boolean> compareAndSet(T expect, T update, PersistenceLevel persistence);


/** /**
* Compares the current value and updated it if expected value == the current value. * Compares the current value and updated it if expected value == the current value.
* *
* @param expect The expected value. * @param expect The expected value.
* @param update The updated value. * @param update The updated value.
* @param ttl The time after which to expire the value. * @param ttl The time after which to expire the value.
* @param mode The write mode. * @param persistence The write persistence.
* @return A completable future to be completed with a boolean value indicating whether the value was updated. * @return A completable future to be completed with a boolean value indicating whether the value was updated.
*/ */
CompletableFuture<Boolean> compareAndSet(T expect, T update, long ttl, Mode mode); CompletableFuture<Boolean> compareAndSet(T expect, T update, long ttl, PersistenceLevel persistence);


/** /**
* Compares the current value and updated it if expected value == the current value. * Compares the current value and updated it if expected value == the current value.
Expand All @@ -241,10 +241,10 @@ public interface AsyncReference<T> {
* @param update The updated value. * @param update The updated value.
* @param ttl The time after which to expire the value. * @param ttl The time after which to expire the value.
* @param unit The expiration time unit. * @param unit The expiration time unit.
* @param mode The write mode. * @param persistence The write persistence.
* @return A completable future to be completed with a boolean value indicating whether the value was updated. * @return A completable future to be completed with a boolean value indicating whether the value was updated.
*/ */
CompletableFuture<Boolean> compareAndSet(T expect, T update, long ttl, TimeUnit unit, Mode mode); CompletableFuture<Boolean> compareAndSet(T expect, T update, long ttl, TimeUnit unit, PersistenceLevel persistence);


/** /**
* Registers a change listener. * Registers a change listener.
Expand Down
Expand Up @@ -99,28 +99,28 @@ public CompletableFuture<Void> set(T value, long ttl, TimeUnit unit) {
} }


@Override @Override
public CompletableFuture<Void> set(T value, Mode mode) { public CompletableFuture<Void> set(T value, PersistenceLevel persistence) {
return submit(ReferenceCommands.Set.builder() return submit(ReferenceCommands.Set.builder()
.withValue(value) .withValue(value)
.withMode(mode) .withPersistence(persistence)
.build()); .build());
} }


@Override @Override
public CompletableFuture<Void> set(T value, long ttl, Mode mode) { public CompletableFuture<Void> set(T value, long ttl, PersistenceLevel persistence) {
return submit(ReferenceCommands.Set.builder() return submit(ReferenceCommands.Set.builder()
.withValue(value) .withValue(value)
.withTtl(ttl) .withTtl(ttl)
.withMode(mode) .withPersistence(persistence)
.build()); .build());
} }


@Override @Override
public CompletableFuture<Void> set(T value, long ttl, TimeUnit unit, Mode mode) { public CompletableFuture<Void> set(T value, long ttl, TimeUnit unit, PersistenceLevel persistence) {
return submit(ReferenceCommands.Set.builder() return submit(ReferenceCommands.Set.builder()
.withValue(value) .withValue(value)
.withTtl(ttl, unit) .withTtl(ttl, unit)
.withMode(mode) .withPersistence(persistence)
.build()); .build());
} }


Expand Down Expand Up @@ -148,28 +148,28 @@ public CompletableFuture<T> getAndSet(T value, long ttl, TimeUnit unit) {
} }


@Override @Override
public CompletableFuture<T> getAndSet(T value, Mode mode) { public CompletableFuture<T> getAndSet(T value, PersistenceLevel persistence) {
return submit(ReferenceCommands.GetAndSet.<T>builder() return submit(ReferenceCommands.GetAndSet.<T>builder()
.withValue(value) .withValue(value)
.withMode(mode) .withPersistence(persistence)
.build()); .build());
} }


@Override @Override
public CompletableFuture<T> getAndSet(T value, long ttl, Mode mode) { public CompletableFuture<T> getAndSet(T value, long ttl, PersistenceLevel persistence) {
return submit(ReferenceCommands.GetAndSet.<T>builder() return submit(ReferenceCommands.GetAndSet.<T>builder()
.withValue(value) .withValue(value)
.withTtl(ttl) .withTtl(ttl)
.withMode(mode) .withPersistence(persistence)
.build()); .build());
} }


@Override @Override
public CompletableFuture<T> getAndSet(T value, long ttl, TimeUnit unit, Mode mode) { public CompletableFuture<T> getAndSet(T value, long ttl, TimeUnit unit, PersistenceLevel persistence) {
return submit(ReferenceCommands.GetAndSet.<T>builder() return submit(ReferenceCommands.GetAndSet.<T>builder()
.withValue(value) .withValue(value)
.withTtl(ttl, unit) .withTtl(ttl, unit)
.withMode(mode) .withPersistence(persistence)
.build()); .build());
} }


Expand Down Expand Up @@ -200,31 +200,31 @@ public CompletableFuture<Boolean> compareAndSet(T expect, T update, long ttl, Ti
} }


@Override @Override
public CompletableFuture<Boolean> compareAndSet(T expect, T update, Mode mode) { public CompletableFuture<Boolean> compareAndSet(T expect, T update, PersistenceLevel persistence) {
return submit(ReferenceCommands.CompareAndSet.builder() return submit(ReferenceCommands.CompareAndSet.builder()
.withExpect(expect) .withExpect(expect)
.withUpdate(update) .withUpdate(update)
.withMode(mode) .withPersistence(persistence)
.build()); .build());
} }


@Override @Override
public CompletableFuture<Boolean> compareAndSet(T expect, T update, long ttl, Mode mode) { public CompletableFuture<Boolean> compareAndSet(T expect, T update, long ttl, PersistenceLevel persistence) {
return submit(ReferenceCommands.CompareAndSet.builder() return submit(ReferenceCommands.CompareAndSet.builder()
.withExpect(expect) .withExpect(expect)
.withUpdate(update) .withUpdate(update)
.withTtl(ttl) .withTtl(ttl)
.withMode(mode) .withPersistence(persistence)
.build()); .build());
} }


@Override @Override
public CompletableFuture<Boolean> compareAndSet(T expect, T update, long ttl, TimeUnit unit, Mode mode) { public CompletableFuture<Boolean> compareAndSet(T expect, T update, long ttl, TimeUnit unit, PersistenceLevel persistence) {
return submit(ReferenceCommands.CompareAndSet.builder() return submit(ReferenceCommands.CompareAndSet.builder()
.withExpect(expect) .withExpect(expect)
.withUpdate(update) .withUpdate(update)
.withTtl(ttl, unit) .withTtl(ttl, unit)
.withMode(mode) .withPersistence(persistence)
.build()); .build());
} }


Expand Down
Expand Up @@ -21,7 +21,7 @@
import net.kuujo.alleycat.io.BufferInput; import net.kuujo.alleycat.io.BufferInput;
import net.kuujo.alleycat.io.BufferOutput; import net.kuujo.alleycat.io.BufferOutput;
import net.kuujo.copycat.BuilderPool; import net.kuujo.copycat.BuilderPool;
import net.kuujo.copycat.Mode; import net.kuujo.copycat.PersistenceLevel;
import net.kuujo.copycat.raft.Command; import net.kuujo.copycat.raft.Command;
import net.kuujo.copycat.raft.ConsistencyLevel; import net.kuujo.copycat.raft.ConsistencyLevel;
import net.kuujo.copycat.raft.Operation; import net.kuujo.copycat.raft.Operation;
Expand All @@ -43,15 +43,15 @@ private ReferenceCommands() {
* Abstract reference command. * Abstract reference command.
*/ */
public static abstract class ReferenceCommand<V> implements Command<V>, AlleycatSerializable { public static abstract class ReferenceCommand<V> implements Command<V>, AlleycatSerializable {
protected Mode mode = Mode.PERSISTENT; protected PersistenceLevel mode = PersistenceLevel.PERSISTENT;
protected long ttl; protected long ttl;


/** /**
* Returns the persistence mode. * Returns the persistence mode.
* *
* @return The persistence mode. * @return The persistence mode.
*/ */
public Mode mode() { public PersistenceLevel mode() {
return mode; return mode;
} }


Expand All @@ -72,7 +72,7 @@ public void writeObject(BufferOutput buffer, Alleycat alleycat) {


@Override @Override
public void readObject(BufferInput buffer, Alleycat alleycat) { public void readObject(BufferInput buffer, Alleycat alleycat) {
mode = Mode.values()[buffer.readByte()]; mode = PersistenceLevel.values()[buffer.readByte()];
ttl = buffer.readLong(); ttl = buffer.readLong();
} }


Expand All @@ -91,7 +91,7 @@ protected Builder(BuilderPool<T, U> pool) {
* @return The command builder. * @return The command builder.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public T withMode(Mode mode) { public T withPersistence(PersistenceLevel mode) {
if (mode == null) if (mode == null)
throw new NullPointerException("mode cannot be null"); throw new NullPointerException("mode cannot be null");
command.mode = mode; command.mode = mode;
Expand Down
Expand Up @@ -15,7 +15,7 @@
*/ */
package net.kuujo.copycat.atomic.state; package net.kuujo.copycat.atomic.state;


import net.kuujo.copycat.Mode; import net.kuujo.copycat.PersistenceLevel;
import net.kuujo.copycat.log.Compaction; import net.kuujo.copycat.log.Compaction;
import net.kuujo.copycat.raft.Session; import net.kuujo.copycat.raft.Session;
import net.kuujo.copycat.raft.server.Apply; import net.kuujo.copycat.raft.server.Apply;
Expand Down Expand Up @@ -67,7 +67,7 @@ public void close(Session session) {
private boolean isActive(Commit<? extends ReferenceCommands.ReferenceCommand> commit) { private boolean isActive(Commit<? extends ReferenceCommands.ReferenceCommand> commit) {
if (commit == null) { if (commit == null) {
return false; return false;
} else if (commit.operation().mode() == Mode.EPHEMERAL && !sessions.contains(commit.session().id())) { } else if (commit.operation().mode() == PersistenceLevel.EPHEMERAL && !sessions.contains(commit.session().id())) {
return false; return false;
} else if (commit.operation().ttl() != 0 && commit.operation().ttl() < time - commit.timestamp()) { } else if (commit.operation().ttl() != 0 && commit.operation().ttl() < time - commit.timestamp()) {
return false; return false;
Expand Down
Expand Up @@ -15,7 +15,7 @@
*/ */
package net.kuujo.copycat.collections; package net.kuujo.copycat.collections;


import net.kuujo.copycat.Mode; import net.kuujo.copycat.PersistenceLevel;
import net.kuujo.copycat.raft.ConsistencyLevel; import net.kuujo.copycat.raft.ConsistencyLevel;


import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -106,10 +106,10 @@ public interface AsyncMap<K, V> {
* *
* @param key The key to set. * @param key The key to set.
* @param value The value to set. * @param value The value to set.
* @param mode The mode in which to set the key. * @param persistence The persistence in which to set the key.
* @return A completable future to be completed with the result once complete. * @return A completable future to be completed with the result once complete.
*/ */
CompletableFuture<V> put(K key, V value, Mode mode); CompletableFuture<V> put(K key, V value, PersistenceLevel persistence);


/** /**
* Puts a value in the map. * Puts a value in the map.
Expand All @@ -127,10 +127,10 @@ public interface AsyncMap<K, V> {
* @param key The key to set. * @param key The key to set.
* @param value The value to set. * @param value The value to set.
* @param ttl The time to live in milliseconds. * @param ttl The time to live in milliseconds.
* @param mode The mode in which to set the key. * @param persistence The persistence in which to set the key.
* @return A completable future to be completed with the result once complete. * @return A completable future to be completed with the result once complete.
*/ */
CompletableFuture<V> put(K key, V value, long ttl, Mode mode); CompletableFuture<V> put(K key, V value, long ttl, PersistenceLevel persistence);


/** /**
* Puts a value in the map. * Puts a value in the map.
Expand All @@ -150,10 +150,10 @@ public interface AsyncMap<K, V> {
* @param value The value to set. * @param value The value to set.
* @param ttl The time to live in milliseconds. * @param ttl The time to live in milliseconds.
* @param unit The time to live unit. * @param unit The time to live unit.
* @param mode The mode in which to set the key. * @param persistence The persistence in which to set the key.
* @return A completable future to be completed with the result once complete. * @return A completable future to be completed with the result once complete.
*/ */
CompletableFuture<V> put(K key, V value, long ttl, TimeUnit unit, Mode mode); CompletableFuture<V> put(K key, V value, long ttl, TimeUnit unit, PersistenceLevel persistence);


/** /**
* Removes a value from the map. * Removes a value from the map.
Expand Down Expand Up @@ -207,10 +207,10 @@ public interface AsyncMap<K, V> {
* @param key The key to set. * @param key The key to set.
* @param value The value to set if the given key does not exist. * @param value The value to set if the given key does not exist.
* @param ttl The time to live in milliseconds. * @param ttl The time to live in milliseconds.
* @param mode The mode in which to set the key. * @param persistence The persistence in which to set the key.
* @return A completable future to be completed with the result once complete. * @return A completable future to be completed with the result once complete.
*/ */
CompletableFuture<V> putIfAbsent(K key, V value, long ttl, Mode mode); CompletableFuture<V> putIfAbsent(K key, V value, long ttl, PersistenceLevel persistence);


/** /**
* Puts a value in the map if the given key does not exist. * Puts a value in the map if the given key does not exist.
Expand All @@ -230,10 +230,10 @@ public interface AsyncMap<K, V> {
* @param value The value to set if the given key does not exist. * @param value The value to set if the given key does not exist.
* @param ttl The time to live. * @param ttl The time to live.
* @param unit The time to live unit. * @param unit The time to live unit.
* @param mode The mode in which to set the key. * @param persistence The persistence in which to set the key.
* @return A completable future to be completed with the result once complete. * @return A completable future to be completed with the result once complete.
*/ */
CompletableFuture<V> putIfAbsent(K key, V value, long ttl, TimeUnit unit, Mode mode); CompletableFuture<V> putIfAbsent(K key, V value, long ttl, TimeUnit unit, PersistenceLevel persistence);


/** /**
* Removes a key and value from the map. * Removes a key and value from the map.
Expand Down

0 comments on commit bb66192

Please sign in to comment.