Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String literals should not be duplicated #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 24 additions & 16 deletions src/main/java/net/spy/memcached/MemcachedClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,15 @@
*/
public class MemcachedClient extends SpyObject implements MemcachedClientIF,
ConnectionObserver {


private static final String EXCEPTION_WAITING_FOR_VALUE = "Exception waiting for value";

private static final String INTERRUPTED_WAITING_FOR_VALUE = "Interrupted waiting for value";

private static final String TIMEOUT_WAITING_FOR_VALUE = "Timeout waiting for value";

private static final String WRONG_KEY_RETURNED = "Wrong key returned";

protected volatile boolean shuttingDown;

protected final long operationTimeout;
Expand Down Expand Up @@ -733,15 +741,15 @@ public <T> CASResponse cas(String key, long casId, int exp, T value,
TimeUnit.MILLISECONDS);
return casr;
} catch (InterruptedException e) {
throw new RuntimeException("Interrupted waiting for value", e);
throw new RuntimeException(INTERRUPTED_WAITING_FOR_VALUE, e);
} catch (ExecutionException e) {
if(e.getCause() instanceof CancellationException) {
throw (CancellationException) e.getCause();
} else {
throw new RuntimeException("Exception waiting for value", e);
throw new RuntimeException(EXCEPTION_WAITING_FOR_VALUE, e);
}
} catch (TimeoutException e) {
throw new OperationTimeoutException("Timeout waiting for value: "
throw new OperationTimeoutException(TIMEOUT_WAITING_FOR_VALUE
+ buildTimeoutMessage(operationTimeout, TimeUnit.MILLISECONDS), e);
}
}
Expand Down Expand Up @@ -1030,7 +1038,7 @@ public void receivedStatus(OperationStatus status) {

@Override
public void gotData(String k, int flags, byte[] data) {
assert key.equals(k) : "Wrong key returned";
assert key.equals(k) : WRONG_KEY_RETURNED;
val =
tcService.decode(tc, new CachedData(flags, data, tc.getMaxSize()));
}
Expand Down Expand Up @@ -1088,7 +1096,7 @@ public void receivedStatus(OperationStatus status) {

@Override
public void gotData(String k, int flags, long cas, byte[] data) {
assert key.equals(k) : "Wrong key returned";
assert key.equals(k) : WRONG_KEY_RETURNED;
val =
new CASValue<T>(cas, tc.decode(new CachedData(flags, data,
tc.getMaxSize())));
Expand Down Expand Up @@ -1136,15 +1144,15 @@ public <T> CASValue<T> gets(String key, Transcoder<T> tc) {
try {
return asyncGets(key, tc).get(operationTimeout, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
throw new RuntimeException("Interrupted waiting for value", e);
throw new RuntimeException(INTERRUPTED_WAITING_FOR_VALUE, e);
} catch (ExecutionException e) {
if(e.getCause() instanceof CancellationException) {
throw (CancellationException) e.getCause();
} else {
throw new RuntimeException("Exception waiting for value", e);
throw new RuntimeException(EXCEPTION_WAITING_FOR_VALUE, e);
}
} catch (TimeoutException e) {
throw new OperationTimeoutException("Timeout waiting for value", e);
throw new OperationTimeoutException(TIMEOUT_WAITING_FOR_VALUE, e);
}
}

Expand All @@ -1168,15 +1176,15 @@ public <T> CASValue<T> getAndTouch(String key, int exp, Transcoder<T> tc) {
return asyncGetAndTouch(key, exp, tc).get(operationTimeout,
TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
throw new RuntimeException("Interrupted waiting for value", e);
throw new RuntimeException(INTERRUPTED_WAITING_FOR_VALUE, e);
} catch (ExecutionException e) {
if(e.getCause() instanceof CancellationException) {
throw (CancellationException) e.getCause();
} else {
throw new RuntimeException("Exception waiting for value", e);
throw new RuntimeException(EXCEPTION_WAITING_FOR_VALUE, e);
}
} catch (TimeoutException e) {
throw new OperationTimeoutException("Timeout waiting for value", e);
throw new OperationTimeoutException(TIMEOUT_WAITING_FOR_VALUE, e);
}
}

Expand Down Expand Up @@ -1229,15 +1237,15 @@ public <T> T get(String key, Transcoder<T> tc) {
try {
return asyncGet(key, tc).get(operationTimeout, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
throw new RuntimeException("Interrupted waiting for value", e);
throw new RuntimeException(INTERRUPTED_WAITING_FOR_VALUE, e);
} catch (ExecutionException e) {
if(e.getCause() instanceof CancellationException) {
throw (CancellationException) e.getCause();
} else {
throw new RuntimeException("Exception waiting for value", e);
throw new RuntimeException(EXCEPTION_WAITING_FOR_VALUE, e);
}
} catch (TimeoutException e) {
throw new OperationTimeoutException("Timeout waiting for value: "
throw new OperationTimeoutException(TIMEOUT_WAITING_FOR_VALUE
+ buildTimeoutMessage(operationTimeout, TimeUnit.MILLISECONDS), e);
}
}
Expand Down Expand Up @@ -1525,7 +1533,7 @@ public void complete() {

@Override
public void gotData(String k, int flags, long cas, byte[] data) {
assert k.equals(key) : "Wrong key returned";
assert k.equals(key) : WRONG_KEY_RETURNED;
val =
new CASValue<T>(cas, tc.decode(new CachedData(flags, data,
tc.getMaxSize())));
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/net/spy/memcached/MemcachedConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public class MemcachedConnection extends SpyThread {
"[MEM] Response Rate: Failure";
private static final String OVERALL_RESPONSE_SUCC_METRIC =
"[MEM] Response Rate: Success";
private static final String WAKEUP_RETURNED_THE_WRONG_SELECTOR =
"Wakeup returned the wrong selector.";

/**
* If the connection is alread shut down or shutting down.
Expand Down Expand Up @@ -1247,7 +1249,7 @@ public void insertOperation(final MemcachedNode node, final Operation o) {
metrics.markMeter(OVERALL_REQUEST_METRIC);

Selector s = selector.wakeup();
assert s == selector : "Wakeup returned the wrong selector.";
assert s == selector : WAKEUP_RETURNED_THE_WRONG_SELECTOR;
getLogger().debug("Added %s to %s", o, node);
}

Expand All @@ -1269,7 +1271,7 @@ protected void addOperation(final MemcachedNode node, final Operation o) {
metrics.markMeter(OVERALL_REQUEST_METRIC);

Selector s = selector.wakeup();
assert s == selector : "Wakeup returned the wrong selector.";
assert s == selector : WAKEUP_RETURNED_THE_WRONG_SELECTOR;
getLogger().debug("Added %s to %s", o, node);
}

Expand Down Expand Up @@ -1315,7 +1317,7 @@ public CountDownLatch broadcastOperation(final BroadcastOpFactory of,
}

Selector s = selector.wakeup();
assert s == selector : "Wakeup returned the wrong selector.";
assert s == selector : WAKEUP_RETURNED_THE_WRONG_SELECTOR;
return latch;
}

Expand All @@ -1326,7 +1328,7 @@ public void shutdown() throws IOException {
shutDown = true;
try {
Selector s = selector.wakeup();
assert s == selector : "Wakeup returned the wrong selector.";
assert s == selector : WAKEUP_RETURNED_THE_WRONG_SELECTOR;
for (MemcachedNode node : locator.getAll()) {
if (node.getChannel() != null) {
node.getChannel().close();
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/spy/memcached/internal/OperationFuture.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class OperationFuture<T>
private Operation op;
private final String key;
private Long cas;

private static final String NO_OPERATTION = "No operation";
/**
* Create an OperationFuture for a given async operation.
*
Expand Down Expand Up @@ -107,7 +107,7 @@ public OperationFuture(String k, CountDownLatch l, AtomicReference<T> oref,
* @return true if the operation has not yet been written to the network
*/
public boolean cancel(boolean ign) {
assert op != null : "No operation";
assert op != null : NO_OPERATTION;
op.cancel();
notifyListeners();
return op.getState() == OperationState.WRITE_QUEUED;
Expand All @@ -119,7 +119,7 @@ public boolean cancel(boolean ign) {
* @return true if the operation has not yet been written to the network
*/
public boolean cancel() {
assert op != null : "No operation";
assert op != null : NO_OPERATTION;
op.cancel();
notifyListeners();
return op.getState() == OperationState.WRITE_QUEUED;
Expand Down Expand Up @@ -286,7 +286,7 @@ public void setOperation(Operation to) {
* @return true if the Operation has been canceled
*/
public boolean isCancelled() {
assert op != null : "No operation";
assert op != null : NO_OPERATTION;
return op.isCancelled();
}

Expand All @@ -301,7 +301,7 @@ public boolean isCancelled() {
* @return true if the Operation is done
*/
public boolean isDone() {
assert op != null : "No operation";
assert op != null : NO_OPERATTION;
return latch.getCount() == 0 || op.isCancelled()
|| op.getState() == OperationState.COMPLETE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
* Operation factory for the ascii protocol.
*/
public class AsciiOperationFactory extends BaseOperationFactory {

private static final String FOR_ASCIII_PROTOCOL = "for ASCII protocol";

private static final String TAP_IS_NOT_SUPPORTED_FOR_ASCII_PROTOCOL = "Tap is not supported for ASCII protocol";

public DeleteOperation delete(String key, DeleteOperation.Callback cb) {
return new DeleteOperationImpl(key, cb);
Expand All @@ -74,7 +78,7 @@ public DeleteOperation delete(String key, DeleteOperation.Callback cb) {
public DeleteOperation delete(String key, long cas,
DeleteOperation.Callback cb) {
throw new UnsupportedOperationException("Delete with CAS is not supported "
+ "for ASCII protocol");
+ FOR_ASCIII_PROTOCOL);
}

public FlushOperation flush(int delay, OperationCallback cb) {
Expand All @@ -84,7 +88,7 @@ public FlushOperation flush(int delay, OperationCallback cb) {
public GetAndTouchOperation getAndTouch(String key, int expiration,
GetAndTouchOperation.Callback cb) {
throw new UnsupportedOperationException("Get and touch is not supported "
+ "for ASCII protocol");
+ FOR_ASCIII_PROTOCOL);
}

public GetOperation get(String key, GetOperation.Callback cb) {
Expand All @@ -102,7 +106,7 @@ public GetlOperation getl(String key, int exp, GetlOperation.Callback cb) {
public ObserveOperation observe(String key, long casId, int index,
ObserveOperation.Callback cb) {
throw new UnsupportedOperationException("Observe is not supported "
+ "for ASCII protocol");
+ FOR_ASCIII_PROTOCOL);
}

public UnlockOperation unlock(String key, long casId,
Expand All @@ -116,7 +120,7 @@ public GetsOperation gets(String key, GetsOperation.Callback cb) {

public StatsOperation keyStats(String key, Callback cb) {
throw new UnsupportedOperationException("Key stats are not supported "
+ "for ASCII protocol");
+ FOR_ASCIII_PROTOCOL);
}

public MutatorOperation mutate(Mutator m, String key, long by, long exp,
Expand Down Expand Up @@ -187,41 +191,37 @@ public SASLAuthOperation saslAuth(String[] mech, String serverName,

@Override
public TapOperation tapBackfill(String id, long date, OperationCallback cb) {
throw new UnsupportedOperationException("Tap is not supported for ASCII"
+ " protocol");
throw new UnsupportedOperationException(TAP_IS_NOT_SUPPORTED_FOR_ASCII_PROTOCOL);
}

@Override
public TapOperation tapCustom(String id, RequestMessage message,
OperationCallback cb) {
throw new UnsupportedOperationException("Tap is not supported for ASCII"
+ " protocol");
throw new UnsupportedOperationException(TAP_IS_NOT_SUPPORTED_FOR_ASCII_PROTOCOL);
}

@Override
public TapOperation tapAck(TapOpcode opcode, int opaque,
OperationCallback cb) {
throw new UnsupportedOperationException("Tap is not supported for ASCII"
+ " protocol");
throw new UnsupportedOperationException(TAP_IS_NOT_SUPPORTED_FOR_ASCII_PROTOCOL);
}

@Override
public TapOperation tapDump(String id, OperationCallback cb) {
throw new UnsupportedOperationException("Tap is not supported for ASCII"
+ " protocol");
throw new UnsupportedOperationException(TAP_IS_NOT_SUPPORTED_FOR_ASCII_PROTOCOL);
}

@Override
public ReplicaGetOperation replicaGet(String key, int index,
ReplicaGetOperation.Callback callback) {
throw new UnsupportedOperationException("Replica get is not supported "
+ "for ASCII protocol");
+ FOR_ASCIII_PROTOCOL);
}

@Override
public ReplicaGetsOperation replicaGets(String key, int index,
ReplicaGetsOperation.Callback callback) {
throw new UnsupportedOperationException("Replica gets is not supported "
+ "for ASCII protocol");
+ FOR_ASCIII_PROTOCOL);
}
}