Search in sources :

Example 31 with Coordinator

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

the class ServerStrictTopLevelAction method interposeResource.

public boolean interposeResource() {
    if (!_registered) {
        _registered = true;
        if ((_theResource != null) && (_theControl != null)) {
            Coordinator realCoordinator = _theControl.originalCoordinator();
            if (!(_valid = registerResource(realCoordinator))) {
            // jtsLogger.i18NLogger.warn_orbspecific_interposition_resources_strict_iptlfailed("ServerStrictNestedAction");
            /*
                * Failed to register. Valid is set, and the interposition
                * controller will now deal with this.
                */
            }
            realCoordinator = null;
        } else
            _valid = false;
    }
    return _valid;
}
Also used : Coordinator(org.omg.CosTransactions.Coordinator)

Example 32 with Coordinator

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

the class ServerStrictNestedAction method interposeResource.

public boolean interposeResource() {
    if (!_registered) {
        _registered = true;
        if ((_theResource != null) && (_theControl != null)) {
            Coordinator realCoordinator = _theControl.originalCoordinator();
            if (!(_valid = registerSubTran(realCoordinator))) {
                jtsLogger.i18NLogger.warn_orbspecific_interposition_resources_strict_ipfailed("ServerStrictNestedAction");
            /*
                     * Failed to register. Valid is set, and the interposition
                     * controller will now deal with this.
                     */
            }
            realCoordinator = null;
        } else
            _valid = false;
    }
    return _valid;
}
Also used : Coordinator(org.omg.CosTransactions.Coordinator)

Example 33 with Coordinator

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

the class OTSManager method destroyControl.

/**
 * Used to destroy a transaction control. Normally garbage collection
 * will take care of this, but in certain circumstances (e.g., a context
 * is propagated implicitly but we do not use interposition and we
 * have to manufacture a local control object) it is not possible for the
 * OTS to know when controls can be removed. This is a problem with the
 * specification and CORBA in general.
 */
public static void destroyControl(ControlImple control) throws ActiveTransaction, ActiveThreads, BadControl, Destroyed, SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("OTS::destroyControl ( " + control + " )");
    }
    if (control == null)
        throw new BadControl();
    /*
	 * Just in case control is a top-level transaction, and has
	 * been registered with the reaper, we need to get it removed.
	 *
	 */
    Coordinator coord = null;
    try {
        coord = control.get_coordinator();
    } catch (Exception e) {
        // nothing else we can do!
        coord = null;
    }
    if (coord != null) {
        try {
            if (coord.is_top_level_transaction()) {
                if (jtsLogger.logger.isTraceEnabled()) {
                    jtsLogger.logger.trace("OTS::destroyControl - removing control from reaper.");
                }
                // wrap the control so it gets compared against reaper list entries using the correct test
                PseudoControlWrapper wrapper = new PseudoControlWrapper(control);
                TransactionReaper.transactionReaper().remove(wrapper);
            }
        } catch (Exception e) {
        }
        coord = null;
    }
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("OTS::destroyControl - local transaction: " + control.get_uid());
    }
    control.destroy();
    control = null;
}
Also used : BadControl(com.arjuna.ArjunaOTS.BadControl) PseudoControlWrapper(com.arjuna.ats.internal.jts.PseudoControlWrapper) Coordinator(org.omg.CosTransactions.Coordinator) SystemException(org.omg.CORBA.SystemException)

Example 34 with Coordinator

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

the class InterpositionClientRequestInterceptorImpl method send_request.

