Skip to content

Commit

Permalink
Refactor core API methods for coding standards.
Browse files Browse the repository at this point in the history
  • Loading branch information
kuujo committed Jun 23, 2017
1 parent f1a7ee1 commit 547f656
Show file tree
Hide file tree
Showing 30 changed files with 60 additions and 125 deletions.
3 changes: 2 additions & 1 deletion core/src/main/java/io/atomix/cluster/LockEvent.java
Expand Up @@ -26,7 +26,8 @@ public class LockEvent extends AbstractEvent<LockEvent.Type, NodeId> {
* Lock event type. * Lock event type.
*/ */
public enum Type { public enum Type {
LOCK LOCK,
UNLOCK,
} }


public LockEvent(Type type, NodeId subject) { public LockEvent(Type type, NodeId subject) {
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/io/atomix/cluster/Node.java
Expand Up @@ -68,20 +68,20 @@ public boolean isReady() {
* *
* @return instance identifier * @return instance identifier
*/ */
NodeId id(); NodeId getNodeId();


/** /**
* Returns the IP address of the controller instance. * Returns the IP address of the controller instance.
* *
* @return IP address * @return IP address
*/ */
InetAddress ip(); InetAddress getInetAddress();


/** /**
* Returns the TCP port on which the node listens for connections. * Returns the TCP port on which the node listens for connections.
* *
* @return TCP port * @return TCP port
*/ */
int tcpPort(); int getTcpPort();


} }
2 changes: 1 addition & 1 deletion core/src/main/java/io/atomix/cluster/Partition.java
Expand Up @@ -28,7 +28,7 @@ public interface Partition {
* *
* @return partition identifier * @return partition identifier
*/ */
PartitionId getId(); PartitionId getPartitionId();


/** /**
* Returns the controller nodes that are members of this partition. * Returns the controller nodes that are members of this partition.
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/io/atomix/leadership/Leader.java
Expand Up @@ -49,7 +49,7 @@ public Leader(NodeId nodeId, long term, long termStartTime) {
* *
* @return node identifier * @return node identifier
*/ */
public NodeId nodeId() { public NodeId getNodeId() {
return nodeId; return nodeId;
} }


Expand All @@ -58,7 +58,7 @@ public NodeId nodeId() {
* *
* @return leader term * @return leader term
*/ */
public long term() { public long getTerm() {
return term; return term;
} }


Expand All @@ -67,7 +67,7 @@ public long term() {
* *
* @return current leader term start time * @return current leader term start time
*/ */
public long termStartTime() { public long getTimestamp() {
return termStartTime; return termStartTime;
} }


Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/io/atomix/leadership/Leadership.java
Expand Up @@ -56,7 +56,7 @@ public String topic() {
* @return leader node identifier; will be null if there is no leader * @return leader node identifier; will be null if there is no leader
*/ */
public NodeId leaderNodeId() { public NodeId leaderNodeId() {
return leader == null ? null : leader.nodeId(); return leader == null ? null : leader.getNodeId();
} }


/** /**
Expand Down
Expand Up @@ -138,14 +138,14 @@ enum Status {
* *
* @return name * @return name
*/ */
String name(); String getName();


/** /**
* Returns the type of primitive. * Returns the type of primitive.
* *
* @return primitive type * @return primitive type
*/ */
Type primitiveType(); Type getPrimitiveType();


/** /**
* Purges state associated with this primitive. * Purges state associated with this primitive.
Expand Down
Expand Up @@ -17,9 +17,6 @@


import io.atomix.serializer.Serializer; import io.atomix.serializer.Serializer;


import java.util.concurrent.Executor;
import java.util.function.Supplier;

/** /**
* Abstract builder for distributed primitives. * Abstract builder for distributed primitives.
* *
Expand All @@ -31,9 +28,6 @@ public abstract class DistributedPrimitiveBuilder<B extends DistributedPrimitive
private final DistributedPrimitive.Type type; private final DistributedPrimitive.Type type;
private String name; private String name;
private Serializer serializer; private Serializer serializer;
private Supplier<Executor> executorSupplier;
private boolean partitionsDisabled = false;
private boolean meteringDisabled = false;
private boolean readOnly = false; private boolean readOnly = false;
private boolean relaxedReadConsistency = false; private boolean relaxedReadConsistency = false;


Expand All @@ -47,6 +41,7 @@ public DistributedPrimitiveBuilder(DistributedPrimitive.Type type) {
* @param name primitive name * @param name primitive name
* @return this builder * @return this builder
*/ */
@SuppressWarnings("unchecked")
public B withName(String name) { public B withName(String name) {
this.name = name; this.name = name;
return (B) this; return (B) this;
Expand All @@ -58,53 +53,18 @@ public B withName(String name) {
* @param serializer serializer * @param serializer serializer
* @return this builder * @return this builder
*/ */
@SuppressWarnings("unchecked")
public B withSerializer(Serializer serializer) { public B withSerializer(Serializer serializer) {
this.serializer = serializer; this.serializer = serializer;
return (B) this; return (B) this;
} }


/**
* Sets the executor to use for asynchronous callbacks.
* <p>
* For partitioned primitives, the provided executor will be shared across all partitions.
*
* @param executor the executor to use for asynchronous callbacks
* @return this builder
*/
public B withExecutor(Executor executor) {
return withExecutorSupplier(() -> executor);
}

/**
* Sets the supplier to be used to create executors.
* <p>
* When a factory is set, the supplier will be used to create a separate executor for each partition.
*
* @param executorSupplier the executor supplier
* @return this builder
*/
public B withExecutorSupplier(Supplier<Executor> executorSupplier) {
this.executorSupplier = executorSupplier;
return (B) this;
}

/**
* Disables recording usage stats for this primitive.
*
* @return this builder
* @deprecated usage of this method is discouraged for most common scenarios.
*/
@Deprecated
public B withMeteringDisabled() {
this.meteringDisabled = true;
return (B) this;
}

/** /**
* Disables state changing operations on the returned distributed primitive. * Disables state changing operations on the returned distributed primitive.
* *
* @return this builder * @return this builder
*/ */
@SuppressWarnings("unchecked")
public B withUpdatesDisabled() { public B withUpdatesDisabled() {
this.readOnly = true; this.readOnly = true;
return (B) this; return (B) this;
Expand All @@ -115,35 +75,18 @@ public B withUpdatesDisabled() {
* *
* @return this builder * @return this builder
*/ */
@SuppressWarnings("unchecked")
public B withRelaxedReadConsistency() { public B withRelaxedReadConsistency() {
this.relaxedReadConsistency = true; this.relaxedReadConsistency = true;
return (B) this; return (B) this;
} }


/**
* Returns if metering is enabled.
*
* @return {@code true} if yes; {@code false} otherwise
*/
public final boolean meteringEnabled() {
return !meteringDisabled;
}

/**
* Returns if partitions are disabled.
*
* @return {@code true} if yes; {@code false} otherwise
*/
public final boolean partitionsDisabled() {
return partitionsDisabled;
}

/** /**
* Returns if updates are disabled. * Returns if updates are disabled.
* *
* @return {@code true} if yes; {@code false} otherwise * @return {@code true} if yes; {@code false} otherwise
*/ */
public final boolean readOnly() { public final boolean isReadOnly() {
return readOnly; return readOnly;
} }


Expand All @@ -152,7 +95,7 @@ public final boolean readOnly() {
* *
* @return {@code true} if yes; {@code false} otherwise * @return {@code true} if yes; {@code false} otherwise
*/ */
public final boolean relaxedReadConsistency() { public final boolean isRelaxedReadConsistency() {
return relaxedReadConsistency; return relaxedReadConsistency;
} }


Expand All @@ -161,25 +104,16 @@ public final boolean relaxedReadConsistency() {
* *
* @return serializer * @return serializer
*/ */
public final Serializer serializer() { public final Serializer getSerializer() {
return serializer; return serializer;
} }


/**
* Returns the executor supplier.
*
* @return executor supplier
*/
public final Supplier<Executor> executorSupplier() {
return executorSupplier;
}

/** /**
* Returns the name of the primitive. * Returns the name of the primitive.
* *
* @return primitive name * @return primitive name
*/ */
public final String name() { public final String getName() {
return name; return name;
} }


Expand All @@ -188,7 +122,7 @@ public final String name() {
* *
* @return primitive type * @return primitive type
*/ */
public final DistributedPrimitive.Type type() { public final DistributedPrimitive.Type getPrimitiveType() {
return type; return type;
} }


Expand Down
24 changes: 12 additions & 12 deletions core/src/main/java/io/atomix/primitives/PrimitiveService.java
Expand Up @@ -40,7 +40,7 @@ public interface PrimitiveService {
* @param <V> value type * @param <V> value type
* @return builder for an eventually consistent map * @return builder for an eventually consistent map
*/ */
<K, V> EventuallyConsistentMapBuilder<K, V> eventuallyConsistentMapBuilder(); <K, V> EventuallyConsistentMapBuilder<K, V> newEventuallyConsistentMapBuilder();


/** /**
* Creates a new ConsistentMapBuilder. * Creates a new ConsistentMapBuilder.
Expand All @@ -49,23 +49,23 @@ public interface PrimitiveService {
* @param <V> value type * @param <V> value type
* @return builder for a consistent map * @return builder for a consistent map
*/ */
<K, V> ConsistentMapBuilder<K, V> consistentMapBuilder(); <K, V> ConsistentMapBuilder<K, V> newConsistentMapBuilder();


/** /**
* Creates a new ConsistentMapBuilder. * Creates a new ConsistentMapBuilder.
* *
* @param <V> value type * @param <V> value type
* @return builder for a consistent map * @return builder for a consistent map
*/ */
<V> DocumentTreeBuilder<V> documentTreeBuilder(); <V> DocumentTreeBuilder<V> newDocumentTreeBuilder();


/** /**
* Creates a new {@code AsyncConsistentTreeMapBuilder}. * Creates a new {@code AsyncConsistentTreeMapBuilder}.
* *
* @param <V> value type * @param <V> value type
* @return builder for a async consistent tree map * @return builder for a async consistent tree map
*/ */
<V> ConsistentTreeMapBuilder<V> consistentTreeMapBuilder(); <V> ConsistentTreeMapBuilder<V> newConsistentTreeMapBuilder();


/** /**
* Creates a new {@code AsyncConsistentSetMultimapBuilder}. * Creates a new {@code AsyncConsistentSetMultimapBuilder}.
Expand All @@ -74,58 +74,58 @@ public interface PrimitiveService {
* @param <V> value type * @param <V> value type
* @return builder for a set based async consistent multimap * @return builder for a set based async consistent multimap
*/ */
<K, V> ConsistentMultimapBuilder<K, V> consistentMultimapBuilder(); <K, V> ConsistentMultimapBuilder<K, V> newConsistentMultimapBuilder();


/** /**
* Creates a new {@code AtomicCounterMapBuilder}. * Creates a new {@code AtomicCounterMapBuilder}.
* *
* @param <K> key type * @param <K> key type
* @return builder for an atomic counter map * @return builder for an atomic counter map
*/ */
<K> AtomicCounterMapBuilder<K> atomicCounterMapBuilder(); <K> AtomicCounterMapBuilder<K> newAtomicCounterMapBuilder();


/** /**
* Creates a new DistributedSetBuilder. * Creates a new DistributedSetBuilder.
* *
* @param <E> set element type * @param <E> set element type
* @return builder for an distributed set * @return builder for an distributed set
*/ */
<E> DistributedSetBuilder<E> setBuilder(); <E> DistributedSetBuilder<E> newSetBuilder();


/** /**
* Creates a new AtomicCounterBuilder. * Creates a new AtomicCounterBuilder.
* *
* @return atomic counter builder * @return atomic counter builder
*/ */
AtomicCounterBuilder atomicCounterBuilder(); AtomicCounterBuilder newAtomicCounterBuilder();


/** /**
* Creates a new AtomicIdGeneratorBuilder. * Creates a new AtomicIdGeneratorBuilder.
* *
* @return atomic ID generator builder * @return atomic ID generator builder
*/ */
AtomicIdGeneratorBuilder atomicIdGeneratorBuilder(); AtomicIdGeneratorBuilder newAtomicIdGeneratorBuilder();


/** /**
* Creates a new AtomicValueBuilder. * Creates a new AtomicValueBuilder.
* *
* @param <V> atomic value type * @param <V> atomic value type
* @return atomic value builder * @return atomic value builder
*/ */
<V> AtomicValueBuilder<V> atomicValueBuilder(); <V> AtomicValueBuilder<V> newAtomicValueBuilder();


/** /**
* Creates a new LeaderElectorBuilder. * Creates a new LeaderElectorBuilder.
* *
* @return leader elector builder * @return leader elector builder
*/ */
LeaderElectorBuilder leaderElectorBuilder(); LeaderElectorBuilder newLeaderElectorBuilder();


/** /**
* Creates a new DistributedLockBuilder. * Creates a new DistributedLockBuilder.
* *
* @return distributed lock builder * @return distributed lock builder
*/ */
DistributedLockBuilder lockBuilder(); DistributedLockBuilder newLockBuilder();


} }
8 changes: 4 additions & 4 deletions core/src/main/java/io/atomix/primitives/Synchronous.java
Expand Up @@ -32,13 +32,13 @@ public Synchronous(T primitive) {
} }


@Override @Override
public String name() { public String getName() {
return primitive.name(); return primitive.getName();
} }


@Override @Override
public Type primitiveType() { public Type getPrimitiveType() {
return primitive.primitiveType(); return primitive.getPrimitiveType();
} }


@Override @Override
Expand Down
Expand Up @@ -26,7 +26,7 @@
public interface AsyncAtomicCounter extends DistributedPrimitive { public interface AsyncAtomicCounter extends DistributedPrimitive {


@Override @Override
default DistributedPrimitive.Type primitiveType() { default DistributedPrimitive.Type getPrimitiveType() {
return DistributedPrimitive.Type.COUNTER; return DistributedPrimitive.Type.COUNTER;
} }


Expand Down

0 comments on commit 547f656

Please sign in to comment.