|
| Foundation |
|
| |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||||
com.sas.services.discovery.HostAttribute
public final class HostAttribute
A foundation service discovery attribute which may be used to locate a service which has been deployed on a particular host by using the host's name and/or IP address.
When a service is deployed, a HostAttribute
will be added to its service discovery configuration
for each InetAddress associated with its host. This will enable
one to find a service that is deployed on a particular host.
Examples are provided to find a foundation service deployed on:
To find a service that
was deployed on this host,
define a service template that specifies one or more interfaces that the desired service must satisfy
and a HostAttribute initialized to the desired host by specifying either
the host's name and/or its IP address.
import java.net.InetAddress;
import com.sas.services.discovery.DiscoveryService;
import com.sas.services.discovery.HostAttribute;
import com.sas.services.discovery.ServiceTemplate;
import com.sas.services.security.AuthenticationServiceInterface;
...
// define a service template that can be used to
// lookup an Authentication Service
Class[] desiredServiceInterface = new Class[] {
AuthenticationServiceInterface.class};
// get this host's InetAddress
// note: a host may have multiple addresses
InetAddress inetAddress = getInetAddress();
ServiceAttributeInterface serviceAttributes = new ServiceAttributeInterface[] {
new HostAttribute(inetAddress)};
// create a service lookup template specifying the required
// service interface(s) and a service attribute for a
// service that was deployed on this host
ServiceTemplate serviceTemplate = new ServiceTemplate(
desiredServiceInterface,
serviceAttributes);
// discover a service satisfying the service template
AuthenticationServiceInterface authenticationService = (AuthenticationServiceInterface)
DiscoveryService.defaultInstance().findService(serviceTemplate);
...
// Utility method used to determine the host's InetAddress:
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;
import com.sas.services.deployment.RMIConfiguration;
...
// get this host's InetAddress discarding the "localhost" address
InetAddress getInetAddress () {
InetAddress theInetAddress = null;
try {
final Enumeration netInterfaces = NetworkInterface.getNetworkInterfaces();
NetworkInterface networkInterface = null;
InetAddress inetAddress = null;
Enumeration inetAddresses = null;
while (netInterfaces.hasMoreElements()) {
networkInterface= (NetworkInterface) netInterfaces.nextElement();
inetAddresses = networkInterface.getInetAddresses();
while (inetAddresses.hasMoreElements()) {
inetAddress = (InetAddress) inetAddresses.nextElement();
if (!RMIConfiguration.LOCALHOST.equals(inetAddress.getHostName())) {
theInetAddress = inetAddress;
break;
}
}
}
}
catch (ClassCastException e) {
// handle exception
}
return theInetAddress;
}
To find a service that
was deployed on this host,
define a service template that specifies one or more interfaces that the desired service must satisfy
and a HostAttribute initialized using the host's name.
import com.sas.services.discovery.DiscoveryService;
import com.sas.services.discovery.HostAttribute;
import com.sas.services.discovery.ServiceTemplate;
import com.sas.services.security.AuthenticationServiceInterface;
...
// define a service template that can be used to
// lookup an Authentication Service
Class[] desiredServiceInterface = new Class[] {
AuthenticationServiceInterface.class};
// the name of the desired host on which a service was deployed
String hostName = "xxx.acme.com";
// find a service on for a given host name
ServiceAttributeInterface serviceAttributes = new ServiceAttributeInterface[] {
new HostAttribute(
hostName,
null)};//don't care about the host's address
// create a service lookup template specifying the required
// service interface(s) and a service attribute for a
// service that was deployed on the specified host
ServiceTemplate serviceTemplate = new ServiceTemplate(
desiredServiceInterface,
serviceAttributes);
// discover a service satisfying the service template
AuthenticationServiceInterface authenticationService = (AuthenticationServiceInterface)
DiscoveryService.defaultInstance().findService(serviceTemplate);
To find a service that
was deployed on this host,
define a service template that specifies one or more interfaces that the desired service must satisfy
and a HostAttribute initialized using the host's address.
import com.sas.services.discovery.DiscoveryService;
import com.sas.services.discovery.HostAttribute;
import com.sas.services.discovery.ServiceTemplate;
import com.sas.services.security.AuthenticationServiceInterface;
...
// define a service template that can be used to
// lookup an Authentication Service
Class[] desiredServiceInterface = new Class[] {
AuthenticationServiceInterface.class};
// the IP address of the desired host on which a service was deployed
String hostAddress = "99.99.99.99";
// find a service on for a given host name
ServiceAttributeInterface serviceAttributes = new ServiceAttributeInterface[] {
new HostAttribute(
null,//don't care about the host's name
hostAddress)};
// create a service lookup template specifying the required
// service interface(s) and a service attribute for a
// service that was deployed on the specified host
ServiceTemplate serviceTemplate = new ServiceTemplate(
desiredServiceInterface,
serviceAttributes);
// discover a service satisfying the service template
AuthenticationServiceInterface authenticationService = (AuthenticationServiceInterface)
DiscoveryService.defaultInstance().findService(serviceTemplate);
| Field Summary | |
|---|---|
java.lang.String |
address
The host's IP address. |
java.lang.String |
host
The host's name. |
| Constructor Summary | |
|---|---|
HostAttribute()
Constructs a service discovery attribute representing a host with its name and address to null. |
|
HostAttribute(java.net.InetAddress inetAddress)
Constructs a service discovery attribute representing a host by initializing the host's name and address using values obtained from InetAddress.getHostName() and
InetAddress.getHostAddress(). |
|
HostAttribute(java.lang.String hostName)
Constructs an attribute which may be used to locate a remotely accessible foundation service which was deployed on a particular host. |
|
HostAttribute(java.lang.String hostName,
java.lang.String hostAddress)
Constructs a service discovery attribute representing a host using the specified name and address. |
|
| Method Summary | |
|---|---|
java.util.Map |
getFieldNameToValueMap()
Gets a map of this attribute's fields and their values. |
| Methods inherited from class com.sas.services.AbstractServiceAttribute |
|---|
equals, hashCode, toString |
| Field Detail |
|---|
public java.lang.String host
public java.lang.String address
| Constructor Detail |
|---|
public HostAttribute()
null.
public HostAttribute(java.net.InetAddress inetAddress)
InetAddress.getHostName() and
InetAddress.getHostAddress().
Since this attribute initializes both the name and address, a client can locate a foundation service deployed on a particular host by matching the host's name and/or address.
One may also use HostAttribute(String, String) to construct
an instance using string values for the host's name and address.
inetAddress - An address representing the host on which a foundation service has
been deployed.
java.lang.IllegalArgumentException - if a null parameter is specified.public HostAttribute(java.lang.String hostName)
hostName - Internet host name.
public HostAttribute(java.lang.String hostName,
java.lang.String hostAddress)
A convenience constructor HostAttribute(InetAddress) is also
provided if one would prefer to initialize this attribute using a
host name and address obtained from an InetAddress.
hostName - Internet host name.hostAddress - Internet host address.| Method Detail |
|---|
public java.util.Map getFieldNameToValueMap()
getFieldNameToValueMap in class AbstractServiceAttribute
|
| Foundation |
|
| |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||||