Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.jacorb.transaction;
  
  /*
   *        JacORB transaction service - a free TS for JacORB
   *
   *   Copyright (C) 1999-2004 LogicLand group Alex Sinishin.
   *
   *   This library is free software; you can redistribute it and/or
   *   modify it under the terms of the GNU Library General Public
  *   License as published by the Free Software Foundation; either
  *   version 2 of the License, or (at your option) any later version.
  *
  *   This library is distributed in the hope that it will be useful,
  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  *   Library General Public License for more details.
  *
  *   You should have received a copy of the GNU Library General Public
  *   License along with this library; if not, write to the Free
  *   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
Instances of this class represent transactions. A single instance is used for implementing the Coordinator, Terminator and Control CORBA objects.

Author(s):
Nicolas Noffke
Vladimir Mencl
 
 
 public class CoordinatorImpl 
     implements SleeperCoordinatorOperations
                ControlOperationsTerminatorOperations 
 {
     private Terminator        term_ref;
     private TerminatorPOATie  term_skel;
     private Coordinator       coord_ref;
     private CoordinatorPOATie coord_skel;
     private Control           contr_ref;
     private ControlPOATie     contr_skel;
 
     private int               transaction_id;
     private int               hash_code;
 
     private int               status;
     private String            stat_semaphore;
 
     private Vector            resources;
     private Vector            votes;
     private Vector            syncs;
 
     private org.omg.PortableServer.POA poa;
 
     CoordinatorImpl(org.omg.PortableServer.POA _poaint _trans_id,
                     int _hash_codeint time)
     {
          = _trans_id;
               = _hash_code;
          = _poa;
          = new String("sss");
               = new Vector();
                   = new Vector();
                   = new Vector();
         try {
              = new CoordinatorPOATie(this);
               = CoordinatorHelper.narrow(.servant_to_reference());
              = new TerminatorPOATie(this);
               = TerminatorHelper.narrow(.servant_to_reference());
             = new ControlPOATie(this);
              = ControlHelper.narrow(.servant_to_reference());
        } catch (org.omg.PortableServer.POAPackage.ServantNotActive esn){
            throw new org.omg.CORBA.INTERNAL();
        } catch (org.omg.PortableServer.POAPackage.WrongPolicy ew){
            throw new org.omg.CORBA.INTERNAL();
        }
         = .;
        if (time != 0){
            TransactionService.get_timer().add_channel(thistime);
        }
    }
    private void destroy(){
        try {
            byte[] oid = .reference_to_id();
            .deactivate_object(oid);
            ._release();
            oid = .reference_to_id();
            .deactivate_object(oid);
            ._release();
            oid = .reference_to_id();
            .deactivate_object(oid);
            ._release();
        } catch (org.omg.PortableServer.POAPackage.ObjectNotActive esn){
            throw new org.omg.CORBA.INTERNAL();
        } catch (org.omg.PortableServer.POAPackage.WrongPolicy ew){
            throw new org.omg.CORBA.INTERNAL();
        } catch (org.omg.PortableServer.POAPackage.WrongAdapter ew){
            throw new org.omg.CORBA.INTERNAL();
        }
        TransactionService.release_coordinator();
    }
    private boolean move_to_state(int new_status){
        synchronized(){
            switch(){
            case .:
                switch(new_status){
                case .:
                case .:
                case .:
                     = new_status;
                    return true;
                default:
                    return false;
                }
            case .:
                switch(new_status){
                case .:
                     = new_status;
                    return true;
                default:
                    return false;
                }
            case .:
                switch(new_status){
                case .:
                     = new_status;
                    return true;
                default:
                    return false;
                }
            case .:
                switch(new_status){
                case .:
                     = new_status;
                    return true;
                default:
                    return false;
                }
            case .:
                switch(new_status){
                case .:
                     = new_status;
                    return true;
                default:
                    return false;
                }
            case .:
                throw new org.omg.CORBA.INTERNAL();
            case .:
                throw new org.omg.CORBA.INTERNAL();
            case .:
                switch(new_status){
                case .:
                case .:
                     = new_status;
                    return true;
                default:
                    return false;
                }
            case .:
                switch(new_status){
                case .:
                     = new_status;
                    return true;
                default:
                    return false;
                }
            case .:
                switch(new_status){
                case .:
                     = new_status;
                    return true;
                default:
                    return false;
                }
            default:
                throw new org.omg.CORBA.INTERNAL();
            }
        }
    }
    public void wakeup(){
        TransactionService.get_timer().kill_channel(this);
            rolling_to_back();
        }
    }
    int _get_transaction_id(){
        return ;
    }
        return ;
    }
    public Status get_status(){
        return Status.from_int();
    }
    public Status get_parent_status(){
        throw new org.omg.CORBA.NO_IMPLEMENT();
    }
    public Status get_top_level_status(){
        return Status.from_int();
    }
    public boolean is_same_transaction(Coordinator tc){
        return ( == tc.hash_transaction());
    }
    public boolean is_related_transaction(Coordinator tc){
        throw new org.omg.CORBA.NO_IMPLEMENT();
    }
    public boolean is_ancestor_transaction(Coordinator tc){
        throw new org.omg.CORBA.NO_IMPLEMENT();
    }
    public boolean is_descendant_transaction(Coordinator tc){
        throw new org.omg.CORBA.NO_IMPLEMENT();
    }
    public boolean is_top_level_transaction(){
        return true;
    }
    public int hash_transaction(){
        return ;
    }
    public int hash_top_level_tran(){
        throw new org.omg.CORBA.NO_IMPLEMENT();
    }
        synchronized(){
            if ( == .){
                throw new org.omg.CORBA.TRANSACTION_ROLLEDBACK();
            }
            if ( != .){
                throw new Inactive();
            }
            .addElement(r);
            .addElement(null);
        }
        return null;
    }
    public void register_synchronization(Synchronization sync)
        throws InactiveSynchronizationUnavailable{
        synchronized(){
            if ( == .){
                throw new org.omg.CORBA.TRANSACTION_ROLLEDBACK();
            }
            if ( != .){
                throw new Inactive();
            }
            .addElement(sync);
        }
    }
        throws InactiveNotSubtransaction{
        throw new org.omg.CORBA.NO_IMPLEMENT();
    }
    public void rollback_only() throws Inactive{
            throw new Inactive();
        }
    }
    public String get_transaction_name(){
        return "Transaction_" + ;
    }
        throws SubtransactionsUnavailableInactive{
        throw new org.omg.CORBA.NO_IMPLEMENT();
    }
    public PropagationContext get_txcontext() throws Unavailable{
        throw new org.omg.CORBA.NO_IMPLEMENT();
    }
    public Terminator get_terminator() throws Unavailable{
        if ( == .){
            throw new Unavailable();
        }
        return ;
    }
    public Coordinator get_coordinator() throws Unavailable{
        if ( == .){
            throw new Unavailable();
        }
        return ;
    }
    private void forget(){
        .removeAllElements();
        .removeAllElements();
        .removeAllElements();
    }
    public void commit(boolean report_heuristicsthrows HeuristicMixed,
        HeuristicHazard{
        if (!move_to_state(.)){
            if (move_to_state(.)){
                TransactionService.get_timer().kill_channel(this);
                rolling_to_back();
                throw new org.omg.CORBA.TRANSACTION_ROLLEDBACK();
            }
            throw new org.omg.CORBA.INTERNAL();
        }
        TransactionService.get_timer().kill_channel(this);
        for (int i = 0;i < .size();i++){
            Synchronization sync = (Synchronization).elementAt(i);
            sync.before_completion();
        }
        if (.size() == 1){
            Resource r = (Resource).elementAt(0);
            try {
                r.commit_one_phase();
	    } catch(org.omg.CORBA.TRANSACTION_ROLLEDBACK tr) {
              // the only one resource requested a rollback
	      rollback();
	      throw new org.omg.CORBA.TRANSACTION_ROLLEDBACK();
            } catch(HeuristicHazard hh) {
                throw new org.omg.CORBA.NO_IMPLEMENT();
            }
            if (!move_to_state(.)){
                throw new org.omg.CORBA.INTERNAL();
            }
            if (!move_to_state(.)){
                throw new org.omg.CORBA.INTERNAL();
            }
        } else {
            for (int i = 0;i < .size();i++){
                Resource r = (Resource).elementAt(i);
                try {
                    Vote v = r.prepare();
                    .setElementAt(vi);
                    if (v.value() == .){
                        rollback();
                        throw new org.omg.CORBA.TRANSACTION_ROLLEDBACK();
                    }
                } catch(HeuristicHazard hh) {
                    throw new org.omg.CORBA.NO_IMPLEMENT();
                } catch(HeuristicMixed hm) {
                    throw new org.omg.CORBA.NO_IMPLEMENT();
                }
            }
            if (!move_to_state(.)){
                throw new org.omg.CORBA.INTERNAL();
            }
            if (!move_to_state(.)){
                throw new org.omg.CORBA.INTERNAL();
            }
            for (int i = 0;i < .size();i++){
                Resource r = (Resource).elementAt(i);
                Vote     v = (Vote).elementAt(i);
                
                try {
                    if (v == null){
                        throw new org.omg.CORBA.INTERNAL();
                    } else {
                        if (v.value() == .){
                            r.commit();
                        }
                    }
                } catch(NotPrepared np) {
                    throw new org.omg.CORBA.NO_IMPLEMENT();
                } catch(HeuristicRollback hr) {
                    throw new org.omg.CORBA.NO_IMPLEMENT();
                } catch(HeuristicHazard hh) {
                    throw new org.omg.CORBA.NO_IMPLEMENT();
                } catch(HeuristicMixed hm) {
                    throw new org.omg.CORBA.NO_IMPLEMENT();
                }
            }
        }
        if (!move_to_state(.)){
            throw new org.omg.CORBA.INTERNAL();
        }
        forget();
            throw new org.omg.CORBA.INTERNAL();
        }
        destroy();
    }
    private void rolling_to_back(){
        for (int i = 0;i < .size();i++){
            Resource r = (Resource).elementAt(i);
            Vote     v = (Vote).elementAt(i);
            try {
                if (v == null){
                    r.rollback();
                } else {
                    if (v.value() == .){
                        r.rollback();
                    }
                }
            } catch(HeuristicCommit hc) {
                throw new org.omg.CORBA.NO_IMPLEMENT();
            } catch(HeuristicMixed hm) {
                throw new org.omg.CORBA.NO_IMPLEMENT();
            } catch(HeuristicHazard hh) {
                throw new org.omg.CORBA.NO_IMPLEMENT();
            }
        }
        if (!move_to_state(.)){
            throw new org.omg.CORBA.INTERNAL();
        }
        forget();
            throw new org.omg.CORBA.INTERNAL();
        }
        destroy();
    }
    public void rollback(){
        if (!move_to_state(.)){
            throw new org.omg.CORBA.TRANSACTION_REQUIRED();
        }
        TransactionService.get_timer().kill_channel(this);
        rolling_to_back();
    }
New to GrepCode? Check out our FAQ X