From: David ‘Bombe’ Roden Date: Thu, 2 Jul 2015 05:30:49 +0000 (+0200) Subject: Move anonymous class to its own method and use a lambda to call it X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=4e2d66eee125e3d2136790619c07ab0ad5b25929;p=jFCPlib.git Move anonymous class to its own method and use a lambda to call it --- 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 {