Search in sources :

Example 6 with Unavailable

use of org.omg.CosTransactions.Unavailable in project narayana by jbosstm.

the class ContextClientRequestInterceptorImpl method send_request.

public void send_request(ClientRequestInfo request_info) throws SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ContextClientRequestInterceptorImpl::send_request ( " + request_info + " )");
    }
    if (systemCall(request_info))
        return;
    final boolean otsAlwaysPropagate = InterceptorInfo.getAlwaysPropagate();
    try {
        if (!otsAlwaysPropagate) {
            TransactionalObject ptr = TransactionalObjectHelper.narrow(request_info.target());
            if (ptr == null)
                throw new BAD_PARAM();
        } else {
            /**
             * If the value is not null then we are currently in use *
             */
            if (_inUse.get() != null) {
                return;
            } else {
                _inUse.set(_inUse);
            }
        }
        try {
            /*
		 * We get back an Any, which contains a key which we must
		 * now use to get the actual transaction context. This
		 * saves use having to pack and unpack the context every
		 * time it changes, even if we don't then make a remote
		 * invocation.
		 */
            Any localData = request_info.get_slot(_localSlot);
            String threadId = null;
            boolean problem = false;
            String stringRef = null;
            if (localData.type().kind().value() != TCKind._tk_null) {
                if ((threadId = localData.extract_string()) == null)
                    throw new UNKNOWN(jtsLogger.i18NLogger.get_orbspecific_javaidl_interceptors_context_invalidparam());
            } else
                threadId = ThreadUtil.getThreadId();
            if (threadId != null) {
                ControlWrapper theControl = OTSImpleManager.current().contextManager().current(threadId);
                if (theControl != null) {
                    try {
                        Coordinator theCoordinator = theControl.get_coordinator();
                        if (theCoordinator != null) {
                            stringRef = ORBManager.getORB().orb().object_to_string(theCoordinator);
                        } else {
                            problem = true;
                        }
                    } catch (Unavailable e) {
                        problem = true;
                    }
                    theControl = null;
                } else
                    problem = true;
            } else
                problem = true;
            if (problem) {
                if (InterceptorInfo.getNeedTranContext())
                    throw new TRANSACTION_REQUIRED();
                else
                    stringRef = null;
            }
            if (stringRef != null) {
                Any data = ORBManager.getORB().orb().create_any();
                data.insert_string(stringRef);
                byte[] octets = _codec.encode_value(data);
                ServiceContext service_context = new ServiceContext(OTSManager.serviceId, octets);
                request_info.add_request_service_context(service_context, true);
            }
        } catch (SystemException e) {
            throw e;
        } catch (Exception ex) {
            jtsLogger.i18NLogger.warn_orbspecific_javaidl_interceptors_context_error(ex);
            throw new UNKNOWN(ex.toString());
        } finally {
            /**
             * If we are set to always propagate then ensure we clear the inuse flag *
             */
            if (otsAlwaysPropagate) {
                _inUse.set(null);
            }
        }
    } catch (BAD_PARAM ex) {
    // narrow failed, so not a transactional object.
    }
}
Also used : ServiceContext(org.omg.IOP.ServiceContext) BAD_PARAM(org.omg.CORBA.BAD_PARAM) Coordinator(org.omg.CosTransactions.Coordinator) Any(org.omg.CORBA.Any) SystemException(org.omg.CORBA.SystemException) Unavailable(org.omg.CosTransactions.Unavailable) SystemException(org.omg.CORBA.SystemException) ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper) TransactionalObject(org.omg.CosTransactions.TransactionalObject) UNKNOWN(org.omg.CORBA.UNKNOWN) TRANSACTION_REQUIRED(org.omg.CORBA.TRANSACTION_REQUIRED)

Example 7 with Unavailable

use of org.omg.CosTransactions.Unavailable in project narayana by jbosstm.

the class ContextClientRequestInterceptorImpl method send_request.

