com.sun.jini.discovery
Class DiscoveryV2

java.lang.Object
  extended by com.sun.jini.discovery.Discovery
      extended by com.sun.jini.discovery.DiscoveryV2

 class DiscoveryV2
extends Discovery

Class providing methods for implementing discovery protocol version 2.


Nested Class Summary
private static class DiscoveryV2.DatagramBuffers
          Buffer factory passed to multicast request and announcement encoders.
 
Field Summary
private static int FORMAT_ID_LEN
           
private  Map[] formatIdMaps
           
private static WeakIdentityMap instances
           
private static Logger logger
           
private static byte MULTICAST_ANNOUNCEMENT
           
private static int MULTICAST_ANNOUNCEMENT_DECODER
           
private static int MULTICAST_ANNOUNCEMENT_ENCODER
           
private static int MULTICAST_HEADER_LEN
           
private static byte MULTICAST_REQUEST
           
private static int MULTICAST_REQUEST_DECODER
           
private static int MULTICAST_REQUEST_ENCODER
           
private static long NULL_FORMAT_ID
           
private static int NUM_PROVIDER_TYPES
           
private static Class[] providerTypes
           
private static int UNICAST_DISCOVERY_CLIENT
           
private static int UNICAST_DISCOVERY_SERVER
           
private static int UNICAST_REQUEST_HEADER_LEN
           
private static int UNICAST_RESPONSE_HEADER_LEN
           
 
Fields inherited from class com.sun.jini.discovery.Discovery
MIN_MAX_PACKET_SIZE, PROTOCOL_VERSION_1, PROTOCOL_VERSION_2
 
Constructor Summary
private DiscoveryV2(List[] providers)
           
 
Method Summary
private static List asList(Object[] a)
           
private static long computeFormatID(String format)
           
 MulticastAnnouncement decodeMulticastAnnouncement(DatagramPacket packet, InvocationConstraints constraints)
          Decodes the multicast announcement data contained in the given datagram in a manner that satisfies the specified constraints, returning a MulticastAnnouncement instance that contains the decoded data.
 MulticastAnnouncement decodeMulticastAnnouncement(DatagramPacket packet, InvocationConstraints constraints, boolean delayConstraintCheck)
          Decodes the multicast announcement data contained in the given datagram in a manner that satisfies the specified constraints, returning a MulticastAnnouncement instance that contains the decoded data, with constraint checking optionally delayed.
 MulticastRequest decodeMulticastRequest(DatagramPacket packet, InvocationConstraints constraints, ClientSubjectChecker checker)
          Decodes the multicast request data contained in the given datagram in a manner that satisfies the specified constraints and client subject checker (if any), returning a MulticastRequest instance that contains the decoded data.
 MulticastRequest decodeMulticastRequest(DatagramPacket packet, InvocationConstraints constraints, ClientSubjectChecker checker, boolean delayConstraintCheck)
          Decodes the multicast request data contained in the given datagram in a manner that satisfies the specified constraints and client subject checker (if any), returning a MulticastRequest instance that contains the decoded data, with constraint checking optionally delayed.
 UnicastResponse doUnicastDiscovery(Socket socket, InvocationConstraints constraints, ClassLoader defaultLoader, ClassLoader verifierLoader, Collection context)
          Performs the client side of unicast discovery, obtaining the returned response data over the provided socket using the given default and codebase verifier class loaders and collection of object stream context objects in a manner that satisfies the specified constraints.
 EncodeIterator encodeMulticastAnnouncement(MulticastAnnouncement announcement, int maxPacketSize, InvocationConstraints constraints)
          Returns an iterator which can be used to encode the given multicast announcement data into sets of DatagramPackets, each bounded in length by the specified maximum packet size, in a manner that satisfies the given constraints.
 EncodeIterator encodeMulticastRequest(MulticastRequest request, int maxPacketSize, InvocationConstraints constraints)
          Returns an iterator which can be used to encode the given multicast request data into sets of DatagramPackets, each bounded in length by the specified maximum packet size, in a manner that satisfies the given constraints.
private static ClassLoader getContextClassLoader()
           
(package private) static DiscoveryV2 getInstance(ClassLoader loader)
          Returns DiscoveryV2 instance which uses providers loaded from the given class loader, or the current context class loader if the given loader is null.
