From b14a03561280cccc0ccf15a4716107c724c60e33 Mon Sep 17 00:00:00 2001 From: brido4125 Date: Wed, 24 Jan 2024 15:04:39 +0900 Subject: [PATCH] INTERNAL: Remove TranscodeService. --- .../net/spy/memcached/MemcachedClient.java | 5 - .../transcoders/TranscodeService.java | 117 ------------------ .../transcoders/TranscodeServiceTest.java | 60 --------- 3 files changed, 182 deletions(-) delete mode 100644 src/main/java/net/spy/memcached/transcoders/TranscodeService.java delete mode 100644 src/test/java/net/spy/memcached/transcoders/TranscodeServiceTest.java diff --git a/src/main/java/net/spy/memcached/MemcachedClient.java b/src/main/java/net/spy/memcached/MemcachedClient.java index f85634109..621f83c4a 100644 --- a/src/main/java/net/spy/memcached/MemcachedClient.java +++ b/src/main/java/net/spy/memcached/MemcachedClient.java @@ -66,7 +66,6 @@ import net.spy.memcached.ops.OperationStatus; import net.spy.memcached.ops.StatsOperation; import net.spy.memcached.ops.StoreType; -import net.spy.memcached.transcoders.TranscodeService; import net.spy.memcached.transcoders.Transcoder; /** @@ -132,8 +131,6 @@ public class MemcachedClient extends SpyThread protected final Transcoder transcoder; - private final TranscodeService tcService; - private final AuthDescriptor authDescriptor; private final byte delimiter; @@ -214,7 +211,6 @@ public MemcachedClient(ConnectionFactory cf, String name, List(100), - new BasicThreadFactory("transcoder", daemon), - new ThreadPoolExecutor.DiscardPolicy()); - } - - /** - * Perform a decode. - */ - public Future decode(final Transcoder tc, - final CachedData cachedData) { - - assert !pool.isShutdown() : "Pool has already shut down."; - - TranscodeService.Task task = new TranscodeService.Task( - new Callable() { - public T call() { - return tc.decode(cachedData); - } - }); - - if (tc.asyncDecode(cachedData)) { - this.pool.execute(task); - } - return task; - } - - /** - * Perform a decode. - */ - public Future> decode(final Transcoder tc, - final long cas, - final CachedData cachedData) { - - assert !pool.isShutdown() : "Pool has already shut down."; - - TranscodeService.Task> task = new TranscodeService.Task>( - new Callable>() { - public CASValue call() { - return new CASValue(cas, tc.decode(cachedData)); - } - }); - - if (tc.asyncDecode(cachedData)) { - this.pool.execute(task); - } - return task; - } - - /** - * Shut down the pool. - */ - public void shutdown() { - pool.shutdown(); - } - - /** - * Ask whether this service has been shut down. - */ - public boolean isShutdown() { - return pool.isShutdown(); - } - - private static class Task extends FutureTask { - private final AtomicBoolean isRunning = new AtomicBoolean(false); - - public Task(Callable callable) { - super(callable); - } - - @Override - public T get() throws InterruptedException, ExecutionException { - this.run(); - return super.get(); - } - - @Override - public T get(long timeout, TimeUnit unit) throws InterruptedException, - ExecutionException, TimeoutException { - this.run(); - return super.get(timeout, unit); - } - - @Override - public void run() { - if (this.isRunning.compareAndSet(false, true)) { - super.run(); - } - } - } - -} diff --git a/src/test/java/net/spy/memcached/transcoders/TranscodeServiceTest.java b/src/test/java/net/spy/memcached/transcoders/TranscodeServiceTest.java deleted file mode 100644 index e4619e715..000000000 --- a/src/test/java/net/spy/memcached/transcoders/TranscodeServiceTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package net.spy.memcached.transcoders; - -import java.util.concurrent.Future; - -import junit.framework.TestCase; - -import net.spy.memcached.CachedData; - -/** - * Test the transcode service. - */ -public class TranscodeServiceTest extends TestCase { - - private TranscodeService ts = null; - - @Override - protected void setUp() throws Exception { - super.setUp(); - ts = new TranscodeService(false); - } - - @Override - protected void tearDown() throws Exception { - ts.shutdown(); - assertTrue(ts.isShutdown()); - super.tearDown(); - } - - public void testNonExecuting() throws Exception { - CachedData cd = new CachedData(0, new byte[0], 0); - Future fs = ts.decode(new TestTranscoder(), cd); - assertEquals("Stuff!", fs.get()); - } - - public void testExecuting() throws Exception { - CachedData cd = new CachedData(1, new byte[0], 0); - Future fs = ts.decode(new TestTranscoder(), cd); - assertEquals("Stuff!", fs.get()); - } - - private static final class TestTranscoder implements Transcoder { - - public boolean asyncDecode(CachedData d) { - return d.getFlags() == 1; - } - - public String decode(CachedData d) { - return "Stuff!"; - } - - public CachedData encode(String o) { - throw new RuntimeException("Not invoked."); - } - - public int getMaxSize() { - return 5; - } - - } -}