Search in sources :

Example 1 with AcsJStateMachineActionEx

use of alma.ACSErrTypeCommon.wrappers.AcsJStateMachineActionEx in project ACS by ACS-Community.

the class NCSubscriber method createEnvironmentAction.

////////////////////////////////////////////////////////////////////////////////////////
/////////////////////// State machine actions //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
protected void createEnvironmentAction(EventDispatcher evtDispatcher, ErrorReporter errRep, SCInstance scInstance, Collection<TriggerEvent> derivedEvents) throws AcsJStateMachineActionEx {
    super.createEnvironmentAction(evtDispatcher, errRep, scInstance, derivedEvents);
    try {
        // get the channel
        channel = helper.getNotificationChannel(getNotificationFactoryName());
        // get the admin object
        // Note that admin creation and proxy supplier creation are not synchronized across subscribers,
        // which means that concurrent creation of subscribers can lead to race conditions
        // where we end up with too many (> PROXIES_PER_ADMIN) subscribers
        // for the same admin object.
        // It would be easy to put a static lock around these two calls, which would take care of 
        // concurrent subscribers from the same component or client. Still there would be the same 
        // racing issues coming from distributed subscribers.
        // We prefer to not even do local synchronization because then even in simple unit tests
        // from a single process we can verify the concurrency behavior of subscribers and notifyService.
        // TODO: Revisit the "synchronized(NCSubscriber.class)" block we currently have inside getSharedAdmin(),
        // which is giving partial local synchronization, leading to fewer race conditions.
        // Probably should be removed, or pulled up here and extended around createProxySupplier.
        sharedConsumerAdmin = getSharedAdmin();
        // get the proxy Supplier
        proxySupplier = createProxySupplier();
        // Just check if our shared consumer admin is handling more proxies than it should, and log it
        // (11) goes for the dummy proxy that we're using the transition between old and new NC classes
        int currentProxies = sharedConsumerAdmin.push_suppliers().length - 1;
        if (currentProxies > PROXIES_PER_ADMIN) {
            LOG_NC_ConsumerAdmin_Overloaded.log(logger, sharedConsumerAdmin.MyID(), currentProxies, PROXIES_PER_ADMIN, channelName, channelNotifyServiceDomainName == null ? "none" : channelNotifyServiceDomainName);
        }
        // The user might create this object, and later call startReceivingEvents(), without attaching any receiver.
        // If so, it's useless to get all the events, so we start with an all-exclusive filter in the server
        discardAllEvents();
    //		} catch (OBJECT_NOT_EXIST ex) {
    //			TODO handle dangling NC binding in the naming service (after notify service restart)
    } catch (Throwable thr) {
        throw new AcsJStateMachineActionEx(thr);
    }
}
Also used : AcsJStateMachineActionEx(alma.ACSErrTypeCommon.wrappers.AcsJStateMachineActionEx)

Example 2 with AcsJStateMachineActionEx

use of alma.ACSErrTypeCommon.wrappers.AcsJStateMachineActionEx in project ACS by ACS-Community.

the class NCSubscriber method suspendAction.

protected void suspendAction(EventDispatcher evtDispatcher, ErrorReporter errRep, SCInstance scInstance, Collection<TriggerEvent> derivedEvents) throws AcsJStateMachineActionEx {
    super.suspendAction(evtDispatcher, errRep, scInstance, derivedEvents);
    // Stop the thread responsible for checking the connection and wait until the thread ended 
    stopConCheckerThread();
    try {
        // See OMG NC spec 3.4.13.2. Server will continue to queue events.
        proxySupplier.suspend_connection();
    } catch (org.omg.CosNotifyChannelAdmin.ConnectionAlreadyInactive ex) {
        throw new AcsJStateMachineActionEx(ex);
    } catch (org.omg.CosNotifyChannelAdmin.NotConnected ex) {
        throw new AcsJStateMachineActionEx(ex);
    } catch (org.omg.CORBA.OBJECT_NOT_EXIST ex) {
        throw new AcsJStateMachineActionEx("Remote resources already destroyed.", ex);
    }
}
Also used : AcsJStateMachineActionEx(alma.ACSErrTypeCommon.wrappers.AcsJStateMachineActionEx)

Example 3 with AcsJStateMachineActionEx

use of alma.ACSErrTypeCommon.wrappers.AcsJStateMachineActionEx in project ACS by ACS-Community.

the class NCSubscriber method resumeAction.

