12.2.4. Service Group event handlers
Interface ClientEventListener declares 6 event handlers associated with Service Group. The first 5 of them have a parameter of type RemoteServiceEvent:
void onServiceOnline(RemoteServiceEvent e)
void onServiceOffline(RemoteServiceEvent e)
void onServiceIncluded(RemoteServiceEvent e)
void onServiceRemoved(RemoteServiceEvent e)
void onServiceUpdated(RemoteServiceEvent e)
They are invoked when only one remote service has its properties changed. Parameter ‘e’ contains the affected remote service in the ‘service’ field. The following example demonstrates this idea:
public void onServiceOnline(RemoteServiceEvent e) {
System.out.println("Remote service online!");
System.out.println("Hostname: " + e.service.getHostname());
System.out.println("Service Version: " + e.service.getVersion());
}
If two or more remote services could have their properties changed the following handler is invoked:
void onServicesUpdated(ClientEndpointEvent e)
The parameter e does not convey information about affected services. The application can only get an updated list of RemoteService objects from the endpoint and look through the properties, as shown in the following example:
public void onServicesUpdated(ClientEndpointEvent e) {
ClientEndpoint clientEndpoint = e.getEndpoint();
RemoteService[] remoteServices = clientEndpoint.getServices();
System.out.println("Remote service list updated!");
for(RemoteService service: remoteServices) {
System.out.println("Hostname: " + service.getHostname());
System.out.println("Version: " + service.getVersion());
System.out.println();
}
}