(package private) static DiscoveryV2 getInstance(MulticastRequestEncoder[] mre, MulticastRequestDecoder[] mrd, MulticastAnnouncementEncoder[] mae, MulticastAnnouncementDecoder[] mad, UnicastDiscoveryClient[] udc, UnicastDiscoveryServer[] uds)
          Returns DiscoveryV2 instance which uses the given providers.
private static List[] getProviders(ClassLoader ldr)
           
 void handleUnicastDiscovery(UnicastResponse response, Socket socket, InvocationConstraints constraints, ClientSubjectChecker checker, Collection context)
          Handles the server side of unicast discovery, transmitting the given response data over the provided socket using the given collection of object stream context objects in a manner that satisfies the specified constraints and client subject checker (if any).
private static Map makeFormatIdMap(List providers)
           
 String toString()
           
 
Methods inherited from class com.sun.jini.discovery.Discovery
getProtocol1, getProtocol2, getProtocol2
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MULTICAST_ANNOUNCEMENT

private static final byte MULTICAST_ANNOUNCEMENT
See Also:
Constant Field Values

MULTICAST_REQUEST

private static final byte MULTICAST_REQUEST
See Also:
Constant Field Values

NULL_FORMAT_ID

private static final long NULL_FORMAT_ID
See Also:
Constant Field Values

FORMAT_ID_LEN

private static final int FORMAT_ID_LEN
See Also:
Constant Field Values

MULTICAST_HEADER_LEN

private static final int MULTICAST_HEADER_LEN
See Also:
Constant Field Values

UNICAST_REQUEST_HEADER_LEN

private static final int UNICAST_REQUEST_HEADER_LEN
See Also:
Constant Field Values

UNICAST_RESPONSE_HEADER_LEN

private static final int UNICAST_RESPONSE_HEADER_LEN
See Also:
Constant Field Values

MULTICAST_REQUEST_ENCODER

private static final int MULTICAST_REQUEST_ENCODER
See Also:
Constant Field Values

MULTICAST_REQUEST_DECODER

private static final int MULTICAST_REQUEST_DECODER
See Also:
Constant Field Values

MULTICAST_ANNOUNCEMENT_ENCODER

private static final int MULTICAST_ANNOUNCEMENT_ENCODER
See Also:
Constant Field Values

MULTICAST_ANNOUNCEMENT_DECODER

private static final int MULTICAST_ANNOUNCEMENT_DECODER
See Also:
Constant Field Values

UNICAST_DISCOVERY_CLIENT

private static final int UNICAST_DISCOVERY_CLIENT
See Also:
Constant Field Values

UNICAST_DISCOVERY_SERVER

private static final int UNICAST_DISCOVERY_SERVER
See Also:
Constant Field Values

NUM_PROVIDER_TYPES

private static final int NUM_PROVIDER_TYPES
See Also:
Constant Field Values

providerTypes

private static final Class[] providerTypes

instances

private static final WeakIdentityMap instances

logger

private static final Logger logger

formatIdMaps

private final Map[] formatIdMaps
Constructor Detail

DiscoveryV2

private DiscoveryV2(List[] providers)
Method Detail

getInstance

static DiscoveryV2 getInstance(ClassLoader loader)
Returns DiscoveryV2 instance which uses providers loaded from the given class loader, or the current context class loader if the given loader is null.


getInstance

static DiscoveryV2 getInstance(MulticastRequestEncoder[] mre,
                               MulticastRequestDecoder[] mrd,
                               MulticastAnnouncementEncoder[] mae,
                               MulticastAnnouncementDecoder[] mad,
                               UnicastDiscoveryClient[] udc,
                               UnicastDiscoveryServer[] uds)
Returns DiscoveryV2 instance which uses the given providers.


encodeMulticastRequest

public EncodeIterator encodeMulticastRequest(MulticastRequest request,
                                             int maxPacketSize,
                                             InvocationConstraints constraints)
Description copied from class: Discovery
Returns an iterator which can be used to encode the given multicast request data into sets of DatagramPackets, each bounded in length by the specified maximum packet size, in a manner that satisfies the given constraints. null constraints are considered equivalent to empty constraints. The destination of each DatagramPacket produced by the returned iterator is set to the address returned by Constants.getRequestAddress(), with the value of Constants.discoveryPort used as the destination port.

