com.sun.jini.discovery
Class DiscoveryConstraints

java.lang.Object
  extended by com.sun.jini.discovery.DiscoveryConstraints

public class DiscoveryConstraints
extends Object

Class for processing constraints which apply to the discovery protocol: DiscoveryProtocolVersion, MulticastMaxPacketSize, MulticastTimeToLive, UnicastSocketTimeout, ConnectionRelativeTime, ConnectionAbsoluteTime.

Since:
2.0
Author:
Sun Microsystems, Inc.

Nested Class Summary
private static class DiscoveryConstraints.ConnectionAbsoluteTimeReducer
           
private static class DiscoveryConstraints.ConstraintReducer
          Utility for reducing constraints of a given type into a base set of alternatives.
private static class DiscoveryConstraints.MaxValueReducer
           
private static class DiscoveryConstraints.MulticastMaxPacketSizeReducer
           
 
Field Summary
private  ConnectionAbsoluteTime connectionAbsoluteTime
           
private  int hashcode
           
private  MulticastMaxPacketSize maxPacketSize
           
static Method multicastAnnouncementMethod
          Method object for the multicastAnnouncement method of this class.
static Method multicastRequestMethod
          Method object for the multicastRequest method of this class.
private  int preferredProtocolVersion
           
private  Set protocolVersions
           
private  UnicastSocketTimeout socketTimeout
           
private static Set supportedProtocols
           
private  MulticastTimeToLive timeToLive
           
private  InvocationConstraints unfulfilled
           
static Method unicastDiscoveryMethod
          Method object for the unicastDiscovery method of this class.
 
Constructor Summary
private DiscoveryConstraints(InvocationConstraints constraints)
           
 
Method Summary
 void checkProtocolVersion(int version)
          Checks the protocol version of an incoming multicast request, announcement, or unicast discovery attempt, throwing an UnsupportedConstraintException if handling of the given protocol does not satisfy the constraints of this instance.
 int chooseProtocolVersion()
          Returns the protocol version to use for sending multicast requests or announcements, or initiating unicast discovery.
private static int chooseProtocolVersion(Set protocolVersions, Set protocolVersionPrefs, InvocationConstraints unfulfilled)
           
 boolean equals(Object o)
           
 long getConnectionDeadline(long defaultValue)
          Returns the deadline by which a network connection must be established during unicast discovery, or defaultValue if not constrained.
private static Object getElement(Set s)
           
 int getMulticastMaxPacketSize(int defaultValue)
          Returns the maximum multicast packet size to allow, or the specified default value if not constrained.
 int getMulticastTimeToLive(int defaultValue)
          Returns the multicast time to live value to use, or the specified default value if not constrained.
private static Set getUnfulfilled(Set constraints)
           
 InvocationConstraints getUnfulfilledConstraints()
          Returns the constraints for this instance which are not, or do not contain as alternatives, instances of the "fulfillable" (by this layer) constraint types DiscoveryProtocolVersion, ConnectionRelativeTime, MulticastMaxPacketSize, MulticastTimeToLive, and UnicastSocketTimeout.
 int getUnicastSocketTimeout(int defaultValue)
          Returns socket read timeout to use for unicast discovery, or the specified default value if not constrained.
 int hashCode()
           
private static Set intersect(Set s1, Set s2)
           
static void multicastAnnouncement()
          Empty method which serves as a MethodConstraints key for looking up InvocationConstraints that apply to multicast announcements.
static void multicastRequest()
          Empty method which serves as a MethodConstraints key for looking up InvocationConstraints that apply to multicast requests.
static DiscoveryConstraints process(InvocationConstraints constraints)
          Processes the discovery-related constraints in the given set of constraints, returning a DiscoveryConstraints instance from which the constraint results can be queried.
static void unicastDiscovery()
          Empty method which serves as a MethodConstraints key for looking up InvocationConstraints that apply to unicast discovery.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

multicastRequestMethod

public static final Method multicastRequestMethod
Method object for the multicastRequest method of this class.


multicastAnnouncementMethod

public static final Method multicastAnnouncementMethod
Method object for the multicastAnnouncement method of this class.


unicastDiscoveryMethod

public static final Method unicastDiscoveryMethod
Method object for the unicastDiscovery method of this class.


supportedProtocols

private static final Set supportedProtocols

unfulfilled

private final InvocationConstraints unfulfilled

protocolVersions

private final Set protocolVersions

preferredProtocolVersion

private final int preferredProtocolVersion