public void send_request(ClientRequestInfo request_info) throws SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ContextClientRequestInterceptorImpl::send_request ( " + request_info + " )");
    }
    if (systemCall(request_info))
        return;
    final boolean otsAlwaysPropagate = InterceptorInfo.getAlwaysPropagate();
    try {
        if (!otsAlwaysPropagate) {
            TransactionalObject ptr = TransactionalObjectHelper.narrow(request_info.target());
            if (ptr == null)
                throw new BAD_PARAM();
        } else {
            /**
             * If the value is not null then we are currently in use *
             */
            if (_inUse.get() != null) {
                return;
            } else {
                _inUse.set(_inUse);
            }
        }
        try {
            /*
		 * We get back an Any, which contains a key which we must
		 * now use to get the actual transaction context. This
		 * saves use having to pack and unpack the context every
		 * time it changes, even if we don't then make a remote
		 * invocation.
		 */
            Any localData = request_info.get_slot(_localSlot);
            String threadId = null;
            boolean problem = false;
            String stringRef = null;
            if (localData.type().kind().value() != TCKind._tk_null) {
                if ((threadId = localData.extract_string()) == null)
                    throw new UNKNOWN(jtsLogger.i18NLogger.get_orbspecific_javaidl_interceptors_context_invalidparam());
            } else
                threadId = ThreadUtil.getThreadId();
            if (threadId != null) {
                ControlWrapper theControl = OTSImpleManager.current().contextManager().current(threadId);
                if (theControl != null) {
                    try {
                        Coordinator theCoordinator = theControl.get_coordinator();
                        if (theCoordinator != null) {
                            stringRef = ORBManager.getORB().orb().object_to_string(theCoordinator);
                        } else {
                            problem = true;
                        }
                    } catch (Unavailable e) {
                        problem = true;
                    }
                    theControl = null;
                } else
                    problem = true;
            } else
                problem = true;
            if (problem) {
                if (InterceptorInfo.getNeedTranContext())
                    throw new TRANSACTION_REQUIRED();
                else
                    stringRef = null;
            }
            if (stringRef != null) {
                Any data = ORBManager.getORB().orb().create_any();
                data.insert_string(stringRef);
                byte[] octets = _codec.encode_value(data);
                ServiceContext service_context = new ServiceContext(OTSManager.serviceId, octets);
                request_info.add_request_service_context(service_context, true);
            }
        } catch (SystemException e) {
            throw e;
        } catch (Exception ex) {
            jtsLogger.i18NLogger.warn_orbspecific_javaidl_interceptors_context_error(ex);
            throw new UNKNOWN(ex.toString());
        } finally {
            /**
             * If we are set to always propagate then ensure we clear the inuse flag *
             */
            if (otsAlwaysPropagate) {
                _inUse.set(null);
            }
        }
    } catch (BAD_PARAM ex) {
    // narrow failed, so not a transactional object.
    }
}
Also used : ServiceContext(org.omg.IOP.ServiceContext) BAD_PARAM(org.omg.CORBA.BAD_PARAM) Coordinator(org.omg.CosTransactions.Coordinator) Any(org.omg.CORBA.Any) SystemException(org.omg.CORBA.SystemException) Unavailable(org.omg.CosTransactions.Unavailable) SystemException(org.omg.CORBA.SystemException) ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper) TransactionalObject(org.omg.CosTransactions.TransactionalObject) UNKNOWN(org.omg.CORBA.UNKNOWN) TRANSACTION_REQUIRED(org.omg.CORBA.TRANSACTION_REQUIRED)

Example 8 with Unavailable

use of org.omg.CosTransactions.Unavailable in project narayana by jbosstm.

the class ControlWrapper method register_subtran_aware.

public final void register_subtran_aware(SubtransactionAwareResource sr) throws Inactive, NotSubtransaction, SystemException {
    try {
        if (_controlImpl != null)
            _controlImpl.getImplHandle().register_subtran_aware(sr);
        else {
            try {
                Coordinator coord = _control.get_coordinator();
                coord.register_subtran_aware(sr);
            } catch (Unavailable e2) {
                throw new Inactive();
            } catch (SystemException e3) {
                throw new UNKNOWN();
            } catch (final NullPointerException ex) {
                throw new UNKNOWN();
            }
        }
    } catch (NullPointerException e1) {
        throw new Inactive();
    }
}
Also used : SystemException(org.omg.CORBA.SystemException) Inactive(org.omg.CosTransactions.Inactive) UNKNOWN(org.omg.CORBA.UNKNOWN) UidCoordinator(com.arjuna.ArjunaOTS.UidCoordinator) Coordinator(org.omg.CosTransactions.Coordinator) SynchronizationUnavailable(org.omg.CosTransactions.SynchronizationUnavailable) SubtransactionsUnavailable(org.omg.CosTransactions.SubtransactionsUnavailable) Unavailable(org.omg.CosTransactions.Unavailable)

Example 9 with Unavailable

use of org.omg.CosTransactions.Unavailable in project narayana by jbosstm.

the class ControlWrapper method register_synchronization.

public final void register_synchronization(Synchronization sync) throws Inactive, SynchronizationUnavailable, SystemException {
    try {
        if (_controlImpl != null)
            _controlImpl.getImplHandle().register_synchronization(sync);
        else {
            try {
                Coordinator coord = _control.get_coordinator();
                coord.register_synchronization(sync);
            } catch (final Unavailable e2) {
                throw new Inactive();
            } catch (final Exception e3) {
                throw new UNKNOWN();
            }
        }
    } catch (final NullPointerException e1) {
        throw new Inactive();
    }
}
Also used : Inactive(org.omg.CosTransactions.Inactive) UNKNOWN(org.omg.CORBA.UNKNOWN) UidCoordinator(com.arjuna.ArjunaOTS.UidCoordinator) Coordinator(org.omg.CosTransactions.Coordinator) SystemException(org.omg.CORBA.SystemException) SynchronizationUnavailable(org.omg.CosTransactions.SynchronizationUnavailable) SubtransactionsUnavailable(org.omg.CosTransactions.SubtransactionsUnavailable) Unavailable(org.omg.CosTransactions.Unavailable)

