/*
 * JBoss, Home of Professional Open Source
 * Copyright 2006, JBoss Inc., and individual contributors as indicated
 * by the @authors tag.  All rights reserved. 
 * See the copyright.txt in the distribution for a full listing 
 * of individual contributors.
 * This copyrighted material is made available to anyone wishing to use,
 * modify, copy, or redistribute it subject to the terms and conditions
 * of the GNU General Public License, v. 2.0.
 * This program is distributed in the hope that it will be useful, but WITHOUT A 
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
 * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License,
 * v. 2.0 along with this distribution; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
 * MA  02110-1301, USA.
 * 
 * (C) 2005-2006,
 * @author JBoss Inc.
 */
/*
 * Copyright (C) 1999-2001 by HP Bluestone Software, Inc. All rights Reserved.
 *
 * HP Arjuna Labs,
 * Newcastle upon Tyne,
 * Tyne and Wear,
 * UK.
 *
 * $Id: ArjunaOTS.idl 2342 2006-03-30 13:06:17Z  $
 */

#ifndef ARJUNAOTS_IDL_
#define ARJUNAOTS_IDL_

#ifndef NO_PRAGMA_SUPPORT
#pragma prefix "arjuna.com"
#endif

#include <CosTransactions.idl>

#ifdef HAVE_JAVAPACKAGE
#pragma javaPackage "com.arjuna"
#endif

module ArjunaOTS
{
    enum TransactionType { TransactionTypeActive, TransactionTypeTerminated, TransactionTypeUnresolved };

    struct GlobalTransactionInfo
    {
	long  totalNumberOfTransactions;
	long  numberOfCommittedTransactions;
	long  numberOfAbortedTransactions;
	float averageLifetime;
	long  numberOfHeuristics;
	long  reaperTimeout;
	long  defaultTimeout;
    };

    struct TransactionInfo
    {
	long currentDepth;
	long timeout;
	long numberOfThreads;
    };
    
    typedef sequence<CosTransactions::otid_t> txIds;

    // Some useful exceptions

    exception ActiveTransaction {};
    exception BadControl {};
    exception Destroyed {};
    exception ActiveThreads {};
    exception InterpositionFailed {};

    exception NoContext {};

    interface UidCoordinator : CosTransactions::Coordinator
    {
	readonly attribute string uid;
	readonly attribute string topLevelUid;
    };

    interface ActionControl : CosTransactions::Control
    {
        CosTransactions::Control getParentControl () raises(CosTransactions::Unavailable);

        void destroy () raises (ActiveTransaction, ActiveThreads, BadControl, Destroyed);
    };

    interface ArjunaSubtranAwareResource : CosTransactions::SubtransactionAwareResource
    {
	CosTransactions::Vote prepare_subtransaction ();
    };

    /*
     * At the moment these management methods occur on the ArjunaFactory.
     * However, we could have a separate interface which the factory gives
     * out an implementation to, and that is then used.
     */

    interface ArjunaFactory : CosTransactions::TransactionFactory
    {
	txIds numberOfTransactions (in ArjunaOTS::TransactionType t) raises(CosTransactions::Inactive, CosTransactions::NoTransaction);

	txIds getChildTransactions (in CosTransactions::otid_t parent) raises(CosTransactions::Inactive, CosTransactions::NoTransaction);

	CosTransactions::Status getCurrentStatus (in CosTransactions::otid_t uid) raises(CosTransactions::NoTransaction);
	CosTransactions::Status getStatus (in CosTransactions::otid_t uid) raises(CosTransactions::NoTransaction);

	GlobalTransactionInfo getGlobalInfo ();
	TransactionInfo getTransactionInfo (in CosTransactions::otid_t uid) raises(CosTransactions::NoTransaction);

	CosTransactions::Control getTransaction (in CosTransactions::otid_t uid) raises(CosTransactions::NoTransaction);
    };

    interface ArjunaTransaction : UidCoordinator, CosTransactions::Terminator
    {
    };

    interface Current : CosTransactions::Current
    {
	long get_timeout ();
    };

    interface OTSAbstractRecord : ArjunaSubtranAwareResource
    {
	readonly attribute long type_id;
	readonly attribute string uid;

	boolean propagateOnAbort ();
	boolean propagateOnCommit ();

	boolean saveRecord ();
    
	void merge (in OTSAbstractRecord record);
	void alter (in OTSAbstractRecord record);

	boolean shouldAdd (in OTSAbstractRecord record);
	boolean shouldAlter (in OTSAbstractRecord record);
	boolean shouldMerge (in OTSAbstractRecord record);
	boolean shouldReplace (in OTSAbstractRecord record);
    };
};

#endif

