/*
 * 
 * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
 * 
 * The contents of this file are subject to the Sun Community Source
 * License v3.0/Jini Technology Specific Attachment v 1.0 (the
 * "License"). You may not use this file except in compliance with the
 * License. You may obtain a copy of the License at
 * http://wwws.sun.com/software/jini/licensing/SCSL3_JiniTSA1.html.
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 * the License for the specific language governing rights and limitations
 * under the License.
 * 
 * The Reference Code is Jini Technology Core Platform code, v2.0. The
 * Developer of the Reference Code is Sun Microsystems, Inc.
 * 
 * Contributor(s): Sun Microsystems, Inc.
 * 
 * The contents of this file comply with the Jini Technology Core
 * Platform Compatibility Kit, v2.0A.
 * 
 * Tester(s): Sun Microsystems, Inc.
 * 
 * Test Platform(s):
 * Java 2 SDK, Standard Edition, Version 1.4.2_03 for Solaris(TM)SPARC/x86
 * Java 2 SDK, Standard Edition, Version 1.4.2_03 for Linux (Intel x86)
 * Java 2 SDK, Standard Edition, Version 1.4.2_03 for Windows (Intel Platform)
 * 
 */

package com.sun.jini.discovery;

import java.io.IOException;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.util.Collection;
import net.jini.core.constraint.InvocationConstraints;
import net.jini.io.UnsupportedConstraintException;

/**
 * Interface implemented by classes which perform the client (discovering) side
 * of unicast discovery.
 *
 * @author Sun Microsystems, Inc.
 * @since 2.0
 */
public interface UnicastDiscoveryClient extends DiscoveryFormatProvider {

    /**
     * Checks and returns normally if this client is capable of fulfilling the
     * given absolute constraints.  <code>null</code> constraints are
     * considered equivalent to empty constraints.
     *
     * @param constraints the constraints to check, or <code>null</code>
     * @throws UnsupportedConstraintException if unable to satisfy the
     * specified constraints
     * @throws SecurityException if the given constraints cannot be satisfied
     * due to insufficient caller permissions
     */
    void checkUnicastDiscoveryConstraints(InvocationConstraints constraints)
	throws UnsupportedConstraintException;

    /**
     * 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 absolute constraints.
     * Byte buffers containing the data sent and received so far over the given
     * socket (for the unicast discovery protocol 2 handshake) are provided for
     * use by formats which integrity protect or otherwise incorporate the
     * handshake data.  <code>null</code> constraints are considered equivalent
     * to empty constraints.
     *
     * @param socket the socket on which to perform unicast discovery
     * @param constraints the constraints to apply to unicast discovery, or
     * <code>null</code>
     * @param defaultLoader the class loader value (possibly <code>null</code>)
     * to be passed as the <code>defaultLoader</code> argument to
     * <code>RMIClassLoader</code> methods when unmarshalling the registrar
     * proxy
     * @param verifierLoader the class loader value (possibly
     * <code>null</code>) to pass to {@link
     * net.jini.security.Security#verifyCodebaseIntegrity
     * Security.verifyCodebaseIntegrity}, if codebase integrity verification is
     * used when unmarshalling the registrar proxy
     * @param context the collection of context information objects (possibly
     * <code>null</code>) to use when unmarshalling the registrar proxy
     * @param sent a buffer containing the data already sent
     * @param received a buffer containing the data already received
     * @return the received unicast response data
     * @throws IOException if an error occurs in interpreting received data or
     * in formatting data to send
     * @throws UnsupportedConstraintException if unable to satisfy the
     * specified constraints
     * @throws SecurityException if the given constraints cannot be satisfied
     * due to insufficient caller permissions
     * @throws ClassNotFoundException if the class of the discovered registrar
     * cannot be resolved
     * @throws NullPointerException if <code>socket</code>, <code>sent</code>,
     * or <code>received</code> is <code>null</code>
     */
    UnicastResponse doUnicastDiscovery(Socket socket,
				       InvocationConstraints constraints,
				       ClassLoader defaultLoader,
				       ClassLoader verifierLoader,
				       Collection context,
				       ByteBuffer sent,
				       ByteBuffer received)
	throws IOException, ClassNotFoundException;
}
