Skip to content

Commit

Permalink
INTERNAL: make waitForQueues method into private
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviarla authored and jhpark816 committed Aug 13, 2024
1 parent 0bfdbb8 commit e99869f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 28 deletions.
5 changes: 0 additions & 5 deletions src/main/java/net/spy/memcached/ArcusClientPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -461,11 +461,6 @@ public Future<Boolean> flush() {
return this.getClient().flush();
}

@Override
public boolean waitForQueues(long timeout, TimeUnit unit) {
return this.getClient().waitForQueues(timeout, unit);
}

@Override
public boolean addObserver(ConnectionObserver obs) {
return this.getClient().addObserver(obs);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/spy/memcached/MemcachedClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2122,7 +2122,7 @@ public boolean shutdown(long timeout, TimeUnit unit) {
* @throws IllegalStateException in the rare circumstance where queue
* is too full to accept any more requests
*/
public boolean waitForQueues(long timeout, TimeUnit unit) {
private boolean waitForQueues(long timeout, TimeUnit unit) {
Collection<MemcachedNode> nodes = getAllNodes();
final CountDownLatch latch = new CountDownLatch(nodes.size());

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/net/spy/memcached/MemcachedClientIF.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,6 @@ long decr(String key, int by, long def)

boolean shutdown(long timeout, TimeUnit unit);

boolean waitForQueues(long timeout, TimeUnit unit);

boolean addObserver(ConnectionObserver obs);

boolean removeObserver(ConnectionObserver obs);
Expand Down
17 changes: 1 addition & 16 deletions src/test/manual/net/spy/memcached/test/MemcachedThreadBench.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
*/
package net.spy.memcached.test;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import junit.framework.TestCase;

import net.spy.memcached.AddrUtil;
Expand Down Expand Up @@ -135,8 +132,6 @@ public static void main(String[] args) throws Exception {
}

private static class SetterThread extends Thread {
private static final AtomicInteger total = new AtomicInteger(0);
private static final int MAX_QUEUE = 10000;
private final MemcachedClient mc;
private final WorkerStat stat;

Expand All @@ -157,25 +152,15 @@ public void run() {
long begin = System.currentTimeMillis();
for (int i = stat.start; i < stat.start + stat.runs; i++) {
try {
mc.set("" + i + keyBase, 3600, object).get();
mc.set(i + keyBase, 3600, object).get();
} catch (Exception e) {
fail(e.getMessage());
}
if (total.incrementAndGet() >= MAX_QUEUE) {
flush();
}
}
long end = System.currentTimeMillis();

stat.setterTime = end - begin;
}

private synchronized void flush() {
if (total.intValue() >= MAX_QUEUE) {
mc.waitForQueues(5, TimeUnit.SECONDS);
total.set(0);
}
}
}

private static class GetterThread extends Thread {
Expand Down
12 changes: 8 additions & 4 deletions src/test/manual/net/spy/memcached/test/ObserverToy.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public final class ObserverToy {
private ObserverToy() {
}

public static void main(String args[]) throws Exception {
public static void main(String[] args) throws Exception {
final ConnectionObserver obs = new ConnectionObserver() {
public void connectionEstablished(SocketAddress sa,
int reconnectCount) {
Expand All @@ -33,7 +33,7 @@ public void connectionLost(SocketAddress sa) {

};

MemcachedClient c = new MemcachedClient(new DefaultConnectionFactory() {
MemcachedClient client = new MemcachedClient(new DefaultConnectionFactory() {

@Override
public Collection<ConnectionObserver> getInitialObservers() {
Expand All @@ -48,8 +48,12 @@ public boolean isDaemon() {
}, AddrUtil.getAddresses("localhost:11212"));

while (true) {
c.waitForQueues(1, TimeUnit.SECONDS);
Thread.sleep(1000);
try {
client.asyncGet("ObserverToy").get(1, TimeUnit.SECONDS);
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Expand Down

0 comments on commit e99869f

Please sign in to comment.