protected void resumeAction(EventDispatcher evtDispatcher, ErrorReporter errRep, SCInstance scInstance, Collection<TriggerEvent> derivedEvents) throws AcsJStateMachineActionEx {
    try {
        proxySupplier.resume_connection();
        // Create the thread responsible for checking the connection
        createConCheckerThread();
    } catch (org.omg.CosNotifyChannelAdmin.ConnectionAlreadyActive ex) {
        throw new AcsJStateMachineActionEx(ex);
    } catch (org.omg.CosNotifyChannelAdmin.NotConnected ex) {
        throw new AcsJStateMachineActionEx(ex);
    } catch (Throwable ex) {
        if (autoreconnect) {
            int nRetries = 0;
            boolean connected = false;
            while (!connected && nRetries < MAX_RECONNECT_ATTEMPTS) {
                try {
                    reconnect();
                    connected = true;
                } catch (Throwable exr) {
                    try {
                        // Wait 1 second
                        Thread.sleep(1000);
                    } catch (InterruptedException exi) {
                    }
                }
                ++nRetries;
            }
            if (connected) {
                createConCheckerThread();
            } else {
                logger.log(AcsLogLevel.ERROR, "Consumer couldn't reconnect after " + String.valueOf(nRetries) + " attempts to the channel " + channelName);
                throw new AcsJStateMachineActionEx(ex);
            }
        } else {
            throw new AcsJStateMachineActionEx(ex);
        }
    }
    super.resumeAction(evtDispatcher, errRep, scInstance, derivedEvents);
}
Also used : AcsJStateMachineActionEx(alma.ACSErrTypeCommon.wrappers.AcsJStateMachineActionEx)

Example 4 with AcsJStateMachineActionEx

use of alma.ACSErrTypeCommon.wrappers.AcsJStateMachineActionEx in project ACS by ACS-Community.

the class NCSubscriber method createConnectionAction.

protected void createConnectionAction(EventDispatcher evtDispatcher, ErrorReporter errRep, SCInstance scInstance, Collection<TriggerEvent> derivedEvents) throws AcsJStateMachineActionEx {
    super.createConnectionAction(evtDispatcher, errRep, scInstance, derivedEvents);
    try {
        // Register callback for subscribed events
        if (corbaRef == null) {
            corbaObj = new OSPushConsumerPOATie(NCSubscriber.this);
            corbaRef = OSPushConsumerHelper.narrow(helper.getContainerServices().activateOffShoot(corbaObj));
        }
        // Register callback for reconnection requests
        channelReconnectionCallback = new AcsNcReconnectionCallback(NCSubscriber.this, logger);
        // if the factory is null, the reconnection callback is not registered
        channelReconnectionCallback.registerForReconnect(services, helper.getNotifyFactory());
        proxySupplier.connect_structured_push_consumer(org.omg.CosNotifyComm.StructuredPushConsumerHelper.narrow(corbaRef));
    } catch (AcsJContainerServicesEx e) {
        LOG_NC_SubscriptionConnect_FAIL.log(logger, channelName, getNotificationFactoryName());
        throw new AcsJStateMachineActionEx(e);
    } catch (org.omg.CosEventChannelAdmin.AlreadyConnected e) {
        throw new AcsJStateMachineActionEx(new AcsJIllegalStateEventEx(e));
    } catch (org.omg.CosEventChannelAdmin.TypeError ex) {
        LOG_NC_SubscriptionConnect_FAIL.log(logger, channelName, getNotificationFactoryName());
        throw new AcsJStateMachineActionEx(ex);
    } catch (AcsJIllegalArgumentEx ex) {
        throw new AcsJStateMachineActionEx(ex);
    }
    // Create the thread responsible for checking the connection and reconnect
    createConCheckerThread();
    LOG_NC_SubscriptionConnect_OK.log(logger, channelName, getNotificationFactoryName());
}
Also used : AcsJIllegalStateEventEx(alma.ACSErrTypeCommon.wrappers.AcsJIllegalStateEventEx) OSPushConsumerPOATie(alma.acsnc.OSPushConsumerPOATie) AcsJIllegalArgumentEx(alma.ACSErrTypeCommon.wrappers.AcsJIllegalArgumentEx) AcsJStateMachineActionEx(alma.ACSErrTypeCommon.wrappers.AcsJStateMachineActionEx) AcsJContainerServicesEx(alma.JavaContainerError.wrappers.AcsJContainerServicesEx)

Aggregations

AcsJStateMachineActionEx (alma.ACSErrTypeCommon.wrappers.AcsJStateMachineActionEx)4 AcsJIllegalArgumentEx (alma.ACSErrTypeCommon.wrappers.AcsJIllegalArgumentEx)1 AcsJIllegalStateEventEx (alma.ACSErrTypeCommon.wrappers.AcsJIllegalStateEventEx)1 AcsJContainerServicesEx (alma.JavaContainerError.wrappers.AcsJContainerServicesEx)1 OSPushConsumerPOATie (alma.acsnc.OSPushConsumerPOATie)1