|
| Foundation |
|
| |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||||
com.sas.services.discovery.DiscoveryService
@SASScope(value="ALL") @SubjectToChange public class DiscoveryService
Discovery service used to store registered services and discovery delegates.
This service provides the mechanism to discover and obtain one or more implementations of a service satisfying a specified service template which is expressed in terms of service capabilities and optional attributes. Service capabilities are expressed in terms of what a service is, extends, or interface it implements.
The following permission actions may be used to control authorization to execute service operations.
| Permission | Action | Description |
|---|---|---|
| java.lang.RuntimePermission | shutdownHooks | allows the discovery service to register a JVM shutdown hook, which when called will destroy the discovery service and all registered foundation services started within the application |
| com.sas.services.ServicePermission | destroy | allows one to destroy the discovery service and all registered foundation services started within the application |
defaultInstance() to obtain the application's local discovery
service.
LocalDiscoveryServiceInterface discoveryService =
DiscoveryService.defaultInstance();
DiscoveryService.defaultInstance().destroy;
ServiceLoader.deployServices(MetadataSourceInterface metadataSource)
or looked up services deployed remotely in another application using
ServiceLoader.lookupRemoteDiscoveryServices(com.sas.services.deployment.MetadataSourceInterface, DiscoveryServiceInterface)
one may use the local discovery service to find services.
This example will attempt to find a service satisfying the specified service template by first searching services instantiated locally within this application. If a service is not found and discovery delegates are defined, then the request will be forwarded to discovery service(s) in remote applications.
...
// application has already either deployed services locally
// or looked up a remote discovery service that resides in
// another application.
import com.sas.services.security.AuthenticationServiceInterface;
...
LocalDiscoveryServiceInterface discoveryService =
DiscoveryService.defaultInstance();
ServiceTemplate serviceTemplate = new ServiceTemplate(
new Class[] {
AuthenticationServiceInterface.class
});
AuthenticationServiceInterface authenticationService =
(AuthenticationServiceInterface) discoveryService.findService(serviceTemplate);
ServiceLoader.deployServices(MetadataSourceInterface metadataSource)
or looked up services deployed remotely in another application using
ServiceLoader.lookupRemoteDiscoveryServices(com.sas.services.deployment.MetadataSourceInterface, DiscoveryServiceInterface)
one may use the local discovery service to find services.
This example will attempt to find a service satisfying the specified service template which designates a service interface and service attributes which are used to distinguish between multiple service implementations that satisfy the same service interfaces.
...
// application has already either deployed services locally
// or looked up a remote discovery service that resides in
// another application.
import com.sas.metadata.remote.MetadataObjects;
import com.sas.services.deployment.ServiceDeploymentInterface;
import com.sas.services.security.AuthenticationServiceInterface;
...
// the name of the SoftwareComponent that owns the desired
// Authentication Service
String softwareComponentName = "Query and Reporting";
// desired service: Authentication Service
Class[] serviceTypes = new Class[] {
AuthenticationServiceInterface.class
};
// a Authentication Service that is associated with the
// software component named "Query and Reporting"
ServiceAttributeInterface[] serviceAttributes = new ServiceAttributeInterface[] {
new MetadataAttribute(
null, // a null SoftwareComponent.FQID indicates a don't care
softwareComponentName, // SoftwareComponent.Name
MetadataObjects.SOFTWARECOMPONENT,
ServiceDeploymentInterface.CLASS_IDENTIFIER);
};
ServiceTemplate serviceTemplate = new ServiceTemplate(
serviceTypes,
serviceAttributes);
// find the Authentication Service that belongs to the foundation services
// deployment named "Query and Reporting" by using a service template
// that designates the service interface and an optional service
// attribute designating the service's owning SoftwareComponent.
LocalDiscoveryServiceInterface discoveryService =
DiscoveryService.defaultInstance();
AuthenticationServiceInterface authenticationService =
(AuthenticationServiceInterface) discoveryService.findService(serviceTemplate);
By default this local discovery service implementation does not try to re-attempt to find services if a lookup fails to find a service satisfying requested lookup parameters. Support is provided to optionally specify a lookup policy that will be consulted to determine whether a lookup should be re-attempted in the event that service(s) are not found. This may be useful in cases such as web applications where it is difficult to control application startup sequences.
One policy is to to specify a maximum timeout in msec. Lookups will be re-attempted until the timeout expires. The following code snippet shows how to specify a timeout lookup policy.
LocalDiscoveryServiceInterface discoveryService =
DiscoveryService.defaultInstance();
final long timeoutInMsec = 750;
final LookupPolicyInterface lookupPolicyIf =
new LookupPolicyTimeout(timeoutInMsec);
System.out.println(lookupPolicyIf);
discoveryService.setLookupPolicy(lookupPolicyIf);
Alternatively one can employ a policy of re-attempting lookups for a specified number of times at designated intervals specified in units of msec. The following code example shows how to specify an maximum attempts lookup policy.
LocalDiscoveryServiceInterface discoveryService =
DiscoveryService.defaultInstance();
final long attemptIntervalInMsec = 5000;
final int maxNumAttempts = 2;
final LookupPolicyInterface lookupPolicyIf =
new LookupPolicyAttempts(
maxNumAttempts,
attemptIntervalInMsec);
System.out.println(lookupPolicyIf);
discoveryService.setLookupPolicy(lookupPolicyIf);
If service lookup re-attempt policy is only needed during your application's initialization, then one should clear the policy to enable the lookup to return to its default behavior of not re-attempting lookups after your initialization completes. The following code example shows how to clear the lookup policy.
LocalDiscoveryServiceInterface discoveryService =
DiscoveryService.defaultInstance();
discoveryService.setLookupPolicy(null);
If an alternative lookup policy is desired, then one can implement their own
lookup policy that implements the
LookupPolicyInterface interface.
| Field Summary |
|---|
| Fields inherited from interface com.sas.services.discovery.FindServiceInterface |
|---|
FIND_ALL_MATCHES, FIND_ONE_MATCH |
| 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 | |
|---|---|
DiscoveryService()
Constructs a default instance of a discovery service. |
|
DiscoveryService(java.util.Set<FindServiceInterface> discoveryDelegates)
Constructs an instance of a discovery service and initializes it with discovery delegates specified in the provided collection. |
|
DiscoveryService(java.util.Set<FindServiceInterface> discoveryDelegates,
java.util.Set<RemoteServiceInterface> services)
Constructs an instance of a discovery service and initializes it with discovery delegates specified in the provided collection. |
|
| Method Summary | |
|---|---|
void |
addDiscoveryDelegate(FindServiceInterface discoveryDelegate)
Adds a discovery delegate. |
void |
addService(RemoteServiceInterface service)
Adds a service that is intended to be discovered. |
static LocalDiscoveryServiceInterface |
defaultInstance()
Obtains a singleton instance of the local discovery service. |
void |
destroy()
Destroy this discovery service releasing any resources that have been allocated. |
void |
destroy(UserContextInterface userContext)
Destroy this discovery service releasing any resources that have been allocated. |
Services |
findServices(ServiceTemplate serviceTemplate,
int maxNumMatches,
Services discoveredServices)
Finds a collection of objects via a discovery mechanism. |
Services |
findServices(ServiceTemplate serviceTemplate,
int maxNumMatches,
Services discoveredServices,
java.lang.String serviceRequestId,
int attemptNumber)
Finds a collection of objects via a discovery mechanism. |
java.util.Iterator<FindServiceInterface> |
getDiscoverers()
Gets an iterator for a copy of the set of discovery delegates. |
java.util.Iterator<RemoteServiceInterface> |
getLocalServices()
Gets an iterator of non-remoteable objects that implement the RemoteServiceInterface. |
LookupPolicyInterface |
getLookupPolicy()
Gets the lookup policy that controls whether or not an attempt is made to re-lookup a service in the event that it was not available. |
java.util.Iterator<RemoteServiceInterface> |
getRemoteServices()
Gets an iterator of remoteable objects that implement the RemoteServiceInterface. |
java.lang.String |
getServiceName()
Gets this service's name. |
static boolean |
isOkToProcessRequest(java.lang.String discoveryServiceId,
ServiceTemplate serviceTemplate)
Determines whether or not it is OK to for the specified discovery service to process the requested service template. |
void |
removeDiscoveryDelegate(FindServiceInterface serviceLocator)
Removes a discovery delegate. |
void |
removeService(RemoteServiceInterface service)
Removes a service from this discovery service. |
void |
setLookupPolicy(LookupPolicyInterface lookupPolicy)
Specifies an implementation of policies related to service discovery. |
java.lang.String |
toString()
Gets a string representation of this instance. |
| Methods inherited from class com.sas.services.discovery.AbstractDiscoveryService |
|---|
findService, findServiceUsingId |
| Methods inherited from class com.sas.services.AbstractService |
|---|
configure, getEntityKey |
| Methods inherited from interface com.sas.services.discovery.FindServiceInterface |
|---|
findService, findServiceUsingId |
| Methods inherited from interface com.sas.services.RemoteServiceInterface |
|---|
configure, getCreationTime, getServiceConfiguration, getServiceConfiguration, getServiceProxy, getServiceState, isAccessibleToRemoteClients, isExported, reconfigure, setServiceState |
| Methods inherited from interface com.sas.entities.EntityKeyInterface |
|---|
getEntityKey, sameEntity, setEntityKey |
| Methods inherited from interface com.sas.services.mgmt.ServiceNotificationBroadcasterInterface |
|---|
addServiceObserver, notifyServiceObservers, removeAllServiceObservers, removeServiceObserver |
| Constructor Detail |
|---|
public DiscoveryService()
public DiscoveryService(java.util.Set<FindServiceInterface> discoveryDelegates)
throws java.lang.IllegalArgumentException
discoveryDelegates - Collection containing service locators which implement the
FindServiceInterface interface.
java.lang.IllegalArgumentException - if a null collection is specified
or if the collection does not contain elements that implement FindServiceInterface.
public DiscoveryService(java.util.Set<FindServiceInterface> discoveryDelegates,
java.util.Set<RemoteServiceInterface> services)
throws ServiceException
discoveryDelegates - Collection containing service locators which implement the
FindServiceInterface interface or null if there are
no services to add.services - Collection of services which implement
RemoteServiceInterface or null if there are no services to add.
ServiceException - if a null collection is specified
or if the collection does not contain elements that implement FindServiceInterface.| Method Detail |
|---|
public static final LocalDiscoveryServiceInterface defaultInstance()
This instance should be destroyed by the application when the
application is terminated to enable destruction of all locally
instantiated services. Locally instantiated services will be
destroyed in order from most to least recently instantiated.
When the application is ready to terminate it must destroy the
local discovery service by invoking
DiscoveryService.defaultInstance().destroy()
null if unable to configure the local discovery service.
public final Services findServices(ServiceTemplate serviceTemplate,
int maxNumMatches,
Services discoveredServices)
throws ServiceException,
ServiceNotAvailableException,
java.lang.IllegalStateException,
java.rmi.RemoteException
To be considered a successful match, the service must satisfy the requested service template which may be used to specify:
Note that all of the find service methods funnel their processing to this method.
findServices in interface FindServiceInterfacefindServices in class AbstractDiscoveryServiceserviceTemplate - Service capability template that specifies either
maxNumMatches - Maximum number of services.discoveredServices - A collection containing services that
have already been found. Set this parameter to
null if no services have
been found yet.
ServiceException - if an unanticipated exception occurs while
processing the discovery.
java.rmi.RemoteException - if a network anomaly is encountered.
ServiceNotAvailableException - if no service satisfies
the requested service template.
java.lang.IllegalStateException - if this service has been destroyed and
is no longer accepting requests to find services.ServiceTemplate
public final Services findServices(ServiceTemplate serviceTemplate,
int maxNumMatches,
Services discoveredServices,
java.lang.String serviceRequestId,
int attemptNumber)
throws ServiceException,
ServiceNotAvailableException,
java.rmi.RemoteException
To be considered a successful match, the service must satisfy the requested service template which may be used to specify:
Note that all of the find service methods funnel their processing to this method.
serviceTemplate - Service capability template that specifies either
maxNumMatches - Maximum number of services.discoveredServices - A collection containing services that have already been found.
Set this parameter to null if no services have
been found yet.serviceRequestId - An ID uniquely associated with this service lookup request.attemptNumber - The number of attempts that have been made to find services so far.
ServiceException - if an unanticipated exception occurs while
processing the discovery.
java.rmi.RemoteException - if a network anomaly is encountered.
ServiceNotAvailableException - if no service satisfies
the requested service template.ServiceTemplatepublic java.lang.String getServiceName()
public final java.util.Iterator<FindServiceInterface> getDiscoverers()
getDiscoverers in interface DiscoveryAdminInterfaceFindServiceInterface.
public final void addDiscoveryDelegate(FindServiceInterface discoveryDelegate)
throws java.rmi.RemoteException
addDiscoveryDelegate in interface DiscoveryAdminInterfacediscoveryDelegate - The discovery delegate to add. A warning will be logged if
one attempts to add a delegate which implements
EntityKeyInterface that has already been registered.
java.rmi.RemoteException - if a network anomaly is encounteredpublic final void removeDiscoveryDelegate(FindServiceInterface serviceLocator)
removeDiscoveryDelegate in interface DiscoveryAdminInterfaceserviceLocator - Discovery delegate to remove.
public final void addService(RemoteServiceInterface service)
throws ServiceException
addService in interface DiscoveryAdminInterfaceservice - A service to register with this discovery service.
ServiceException - if unable to add the service.public final void removeService(RemoteServiceInterface service)
removeService in interface DiscoveryAdminInterfaceservice - Service that is to be removed.public java.util.Iterator<RemoteServiceInterface> getLocalServices()
RemoteServiceInterface.
getLocalServices in interface DiscoveryAdminInterfacepublic java.util.Iterator<RemoteServiceInterface> getRemoteServices()
RemoteServiceInterface.
getRemoteServices in interface DiscoveryAdminInterfaceRemoteServiceInterface interface.public final java.lang.String toString()
toString in class AbstractRemoteService
public static final boolean isOkToProcessRequest(java.lang.String discoveryServiceId,
ServiceTemplate serviceTemplate)
discoveryServiceId - A discovery service's entity key.serviceTemplate - Service template containing a passport of discovery services
that have previously processed the requested template.
true if it is OK to process the request or
false if it isn't.public void destroy()
The destruction call is then passed on to the superclass where resources common to all foundation services will be released.
destroy in interface RemoteServiceInterfacedestroy in class AbstractServicepublic void destroy(UserContextInterface userContext)
The destruction call is then passed on to the super class where resources common to all foundation services will be released.
userContext - A User context which is used in a check to
ensure that the caller is authorized for the following permission:
com.sas.services.ServicePermission "destroy"public final LookupPolicyInterface getLookupPolicy()
getLookupPolicy in interface LocalDiscoveryServiceInterfacenull if a lookup
should not be re-attempted.public final void setLookupPolicy(LookupPolicyInterface lookupPolicy)
Refer to LookupPolicyInterface to
determine lookup policy implementations.
setLookupPolicy in interface LocalDiscoveryServiceInterfacelookupPolicy - Policy implementations related to service discovery.
Refer to
LookupPolicyInterface
|
| Foundation |
|
| |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||||