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

Use System.nanoTime() #84

Merged
merged 1 commit into from
May 13, 2013
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ private static ThreadFactory threadFactory(String nameFormat) {
}

static long timeSince(long start, TimeUnit unit) {
return unit.convert(System.currentTimeMillis() - start, TimeUnit.MILLISECONDS);
return unit.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS);
}

/**
Expand Down Expand Up @@ -601,7 +601,7 @@ private boolean shutdown(long timeout, TimeUnit unit) throws InterruptedExceptio

logger.debug("Shutting down");

long start = System.currentTimeMillis();
long start = System.nanoTime();
boolean success = true;

success &= controlConnection.shutdown(timeout, unit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,13 @@ public boolean close(long timeout, TimeUnit unit) throws InterruptedException {
// Make sure all new writes are rejected
isClosed = true;

long start = System.currentTimeMillis();
long start = System.nanoTime();
if (!isDefunct) {
// Busy waiting, we just wait for request to be fully written, shouldn't take long
while (writer.get() > 0 && Cluster.timeSince(start, unit) < timeout)
Uninterruptibles.sleepUninterruptibly(1, unit);
}
return channel.close().await(timeout - unit.convert(System.currentTimeMillis() - start, TimeUnit.MILLISECONDS), unit);
return channel.close().await(timeout - Cluster.timeSince(start, unit), unit);
// Note: we must not call releaseExternalResources on the bootstrap, because this shutdown the executors, which are shared
}

Expand Down Expand Up @@ -419,7 +419,7 @@ public boolean shutdown(long timeout, TimeUnit unit) throws InterruptedException
// Make sure we skip creating connection from now on.
isShutdown = true;

long start = System.currentTimeMillis();
long start = System.nanoTime();
ChannelGroupFuture future = allChannels.close();

channelFactory.releaseExternalResources();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ private void refreshNodeListAndTokenMap(Connection connection) throws Connection

static boolean waitForSchemaAgreement(Connection connection, Metadata metadata) throws ConnectionException, BusyConnectionException, ExecutionException, InterruptedException {

long start = System.currentTimeMillis();
long start = System.nanoTime();
long elapsed = 0;
while (elapsed < MAX_SCHEMA_AGREEMENT_WAIT_MS) {
ResultSetFuture peersFuture = new ResultSetFuture(null, new QueryMessage(SELECT_SCHEMA_PEERS, ConsistencyLevel.DEFAULT_CASSANDRA_CL));
Expand Down Expand Up @@ -415,7 +415,7 @@ static boolean waitForSchemaAgreement(Connection connection, Metadata metadata)
// let's not flood the node too much
Thread.sleep(200);

elapsed = System.currentTimeMillis() - start;
elapsed = Cluster.timeSince(start, TimeUnit.MILLISECONDS);
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,6 @@ public Connection borrowConnection(long timeout, TimeUnit unit) throws Connectio
return leastBusy;
}

private static long elapsed(long start, TimeUnit unit) {
return unit.convert(System.currentTimeMillis() - start, TimeUnit.MILLISECONDS);
}

private void awaitAvailableConnection(long timeout, TimeUnit unit) throws InterruptedException {
waitLock.lock();
try {
Expand Down Expand Up @@ -159,7 +155,7 @@ private void signalAllAvailableConnection() {
}

private Connection waitForConnection(long timeout, TimeUnit unit) throws ConnectionException, TimeoutException {
long start = System.currentTimeMillis();
long start = System.nanoTime();
long remaining = timeout;
do {
try {
Expand Down Expand Up @@ -193,7 +189,7 @@ private Connection waitForConnection(long timeout, TimeUnit unit) throws Connect
return leastBusy;
}

remaining = timeout - elapsed(start, unit);
remaining = timeout - Cluster.timeSince(start, unit);
} while (remaining > 0);

throw new TimeoutException();
Expand Down Expand Up @@ -343,7 +339,7 @@ public int opened() {
}

private boolean discardAvailableConnections(long timeout, TimeUnit unit) throws InterruptedException {
long start = System.currentTimeMillis();
long start = System.nanoTime();
boolean success = true;
for (Connection connection : connections) {
success &= connection.close(timeout - Cluster.timeSince(start, unit), unit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private boolean shutdown(long timeout, TimeUnit unit) throws InterruptedExceptio
if (!isShutdown.compareAndSet(false, true))
return true;

long start = System.currentTimeMillis();
long start = System.nanoTime();
boolean success = true;
for (HostConnectionPool pool : pools.values())
success &= pool.shutdown(timeout - Cluster.timeSince(start, unit), unit);
Expand Down