X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Ffcp%2Fquelaton%2FClientPutCommandImpl.java;h=02d020c78dee9cbce579bf59bc8220e7a42907aa;hb=ff2e4b93bfb1030fd11ec295f4ae6e9bd29b6966;hp=39d525ad01837c01b4e65383a71f02f81fd1a26b;hpb=d05d526e4db3c92e6795c3e25648e159ae9a1473;p=jFCPlib.git diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/ClientPutCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/ClientPutCommandImpl.java index 39d525a..02d020c 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/ClientPutCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/ClientPutCommandImpl.java @@ -54,32 +54,32 @@ class ClientPutCommandImpl implements ClientPutCommand { } @Override - public Keyed> redirectTo(String uri) { + public WithUri>> redirectTo(String uri) { this.redirectUri.set(Objects.requireNonNull(uri, "uri must not be null")); return this::key; } @Override - public Keyed> from(File file) { + public WithUri>> from(File file) { this.file.set(Objects.requireNonNull(file, "file must not be null")); return this::key; } @Override - public Lengthed>> from(InputStream inputStream) { + public WithLength>>> from(InputStream inputStream) { payload.set(Objects.requireNonNull(inputStream, "inputStream must not be null")); return this::length; } - private Keyed> length(long length) { + private WithUri>> length(long length) { this.length.set(length); return this::key; } - private ListenableFuture> key(Key key) { + private Executable> key(String uri) { String identifier = new RandomIdentifierGenerator().generate(); - ClientPut clientPut = createClientPutCommand(key.getKey(), identifier); - return threadPool.submit(() -> new ClientPutReplySequence().send(clientPut).get()); + ClientPut clientPut = createClientPutCommand(uri, identifier); + return () -> threadPool.submit(() -> new ClientPutReplySequence().send(clientPut).get()); } private ClientPut createClientPutCommand(String uri, String identifier) { @@ -119,7 +119,6 @@ class ClientPutCommandImpl implements ClientPutCommand { private class ClientPutReplySequence extends FcpReplySequence> { private final AtomicReference originalClientPut = new AtomicReference<>(); - private final AtomicReference identifier = new AtomicReference<>(); private final AtomicReference directory = new AtomicReference<>(); private final AtomicReference finalKey = new AtomicReference<>(); private final AtomicBoolean putFinished = new AtomicBoolean(); @@ -141,7 +140,6 @@ class ClientPutCommandImpl implements ClientPutCommand { @Override public ListenableFuture> send(FcpMessage fcpMessage) throws IOException { originalClientPut.set(fcpMessage); - identifier.set(fcpMessage.getField("Identifier")); String filename = fcpMessage.getField("Filename"); if (filename != null) { directory.set(new File(filename).getParent()); @@ -151,52 +149,39 @@ class ClientPutCommandImpl implements ClientPutCommand { @Override protected void consumePutSuccessful(PutSuccessful putSuccessful) { - if (putSuccessful.getIdentifier().equals(identifier.get())) { - finalKey.set(new Key(putSuccessful.getURI())); - putFinished.set(true); - } + finalKey.set(new Key(putSuccessful.getURI())); + putFinished.set(true); } @Override protected void consumePutFailed(PutFailed putFailed) { - if (putFailed.getIdentifier().equals(identifier.get())) { - putFinished.set(true); - } + putFinished.set(true); } @Override protected void consumeProtocolError(ProtocolError protocolError) { - if (protocolError.getIdentifier().equals(identifier.get())) { - if (protocolError.getCode() == 25) { - sendMessage(new TestDDARequest(directory.get(), true, false)); - } else { - putFinished.set(true); - } + if (protocolError.getCode() == 25) { + setIdentifier(directory.get()); + sendMessage(new TestDDARequest(directory.get(), true, false)); + } else { + putFinished.set(true); } } @Override protected void consumeTestDDAReply(TestDDAReply testDDAReply) { - if (testDDAReply.getDirectory().equals(directory.get())) { - try { - String readContent = Files.readAllLines(new File(testDDAReply.getReadFilename()).toPath()).get(0); - sendMessage(new TestDDAResponse(directory.get(), readContent)); - } catch (IOException e) { - sendMessage(new TestDDAResponse(directory.get(), "failed-to-read")); - } + try { + String readContent = Files.readAllLines(new File(testDDAReply.getReadFilename()).toPath()).get(0); + sendMessage(new TestDDAResponse(directory.get(), readContent)); + } catch (IOException e) { + sendMessage(new TestDDAResponse(directory.get(), "failed-to-read")); } } @Override protected void consumeTestDDAComplete(TestDDAComplete testDDAComplete) { - if (testDDAComplete.getDirectory().equals(directory.get())) { - sendMessage(originalClientPut.get()); - } - } - - @Override - protected void consumeConnectionClosed(Throwable throwable) { - putFinished.set(true); + setIdentifier(originalClientPut.get().getField("Identifier")); + sendMessage(originalClientPut.get()); } }