public void send_request(ClientRequestInfo request_info) throws SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        trace_request("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;
            Any data = null;
            if (localData.type().kind().value() != TCKind._tk_null) {
                if ((threadId = localData.extract_string()) == null)
                    throw new UNKNOWN(jtsLogger.i18NLogger.get_orbspecific_javaidl_interceptors_interposition_invalidparam());
            } else
                threadId = ThreadUtil.getThreadId();
            if (threadId != null) {
                ControlWrapper theControl = OTSImpleManager.current().contextManager().current(threadId);
                if (theControl != null) {
                    try {
                        Coordinator theCoordinator = theControl.get_coordinator();
                        PropagationContext ctx = null;
                        if (theCoordinator != null) {
                            final Coordinator finalTheCoordinator = theCoordinator;
                            try {
                                ctx = doPrivileged(new PrivilegedExceptionAction<PropagationContext>() {

                                    @Override
                                    public PropagationContext run() throws Unavailable {
                                        return finalTheCoordinator.get_txcontext();
                                    }
                                });
                            } catch (PrivilegedActionException pex) {
                                throw pex.getException();
                            }
                            data = packPropagationContext(ctx);
                            theCoordinator = null;
                        } else
                            throw new Unavailable();
                    } catch (Unavailable ex) {
                        /*
			     * We may have to make calls during
			     * commit (e.g., after_completion)
			     * which are valid, but which will get
			     * Unavailable.
			     */
                        problem = true;
                    }
                } else
                    problem = true;
            } else
                problem = true;
            if (problem) {
                if (InterceptorInfo.getNeedTranContext())
                    throw new TRANSACTION_REQUIRED();
            }
            if (data != null) {
                byte[] octets;
                try {
                    final Any finalData = data;
                    octets = doPrivileged(new PrivilegedExceptionAction<byte[]>() {

                        @Override
                        public byte[] run() throws org.omg.CORBA.UserException {
                            return _codec.encode_value(finalData);
                        }
                    });
                } catch (PrivilegedActionException pex) {
                    throw pex.getException();
                }
                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) {
            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 : PropagationContext(org.omg.CosTransactions.PropagationContext) PrivilegedActionException(java.security.PrivilegedActionException) ServiceContext(org.omg.IOP.ServiceContext) BAD_PARAM(org.omg.CORBA.BAD_PARAM) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) Coordinator(org.omg.CosTransactions.Coordinator) Any(org.omg.CORBA.Any) SystemException(org.omg.CORBA.SystemException) PrivilegedActionException(java.security.PrivilegedActionException) 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 35 with Coordinator

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

the class InterpositionClientRequestInterceptorImpl method send_request.

public void send_request(ClientRequestInfo request_info) throws SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        trace_request("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;
            Any data = null;
            if (localData.type().kind().value() != TCKind._tk_null) {
                if ((threadId = localData.extract_string()) == null)
                    throw new UNKNOWN(jtsLogger.i18NLogger.get_orbspecific_javaidl_interceptors_interposition_invalidparam());
            } else
                threadId = ThreadUtil.getThreadId();
            if (threadId != null) {
                ControlWrapper theControl = OTSImpleManager.current().contextManager().current(threadId);
                if (theControl != null) {
                    try {
                        Coordinator theCoordinator = theControl.get_coordinator();
                        PropagationContext ctx = null;
                        if (theCoordinator != null) {
                            ctx = theCoordinator.get_txcontext();
                            data = packPropagationContext(ctx);
                            theCoordinator = null;
                        } else
                            throw new Unavailable();
                    } catch (Unavailable ex) {
                        /*
			     * We may have to make calls during
			     * commit (e.g., after_completion)
			     * which are valid, but which will get
			     * Unavailable.
			     */
                        problem = true;
                    }
                } else
                    problem = true;
            } else
                problem = true;
            if (problem) {
                if (InterceptorInfo.getNeedTranContext())
                    throw new TRANSACTION_REQUIRED();
            }
            if (data != null) {
                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) {
            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 : PropagationContext(org.omg.CosTransactions.PropagationContext) 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)

Aggregations

Coordinator (org.omg.CosTransactions.Coordinator)47 SystemException (org.omg.CORBA.SystemException)32 UNKNOWN (org.omg.CORBA.UNKNOWN)15 Control (org.omg.CosTransactions.Control)14 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)13 BAD_PARAM (org.omg.CORBA.BAD_PARAM)12 Unavailable (org.omg.CosTransactions.Unavailable)11 ControlWrapper (com.arjuna.ats.internal.jts.ControlWrapper)10 Terminator (org.omg.CosTransactions.Terminator)10 ServerControl (com.arjuna.ats.internal.jts.orbspecific.interposition.ServerControl)9 UidCoordinator (com.arjuna.ArjunaOTS.UidCoordinator)6 Uid (com.arjuna.ats.arjuna.common.Uid)6 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)6 ORB (com.arjuna.orbportability.ORB)6 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 AbstractRecord (com.arjuna.ats.arjuna.coordinator.AbstractRecord)5 PropagationContext (org.omg.CosTransactions.PropagationContext)5