Example 10 with Unavailable

use of org.omg.CosTransactions.Unavailable in project narayana by jbosstm.

the class CurrentImple method commit.

/**
 * It's not possible to commit/abort out of order using the current
 * interface.
 *
 * Do we delete the control if the transaction gives an heuristic result?
 * CurrentImplely we do.
 *
 * If another thread has already terminated the transaction then: (i) if it
 * committed, we do nothing - could throw TransactionRequired of
 * INVALID_TRANSACTION, or NoTransaction. Probably not NoTransaction, since
 * it would be better to distinguish between the situation where the
 * transaction has already been terminated and there really is no
 * transaction for this thread. (ii) if it rolledback, we throw
 * TRANSACTION_ROLLEDBACK.
 */
public void commit(boolean report_heuristics) throws NoTransaction, HeuristicMixed, HeuristicHazard, SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("CurrentImple::commit ( " + report_heuristics + " )");
    }
    ControlWrapper currentAction = _theManager.current();
    if (currentAction != null) {
        try {
            ThreadAssociationControl.updateAssociation(currentAction, TX_COMMITTED);
        } catch (Exception e) {
            /*
				 * An error happened, so mark the transaction as rollback only
				 * (in case it hasn't already been so marked.)
				 */
            rollback_only();
        }
        try {
            currentAction.commit(report_heuristics);
            _theManager.popAction();
        } catch (TRANSACTION_ROLLEDBACK e1) {
            /*
				 * Is ok to destroy transaction. Different for heuristics.
				 */
            _theManager.popAction();
            throw e1;
        } catch (HeuristicMixed e2) {
            _theManager.popAction();
            if (report_heuristics)
                throw e2;
        } catch (HeuristicHazard e3) {
            _theManager.popAction();
            if (report_heuristics)
                throw e3;
        } catch (SystemException e4) {
            _theManager.popAction();
            throw e4;
        } catch (Unavailable e5) {
            /*
				 * If terminated by some other thread then the reference we have
				 * will no longer be valid.
				 */
            _theManager.popAction();
            throw new INVALID_TRANSACTION();
        }
    } else
        throw new NoTransaction();
}
Also used : NoTransaction(org.omg.CosTransactions.NoTransaction) SystemException(org.omg.CORBA.SystemException) ControlWrapper(com.arjuna.ats.internal.jts.ControlWrapper) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) HeuristicMixed(org.omg.CosTransactions.HeuristicMixed) SystemException(org.omg.CORBA.SystemException) UserException(org.omg.CORBA.UserException) HeuristicHazard(org.omg.CosTransactions.HeuristicHazard) SubtransactionsUnavailable(org.omg.CosTransactions.SubtransactionsUnavailable) Unavailable(org.omg.CosTransactions.Unavailable)

Aggregations

Unavailable (org.omg.CosTransactions.Unavailable)15 SystemException (org.omg.CORBA.SystemException)14 UNKNOWN (org.omg.CORBA.UNKNOWN)11 Coordinator (org.omg.CosTransactions.Coordinator)11 ControlWrapper (com.arjuna.ats.internal.jts.ControlWrapper)10 BAD_PARAM (org.omg.CORBA.BAD_PARAM)8 SubtransactionsUnavailable (org.omg.CosTransactions.SubtransactionsUnavailable)8 Any (org.omg.CORBA.Any)6 TRANSACTION_REQUIRED (org.omg.CORBA.TRANSACTION_REQUIRED)6 TransactionalObject (org.omg.CosTransactions.TransactionalObject)6 ServiceContext (org.omg.IOP.ServiceContext)6 Inactive (org.omg.CosTransactions.Inactive)5 UidCoordinator (com.arjuna.ArjunaOTS.UidCoordinator)4 INVALID_TRANSACTION (org.omg.CORBA.INVALID_TRANSACTION)4 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)4 SynchronizationUnavailable (org.omg.CosTransactions.SynchronizationUnavailable)4 NoTransaction (org.omg.CosTransactions.NoTransaction)3 PropagationContext (org.omg.CosTransactions.PropagationContext)3 OTSAbstractRecord (com.arjuna.ArjunaOTS.OTSAbstractRecord)2 AbstractRecord (com.arjuna.ats.arjuna.coordinator.AbstractRecord)2