/*
 * 
 * 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 net.jini.io.context;

/**
 * A server context element for registering interest in receiving an
 * acknowledgment that the remote call's result data has been
 * delivered to and processed by the client.
 *
 * @author Sun Microsystems, Inc.
 * @see net.jini.export.ServerContext#getServerContextElement
 * @since 2.0
 **/
public interface AcknowledgmentSource {

    /**
     * Registers the specified listener as interested in receiving an
     * acknowledgment that the remote call's result data has been
     * processed by the client.  Multiple listeners may be registered
     * with this object.
     *
     * <p>The implementation of this interface may refuse a
     * registration, such as if the remote call's result data has
     * already been written.  This method returns <code>true</code> if
     * the listener was successfully registered, and
     * <code>false</code> if the registration was refused.
     *
     * @param listener the listener to register
     *
     * @return <code>true</code> if the listener was successfully
     * registered, and <code>false</code> if the registration was
     * refused
     *
     * @throws NullPointerException if <code>listener</code> is
     * <code>null</code>
     **/
    boolean addAcknowledgmentListener(Listener listener);

    /**
     * A callback object for registering with an {@link
     * AcknowledgmentSource} server context element to handle the
     * receipt of an acknowledgment that the remote call's result data
     * has been processed by the client.
     **/
    interface Listener {

	/**
	 * Handles either receipt of an acknowledgment that the remote
	 * call's result data has been processed by the client or an
	 * indication that no acknowledgment will be received.
	 *
	 * <p>If <code>received</code> is <code>true</code>, then a
	 * positive acknowledgment has been received that the remote
	 * call's result data has been processed by the client.
	 *
	 * If <code>received</code> is <code>false</code>, then the
	 * implementation of this interface has determined that no
	 * positive acknowledgment for the associated data will be
	 * received (perhaps due, for example, to connection failure
	 * or timeout).
	 *
	 * @param received <code>true</code> if an acknowledgment was
	 * received, and <code>false</code> if no acknowledgment will
	 * be received
	 **/
	void acknowledgmentReceived(boolean received);
    }
}