Specified by:
encodeMulticastRequest in class Discovery
Parameters:
request - the request data to encode
maxPacketSize - the maximum size of packets to produce
constraints - the constraints to apply when encoding the data, or null
Returns:
an iterator to use for encoding the data

decodeMulticastRequest

public MulticastRequest decodeMulticastRequest(DatagramPacket packet,
                                               InvocationConstraints constraints,
                                               ClientSubjectChecker checker,
                                               boolean delayConstraintCheck)
                                        throws IOException
Description copied from class: Discovery
Decodes the multicast request data contained in the given datagram in a manner that satisfies the specified constraints and client subject checker (if any), returning a MulticastRequest instance that contains the decoded data, with constraint checking optionally delayed. null constraints are considered equivalent to empty constraints.

The delayConstraintCheck flag is used to control delayed constraint checking. Delayed constraint checking is useful for potentially delaying the expense of complete constraint checking, until other checks have been made on the returned MulticastRequest for preliminary validation. Implementations may ignore the flag, in which case, the behavior is equivalent to that of decodeMulticastRequest.

If delayConstraintCheck is true, the method behaves as follows:

If delayConstraintCheck is false, all the specified constraints are checked before this method returns.

Discovery implements this method to simply invoke decodeMulticastRequest, and thus checks all the specified constraints before returning.

Overrides:
decodeMulticastRequest in class Discovery
Parameters:
packet - the packet to decode
constraints - the constraints to apply when decoding the packet, or null
checker - the object to use to check the client subject, or null
delayConstraintCheck - flag to control delayed constraint checking
Returns:
the decoded multicast request data.
Throws:
IOException - if an error occurs in interpreting the data

decodeMulticastRequest

public MulticastRequest decodeMulticastRequest(DatagramPacket packet,
                                               InvocationConstraints constraints,
                                               ClientSubjectChecker checker)
                                        throws IOException
Description copied from class: Discovery
Decodes the multicast request data contained in the given datagram in a manner that satisfies the specified constraints and client subject checker (if any), returning a MulticastRequest instance that contains the decoded data. null constraints are considered equivalent to empty constraints. All the specified constraints are checked before this method returns.

Specified by:
decodeMulticastRequest in class Discovery
Parameters:
packet - the packet to decode
constraints - the constraints to apply when decoding the packet, or null
checker - the object to use to check the client subject, or null
Returns:
the decoded multicast request data
Throws:
IOException - if an error occurs in interpreting the data
UnsupportedConstraintException - if unable to satisfy the specified constraints

encodeMulticastAnnouncement

public EncodeIterator encodeMulticastAnnouncement(MulticastAnnouncement announcement,
                                                  int maxPacketSize,
                                                  InvocationConstraints constraints)
Description copied from class: Discovery
Returns an iterator which can be used to encode the given multicast announcement data into sets of DatagramPackets, each bounded in length by the specified maximum packet size, in a manner that satisfies the given constraints. null constraints are considered equivalent to empty constraints. The destination of each DatagramPacket produced by the returned iterator is set to the address returned by Constants.getAnnouncementAddress(), with the value of Constants.discoveryPort used as the destination port.

Specified by:
encodeMulticastAnnouncement in class Discovery
Parameters:
announcement - the announcement data to encode
maxPacketSize - the maximum size of packets to produce
constraints - the constraints to apply when encoding the data, or null
Returns:
an iterator to use for encoding the data

decodeMulticastAnnouncement

public MulticastAnnouncement decodeMulticastAnnouncement(DatagramPacket packet,
                                                         InvocationConstraints constraints,
                                                         boolean delayConstraintCheck)
                                                  throws IOException
Description copied from class: Discovery
Decodes the multicast announcement data contained in the given datagram in a manner that satisfies the specified constraints, returning a MulticastAnnouncement instance that contains the decoded data, with constraint checking optionally delayed. null constraints are considered equivalent to empty constraints.

The delayConstraintCheck flag is used to control delayed constraint checking. Delayed constraint checking is useful for potentially delaying the expense of complete constraint checking, until other checks have been made on the returned MulticastAnnouncement for preliminary validation. Implementations may ignore the flag, in which case, the behavior is equivalent to that of decodeMulticastAnnouncement.

