*** This class provides Binary Compatibility only, not Source Compatibility ***
Class JVMAttribute
- All Implemented Interfaces:
ServiceAttributeInterface,Serializable
When a service is deployed, a JVMAttribute
will be added to its service discovery configuration. This will enable
one to find a service that is deployed in a particular JVM.
Examples
Examples are provided to find a service that was deployed in:
- this JVM
- the same JVM as a previously discovered service
Example 1: Find a service that was deployed in this JVM
To find a service that was instantiated in this JVM, define a service template that specifies one or more interfaces that the desired service must implement and this attribute using its default constructor.The following example shows how to define a service template that can be used to discover an Authentication service that was deployed in this JVM.
import com.sas.services.discovery.DiscoveryService;
import com.sas.services.discovery.JVMAttribute;
import com.sas.services.discovery.ServiceAttributeInterface;
import com.sas.services.discovery.ServiceTemplate;
import com.sas.services.security.AuthenticationServiceInterface;
...
// specify the desired service type(s)
Class[] desiredServiceTypes = new Class[] {
AuthenticationServiceInterface.class};
// specify the optional attributes to be used to qualify a discovery lookup
// to include only those services which were instantiated in this JVM
ServiceAttributeInterface[] serviceAttributes =
new ServiceAttributeInterface[] {
new JVMAttribute()};
// create a service lookup template specifying the required
// service interface(s) and a service attribute for a
// service that was instantiated in this JVM
ServiceTemplate serviceTemplate = new ServiceTemplate(
desiredServiceTypes,
serviceAttributes);
// discover a service satisfying the service template
AuthenticationServiceInterface authenticationService = (AuthenticationServiceInterface)
DiscoveryService.defaultInstance().findService(serviceTemplate);
Example 2: Find a service that was deployed in the same JVM as another service
To find a service that was deployed in the same JVM as a previously discovered service, define a service template that specifies one or more interfaces that the desired service must implement and a JVMAttribute initialized with the desired ID which may be queried from a service's JVMAttribute stored in its service discovery configuration.The following example shows how to define a service template that can be used to discover an Authentication Service that was instantiated in the same JVM as another service.
import com.sas.services.ServiceConfigurationInterface;
import com.sas.services.discovery.DiscoveryService;
import com.sas.services.discovery.JVMAttribute;
import com.sas.services.discovery.ServiceAttributeInterface;
import com.sas.services.discovery.ServiceDiscoveryConfigurationInterface;
import com.sas.services.discovery.ServiceTemplate;
import com.sas.services.security.AuthenticationServiceInterface;
import com.sas.services.user.UserServiceInterface;
...
// specify the desired service type(s)
final Class[] desiredServiceTypes = new Class[] {
AuthenticationServiceInterface.class};
// part 1:
// find a foundation User service and determine its JVM ID
// from its service discovery configuration, so that we
// can lookup another service that was instantiated in the same JVM
ServiceTemplate serviceTemplate = new ServiceTemplate(
new Class[] {UserServiceInterface.class});
RemoteServiceInterface userService =
DiscoveryService.defaultInstance().findService(serviceTemplate);
ServiceDiscoveryConfigurationInterface serviceDiscoveryConfig =
(ServiceDiscoveryConfigurationInterface) userService.getServiceConfiguration(
ServiceConfigurationInterface.CONFIGURATION_SERVICE_DISCOVERY);
String jvmId = serviceDiscoveryConfig.getJVMId();
if (jvmId != null) {
// part 2:
// find a Authentication service that was deployed in the same JVM as the
// previously discovered User service
// specify the optional attributes to be used to qualify a discovery lookup
// to include only those services which are not accessible to remote clients
ServiceAttributeInterface[] serviceAttributes =
new ServiceAttributeInterface[] {
new JVMAttribute(jvmId)}; // ID of the desired JVM
// create a service lookup template specifying the required
// service interface(s) and a service attribute for a
// service that was instantiated in the same JVM as the previously
// discovered User service
ServiceTemplate serviceTemplate = new ServiceTemplate(
desiredServiceTypes,
serviceAttributes);
// discover a service satisfying the service template
AuthenticationServiceInterface authenticationService = (AuthenticationServiceInterface)
DiscoveryService.defaultInstance().findService(serviceTemplate);
}
- Since:
- 9.2
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringIdentifier unique to this JVM that can be used to determine whether another service was instantiated in the same JVM.Fields inherited from class com.sas.services.discovery.IdAttribute
id, idType -
Constructor Summary
ConstructorsConstructorDescriptionConstructs an instance of a service discovery attribute that is initialized with an identifier representing this JVM.JVMAttribute(String id) Constructs a service discovery attribute which may be used to lookup a service which has been instantiated in a JVM with the specified ID. -
Method Summary
Methods inherited from class com.sas.services.discovery.IdAttribute
getFieldNameToValueMapMethods inherited from class com.sas.services.AbstractServiceAttribute
equals, hashCode, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Field Details
-
JVM_ID
public static final String JVM_IDIdentifier unique to this JVM that can be used to determine whether another service was instantiated in the same JVM.
-
-
Constructor Details
-
JVMAttribute
public JVMAttribute()Constructs an instance of a service discovery attribute that is initialized with an identifier representing this JVM.Use this constructor to instantiate a service discovery attribute to be associated with a service that is being instantiated in this JVM.
A discovery service consumer can use this constructor to create a service discovery attribute which may be used to locate a service that has been instantiated in the same JVM.
This constructor initializes the value of the
idto the value of this JVM'sid. -
JVMAttribute
public JVMAttribute(String id) Constructs a service discovery attribute which may be used to lookup a service which has been instantiated in a JVM with the specified ID.- Parameters:
id- The ID of the JVM attribute.If you wish to locate a foundation service that has been started in the same JVM use the default constructor
JVMAttribute()instead.
-