Search in sources :

Example 31 with NameComponent

use of org.omg.CosNaming.NameComponent in project ACS by ACS-Community.

the class EventModel method resolveMonitorControl.

/**
	 * Resolves the TAO monitor-control object that is bound in the naming service with the given name.
	 */
private NotificationServiceMonitorControl resolveMonitorControl(String notifyBindingName) throws CannotProceed, org.omg.CosNaming.NamingContextPackage.InvalidName, NotFound {
    String name = "MC_" + notifyBindingName;
    NameComponent[] ncomp = new NameComponent[1];
    ncomp[0] = new NameComponent(name, "");
    NotificationServiceMonitorControl nsmc = NotificationServiceMonitorControlHelper.narrow(nctx.resolve(ncomp));
    return nsmc;
}
Also used : NameComponent(org.omg.CosNaming.NameComponent) NotificationServiceMonitorControl(gov.sandia.CosNotification.NotificationServiceMonitorControl)

Example 32 with NameComponent

use of org.omg.CosNaming.NameComponent in project ACS by ACS-Community.

the class EventModel method resolveNotificationChannel.

/**
	 * Resolves a notification channel in the naming service.
	 * 
	 * @return Reference to the event channel specified by channelName.
	 * @param bindingName
	 *           Name of the event channel and trailing domain name, as the NC is registered with the CORBA Naming Service
	 * @throws AcsJException
	 *            Standard ACS Java exception.
	 */
protected EventChannel resolveNotificationChannel(String bindingName) throws AcsJException {
    EventChannel retValue = null;
    String nameServiceKind = alma.acscommon.NC_KIND.value;
    //m_logger.info("Will call 'nctx.resolve' for binding='" + bindingName + "', kind='" + nameServiceKind + "'.");
    try {
        NameComponent[] t_NameSequence = { new NameComponent(bindingName, nameServiceKind) };
        retValue = EventChannelHelper.narrow(nctx.resolve(t_NameSequence));
    } catch (OBJECT_NOT_EXIST ex) {
        m_logger.severe("The NC '" + bindingName + "' no longer exists, probably because its notify service was restarted. The naming service still lists this NC.");
        throw new AcsJUnexpectedExceptionEx(ex);
    } catch (org.omg.CosNaming.NamingContextPackage.NotFound e) {
        // No other suppliers have created the channel yet
        m_logger.info("The '" + bindingName + "' channel has not been created yet.");
        throw new AcsJUnexpectedExceptionEx(e);
    } 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);
    }
    return retValue;
}
Also used : EventChannel(org.omg.CosNotifyChannelAdmin.EventChannel) NameComponent(org.omg.CosNaming.NameComponent) OBJECT_NOT_EXIST(org.omg.CORBA.OBJECT_NOT_EXIST) NotFound(org.omg.CosNaming.NamingContextPackage.NotFound) AcsJUnexpectedExceptionEx(alma.ACSErrTypeCommon.wrappers.AcsJUnexpectedExceptionEx) CannotProceed(org.omg.CosNaming.NamingContextPackage.CannotProceed)

Example 33 with NameComponent

use of org.omg.CosNaming.NameComponent 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)

Example 34 with NameComponent

use of org.omg.CosNaming.NameComponent in project ACS by ACS-Community.

the class ACSRemoteAccess method resolveNotifyChannel.

private boolean resolveNotifyChannel(String channelName, NamingContext namingContext) {
    // Cannot use jcontnc Helper for this, due to module order...
    String channelWithDomain = channelName + NAMESERVICE_BINDING_NC_DOMAIN_SEPARATOR.value + ACS_NC_DOMAIN_LOGGING.value;
    listenersDispatcher.publishReport("Resolving channel \"" + channelWithDomain + "\" from Notify Service...");
    try {
        NameComponent[] nc = new NameComponent[1];
        nc[0] = new NameComponent(channelWithDomain, alma.acscommon.NC_KIND.value);
        org.omg.CORBA.Object obj = namingContext.resolve(nc);
        eventChannel = EventChannelHelper.narrow(obj);
    } catch (Exception e) {
        listenersDispatcher.publishReport("Exception occurred when obtaining channel \"" + channelWithDomain + "\" from the Notify Service.");
        System.out.println("ACSRemoteAccess::Exception in resolveNotifyChannel(): " + e);
        return false;
    }
    listenersDispatcher.publishReport("Channel \"" + channelWithDomain + "\" resolved.");
    return true;
}
Also used : NameComponent(org.omg.CosNaming.NameComponent)

Aggregations

NameComponent (org.omg.CosNaming.NameComponent)34 NamingContext (org.omg.CosNaming.NamingContext)12 NotFound (org.omg.CosNaming.NamingContextPackage.NotFound)10 InvalidName (org.omg.CosNaming.NamingContextPackage.InvalidName)9 CannotProceed (org.omg.CosNaming.NamingContextPackage.CannotProceed)8 AcsJCORBAProblemEx (alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx)3 NamingException (javax.naming.NamingException)3 AcsJUnexpectedExceptionEx (alma.ACSErrTypeCommon.wrappers.AcsJUnexpectedExceptionEx)2 EventChannel (gov.sandia.NotifyMonitoringExt.EventChannel)2 FileWriter (java.io.FileWriter)2 PrintWriter (java.io.PrintWriter)2 Properties (java.util.Properties)2 CannotProceedException (javax.naming.CannotProceedException)2 Name (javax.naming.Name)2 NameNotFoundException (javax.naming.NameNotFoundException)2 ORB (org.omg.CORBA.ORB)2 Object (org.omg.CORBA.Object)2 AlreadyBound (org.omg.CosNaming.NamingContextPackage.AlreadyBound)2 POA (org.omg.PortableServer.POA)2 AcsJNarrowFailedEx (alma.ACSErrTypeCORBA.wrappers.AcsJNarrowFailedEx)1