Package com.sas.services
Class AbstractRemoteService
java.lang.Object
com.sas.services.AbstractRemoteService
- All Implemented Interfaces:
com.sas.entities.EntityKeyInterface,ServiceNotificationBroadcasterInterface,RemoteServiceInterface,Remote
- Direct Known Subclasses:
AbstractService,ActivatableDiscoveryService,AuthenticationService,EventBrokerDiscoveryService,EventBrokerService,InformationService,SessionService,UserService
public abstract class AbstractRemoteService
extends Object
implements RemoteServiceInterface, ServiceNotificationBroadcasterInterface
Abstract implementation of a service which can be accessed from a remote JVM. A service
may extend this implementation if it is intended to be
deployed in a distributed environment.
Note that this class is extended by
AbstractService
which provides a version that may be used
locally within a JVM process. Methods specified in the local version do
not throw RemoteException.
- Since:
- 1.0
- See Also:
-
Field Summary
Fields inherited from interface com.sas.services.RemoteServiceInterface
CLASS_IDENTIFIER, CLASS_IDENTIFIER_1_1, CLASS_IDENTIFIER_1_2, CLASS_IDENTIFIER_SERVICE_TYPE, CLASS_IDENTIFIER_SERVICE_TYPE_1_1, CLASS_IDENTIFIER_SERVICE_TYPE_1_2 -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a service.AbstractRemoteService(DiscoveryServiceInterface discoveryService) Constructs a service. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddServiceObserver(ServiceRemoteObserverInterface serviceObserver) Adds a service observer.voidBinds this service to the discovery service.voidconfigure(ServiceConfigurationInterface serviceConfiguration) Configures the service.voiddestroy()Handles the destruction of this service.final longGets the time at which this configuration was created.StringReturns a String representation of this service.Gets the discovery service.StringGets this service's entity key.protected final EnvironmentGet the Environment object.Gets this service's configuration.getServiceConfiguration(Object key) Gets the service configuration associated with the specified lookup key.Gets the service proxy.shortGets the service's state.voidHandles JVM shutdown to destroy resources allocated by this service.booleanDetermines whether or not the service is intended to be accessible to remote clients.booleanDetermines whether or not the service has been exported to the RMI system.final booleanDetermines whether or not this service is currently handling a JVM shutdown.final voidnotifyServiceObservers(ServiceEvent serviceEvent) Notify all registered service observers of the specified service event.voidreconfigure(ServiceConfigurationInterface serviceConfiguration) Re-configures the service.final voidRemoves all service observers.final voidremoveServiceObserver(ServiceRemoteObserverInterface serviceObserver) Removes a service observer.booleansameEntity(com.sas.entities.EntityKeyInterface entity) Determines whether or not this service entity is the same as the specified entity.voidsetDiscoveryService(DiscoveryServiceInterface discoveryService) Sets the discovery service which may be used to locate other services.voidsetEntityKey(String entityKey) Set the unique entity key for the service.voidsetRemoteableExporter(com.sas.net.rmi.RemoteObjectExporterInterface remoteableExporter) Sets the remoteable exporter.voidsetServiceState(ServiceState serviceState) Sets the service's state.StringtoString()Returns a String representation of this service that includes the service's entity key.voidRemoves this service from the discovery service.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Constructor Details
-
AbstractRemoteService
public AbstractRemoteService()Constructs a service. -
AbstractRemoteService
Constructs a service.- Parameters:
discoveryService- A discovery service which may be used to locate other services and to which a service must be bound in order to be discovered by other services.
-
-
Method Details
-
getDiscoveryService
Gets the discovery service.- Returns:
- Discovery service or
nullif undefined.
-
bindToDiscoveryService
Binds this service to the discovery service.- Throws:
ServiceException- if an exception was encountered binding this service to the discovery service.
-
unbindFromDiscoveryService
Removes this service from the discovery service.- Throws:
ServiceException- if an exception was encountered removing this service from the discovery service.
-
setDiscoveryService
Sets the discovery service which may be used to locate other services.- Parameters:
discoveryService- Discovery service which may be used to locate other services.
-
setRemoteableExporter
public void setRemoteableExporter(com.sas.net.rmi.RemoteObjectExporterInterface remoteableExporter) throws IllegalStateException Sets the remoteable exporter.- Parameters:
remoteableExporter- Utility to export/unexport a remoteable object.- Throws:
IllegalStateException- if the service has been destroyed.
-
getServiceConfiguration
Gets this service's configuration. The service configuration may contain ancillary sub-configurations which are available via a hash map lookup.The service's configuration can always be retrieved regardless of the service's state.
- Specified by:
getServiceConfigurationin interfaceRemoteServiceInterface- Returns:
- Service's configuration.
- Throws:
IllegalStateException- if the service has been destroyed.
-
getServiceConfiguration
public ServiceConfigurationInterface getServiceConfiguration(Object key) throws IllegalStateException Gets the service configuration associated with the specified lookup key. For example, if the base service configuration contained an ancillary configuration keyed by a value likeServiceConfigurationInterface.CONFIGURATION_SERVICE_DISCOVERYthen this configuration would be returned if defined. If anulllookup key is specified, then the base service configuration is returned.The service's configuration can always be retrieved regardless of the service's state.
- Specified by:
getServiceConfigurationin interfaceRemoteServiceInterface- Parameters:
key- Key designating an ancillary configuration.- Returns:
- Service configuration associated with the specified key or
nullif no configuration is defined for the specified key. - Throws:
IllegalStateException- if the service has been destroyed.
-
configure
public void configure(ServiceConfigurationInterface serviceConfiguration) throws InitializationException, RemoteException, ServiceException Configures the service.- Specified by:
configurein interfaceRemoteServiceInterface- Parameters:
serviceConfiguration- Service's configuration.- Throws:
InitializationException- in unable to configure the service.RemoteException- if a network anomaly is encountered.ServiceException- if a service exception is encountered.
-
reconfigure
public void reconfigure(ServiceConfigurationInterface serviceConfiguration) throws ServiceException, RemoteException Re-configures the service.- Specified by:
reconfigurein interfaceRemoteServiceInterface- Parameters:
serviceConfiguration- Service's configuration.- Throws:
ServiceException- in unable to reconfigure the service.RemoteException- if a network anomaly is encountered.
-
getEntityKey
public String getEntityKey() throws RemoteException, IllegalStateExceptionGets this service's entity key.- Specified by:
getEntityKeyin interfacecom.sas.entities.EntityKeyInterface- Returns:
- Service's entity key.
- Throws:
RemoteException- if a network anomaly occurs.IllegalStateException- if the service has been destroyed.
-
setEntityKey
public void setEntityKey(String entityKey) throws RemoteException, IllegalStateException Set the unique entity key for the service. The entity key for the services cannot be changed. This method will throw an IllegalStateException.- Specified by:
setEntityKeyin interfacecom.sas.entities.EntityKeyInterface- Parameters:
entityKey- Unique entity key.- Throws:
RemoteException- if a network anomaly occurs.IllegalStateException- if the service has been destroyed or if an attempt is made to alter the entity key which is immutable.
-
sameEntity
public boolean sameEntity(com.sas.entities.EntityKeyInterface entity) throws RemoteException, IllegalStateException Determines whether or not this service entity is the same as the specified entity.- Specified by:
sameEntityin interfacecom.sas.entities.EntityKeyInterface- Parameters:
entity- Entity to be compared to this service entity.- Returns:
trueif the service entities are the same orfalseif they aren't.- Throws:
RemoteException- if a network anomaly occurs.IllegalStateException- if the service has been destroyed.
-
getServiceState
public short getServiceState()Gets the service's state.- Specified by:
getServiceStatein interfaceRemoteServiceInterface- Returns:
- Service's state.
-
setServiceState
Sets the service's state.- Specified by:
setServiceStatein interfaceRemoteServiceInterface- Parameters:
serviceState- Service's new state.- Throws:
ServiceException- if unable to process the request.IllegalArgumentException- if anullservice state is specified.
-
isExported
public boolean isExported() throws IllegalStateExceptionDetermines whether or not the service has been exported to the RMI system. This method can only be invoked after the service has been configured.- Specified by:
isExportedin interfaceRemoteServiceInterface- Returns:
trueif the service has been exported orfalseif it hasn't.- Throws:
IllegalStateException- if the service has not been configured or has been destroyed.
-
isAccessibleToRemoteClients
public boolean isAccessibleToRemoteClients() throws IllegalStateExceptionDetermines whether or not the service is intended to be accessible to remote clients. This method can only be invoked after the service has been configured.- Specified by:
isAccessibleToRemoteClientsin interfaceRemoteServiceInterface- Returns:
trueif the service is intended to be accessible to remote clients orfalseif it isn't.- Throws:
IllegalStateException- if the service has not been configured or has been destroyed.
-
handleJVMShutdown
Handles JVM shutdown to destroy resources allocated by this service. Note that in the case of a JVM shutdown that each service will be notified by the JVM that a shutdown is occurring. No call back order is guaranteed, so when this occurs a service should not rely upon any other services being available since they may have already been destroyed.- Throws:
ServiceException- if unable to shutdown cleanly.
-
isHandlingJVMShutdown
public final boolean isHandlingJVMShutdown()Determines whether or not this service is currently handling a JVM shutdown.- Returns:
trueif the service is destroying itself in response to a JVM shutdown call back.
-
destroy
Handles the destruction of this service. If this service was previously exported to make it accessible to remote clients, then it will be unexported.Once a service has been destroyed it should never be used again. The service's state is set to
ServiceState.SERVICE_STATE_DEACTIVATED.- Specified by:
destroyin interfaceRemoteServiceInterface- Throws:
RemoteException- if a network anomaly is encountered.ServiceException- if a service exception is encountered.
-
addServiceObserver
public final void addServiceObserver(ServiceRemoteObserverInterface serviceObserver) throws RemoteException, IllegalStateException Adds a service observer. This method can only be invoked after the service has been configured.- Specified by:
addServiceObserverin interfaceServiceNotificationBroadcasterInterface- Parameters:
serviceObserver- An observer interested in receiving service notifications.- Throws:
RemoteException- if a network anomaly is encountered.IllegalStateException- if the service has not been configured or has been destroyed.
-
removeServiceObserver
public final void removeServiceObserver(ServiceRemoteObserverInterface serviceObserver) throws RemoteException Removes a service observer.- Specified by:
removeServiceObserverin interfaceServiceNotificationBroadcasterInterface- Parameters:
serviceObserver- An observer no longer interested in receiving service notifications.- Throws:
RemoteException- if a network anomaly is encountered.
-
removeAllServiceObservers
public final void removeAllServiceObservers() throws RemoteExceptionRemoves all service observers.- Specified by:
removeAllServiceObserversin interfaceServiceNotificationBroadcasterInterface- Throws:
RemoteException- if a network anomaly is encountered.
-
notifyServiceObservers
public final void notifyServiceObservers(ServiceEvent serviceEvent) throws RemoteException, IllegalArgumentException Notify all registered service observers of the specified service event.- Specified by:
notifyServiceObserversin interfaceServiceNotificationBroadcasterInterface- Parameters:
serviceEvent- Service event to be broadcast to all registered service observers.- Throws:
RemoteException- if a network anomaly is encountered.IllegalArgumentException- if anullservice event is specified.
-
getCreationTime
public final long getCreationTime()Gets the time at which this configuration was created. Can be used to order services based upon their creation times. Originally specified using currentTimeMillis().- Specified by:
getCreationTimein interfaceRemoteServiceInterface- Returns:
- Time at which this configuration was created.
-
getServiceProxy
Gets the service proxy. A subclass should override this method if a proxy is available. This method can only be invoked after the service has been configured.- Specified by:
getServiceProxyin interfaceRemoteServiceInterface- Returns:
- A proxy to this service or
nullif a proxy is not available. - Throws:
IllegalStateException- if the service has not been configured or has been destroyed.
-
getDetails
public String getDetails()Returns a String representation of this service.- Returns:
- String representation of this service.
-
toString
public String toString()Returns a String representation of this service that includes the service's entity key.- Overrides:
toStringin classObject- Returns:
- String representation of this service.
-
getEnvironment
Get the Environment object. An Environment object encapsulates resources provided by the container.- Returns:
- Environment which may be used to access resources provided
by a container or
null.
-