import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
private class AddPeerDialog extends FcpDialog<Optional<Peer>> {
- private final AtomicBoolean finished = new AtomicBoolean();
- private final AtomicReference<Peer> peer = new AtomicReference<>();
-
public AddPeerDialog() throws IOException {
- super(threadPool, connectionSupplier.get());
- }
-
- @Override
- protected boolean isFinished() {
- return finished.get();
- }
-
- @Override
- protected Optional<Peer> getResult() {
- return Optional.ofNullable(peer.get());
+ super(threadPool, connectionSupplier.get(), Optional.empty());
}
@Override
protected void consumePeer(Peer peer) {
- this.peer.set(peer);
- finished.set(true);
+ setResult(Optional.ofNullable(peer));
}
@Override
protected void consumeProtocolError(ProtocolError protocolError) {
- finished.set(true);
+ finish();
}
}
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier;
import net.pterodactylus.fcp.AllData;
private class ClientGetDialog extends FcpDialog<Optional<Data>> {
- private final AtomicBoolean finished = new AtomicBoolean();
- private final AtomicBoolean failed = new AtomicBoolean();
-
- private String contentType;
- private long dataLength;
- private InputStream payload;
-
public ClientGetDialog() throws IOException {
- super(ClientGetCommandImpl.this.threadPool, ClientGetCommandImpl.this.connectionSupplier.get());
+ super(ClientGetCommandImpl.this.threadPool, ClientGetCommandImpl.this.connectionSupplier.get(), Optional.<Data>empty());
}
@Override
- protected boolean isFinished() {
- return finished.get() || failed.get();
+ protected void consumeAllData(AllData allData) {
+ synchronized (this) {
+ String contentType = allData.getContentType();
+ long dataLength = allData.getDataLength();
+ try {
+ InputStream payload = new TempInputStream(allData.getPayloadInputStream(), dataLength);
+ setResult(Optional.of(createData(contentType, dataLength, payload)));
+ } catch (IOException e) {
+ // TODO – logging
+ finish();
+ }
+ }
}
- @Override
- protected Optional<Data> getResult() {
- return failed.get() ? Optional.empty() : Optional.of(new Data() {
+ private Data createData(String contentType, long dataLength, InputStream payload) {
+ return new Data() {
@Override
public String getMimeType() {
return contentType;
public InputStream getInputStream() {
return payload;
}
- });
- }
-
- @Override
- protected void consumeAllData(AllData allData) {
- synchronized (this) {
- contentType = allData.getContentType();
- dataLength = allData.getDataLength();
- try {
- payload = new TempInputStream(allData.getPayloadInputStream(), dataLength);
- finished.set(true);
- } catch (IOException e) {
- // TODO – logging
- failed.set(true);
- }
- }
+ };
}
@Override
protected void consumeGetFailed(GetFailed getFailed) {
- failed.set(true);
+ finish();
}
}
private class ClientHelloDialog extends FcpDialog<Boolean> {
- private final AtomicReference<NodeHello> receivedNodeHello = new AtomicReference<>();
-
public ClientHelloDialog(FcpConnection connection) {
- super(ClientHelloImpl.this.threadPool, connection);
- }
-
- @Override
- protected boolean isFinished() {
- return receivedNodeHello.get() != null;
- }
-
- @Override
- protected Boolean getResult() {
- return receivedNodeHello.get() != null;
+ super(ClientHelloImpl.this.threadPool, connection, false);
}
@Override
protected void consumeNodeHello(NodeHello nodeHello) {
- receivedNodeHello.set(nodeHello);
+ setResult(true);
}
}
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
private final AtomicReference<FcpMessage> originalClientPut = new AtomicReference<>();
private final AtomicReference<String> directory = new AtomicReference<>();
- private final AtomicReference<Key> finalKey = new AtomicReference<>();
- private final AtomicBoolean putFinished = new AtomicBoolean();
public ClientPutDialog() throws IOException {
- super(ClientPutCommandImpl.this.threadPool, ClientPutCommandImpl.this.connectionSupplier.get());
- }
-
- @Override
- protected boolean isFinished() {
- return putFinished.get();
- }
-
- @Override
- protected Optional<Key> getResult() {
- return Optional.ofNullable(finalKey.get());
+ super(ClientPutCommandImpl.this.threadPool, ClientPutCommandImpl.this.connectionSupplier.get(), Optional.<Key>empty());
}
@Override
@Override
protected void consumePutSuccessful(PutSuccessful putSuccessful) {
- finalKey.set(new Key(putSuccessful.getURI()));
- putFinished.set(true);
+ setResult(Optional.of(new Key(putSuccessful.getURI())));
}
@Override
protected void consumePutFailed(PutFailed putFailed) {
- putFinished.set(true);
+ finish();
}
@Override
setIdentifier(directory.get());
sendMessage(new TestDDARequest(directory.get(), true, false));
} else {
- putFinished.set(true);
+ finish();
}
}
private final AtomicReference<String> identifier = new AtomicReference<>();
private final AtomicBoolean connectionClosed = new AtomicBoolean();
private final AtomicReference<Throwable> connectionFailureReason = new AtomicReference<>();
+ private final AtomicBoolean finished = new AtomicBoolean();
+ private final AtomicReference<R> result = new AtomicReference<>();
- public FcpDialog(ExecutorService executorService, FcpConnection fcpConnection) {
+ public FcpDialog(ExecutorService executorService, FcpConnection fcpConnection, R initialResult) {
this.executorService = MoreExecutors.listeningDecorator(executorService);
this.fcpConnection = fcpConnection;
+ result.set(initialResult);
}
protected void setIdentifier(String identifier) {
this.identifier.set(identifier);
}
- protected abstract boolean isFinished();
+ public final boolean isFinished() {
+ return finished.get();
+ }
+
+ protected final void finish() {
+ finished.set(true);
+ }
+
+ protected final void setResult(R result) {
+ this.result.set(result);
+ finish();
+ }
public ListenableFuture<R> send(FcpMessage fcpMessage) throws IOException {
setIdentifier(fcpMessage.getField("Identifier"));
}
}
- protected R getResult() {
- return null;
+ protected final R getResult() {
+ return result.get();
}
@Override
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.atomic.AtomicReference;
import net.pterodactylus.fcp.FcpKeyPair;
import net.pterodactylus.fcp.GenerateSSK;
private class FcpKeyPairDialog extends FcpDialog<FcpKeyPair> {
- private AtomicReference<FcpKeyPair> keyPair = new AtomicReference<>();
-
public FcpKeyPairDialog() throws IOException {
- super(GenerateKeypairCommandImpl.this.threadPool, GenerateKeypairCommandImpl.this.connectionSupplier.get());
- }
-
- @Override
- protected boolean isFinished() {
- return keyPair.get() != null;
- }
-
- @Override
- protected FcpKeyPair getResult() {
- return keyPair.get();
+ super(GenerateKeypairCommandImpl.this.threadPool, GenerateKeypairCommandImpl.this.connectionSupplier.get(), null);
}
@Override
protected void consumeSSKKeypair(SSKKeypair sskKeypair) {
- keyPair.set(new FcpKeyPair(sskKeypair.getRequestURI(), sskKeypair.getInsertURI()));
+ setResult(new FcpKeyPair(sskKeypair.getRequestURI(), sskKeypair.getInsertURI()));
}
}
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
import net.pterodactylus.fcp.ConfigData;
private class GetConfigDialog extends FcpDialog<ConfigData> {
- private final AtomicReference<ConfigData> configData = new AtomicReference<>();
-
public GetConfigDialog() throws IOException {
- super(threadPool, connectionSupplier.get());
- }
-
- @Override
- protected boolean isFinished() {
- return configData.get() != null;
- }
-
- @Override
- protected ConfigData getResult() {
- return configData.get();
+ super(threadPool, connectionSupplier.get(), null);
}
@Override
protected void consumeConfigData(ConfigData configData) {
- this.configData.set(configData);
+ setResult(configData);
}
}
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
import net.pterodactylus.fcp.GetNode;
private class GetNodeDialog extends FcpDialog<NodeData> {
- private final AtomicReference<NodeData> nodeData = new AtomicReference<>();
-
public GetNodeDialog() throws IOException {
- super(threadPool, connectionSupplier.get());
- }
-
- @Override
- protected boolean isFinished() {
- return nodeData.get() != null;
- }
-
- @Override
- protected NodeData getResult() {
- return nodeData.get();
+ super(threadPool, connectionSupplier.get(), null);
}
@Override
protected void consumeNodeData(NodeData nodeData) {
- this.nodeData.set(nodeData);
+ setResult(nodeData);
}
}
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
import net.pterodactylus.fcp.GetPluginInfo;
private class GetPluginInfoDialog extends FcpDialog<Optional<PluginInfo>> {
- private final AtomicBoolean finished = new AtomicBoolean();
- private final AtomicReference<PluginInfo> pluginInfo = new AtomicReference<>();
-
public GetPluginInfoDialog() throws IOException {
- super(threadPool, connectionSupplier.get());
- }
-
- @Override
- protected boolean isFinished() {
- return finished.get();
- }
-
- @Override
- protected Optional<PluginInfo> getResult() {
- return Optional.ofNullable(pluginInfo.get());
+ super(threadPool, connectionSupplier.get(), Optional.<PluginInfo>empty());
}
@Override
protected void consumePluginInfo(PluginInfo pluginInfo) {
- this.pluginInfo.set(pluginInfo);
- finished.set(true);
+ setResult(Optional.ofNullable(pluginInfo));
}
@Override
protected void consumeProtocolError(ProtocolError protocolError) {
- finished.set(true);
+ finish();
}
}
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
private class ListPeerDialog extends FcpDialog<Peer> {
- private final AtomicBoolean finished = new AtomicBoolean();
- private final AtomicReference<Peer> peer = new AtomicReference<>();
-
public ListPeerDialog() throws IOException {
- super(threadPool, connectionSupplier.get());
- }
-
- @Override
- protected boolean isFinished() {
- return finished.get();
- }
-
- @Override
- protected Peer getResult() {
- return peer.get();
+ super(threadPool, connectionSupplier.get(), null);
}
@Override
protected void consumePeer(Peer peer) {
- this.peer.set(peer);
- finished.set(true);
+ setResult(peer);
}
@Override
protected void consumeUnknownNodeIdentifier(UnknownNodeIdentifier unknownNodeIdentifier) {
- finished.set(true);
+ finish();
}
}
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
private class ListPeerNotesDialog extends FcpDialog<Optional<PeerNote>> {
- private final AtomicReference<PeerNote> peerNote = new AtomicReference<>();
- private final AtomicBoolean finished = new AtomicBoolean();
-
public ListPeerNotesDialog() throws IOException {
- super(threadPool, connectionSupplier.get());
- }
-
- @Override
- protected boolean isFinished() {
- return finished.get();
- }
-
- @Override
- protected Optional<PeerNote> getResult() {
- return Optional.ofNullable(peerNote.get());
+ super(threadPool, connectionSupplier.get(), Optional.<PeerNote>empty());
}
@Override
protected void consumePeerNote(PeerNote peerNote) {
- this.peerNote.set(peerNote);
+ setResult(Optional.ofNullable(peerNote));
}
@Override
protected void consumeEndListPeerNotes(EndListPeerNotes endListPeerNotes) {
- finished.set(true);
+ finish();
}
@Override
protected void consumeUnknownNodeIdentifier(UnknownNodeIdentifier unknownNodeIdentifier) {
- finished.set(true);
+ finish();
}
}
import java.io.IOException;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashSet;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
private class ListPeersDialog extends FcpDialog<Collection<Peer>> {
private final Collection<Peer> peers = new HashSet<>();
- private final AtomicBoolean finished = new AtomicBoolean(false);
public ListPeersDialog() throws IOException {
- super(threadPool, connectionSupplier.get());
- }
-
- @Override
- protected boolean isFinished() {
- return finished.get();
- }
-
- @Override
- protected Collection<Peer> getResult() {
- return peers;
+ super(threadPool, connectionSupplier.get(), Collections.<Peer>emptyList());
}
@Override
@Override
protected void consumeEndListPeers(EndListPeers endListPeers) {
- finished.set(true);
+ setResult(peers);
}
}
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
import net.pterodactylus.fcp.LoadPlugin;
private class LoadPluginDialog extends FcpDialog<Optional<PluginInfo>> {
- private final AtomicBoolean finished = new AtomicBoolean();
- private final AtomicReference<PluginInfo> pluginInfo = new AtomicReference<>();
-
public LoadPluginDialog() throws IOException {
- super(threadPool, connectionSupplier.get());
- }
-
- @Override
- protected boolean isFinished() {
- return finished.get();
- }
-
- @Override
- protected Optional<PluginInfo> getResult() {
- return Optional.ofNullable(pluginInfo.get());
+ super(threadPool, connectionSupplier.get(), Optional.<PluginInfo>empty());
}
@Override
protected void consumePluginInfo(PluginInfo pluginInfo) {
- this.pluginInfo.set(pluginInfo);
- finished.set(true);
+ setResult(Optional.ofNullable(pluginInfo));
}
@Override
protected void consumeProtocolError(ProtocolError protocolError) {
- finished.set(true);
+ finish();
}
}
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
import net.pterodactylus.fcp.ConfigData;
private class ModifyConfigDialog extends FcpDialog<ConfigData> {
- private final AtomicBoolean finished = new AtomicBoolean();
- private final AtomicReference<ConfigData> configData = new AtomicReference<>();
-
public ModifyConfigDialog() throws IOException {
- super(threadPool, connectionSupplier.get());
- }
-
- @Override
- protected boolean isFinished() {
- return finished.get();
- }
-
- @Override
- protected ConfigData getResult() {
- return configData.get();
+ super(threadPool, connectionSupplier.get(), null);
}
@Override
protected void consumeConfigData(ConfigData configData) {
- this.configData.set(configData);
- finished.set(true);
+ setResult(configData);
}
}
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
private class ModifyPeerDialog extends FcpDialog<Optional<Peer>> {
- private final AtomicBoolean finished = new AtomicBoolean();
- private final AtomicReference<Peer> peer = new AtomicReference<>();
-
public ModifyPeerDialog() throws IOException {
- super(threadPool, connectionSupplier.get());
- }
-
- @Override
- protected boolean isFinished() {
- return finished.get();
- }
-
- @Override
- protected Optional<Peer> getResult() {
- return Optional.ofNullable(peer.get());
+ super(threadPool, connectionSupplier.get(), Optional.<Peer>empty());
}
@Override
protected void consumePeer(Peer peer) {
- this.peer.set(peer);
- finished.set(true);
+ setResult(Optional.ofNullable(peer));
}
@Override
protected void consumeUnknownNodeIdentifier(UnknownNodeIdentifier unknownNodeIdentifier) {
- finished.set(true);
+ finish();
}
}
import java.nio.charset.StandardCharsets;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
private class ModifyPeerNoteDialog extends FcpDialog<Boolean> {
- private final AtomicBoolean finished = new AtomicBoolean();
- private final AtomicBoolean successful = new AtomicBoolean();
-
public ModifyPeerNoteDialog() throws IOException {
- super(threadPool, connectionSupplier.get());
- }
-
- @Override
- protected boolean isFinished() {
- return finished.get();
- }
-
- @Override
- protected Boolean getResult() {
- return successful.get();
+ super(threadPool, connectionSupplier.get(), false);
}
@Override
protected void consumePeerNote(PeerNote peerNote) {
- successful.set(true);
- finished.set(true);
+ setResult(true);
}
@Override
protected void consumeUnknownNodeIdentifier(UnknownNodeIdentifier unknownNodeIdentifier) {
- finished.set(true);
+ finish();
}
}
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
import net.pterodactylus.fcp.PluginInfo;
private class ReloadPluginDialog extends FcpDialog<Optional<PluginInfo>> {
- private final AtomicBoolean finished = new AtomicBoolean();
- private final AtomicReference<PluginInfo> pluginInfo = new AtomicReference<>();
-
public ReloadPluginDialog() throws IOException {
- super(threadPool, connectionSupplier.get());
- }
-
- @Override
- protected boolean isFinished() {
- return finished.get();
- }
-
- @Override
- protected Optional<PluginInfo> getResult() {
- return Optional.ofNullable(pluginInfo.get());
+ super(threadPool, connectionSupplier.get(), Optional.<PluginInfo>empty());
}
@Override
protected void consumePluginInfo(PluginInfo pluginInfo) {
- this.pluginInfo.set(pluginInfo);
- finished.set(true);
+ setResult(Optional.ofNullable(pluginInfo));
}
@Override
protected void consumeProtocolError(ProtocolError protocolError) {
- finished.set(true);
+ finish();
}
}
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
private class RemovePeerDialog extends FcpDialog<Boolean> {
- private final AtomicBoolean finished = new AtomicBoolean();
- private final AtomicBoolean removed = new AtomicBoolean();
-
public RemovePeerDialog() throws IOException {
- super(threadPool, connectionSupplier.get());
- }
-
- @Override
- protected boolean isFinished() {
- return finished.get() || removed.get();
- }
-
- @Override
- protected Boolean getResult() {
- return removed.get();
+ super(threadPool, connectionSupplier.get(), false);
}
@Override
protected void consumePeerRemoved(PeerRemoved peerRemoved) {
- removed.set(true);
+ setResult(true);
}
@Override
protected void consumeUnknownNodeIdentifier(UnknownNodeIdentifier unknownNodeIdentifier) {
- finished.set(true);
+ finish();
}
}
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier;
import net.pterodactylus.fcp.PluginRemoved;
private class RemovePluginDialog extends FcpDialog<Boolean> {
- private final AtomicBoolean finished = new AtomicBoolean();
- private final AtomicBoolean pluginRemoved = new AtomicBoolean();
-
public RemovePluginDialog() throws IOException {
- super(threadPool, connectionSupplier.get());
- }
-
- @Override
- protected boolean isFinished() {
- return finished.get();
- }
-
- @Override
- protected Boolean getResult() {
- return pluginRemoved.get();
+ super(threadPool, connectionSupplier.get(), false);
}
@Override
protected void consumePluginRemoved(PluginRemoved pluginRemoved) {
- this.pluginRemoved.set(true);
- finished.set(true);
+ setResult(true);
}
@Override
protected void consumeProtocolError(ProtocolError protocolError) {
- finished.set(true);
+ finish();
}
}
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier;
import net.pterodactylus.fcp.IdentifierCollision;
private class SubscribeUskDialog extends FcpDialog<Boolean> {
- private final AtomicBoolean finished = new AtomicBoolean();
- private final AtomicBoolean success = new AtomicBoolean();
-
public SubscribeUskDialog() throws IOException {
- super(threadPool, connectionSupplier.get());
- }
-
- @Override
- protected boolean isFinished() {
- return finished.get();
- }
-
- @Override
- protected Boolean getResult() {
- return success.get();
+ super(threadPool, connectionSupplier.get(), false);
}
@Override
protected void consumeSubscribedUSK(SubscribedUSK subscribedUSK) {
- success.set(true);
- finished.set(true);
+ setResult(true);
}
@Override
protected void consumeIdentifierCollision(IdentifierCollision identifierCollision) {
- finished.set(true);
+ finish();
}
}
private class UnsubscribeUskDialog extends FcpDialog<Void> {
public UnsubscribeUskDialog() throws IOException {
- super(threadPool, connectionSupplier.get());
- }
-
- @Override
- protected boolean isFinished() {
- return true;
+ super(threadPool, connectionSupplier.get(), null);
+ finish();
}
}
}
private FcpDialog createBasicDialog() {
- return new FcpDialog(executorService, fcpConnection) {
- @Override
- protected boolean isFinished() {
- return true;
- }
- };
+ return new FcpDialog(executorService, fcpConnection, true) {
+ {
+ finish();
+ }
+ };
}
@Test
private final AtomicBoolean gotPutFailed = new AtomicBoolean();
private final AtomicBoolean gotGetFailed = new AtomicBoolean();
- @Override
- protected boolean isFinished() {
- return gotPutFailed.get() && gotGetFailed.get();
- }
-
- @Override
- protected Boolean getResult() {
- return isFinished();
+ private void checkIfBothFailedsWereReceived() {
+ if (gotPutFailed.get() && gotGetFailed.get()) {
+ setResult(true);
+ }
}
@Override
protected void consumePutFailed(PutFailed putFailed) {
gotPutFailed.set(true);
+ checkIfBothFailedsWereReceived();
}
@Override
protected void consumeGetFailed(GetFailed getFailed) {
gotGetFailed.set(true);
+ checkIfBothFailedsWereReceived();
}
};
Future<?> result = testFcpDialog.send(fcpMessage);
private static class TestFcpDialog extends FcpDialog<Boolean> {
- private final AtomicReference<String> gotMessage = new AtomicReference<>();
private final AtomicReference<String> expectedMessage = new AtomicReference<>();
public TestFcpDialog(ExecutorService executorService, FcpConnection fcpConnection) {
- super(executorService, fcpConnection);
+ super(executorService, fcpConnection, false);
}
public void setExpectedMessage(String expectedMessage) {
this.expectedMessage.set(expectedMessage);
}
- @Override
- protected boolean isFinished() {
- return getResult();
- }
-
- @Override
- protected Boolean getResult() {
- return expectedMessage.get().equals(gotMessage.get());
+ private void verifyReceivedMessage(String message) {
+ if (expectedMessage.get().equals(message)) {
+ setResult(true);
+ }
}
@Override
protected void consumeNodeHello(NodeHello nodeHello) {
- gotMessage.set(nodeHello.getName());
+ verifyReceivedMessage(nodeHello.getName());
}
@Override
protected void consumeSSKKeypair(SSKKeypair sskKeypair) {
- gotMessage.set(sskKeypair.getName());
+ verifyReceivedMessage(sskKeypair.getName());
}
@Override
protected void consumePeer(Peer peer) {
- gotMessage.set(peer.getName());
+ verifyReceivedMessage(peer.getName());
}
@Override
protected void consumeEndListPeers(EndListPeers endListPeers) {
- gotMessage.set(endListPeers.getName());
+ verifyReceivedMessage(endListPeers.getName());
}
@Override
protected void consumePeerNote(PeerNote peerNote) {
- gotMessage.set(peerNote.getName());
+ verifyReceivedMessage(peerNote.getName());
}
@Override
protected void consumeEndListPeerNotes(EndListPeerNotes endListPeerNotes) {
- gotMessage.set(endListPeerNotes.getName());
+ verifyReceivedMessage(endListPeerNotes.getName());
}
@Override
protected void consumePeerRemoved(PeerRemoved peerRemoved) {
- gotMessage.set(peerRemoved.getName());
+ verifyReceivedMessage(peerRemoved.getName());
}
@Override
protected void consumeNodeData(NodeData nodeData) {
- gotMessage.set(nodeData.getName());
+ verifyReceivedMessage(nodeData.getName());
}
@Override
protected void consumeTestDDAReply(TestDDAReply testDDAReply) {
- gotMessage.set(testDDAReply.getName());
+ verifyReceivedMessage(testDDAReply.getName());
}
@Override
protected void consumeTestDDAComplete(TestDDAComplete testDDAComplete) {
- gotMessage.set(testDDAComplete.getName());
+ verifyReceivedMessage(testDDAComplete.getName());
}
@Override
protected void consumePersistentGet(PersistentGet persistentGet) {
- gotMessage.set(persistentGet.getName());
+ verifyReceivedMessage(persistentGet.getName());
}
@Override
protected void consumePersistentPut(PersistentPut persistentPut) {
- gotMessage.set(persistentPut.getName());
+ verifyReceivedMessage(persistentPut.getName());
}
@Override
protected void consumeEndListPersistentRequests(EndListPersistentRequests endListPersistentRequests) {
- gotMessage.set(endListPersistentRequests.getName());
+ verifyReceivedMessage(endListPersistentRequests.getName());
}
@Override
protected void consumeURIGenerated(URIGenerated uriGenerated) {
- gotMessage.set(uriGenerated.getName());
+ verifyReceivedMessage(uriGenerated.getName());
}
@Override
protected void consumeDataFound(DataFound dataFound) {
- gotMessage.set(dataFound.getName());
+ verifyReceivedMessage(dataFound.getName());
}
@Override
protected void consumeAllData(AllData allData) {
- gotMessage.set(allData.getName());
+ verifyReceivedMessage(allData.getName());
}
@Override
protected void consumeSimpleProgress(SimpleProgress simpleProgress) {
- gotMessage.set(simpleProgress.getName());
+ verifyReceivedMessage(simpleProgress.getName());
}
@Override
protected void consumeStartedCompression(StartedCompression startedCompression) {
- gotMessage.set(startedCompression.getName());
+ verifyReceivedMessage(startedCompression.getName());
}
@Override
protected void consumeFinishedCompression(FinishedCompression finishedCompression) {
- gotMessage.set(finishedCompression.getName());
+ verifyReceivedMessage(finishedCompression.getName());
}
@Override
protected void consumeUnknownPeerNoteType(UnknownPeerNoteType unknownPeerNoteType) {
- gotMessage.set(unknownPeerNoteType.getName());
+ verifyReceivedMessage(unknownPeerNoteType.getName());
}
@Override
protected void consumeUnknownNodeIdentifier(UnknownNodeIdentifier unknownNodeIdentifier) {
- gotMessage.set(unknownNodeIdentifier.getName());
+ verifyReceivedMessage(unknownNodeIdentifier.getName());
}
@Override
protected void consumeConfigData(ConfigData configData) {
- gotMessage.set(configData.getName());
+ verifyReceivedMessage(configData.getName());
}
@Override
protected void consumeGetFailed(GetFailed getFailed) {
- gotMessage.set(getFailed.getName());
+ verifyReceivedMessage(getFailed.getName());
}
@Override
protected void consumePutFailed(PutFailed putFailed) {
- gotMessage.set(putFailed.getName());
+ verifyReceivedMessage(putFailed.getName());
}
@Override
protected void consumeIdentifierCollision(IdentifierCollision identifierCollision) {
- gotMessage.set(identifierCollision.getName());
+ verifyReceivedMessage(identifierCollision.getName());
}
@Override
protected void consumePersistentPutDir(PersistentPutDir persistentPutDir) {
- gotMessage.set(persistentPutDir.getName());
+ verifyReceivedMessage(persistentPutDir.getName());
}
@Override
protected void consumePersistentRequestRemoved(PersistentRequestRemoved persistentRequestRemoved) {
- gotMessage.set(persistentRequestRemoved.getName());
+ verifyReceivedMessage(persistentRequestRemoved.getName());
}
@Override
protected void consumeSubscribedUSKUpdate(SubscribedUSKUpdate subscribedUSKUpdate) {
- gotMessage.set(subscribedUSKUpdate.getName());
+ verifyReceivedMessage(subscribedUSKUpdate.getName());
}
@Override
protected void consumePluginInfo(PluginInfo pluginInfo) {
- gotMessage.set(pluginInfo.getName());
+ verifyReceivedMessage(pluginInfo.getName());
}
@Override
protected void consumeFCPPluginReply(FCPPluginReply fcpPluginReply) {
- gotMessage.set(fcpPluginReply.getName());
+ verifyReceivedMessage(fcpPluginReply.getName());
}
@Override
protected void consumePersistentRequestModified(PersistentRequestModified persistentRequestModified) {
- gotMessage.set(persistentRequestModified.getName());
+ verifyReceivedMessage(persistentRequestModified.getName());
}
@Override
protected void consumePutSuccessful(PutSuccessful putSuccessful) {
- gotMessage.set(putSuccessful.getName());
+ verifyReceivedMessage(putSuccessful.getName());
}
@Override
protected void consumePutFetchable(PutFetchable putFetchable) {
- gotMessage.set(putFetchable.getName());
+ verifyReceivedMessage(putFetchable.getName());
}
@Override
protected void consumeSentFeed(SentFeed sentFeed) {
- gotMessage.set(sentFeed.getName());
+ verifyReceivedMessage(sentFeed.getName());
}
@Override
protected void consumeReceivedBookmarkFeed(ReceivedBookmarkFeed receivedBookmarkFeed) {
- gotMessage.set(receivedBookmarkFeed.getName());
+ verifyReceivedMessage(receivedBookmarkFeed.getName());
}
@Override
protected void consumeProtocolError(ProtocolError protocolError) {
- gotMessage.set(protocolError.getName());
+ verifyReceivedMessage(protocolError.getName());
}
@Override
protected void consumeUnknownMessage(FcpMessage fcpMessage) {
- gotMessage.set(fcpMessage.getName());
+ verifyReceivedMessage(fcpMessage.getName());
}
}