If delayConstraintCheck is true, the method behaves as follows:

If delayConstraintCheck is false, all the specified constraints are checked before this method returns.

Discovery implements this method to simply invoke decodeMulticastAnnouncement, and thus checks all the specified constraints before returning.

Overrides:
decodeMulticastAnnouncement in class Discovery
Parameters:
packet - the packet to decode
constraints - the constraints to apply when decoding the packet, or null
delayConstraintCheck - flag to control delayed constraint checking
Returns:
the decoded multicast announcement data.
Throws:
IOException - if an error occurs in interpreting the data
UnsupportedConstraintException - if unable to satisfy the specified constraints

decodeMulticastAnnouncement

public MulticastAnnouncement decodeMulticastAnnouncement(DatagramPacket packet,
                                                         InvocationConstraints constraints)
                                                  throws IOException
Description copied from class: Discovery
Decodes the multicast announcement data contained in the given datagram in a manner that satisfies the specified constraints, returning a MulticastAnnouncement instance that contains the decoded data. null constraints are considered equivalent to empty constraints. All the specified constraints are checked before this method returns.

Specified by:
decodeMulticastAnnouncement in class Discovery
Parameters:
packet - the packet to decode
constraints - the constraints to apply when decoding the packet, or null
Returns:
the decoded multicast announcement data
Throws:
IOException - if an error occurs in interpreting the data
UnsupportedConstraintException - if unable to satisfy the specified constraints

doUnicastDiscovery

public UnicastResponse doUnicastDiscovery(Socket socket,
                                          InvocationConstraints constraints,
                                          ClassLoader defaultLoader,
                                          ClassLoader verifierLoader,
                                          Collection context)
                                   throws IOException,
                                          ClassNotFoundException
Description copied from class: Discovery
Performs the client side of unicast discovery, obtaining the returned response data over the provided socket using the given default and codebase verifier class loaders and collection of object stream context objects in a manner that satisfies the specified constraints. null constraints are considered equivalent to empty constraints.

Specified by:
doUnicastDiscovery in class Discovery
Parameters:
socket - the socket on which to perform unicast discovery
constraints - the constraints to apply to unicast discovery, or null
defaultLoader - the class loader value (possibly null) to be passed as the defaultLoader argument to RMIClassLoader methods when unmarshalling the registrar proxy
verifierLoader - the class loader value (possibly null) to pass to Security.verifyCodebaseIntegrity, if codebase integrity verification is used when unmarshalling the registrar proxy
context - the collection of context information objects (possibly null) to use when unmarshalling the registrar proxy
Returns:
the received unicast response data
Throws:
IOException - if an error occurs in interpreting received data or in formatting data to send
UnsupportedConstraintException - if unable to satisfy the specified constraints
ClassNotFoundException - if the class of the discovered registrar cannot be resolved

handleUnicastDiscovery

public void handleUnicastDiscovery(UnicastResponse response,
                                   Socket socket,
                                   InvocationConstraints constraints,
                                   ClientSubjectChecker checker,
                                   Collection context)
                            throws IOException
Description copied from class: Discovery
Handles the server side of unicast discovery, transmitting the given response data over the provided socket using the given collection of object stream context objects in a manner that satisfies the specified constraints and client subject checker (if any). This method assumes that the protocol version number has already been consumed from the socket, but that no further processing of the connection has occurred. null constraints are considered equivalent to empty constraints.

Specified by:
handleUnicastDiscovery in class Discovery
Parameters:
response - the unicast response data to transmit
socket - the socket on which to handle unicast discovery
constraints - the constraints to apply to unicast discovery, or null
checker - the object to use to check the client subject, or null
context - the collection of context information objects to use when marshalling the registrar proxy
Throws:
IOException - if the protocol handshake fails, or if an error occurs in interpreting received data or in formatting data to send
UnsupportedConstraintException - if unable to satisfy the specified constraints

toString

public String toString()
Overrides:
toString in class Object

getContextClassLoader

private static ClassLoader getContextClassLoader()

getProviders

private static List[] getProviders(ClassLoader ldr)

makeFormatIdMap

private static Map makeFormatIdMap(List providers)

computeFormatID

private static long computeFormatID(String format)

asList

private static List asList(Object[] a)


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