/*
 * 
 * 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.
 * 
 */
package net.jini.core.transaction;

import net.jini.core.transaction.server.NestableTransactionManager;
import net.jini.core.lease.Lease;
import net.jini.core.lease.LeaseDeniedException;
import java.rmi.RemoteException;

/**
 * Interface for classes representing nestable transactions returned by
 * <code>NestableTransactionManager</code> servers for use with transaction
 * participants that implement the default transaction semantics.
 *
 * @author Sun Microsystems, Inc.
 *
 * @see Transaction
 * @see net.jini.core.transaction.server.NestableTransactionManager
 * @see TransactionFactory
 *
 * @since 1.0
 */
public interface NestableTransaction extends Transaction {

    /** Class that holds return values from create methods. */
    public static class Created implements java.io.Serializable {
	static final long serialVersionUID = -2979247545926318953L;

	/**
	 * The transaction.
	 * @serial
	 */
        public final NestableTransaction transaction;
	/**
	 * The lease.
	 * @serial
	 */
        public final Lease lease;

	/**
	 * Simple constructor.
	 *
	 * @param transaction the transaction created
	 * @param lease the lease granted
	 */
	public Created(NestableTransaction transaction, Lease lease) {
	    this.transaction = transaction;
	    this.lease = lease;
        }
    }

    /**
     * Create a new nested transaction, with the current transaction as
     * parent, managed by the given transaction manager.
     *
     * @param mgr the transaction manager to use for this transaction
     * @param leaseTime the requested lease time for the transaction
     * @return the created transaction and the lease granted
     * 
     * @throws UnknownTransactionException if the parent transaction 
     *         is unknown to the parent transaction manager, either 
     *         because the transaction ID is incorrect or because the 
     *         transaction is no longer active and its state has been 
     *         discarded by the manager.
     * @throws CannotJoinException if the parent transaction is known 
     *         to the manager but is no longer active.
     * @throws LeaseDeniedException if this manager is unwilling to 
     *         grant the requested lease time
     * @throws RemoteException if there is a communication error
     */
    Created create(NestableTransactionManager mgr, long leaseTime)
        throws UnknownTransactionException, CannotJoinException,
	       LeaseDeniedException, RemoteException;

    /**
     * Create a new nested transaction, with the current transaction as
     * parent, managed by the same transaction manager as the current
     * transaction.
     *
     * @param leaseTime the requested lease time for the transaction
     * @return the created transaction and the lease granted
     * 
     * @throws UnknownTransactionException if the parent transaction 
     *         is unknown to the parent transaction manager, either 
     *         because the transaction ID is incorrect or because the 
     *         transaction is no longer active and its state has been 
     *         discarded by the manager.
     * @throws CannotJoinException if the parent transaction is known 
     *         to the manager but is no longer active.
     * @throws LeaseDeniedException if this manager is unwilling to 
     *         grant the requested lease time
     * @throws RemoteException if there is a communication error

     */
    Created create(long leaseTime)
        throws UnknownTransactionException, CannotJoinException,
	       LeaseDeniedException, RemoteException;
}
