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.AddPeer;
import net.pterodactylus.fcp.NodeRef;
private final ListeningExecutorService threadPool;
private final ConnectionSupplier connectionSupplier;
+ private final Supplier<String> identifierSupplier;
private final AtomicReference<File> file = new AtomicReference<>();
private final AtomicReference<URL> url = new AtomicReference<>();
private final AtomicReference<NodeRef> nodeRef = new AtomicReference<>();
- public AddPeerCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) {
+ public AddPeerCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier<String> identifierSupplier) {
+ this.identifierSupplier = identifierSupplier;
this.threadPool = MoreExecutors.listeningDecorator(threadPool);
this.connectionSupplier = connectionSupplier;
}
private Optional<Peer> executeDialog() throws IOException, ExecutionException, InterruptedException {
AddPeer addPeer;
if (file.get() != null) {
- addPeer = new AddPeer(new RandomIdentifierGenerator().generate(), file.get().getPath());
+ addPeer = new AddPeer(identifierSupplier.get(), file.get().getPath());
} else if (url.get() != null) {
- addPeer = new AddPeer(new RandomIdentifierGenerator().generate(), url.get());
+ addPeer = new AddPeer(identifierSupplier.get(), url.get());
} else {
- addPeer = new AddPeer(new RandomIdentifierGenerator().generate(), nodeRef.get());
+ addPeer = new AddPeer(identifierSupplier.get(), nodeRef.get());
}
try (AddPeerDialog addPeerDialog = new AddPeerDialog()) {
return addPeerDialog.send(addPeer).get();
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;
import net.pterodactylus.fcp.ClientGet;
private final ListeningExecutorService threadPool;
private final ConnectionSupplier connectionSupplier;
+ private final Supplier<String> identifierGenerator;
private boolean ignoreDataStore;
private boolean dataStoreOnly;
private boolean realTime;
private boolean global;
- public ClientGetCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) {
+ public ClientGetCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier<String> identifierGenerator) {
this.threadPool = MoreExecutors.listeningDecorator(threadPool);
this.connectionSupplier = connectionSupplier;
+ this.identifierGenerator = identifierGenerator;
}
@Override
}
private ClientGet createClientGetCommand(String uri) {
- String identifier = new RandomIdentifierGenerator().generate();
+ String identifier = identifierGenerator.get();
ClientGet clientGet = new ClientGet(uri, identifier, ReturnType.direct);
if (ignoreDataStore) {
clientGet.setIgnoreDataStore(true);
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
+import java.util.function.Supplier;
import net.pterodactylus.fcp.ClientPut;
import net.pterodactylus.fcp.FcpMessage;
private final ListeningExecutorService threadPool;
private final ConnectionSupplier connectionSupplier;
+ private final Supplier<String> identifierGenerator;
private final AtomicReference<String> redirectUri = new AtomicReference<>();
private final AtomicReference<File> file = new AtomicReference<>();
private final AtomicReference<InputStream> payload = new AtomicReference<>();
private final AtomicReference<String> targetFilename = new AtomicReference<>();
private final List<Consumer<String>> keyGenerateds = new CopyOnWriteArrayList<>();
- public ClientPutCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) {
+ public ClientPutCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier<String> identifierGenerator) {
this.threadPool = MoreExecutors.listeningDecorator(threadPool);
this.connectionSupplier = connectionSupplier;
+ this.identifierGenerator = identifierGenerator;
}
@Override
}
private Optional<Key> execute(String uri) throws InterruptedException, ExecutionException, IOException {
- String identifier = new RandomIdentifierGenerator().generate();
- ClientPut clientPut = createClientPutCommand(uri, identifier);
+ ClientPut clientPut = createClientPutCommand(uri, identifierGenerator.get());
try (ClientPutDialog clientPutDialog = new ClientPutDialog()) {
return clientPutDialog.send(clientPut).get();
}
*/
public class DefaultFcpClient implements FcpClient {
+ private final RandomIdentifierGenerator randomIdentifierGenerator = new RandomIdentifierGenerator();
private final ListeningExecutorService threadPool;
private final String hostname;
private final int port;
@Override
public GetNodeCommand getNode() {
- return new GetNodeCommandImpl(threadPool, this::connect);
+ return new GetNodeCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate);
}
@Override
public GetConfigCommand getConfig() {
- return new GetConfigCommandImpl(threadPool, this::connect);
+ return new GetConfigCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate);
}
@Override
public ModifyConfigCommand modifyConfig() {
- return new ModifyConfigCommandImpl(threadPool, this::connect);
+ return new ModifyConfigCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate);
}
@Override
@Override
public ClientGetCommand clientGet() {
- return new ClientGetCommandImpl(threadPool, this::connect);
+ return new ClientGetCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate);
}
@Override
public ClientPutCommand clientPut() {
- return new ClientPutCommandImpl(threadPool, this::connect);
+ return new ClientPutCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate);
}
@Override
public ListPeerCommand listPeer() {
- return new ListPeerCommandImpl(threadPool, this::connect);
+ return new ListPeerCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate);
}
@Override
public ListPeersCommand listPeers() {
- return new ListPeersCommandImpl(threadPool, this::connect);
+ return new ListPeersCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate);
}
@Override
public AddPeerCommand addPeer() {
- return new AddPeerCommandImpl(threadPool, this::connect);
+ return new AddPeerCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate);
}
@Override
public ModifyPeerCommand modifyPeer() {
- return new ModifyPeerCommandImpl(threadPool, this::connect);
+ return new ModifyPeerCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate);
}
@Override
public RemovePeerCommand removePeer() {
- return new RemovePeerCommandImpl(threadPool, this::connect);
+ return new RemovePeerCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate);
}
@Override
public ListPeerNotesCommand listPeerNotes() {
- return new ListPeerNotesCommandImpl(threadPool, this::connect);
+ return new ListPeerNotesCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate);
}
@Override
public ModifyPeerNoteCommand modifyPeerNote() {
- return new ModifyPeerNoteCommandImpl(threadPool, this::connect);
+ return new ModifyPeerNoteCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate);
}
@Override
public LoadPluginCommand loadPlugin() {
- return new LoadPluginCommandImpl(threadPool, this::connect);
+ return new LoadPluginCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate);
}
@Override
public ReloadPluginCommand reloadPlugin() {
- return new ReloadPluginCommandImpl(threadPool, this::connect);
+ return new ReloadPluginCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate);
}
@Override
public RemovePluginCommand removePlugin() {
- return new RemovePluginCommandImpl(threadPool, this::connect);
+ return new RemovePluginCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate);
}
@Override
public GetPluginInfoCommand getPluginInfo() {
- return new GetPluginInfoCommandImpl(threadPool, this::connect);
+ return new GetPluginInfoCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate);
}
@Override
public SubscribeUskCommand subscribeUsk() {
- return new SubscribeUskCommandImpl(threadPool, this::connect, activeSubscriptions);
+ return new SubscribeUskCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate, activeSubscriptions);
}
private UnsubscribeUskCommand unsubscribeUsk() {
- return new UnsubscribeUskCommandImpl(threadPool, this::connect);
+ return new UnsubscribeUskCommandImpl(threadPool, this::connect, randomIdentifierGenerator::generate);
}
}
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;
import net.pterodactylus.fcp.GetConfig;
private final ListeningExecutorService threadPool;
private final ConnectionSupplier connectionSupplier;
+ private final Supplier<String> identifierGenerator;
private final AtomicBoolean withCurrent = new AtomicBoolean();
private final AtomicBoolean withDefaults = new AtomicBoolean();
private final AtomicBoolean withSortOrder = new AtomicBoolean();
private final AtomicBoolean withLongDescription = new AtomicBoolean();
private final AtomicBoolean withDataTypes = new AtomicBoolean();
- public GetConfigCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) {
+ public GetConfigCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier<String> identifierGenerator) {
this.threadPool = MoreExecutors.listeningDecorator(threadPool);
this.connectionSupplier = connectionSupplier;
+ this.identifierGenerator = identifierGenerator;
}
@Override
}
private ConfigData executeDialog() throws IOException, ExecutionException, InterruptedException {
- GetConfig getConfig = new GetConfig(new RandomIdentifierGenerator().generate());
+ GetConfig getConfig = new GetConfig(identifierGenerator.get());
getConfig.setWithCurrent(withCurrent.get());
getConfig.setWithDefaults(withDefaults.get());
getConfig.setWithSortOrder(withSortOrder.get());
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;
import net.pterodactylus.fcp.NodeData;
private final ListeningExecutorService threadPool;
private final ConnectionSupplier connectionSupplier;
+ private final Supplier<String> identifierGenerator;
private final AtomicBoolean giveOpennetRef = new AtomicBoolean(false);
private final AtomicBoolean includePrivate = new AtomicBoolean(false);
private final AtomicBoolean includeVolatile = new AtomicBoolean(false);
- public GetNodeCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) {
+ public GetNodeCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier<String> identifierGenerator) {
this.threadPool = MoreExecutors.listeningDecorator(threadPool);
this.connectionSupplier = connectionSupplier;
+ this.identifierGenerator = identifierGenerator;
}
@Override
}
private NodeData executeDialog() throws InterruptedException, ExecutionException, IOException {
- GetNode getNode = new GetNode(new RandomIdentifierGenerator().generate(), giveOpennetRef.get(),
+ GetNode getNode = new GetNode(identifierGenerator.get(), giveOpennetRef.get(),
includePrivate.get(), includeVolatile.get());
try (GetNodeDialog getNodeDialog = new GetNodeDialog()) {
return getNodeDialog.send(getNode).get();
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;
import net.pterodactylus.fcp.PluginInfo;
*/
public class GetPluginInfoCommandImpl implements GetPluginInfoCommand {
- private static final RandomIdentifierGenerator IDENTIFIER = new RandomIdentifierGenerator();
private final ListeningExecutorService threadPool;
private final ConnectionSupplier connectionSupplier;
- private final GetPluginInfo getPluginInfo = new GetPluginInfo(IDENTIFIER.generate());
+ private final GetPluginInfo getPluginInfo;
- public GetPluginInfoCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) {
+ public GetPluginInfoCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier<String> identifierGenerator) {
this.threadPool = MoreExecutors.listeningDecorator(threadPool);
this.connectionSupplier = connectionSupplier;
+ getPluginInfo = new GetPluginInfo(identifierGenerator.get());
}
@Override
import java.io.IOException;
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.ListPeer;
import net.pterodactylus.fcp.Peer;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
+import com.google.common.util.concurrent.MoreExecutors;
/**
* Default {@link ListPeerCommand} implementation based on {@link FcpDialog}.
private final ListeningExecutorService threadPool;
private final ConnectionSupplier connectionSupplier;
+ private final Supplier<String> identifierGenerator;
private final AtomicReference<String> nodeIdentifier = new AtomicReference<>();
- public ListPeerCommandImpl(ListeningExecutorService threadPool, ConnectionSupplier connectionSupplier) {
- this.threadPool = threadPool;
+ public ListPeerCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier<String> identifierGenerator) {
+ this.threadPool = MoreExecutors.listeningDecorator(threadPool);
this.connectionSupplier = connectionSupplier;
+ this.identifierGenerator = identifierGenerator;
}
@Override
}
private Optional<Peer> executeDialog() throws IOException, ExecutionException, InterruptedException {
- ListPeer listPeer = new ListPeer(new RandomIdentifierGenerator().generate(), nodeIdentifier.get());
+ ListPeer listPeer = new ListPeer(identifierGenerator.get(), nodeIdentifier.get());
try (ListPeerDialog listPeerDialog = new ListPeerDialog()) {
return Optional.ofNullable(listPeerDialog.send(listPeer).get());
}
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.EndListPeerNotes;
import net.pterodactylus.fcp.ListPeerNotes;
private final ListeningExecutorService threadPool;
private final ConnectionSupplier connectionSupplier;
+ private final Supplier<String> identifierGenerator;
private final AtomicReference<String> nodeIdentifier = new AtomicReference<>();
- public ListPeerNotesCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) {
+ public ListPeerNotesCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier<String> identifierGenerator) {
this.threadPool = MoreExecutors.listeningDecorator(threadPool);
this.connectionSupplier = connectionSupplier;
+ this.identifierGenerator = identifierGenerator;
}
@Override
}
private Optional<PeerNote> executeDialog() throws IOException, ExecutionException, InterruptedException {
- ListPeerNotes listPeerNotes =
- new ListPeerNotes(new RandomIdentifierGenerator().generate(), nodeIdentifier.get());
+ ListPeerNotes listPeerNotes = new ListPeerNotes(identifierGenerator.get(), nodeIdentifier.get());
try (ListPeerNotesDialog listPeerNotesDialog = new ListPeerNotesDialog()) {
return listPeerNotesDialog.send(listPeerNotes).get();
}
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.EndListPeers;
import net.pterodactylus.fcp.ListPeers;
private final ListeningExecutorService threadPool;
private final ConnectionSupplier connectionSupplier;
+ private final Supplier<String> identifierGenerator;
private final AtomicBoolean includeMetadata = new AtomicBoolean(false);
private final AtomicBoolean includeVolatile = new AtomicBoolean(false);
- public ListPeersCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) {
+ public ListPeersCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier<String> identifierGenerator) {
this.threadPool = MoreExecutors.listeningDecorator(threadPool);
this.connectionSupplier = connectionSupplier;
+ this.identifierGenerator = identifierGenerator;
}
@Override
}
private Collection<Peer> executeDialog() throws InterruptedException, ExecutionException, IOException {
- String identifier = new RandomIdentifierGenerator().generate();
- ListPeers listPeers = new ListPeers(identifier, includeMetadata.get(), includeVolatile.get());
+ ListPeers listPeers = new ListPeers(identifierGenerator.get(), includeMetadata.get(), includeVolatile.get());
try (ListPeersDialog listPeersDialog = new ListPeersDialog()) {
return listPeersDialog.send(listPeers).get();
}
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;
import net.pterodactylus.fcp.LoadPlugin.OfficialSource;
*/
public class LoadPluginCommandImpl implements LoadPluginCommand {
- private static final RandomIdentifierGenerator IDENTIFIER = new RandomIdentifierGenerator();
private final ListeningExecutorService threadPool;
private final ConnectionSupplier connectionSupplier;
- private final LoadPlugin loadPlugin = new LoadPlugin(IDENTIFIER.generate());
+ private final LoadPlugin loadPlugin;
- public LoadPluginCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) {
+ public LoadPluginCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier<String> identifierGenerator) {
this.threadPool = MoreExecutors.listeningDecorator(threadPool);
this.connectionSupplier = connectionSupplier;
+ loadPlugin = new LoadPlugin(identifierGenerator.get());
}
@Override
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;
import net.pterodactylus.fcp.ModifyConfig;
*/
public class ModifyConfigCommandImpl implements ModifyConfigCommand {
- private final ModifyConfig modifyConfig = new ModifyConfig(new RandomIdentifierGenerator().generate());
private final ListeningExecutorService threadPool;
private final ConnectionSupplier connectionSupplier;
+ private final ModifyConfig modifyConfig;
- public ModifyConfigCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) {
+ public ModifyConfigCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier<String> identifierGenerator) {
this.threadPool = MoreExecutors.listeningDecorator(threadPool);
this.connectionSupplier = connectionSupplier;
+ modifyConfig = new ModifyConfig(identifierGenerator.get());
}
@Override
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.ModifyPeer;
import net.pterodactylus.fcp.Peer;
private final ListeningExecutorService threadPool;
private final ConnectionSupplier connectionSupplier;
+ private final Supplier<String> identifierGenerator;
private final AtomicReference<String> nodeIdentifier = new AtomicReference<>();
private final AtomicReference<Boolean> enabled = new AtomicReference<>();
private final AtomicReference<Boolean> allowLocalAddresses = new AtomicReference<>();
private final AtomicReference<Boolean> listenOnly = new AtomicReference<>();
private final AtomicReference<Boolean> ignoreSource = new AtomicReference<>();
- public ModifyPeerCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) {
+ public ModifyPeerCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier<String> identifierGenerator) {
this.threadPool = MoreExecutors.listeningDecorator(threadPool);
this.connectionSupplier = connectionSupplier;
+ this.identifierGenerator = identifierGenerator;
}
@Override
}
private Optional<Peer> executeDialog() throws IOException, ExecutionException, InterruptedException {
- ModifyPeer modifyPeer = new ModifyPeer(new RandomIdentifierGenerator().generate(), nodeIdentifier.get());
+ ModifyPeer modifyPeer = new ModifyPeer(identifierGenerator.get(), nodeIdentifier.get());
Optional.ofNullable(enabled.get()).ifPresent(enabled -> modifyPeer.setEnabled(enabled));
Optional.ofNullable(allowLocalAddresses.get()).ifPresent(allowed -> modifyPeer.setAllowLocalAddresses(allowed));
Optional.ofNullable(burstOnly.get()).ifPresent(burstOnly -> modifyPeer.setBurstOnly(burstOnly));
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.FreenetBase64;
import net.pterodactylus.fcp.ModifyPeerNote;
public class ModifyPeerNoteCommandImpl implements ModifyPeerNoteCommand {
private static final FreenetBase64 BASE_64 = new FreenetBase64();
- private static final RandomIdentifierGenerator RANDOM_IDENTIFIER_GENERATOR = new RandomIdentifierGenerator();
private final ListeningExecutorService threadPool;
private final ConnectionSupplier connectionSupplier;
+ private final Supplier<String> identifierGenerator;
private final AtomicReference<String> nodeIdentifier = new AtomicReference<>();
private final AtomicReference<String> darknetComment = new AtomicReference<>();
- public ModifyPeerNoteCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) {
+ public ModifyPeerNoteCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier<String> identifierGenerator) {
this.threadPool = MoreExecutors.listeningDecorator(threadPool);
this.connectionSupplier = connectionSupplier;
+ this.identifierGenerator = identifierGenerator;
}
@Override
private Boolean executeDialog() throws IOException, ExecutionException, InterruptedException {
ModifyPeerNote modifyPeerNote =
- new ModifyPeerNote(RANDOM_IDENTIFIER_GENERATOR.generate(), nodeIdentifier.get());
+ new ModifyPeerNote(identifierGenerator.get(), nodeIdentifier.get());
modifyPeerNote.setPeerNoteType(PeerNoteType.PRIVATE_DARKNET_COMMENT);
modifyPeerNote.setNoteText(BASE_64.encode(darknetComment.get().getBytes(StandardCharsets.UTF_8)));
try (ModifyPeerNoteDialog modifyPeerNoteDialog = new ModifyPeerNoteDialog()) {
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;
import net.pterodactylus.fcp.ProtocolError;
*/
public class ReloadPluginCommandImpl implements ReloadPluginCommand {
- private static final RandomIdentifierGenerator IDENTIFIER = new RandomIdentifierGenerator();
private final ListeningExecutorService threadPool;
private final ConnectionSupplier connectionSupplier;
- private final ReloadPlugin reloadPlugin = new ReloadPlugin(IDENTIFIER.generate());
+ private final ReloadPlugin reloadPlugin;
- public ReloadPluginCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) {
+ public ReloadPluginCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier<String> identifierGenerator) {
this.threadPool = MoreExecutors.listeningDecorator(threadPool);
this.connectionSupplier = connectionSupplier;
+ reloadPlugin = new ReloadPlugin(identifierGenerator.get());
}
@Override
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.PeerRemoved;
import net.pterodactylus.fcp.RemovePeer;
private final ListeningExecutorService threadPool;
private final ConnectionSupplier connectionSupplier;
+ private final Supplier<String> identifierGenerator;
private final AtomicReference<String> nodeIdentifier = new AtomicReference<>();
- public RemovePeerCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) {
+ public RemovePeerCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier<String> identifierGenerator) {
this.threadPool = MoreExecutors.listeningDecorator(threadPool);
this.connectionSupplier = connectionSupplier;
+ this.identifierGenerator = identifierGenerator;
}
@Override
}
private boolean executeDialog() throws IOException, ExecutionException, InterruptedException {
- RemovePeer removePeer = new RemovePeer(new RandomIdentifierGenerator().generate(), nodeIdentifier.get());
+ RemovePeer removePeer = new RemovePeer(identifierGenerator.get(), nodeIdentifier.get());
try (RemovePeerDialog removePeerDialog = new RemovePeerDialog()) {
return removePeerDialog.send(removePeer).get();
}
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;
import net.pterodactylus.fcp.ProtocolError;
*/
public class RemovePluginCommandImpl implements RemovePluginCommand {
- private static final RandomIdentifierGenerator IDENTIFIER = new RandomIdentifierGenerator();
private final ListeningExecutorService threadPool;
private final ConnectionSupplier connectionSupplier;
- private final RemovePlugin removePlugin = new RemovePlugin(IDENTIFIER.generate());
+ private final RemovePlugin removePlugin;
- public RemovePluginCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) {
+ public RemovePluginCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier<String> identifierGenerator) {
this.threadPool = MoreExecutors.listeningDecorator(threadPool);
this.connectionSupplier = connectionSupplier;
+ removePlugin = new RemovePlugin(identifierGenerator.get());
}
@Override
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;
import net.pterodactylus.fcp.SubscribeUSK;
*/
public class SubscribeUskCommandImpl implements SubscribeUskCommand {
- private static final RandomIdentifierGenerator IDENTIFIER = new RandomIdentifierGenerator();
private final ListeningExecutorService threadPool;
private final ConnectionSupplier connectionSupplier;
- private final SubscribeUSK subscribeUSK = new SubscribeUSK(IDENTIFIER.generate());
+ private final SubscribeUSK subscribeUSK;
private final ActiveSubscriptions activeSubscriptions;
public SubscribeUskCommandImpl(
- ExecutorService threadPool, ConnectionSupplier connectionSupplier,
+ ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier<String> identifierGenerator,
ActiveSubscriptions activeSubscriptions) {
this.activeSubscriptions = activeSubscriptions;
this.threadPool = MoreExecutors.listeningDecorator(threadPool);
this.connectionSupplier = connectionSupplier;
+ subscribeUSK = new SubscribeUSK(identifierGenerator.get());
}
@Override
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
+import java.util.function.Supplier;
import net.pterodactylus.fcp.UnsubscribeUSK;
*/
public class UnsubscribeUskCommandImpl implements UnsubscribeUskCommand {
- private static final RandomIdentifierGenerator IDENTIFIER = new RandomIdentifierGenerator();
private final ListeningExecutorService threadPool;
private final ConnectionSupplier connectionSupplier;
- private final UnsubscribeUSK unsubscribeUSK = new UnsubscribeUSK(IDENTIFIER.generate());
+ private final UnsubscribeUSK unsubscribeUSK;
- public UnsubscribeUskCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) {
+ public UnsubscribeUskCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier, Supplier<String> identifierGenerator) {
this.threadPool = MoreExecutors.listeningDecorator(threadPool);
this.connectionSupplier = connectionSupplier;
+ unsubscribeUSK = new UnsubscribeUSK(identifierGenerator.get());
}
@Override