connectionAbsoluteTime

private final ConnectionAbsoluteTime connectionAbsoluteTime

maxPacketSize

private final MulticastMaxPacketSize maxPacketSize

timeToLive

private final MulticastTimeToLive timeToLive

socketTimeout

private final UnicastSocketTimeout socketTimeout

hashcode

private final int hashcode
Constructor Detail

DiscoveryConstraints

private DiscoveryConstraints(InvocationConstraints constraints)
                      throws UnsupportedConstraintException
Throws:
UnsupportedConstraintException
Method Detail

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object o)
Overrides:
equals in class Object

multicastRequest

public static void multicastRequest()
Empty method which serves as a MethodConstraints key for looking up InvocationConstraints that apply to multicast requests.


multicastAnnouncement

public static void multicastAnnouncement()
Empty method which serves as a MethodConstraints key for looking up InvocationConstraints that apply to multicast announcements.


unicastDiscovery

public static void unicastDiscovery()
Empty method which serves as a MethodConstraints key for looking up InvocationConstraints that apply to unicast discovery.


process

public static DiscoveryConstraints process(InvocationConstraints constraints)
                                    throws UnsupportedConstraintException
Processes the discovery-related constraints in the given set of constraints, returning a DiscoveryConstraints instance from which the constraint results can be queried. Processing of timeout constraints is time dependent, and subsequent invocations of this method with the same InvocationConstraints may result in DiscoveryConstraint instances with different constraint results.

Parameters:
constraints - the constraints to process
Returns:
an instance representing processed constraints
Throws:
UnsupportedConstraintException - if the discovery-related constraints contain conflicts, or otherwise cannot be processed
NullPointerException - if constraints is null

chooseProtocolVersion

public int chooseProtocolVersion()
Returns the protocol version to use for sending multicast requests or announcements, or initiating unicast discovery.

Returns:
the protocol version to use

checkProtocolVersion

public void checkProtocolVersion(int version)
                          throws UnsupportedConstraintException
Checks the protocol version of an incoming multicast request, announcement, or unicast discovery attempt, throwing an UnsupportedConstraintException if handling of the given protocol does not satisfy the constraints of this instance.

Parameters:
version - protocol version to check
Throws:
UnsupportedConstraintException - if handling of the given protocol does not satisfy the constraints of this instance

getConnectionDeadline

public long getConnectionDeadline(long defaultValue)
Returns the deadline by which a network connection must be established during unicast discovery, or defaultValue if not constrained.

Parameters:
defaultValue - default timeout to return
Returns:
the deadline for the network connection
Since:
2.1

getMulticastMaxPacketSize

public int getMulticastMaxPacketSize(int defaultValue)
Returns the maximum multicast packet size to allow, or the specified default value if not constrained.

Parameters:
defaultValue - the value to return if the multicast packet size is unconstrained
Returns:
the maximum multicast packet size to allow

getMulticastTimeToLive

public int getMulticastTimeToLive(int defaultValue)
Returns the multicast time to live value to use, or the specified default value if not constrained.

Parameters:
defaultValue - the value to return if the multicast time to live value is unconstrained
Returns:
the multicast time to live value to use

getUnicastSocketTimeout

public int getUnicastSocketTimeout(int defaultValue)
Returns socket read timeout to use for unicast discovery, or the specified default value if not constrained.

Parameters:
defaultValue - the value to return if the socket timeout is unconstrained
Returns:
the socket timeout to use

getUnfulfilledConstraints

public InvocationConstraints getUnfulfilledConstraints()
Returns the constraints for this instance which are not, or do not contain as alternatives, instances of the "fulfillable" (by this layer) constraint types DiscoveryProtocolVersion, ConnectionRelativeTime, MulticastMaxPacketSize, MulticastTimeToLive, and UnicastSocketTimeout. Constraint alternatives containing both fulfillable and unfulfillable constraints are treated optimistically--it is assumed that the one of the fulfillable alternatives will be satisfied, so the unfulfillable alternatives are not included in the returned constraints.

Returns:
the unfulfilled constraints for this instance

getUnfulfilled

private static Set getUnfulfilled(Set constraints)

chooseProtocolVersion

private static int chooseProtocolVersion(Set protocolVersions,
                                         Set protocolVersionPrefs,
                                         InvocationConstraints unfulfilled)

intersect

private static Set intersect(Set s1,
                             Set s2)

getElement

private static Object getElement(Set s)


Copyright 2007-2010, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.