org.elkoserver.foundation.server.metadata
Class ServiceDesc

java.lang.Object
  extended by org.elkoserver.foundation.server.metadata.ServiceDesc
All Implemented Interfaces:
Encodable

public class ServiceDesc
extends Object
implements Encodable

Description of a (possibly) registered service.


Constructor Summary
ServiceDesc(String service, OptString hostport, OptString protocol, OptString label, AuthDesc auth, OptString failure, OptInteger providerID)
          JSON-driven constructor.
ServiceDesc(String service, String failure)
          Error constructor.
ServiceDesc(String service, String hostport, String protocol, String label, AuthDesc auth, String failure, int providerID)
          Direct constructor.
 
Method Summary
 HostDesc asHostDesc(int retryInterval)
          Generate a HostDesc object suitable for establishing a connection to the service described by this service descriptor.
 void attachLabel(String label)
          Set this service's a label string.
 AuthDesc auth()
          Get this service's authorization configuration.
 JSONLiteral encode(EncodeControl control)
          Encode this object for transmission or persistence.
static JSONLiteralArray encodeArray(Iterable<ServiceDesc> services)
          Generate a JSONLiteralArray of ServiceDesc objects from a sequence of them.
 JSONLiteralArray encodeAsArray()
          Encode this descriptor as a single-element JSONLiteralArray.
 String failure()
          Get this descriptor's error message.
 String hostport()
          Get this service's host:port string.
 String label()
          Get this service's label string.
 String protocol()
          Get this service's protocol string.
 int providerID()
          Get this service's provider ID.
 String service()
          Get this services's service name.
 void setProviderID(int providerID)
          Set this service's provider ID.
 ServiceDesc subService(String service)
          Generate a service descriptor based on this one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServiceDesc

public ServiceDesc(String service,
                   String hostport,
                   String protocol,
                   String label,
                   AuthDesc auth,
                   String failure,
                   int providerID)
Direct constructor.

Parameters:
service - The name of the service.
hostport - Where to reach the service.
protocol - Protocol to speak to the sevice with.
label - Printable name for the service.
auth - Authorization configuration for connection to the service.
failure - Optional error message.
providerID - Provider ID, or -1 if not set.

ServiceDesc

public ServiceDesc(String service,
                   String failure)
Error constructor.

Parameters:
service - The name of the service.
failure - Error message.

ServiceDesc

@JSONMethod(value={"service","hostport","protocol","label","?auth","failure","provider"})
public ServiceDesc(String service,
                                   OptString hostport,
                                   OptString protocol,
                                   OptString label,
                                   AuthDesc auth,
                                   OptString failure,
                                   OptInteger providerID)
JSON-driven constructor.

Parameters:
service - The name of the service.
hostport - Where to reach the service.
protocol - Protocol to speak to the service with.
label - Optional printable name for the service.
auth - Optional authorization configuration for connection.
failure - Optional error message.
providerID - Optional provider ID.
Method Detail

asHostDesc

public HostDesc asHostDesc(int retryInterval)
Generate a HostDesc object suitable for establishing a connection to the service described by this service descriptor.

Parameters:
retryInterval - Connection retry interval for connecting to this host, or -1 to take the default.
Returns:
a HostDesc for this service's host.

attachLabel

public void attachLabel(String label)
Set this service's a label string.

Parameters:
label - The new label string for this service.

auth

public AuthDesc auth()
Get this service's authorization configuration.

Returns:
this services's authorization configuration.

failure

public String failure()
Get this descriptor's error message.

Returns:
this descriptors's error message (or null if there is none).

hostport

public String hostport()
Get this service's host:port string.

Returns:
this services's host:port string (or null if there is none).

label

public String label()
Get this service's label string.

Returns:
this service's label (or null if there is no label).

protocol

public String protocol()
Get this service's protocol string.

Returns:
this service's protocol (or null if there is none).

providerID

public int providerID()
Get this service's provider ID.

Returns:
this service's provider ID (or -1 if it has none).

service

public String service()
Get this services's service name.

Returns:
this services's service name (or null if it has none).

setProviderID

public void setProviderID(int providerID)
Set this service's provider ID. It is an error to set this value if it has already been set.

Parameters:
providerID - Nominal provider ID number for this service.

subService

public ServiceDesc subService(String service)
Generate a service descriptor based on this one.

Parameters:
service - The service name of the sub-service.
Returns:
a new service descriptor with the same contact information but with a subsidary service name appended.

encode

public JSONLiteral encode(EncodeControl control)
Encode this object for transmission or persistence.

Specified by:
encode in interface Encodable
Parameters:
control - Encode control determining what flavor of encoding should be done.
Returns:
a JSON literal representing this object.

encodeArray

public static JSONLiteralArray encodeArray(Iterable<ServiceDesc> services)
Generate a JSONLiteralArray of ServiceDesc objects from a sequence of them.


encodeAsArray

public JSONLiteralArray encodeAsArray()
Encode this descriptor as a single-element JSONLiteralArray.