Search in sources :

Example 1 with Current

use of org.omg.PortableInterceptor.Current in project Payara by payara.

the class ORBInitializerImpl method post_init.

public void post_init(ORBInitInfo info) {
    // get hold of the codec instance to pass onto interceptors.
    CodecFactory codecFactory = info.codec_factory();
    Encoding enc = new Encoding(ENCODING_CDR_ENCAPS.value, (byte) 1, (byte) 2);
    Codec codec = null;
    try {
        codec = codecFactory.create_codec(enc);
    } catch (UnknownEncoding e) {
        throw new INTERNAL(MinorCode.TSCreateFailed, CompletionStatus.COMPLETED_NO);
    }
    // get hold of PICurrent to allocate a slot for JTS service.
    Current pic = null;
    try {
        pic = (Current) info.resolve_initial_references("PICurrent");
    } catch (InvalidName e) {
        throw new INTERNAL(MinorCode.TSCreateFailed, CompletionStatus.COMPLETED_NO);
    }
    // allocate a PICurrent slotId for the transaction service.
    int[] slotIds = new int[2];
    try {
        slotIds[0] = info.allocate_slot_id();
        slotIds[1] = info.allocate_slot_id();
    } catch (BAD_INV_ORDER e) {
        throw new INTERNAL(MinorCode.TSCreateFailed, CompletionStatus.COMPLETED_NO);
    }
    // get hold of the TSIdentification instance to pass onto interceptors.
    TSIdentification tsi = null;
    try {
        tsi = (TSIdentification) info.resolve_initial_references("TSIdentification");
    } catch (InvalidName e) {
    // the TransactionService is unavailable.
    }
    try {
        info.register_policy_factory(OTS_POLICY_TYPE.value, new OTSPolicyFactory());
    } catch (BAD_INV_ORDER e) {
    // ignore, policy factory already exists.
    }
    try {
        info.register_policy_factory(INVOCATION_POLICY_TYPE.value, new InvocationPolicyFactory());
    } catch (BAD_INV_ORDER e) {
    // ignore, policy factory already exists.
    }
    try {
        info.add_ior_interceptor(new IORInterceptorImpl(codec));
        InterceptorImpl interceptor = new InterceptorImpl(pic, codec, slotIds, tsi);
        info.add_client_request_interceptor(interceptor);
        info.add_server_request_interceptor(interceptor);
    } catch (DuplicateName e) {
        throw new INTERNAL(MinorCode.TSCreateFailed, CompletionStatus.COMPLETED_NO);
    }
}
Also used : DuplicateName(org.omg.PortableInterceptor.ORBInitInfoPackage.DuplicateName) UnknownEncoding(org.omg.IOP.CodecFactoryPackage.UnknownEncoding) UnknownEncoding(org.omg.IOP.CodecFactoryPackage.UnknownEncoding) InvalidName(org.omg.PortableInterceptor.ORBInitInfoPackage.InvalidName) Current(org.omg.PortableInterceptor.Current)

Example 2 with Current

use of org.omg.PortableInterceptor.Current in project Payara by payara.

the class TransactionIIOPInterceptorFactory method createInterceptor.

private void createInterceptor(ORBInitInfo info, Codec codec) {
    if (processEnv.getProcessType().isServer()) {
        try {
            System.setProperty(InterceptorImpl.CLIENT_POLICY_CHECKING, String.valueOf(false));
        } catch (Exception ex) {
            _logger.log(Level.WARNING, "iiop.readproperty_exception", ex);
        }
        initJTSProperties(true);
    } else {
        initJTSProperties(false);
    }
    try {
        // register JTS interceptors
        // first get hold of PICurrent to allocate a slot for JTS service.
        Current pic = (Current) info.resolve_initial_references("PICurrent");
        // allocate a PICurrent slotId for the transaction service.
        int[] slotIds = new int[2];
        slotIds[0] = info.allocate_slot_id();
        slotIds[1] = info.allocate_slot_id();
        interceptor = new InterceptorImpl(pic, codec, slotIds, null);
        // Get the ORB instance on which this interceptor is being
        // initialized
        com.sun.corba.ee.spi.orb.ORB theORB = ((ORBInitInfoExt) info).getORB();
        // Set ORB and TSIdentification: needed for app clients,
        // standalone clients.
        interceptor.setOrb(theORB);
        try {
            DefaultTransactionService jts = new DefaultTransactionService();
            jts.identify_ORB(theORB, tsIdent, jtsProperties);
            interceptor.setTSIdentification(tsIdent);
            // V2-XXX should jts.get_current() be called everytime
            // resolve_initial_references is called ??
            org.omg.CosTransactions.Current transactionCurrent = jts.get_current();
            theORB.getLocalResolver().register(ORBConstants.TRANSACTION_CURRENT_NAME, NullaryFunction.Factory.makeConstant((org.omg.CORBA.Object) transactionCurrent));
            // the JTS PI use this to call the proprietary hooks
            theORB.getLocalResolver().register("TSIdentification", NullaryFunction.Factory.makeConstant((org.omg.CORBA.Object) tsIdent));
            txServiceInitialized = true;
        } catch (Exception ex) {
            throw new INITIALIZE("JTS Exception: " + ex, POASystemException.JTS_INIT_ERROR, CompletionStatus.COMPLETED_MAYBE);
        }
        // Add IOR Interceptor only for OTS tagged components
        TxIORInterceptor iorInterceptor = new TxIORInterceptor(codec, serviceLocator);
        info.add_ior_interceptor(iorInterceptor);
    } catch (Exception e) {
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "Exception registering JTS interceptors", e);
        }
        throw new RuntimeException(e.getMessage());
    }
}
Also used : ORBInitInfoExt(com.sun.corba.ee.spi.legacy.interceptor.ORBInitInfoExt) POASystemException(com.sun.corba.ee.spi.logging.POASystemException) DefaultTransactionService(com.sun.jts.CosTransactions.DefaultTransactionService) Current(org.omg.PortableInterceptor.Current) InterceptorImpl(com.sun.jts.pi.InterceptorImpl)

Aggregations

Current (org.omg.PortableInterceptor.Current)2 ORBInitInfoExt (com.sun.corba.ee.spi.legacy.interceptor.ORBInitInfoExt)1 POASystemException (com.sun.corba.ee.spi.logging.POASystemException)1 DefaultTransactionService (com.sun.jts.CosTransactions.DefaultTransactionService)1 InterceptorImpl (com.sun.jts.pi.InterceptorImpl)1 UnknownEncoding (org.omg.IOP.CodecFactoryPackage.UnknownEncoding)1 DuplicateName (org.omg.PortableInterceptor.ORBInitInfoPackage.DuplicateName)1 InvalidName (org.omg.PortableInterceptor.ORBInitInfoPackage.InvalidName)1