// Discoverer buttons action listeners
private ActionListener refreshServicesAction = (ActionEvent e) -> {
progressBar.setVisible(true);
- new Thread(() -> {
- Cache.log.info("Requesting service reload");
- var task = discoverer.startDiscoverer();
- try {
- task.get();
+ Cache.log.info("Requesting service reload");
+ discoverer.startDiscoverer().handle((_discoverer, exception) -> {
+ if (exception == null)
+ {
Cache.log.info("Reloading done");
- } catch (Exception exc) {
- Cache.log.error("Reloading failed", exc);
- } finally {
- SwingUtilities.invokeLater(() -> progressBar.setVisible(false));
}
- }).start();
+ else
+ {
+ Cache.log.error("Reloading failed", exception);
+ }
+ SwingUtilities.invokeLater(() -> progressBar.setVisible(false));
+ return null;
+ });
};
private ActionListener resetServicesAction = (ActionEvent e) -> {
import java.net.URL;
import java.util.List;
-import java.util.concurrent.Future;
+import java.util.concurrent.CompletableFuture;
public interface WSDiscovererI
{
public void removeServiceChangeListener(ServiceChangeListener listener);
- public Future<WSDiscovererI> startDiscoverer();
+ public CompletableFuture<WSDiscovererI> startDiscoverer();
public String getErrorMessages();
import java.util.Set;
import java.util.StringTokenizer;
import java.util.Vector;
+import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
* @return new thread
*/
@Override
- public FutureTask<WSDiscovererI> startDiscoverer()
+ public CompletableFuture<WSDiscovererI> startDiscoverer()
{
/* if (restart())
{
{
setAborted(true);
}
- FutureTask<WSDiscovererI> task = new FutureTask<>(this, this);
- new Thread(task).start();
+ CompletableFuture<WSDiscovererI> task = CompletableFuture
+ .supplyAsync(() -> {
+ run();
+ return Jws2Discoverer.this;
+ });
return task;
}
import java.util.List;
import java.util.Set;
import java.util.Vector;
+import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
}
private Set<ServiceChangeListener> serviceListeners = new CopyOnWriteArraySet<>();
-
+
@Override
- public void addServiceChangeListener(ServiceChangeListener l) {
+ public void addServiceChangeListener(ServiceChangeListener l)
+ {
serviceListeners.add(l);
}
-
+
@Override
- public void removeServiceChangeListener(ServiceChangeListener l) {
+ public void removeServiceChangeListener(ServiceChangeListener l)
+ {
serviceListeners.remove(l);
}
-
- public void notifyServiceListeners(List<ServiceWithParameters> services) {
- for (var listener : serviceListeners) {
+
+ public void notifyServiceListeners(List<ServiceWithParameters> services)
+ {
+ for (var listener : serviceListeners)
+ {
listener.servicesChanged(this, services);
}
}
private final ExecutorService executor = Executors.newSingleThreadExecutor();
private Vector<Future<?>> discoveryTasks = new Vector<>();
- public Future<WSDiscovererI> startDiscoverer()
+ public CompletableFuture<WSDiscovererI> startDiscoverer()
{
- FutureTask<WSDiscovererI> task = new FutureTask<>(this::reloadServices, this);
+ CompletableFuture<WSDiscovererI> task = CompletableFuture
+ .supplyAsync(() -> {
+ reloadServices();
+ return SlivkaWSDiscoverer.this;
+ }, executor);
discoveryTasks.add(task);
- executor.execute(task);
return task;
}