1 package jalview.ws2.client.api;
4 import java.util.EventListener;
6 import java.util.concurrent.CompletableFuture;
8 import jalview.ws2.api.WebService;
11 * The discoverer and supplier of web services. The discoverer is responsible
12 * for building and storing {@link jalview.ws2.api.WebService} objects
13 * according to the data retrieved from the servers available at specified urls.
17 public interface WebServiceDiscovererI extends WebServiceProviderI
19 public static final int STATUS_OK = 1;
21 public static final int STATUS_NO_SERVICES = 0;
23 public static final int STATUS_INVALID = -1;
25 public static final int STATUS_UNKNOWN = -2;
28 * Get the short name of the discoverer.
30 * @return discoverer name
35 * List the urls used by this discoverer.
40 * Set the list of urls where the discoverer will search for services.
41 * May throw UnsupportedOperationException if the list is unmodifiable.
43 void setUrls(List<URL> wsUrls);
46 * Check if list of urls is modifiable.
48 * @return is list modifiable
50 boolean isUrlsModifiable();
53 * Test if the url is a valid url for that discoverer.
55 default boolean testUrl(URL url)
57 return getStatusForUrl(url) == STATUS_OK;
61 * Get the availability status of the services at the url. Return one of the
62 * status codes {@code STATUS_OK}, {@code STATUS_NO_SERVICES},
63 * {@code STATUS_INVALID} or {@code STATUS_UNKNOWN}.
65 * @return services availability status
67 int getStatusForUrl(URL url);
70 * @return {@value true} if there are services available
72 boolean hasServices();
75 * Check if service discovery is still in progress. List of services may be
76 * incomplete when the discoverer is running.
78 * @return whether the discoverer is running
83 * Check if the discoverer is done searching for services. List of services
84 * should be complete if this methods returns true.
86 * @return whether the discoverer finished
91 * Start the service discovery and return a future which will be set to the
92 * discovery result when the process is completed. This method should be
93 * called once on startup and then every time the urls list is updated.
95 * @return services list future result
97 CompletableFuture<List<WebService<?>>> startDiscoverer();
100 * An interface for the services list observers.
105 interface ServicesChangeListener extends EventListener
108 * Called whenever the services list of the observed discoverer changes with
109 * that discoverer as the first argument and current services list as the
110 * second. The list can be empty if there are no services or the list was
111 * cleared at the beginning of the discovery.
116 public void servicesChanged(WebServiceDiscovererI discoverer,
117 List<WebService<?>> services);
121 * Add a services list observer that will be notified of any changes to the
125 * services list change listener
127 public void addServicesChangeListener(ServicesChangeListener listener);
130 * Remove a listener from the listeners list.
133 * listener to be removed
135 public void removeServicesChangeListener(ServicesChangeListener listener);