From 4e2d66eee125e3d2136790619c07ab0ad5b25929 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 2 Jul 2015 07:30:49 +0200 Subject: [PATCH] Move anonymous class to its own method and use a lambda to call it --- .../fcp/quelaton/DefaultFcpClient.java | 67 +++++++++++----------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/DefaultFcpClient.java b/src/main/java/net/pterodactylus/fcp/quelaton/DefaultFcpClient.java index c37b40a..603b150 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/DefaultFcpClient.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/DefaultFcpClient.java @@ -179,40 +179,39 @@ public class DefaultFcpClient implements FcpClient { @Override public Future> uri(String uri) { - return threadPool.submit(new Callable>() { - @Override - public Optional call() throws Exception { - DefaultFcpClient.this.connect(); - ClientGet clientGet = new ClientGet(uri, identifier, ReturnType.direct); - if (ignoreDataStore) { - clientGet.setIgnoreDataStore(true); - } - if (dataStoreOnly) { - clientGet.setDataStoreOnly(true); - } - if (maxSize != null) { - clientGet.setMaxSize(maxSize); - } - if (priority != null) { - clientGet.setPriority(priority); - } - if (realTime) { - clientGet.setRealTimeFlag(true); - } - if (global) { - clientGet.setGlobal(true); - } - try (FcpReplySequence replySequence = new FcpReplySequence(threadPool, fcpConnection.get())) { - Sequence sequence = new Sequence(identifier); - replySequence.handle(AllData.class).with(sequence::allData); - replySequence.handle(GetFailed.class).with(sequence::getFailed); - replySequence.handleClose().with(sequence::disconnect); - replySequence.waitFor(sequence::isFinished); - replySequence.send(clientGet).get(); - return sequence.isSuccessful() ? Optional.of(sequence.getData()) : Optional.empty(); - } - } - }); + return threadPool.submit(() -> execute(uri)); + } + + private Optional execute(String uri) throws IOException, ExecutionException, InterruptedException { + DefaultFcpClient.this.connect(); + ClientGet clientGet = new ClientGet(uri, identifier, ReturnType.direct); + if (ignoreDataStore) { + clientGet.setIgnoreDataStore(true); + } + if (dataStoreOnly) { + clientGet.setDataStoreOnly(true); + } + if (maxSize != null) { + clientGet.setMaxSize(maxSize); + } + if (priority != null) { + clientGet.setPriority(priority); + } + if (realTime) { + clientGet.setRealTimeFlag(true); + } + if (global) { + clientGet.setGlobal(true); + } + try (FcpReplySequence replySequence = new FcpReplySequence(threadPool, fcpConnection.get())) { + Sequence sequence = new Sequence(identifier); + replySequence.handle(AllData.class).with(sequence::allData); + replySequence.handle(GetFailed.class).with(sequence::getFailed); + replySequence.handleClose().with(sequence::disconnect); + replySequence.waitFor(sequence::isFinished); + replySequence.send(clientGet).get(); + return sequence.isSuccessful() ? Optional.of(sequence.getData()) : Optional.empty(); + } } private class Sequence { -- 2.7.4