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;
}
Aggregations