Search in sources :

Example 6 with EventChannel

use of gov.sandia.NotifyMonitoringExt.EventChannel in project ACS by ACS-Community.

the class Helper method getNotificationChannel.

/**
	 * This method gets a reference to the event channel. If it is not already
	 * registered with the naming service, it is created.
	 * 
	 * @return Reference to the event channel specified by channelName. Never null.
	 * @param channelKind
	 *           Kind of the channel as registered with the CORBA naming service ("channels").
	 * @param notifyFactoryName
	 *           Name of the notification service as registered with the CORBA
	 *           naming service.
	 * @throws AcsJException
	 *            Standard ACS Java exception.
	 */
protected EventChannel getNotificationChannel(String notifyFactoryName) throws AcsJException {
    String channelKind = NC_KIND.value;
    // return value
    EventChannel retValue = null;
    NameComponent[] t_NameSequence = { new NameComponent(combineChannelAndDomainName(channelName, domainName), channelKind) };
    // (retryNumberAttempts * retrySleepSec) = the time before we give up to get a reference or create the channel if 
    // a channel of the given name supposedly gets created already (due to race conditions with other clients).
    int retryNumberAttempts = 20;
    int retrySleepSec = 2;
    do {
        try {
            // @TODO move the check for existing channel from naming service to the NC factory,
            // now that we use the TAO extension with named NCs.
            // The only advantage of still using the naming service is that the naming service is a real system-wide singleton
            // and can return also channels that were by mistake created from a different notify service factory than the one configured in the CDB.
            initializeNotifyFactory(notifyFactoryName);
            retValue = EventChannelHelper.narrow(getNamingService().resolve(t_NameSequence));
        } catch (org.omg.CosNaming.NamingContextPackage.NotFound e) {
        // No other consumers or suppliers have registered the channel yet...
        // This can mean that the channel has never been created, or that it is currently being created but has not yet been registered.
        } catch (org.omg.CosNaming.NamingContextPackage.CannotProceed e) {
            // Think there is virtually no chance of this every happening but...
            throw new AcsJUnexpectedExceptionEx(e);
        } catch (org.omg.CosNaming.NamingContextPackage.InvalidName e) {
            // Think there is virtually no chance of this every happening but...
            throw new AcsJUnexpectedExceptionEx(e);
        }
        if (retValue == null) {
            // but only because we use the TAO extensions that support named NCs.
            try {
                retValue = createNotificationChannel(channelKind, notifyFactoryName);
            } catch (NameAlreadyUsed ex) {
                m_logger.log(Level.INFO, "NC '" + channelName + "' seems to be getting created. Will wait and try again in " + retrySleepSec + " seconds.", ex);
                try {
                    Thread.sleep(retrySleepSec * 1000);
                } catch (InterruptedException ex1) {
                // too bad
                }
            }
        } else // The channel could be resolved from the Naming Service
        {
            // Get the channel timestamp located into the Naming Service or set it to the current time
            initChannelTimestamp();
        //				System.out.println("*** Got NC " + channelName + " from the naming service");
        }
    } while (retValue == null && --retryNumberAttempts >= 0);
    if (retValue == null) {
        AcsJGenericErrorEx ex = new AcsJGenericErrorEx();
        ex.setErrorDesc("Giving up to get reference to channel " + channelName);
        throw ex;
    }
    return retValue;
}
Also used : AcsJGenericErrorEx(alma.ACSErrTypeCommon.wrappers.AcsJGenericErrorEx) NameComponent(org.omg.CosNaming.NameComponent) EventChannel(gov.sandia.NotifyMonitoringExt.EventChannel) AcsJUnexpectedExceptionEx(alma.ACSErrTypeCommon.wrappers.AcsJUnexpectedExceptionEx) NameAlreadyUsed(gov.sandia.NotifyMonitoringExt.NameAlreadyUsed)

Aggregations

EventChannel (gov.sandia.NotifyMonitoringExt.EventChannel)6 ExecutionException (java.util.concurrent.ExecutionException)3 AcsJCORBAProblemEx (alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx)2 StopWatch (alma.acs.util.StopWatch)2 NameAlreadyUsed (gov.sandia.NotifyMonitoringExt.NameAlreadyUsed)2 ArrayList (java.util.ArrayList)2 Callable (java.util.concurrent.Callable)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ExecutorService (java.util.concurrent.ExecutorService)2 Future (java.util.concurrent.Future)2 AssertionFailedError (junit.framework.AssertionFailedError)2 NameComponent (org.omg.CosNaming.NameComponent)2 AcsJNarrowFailedEx (alma.ACSErrTypeCORBA.wrappers.AcsJNarrowFailedEx)1 AcsJGenericErrorEx (alma.ACSErrTypeCommon.wrappers.AcsJGenericErrorEx)1 AcsJUnexpectedExceptionEx (alma.ACSErrTypeCommon.wrappers.AcsJUnexpectedExceptionEx)1 AcsJException (alma.acs.exceptions.AcsJException)1 NotificationServiceMonitorControlHelper (gov.sandia.CosNotification.NotificationServiceMonitorControlHelper)1 NameMapError (gov.sandia.NotifyMonitoringExt.NameMapError)1 BAD_PARAM (org.omg.CORBA.BAD_PARAM)1 IntHolder (org.omg.CORBA.IntHolder)1