use of gov.sandia.NotifyMonitoringExt.ConsumerAdmin in project ACS by ACS-Community.
the class NCSubscriber method getSharedAdmin.
////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////// Helper methods ////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
/**
* Creates or reuses a shared server-side NC consumer admin object.
*
* @throws AcsJException
*/
private ConsumerAdmin getSharedAdmin() throws AcsJCORBAProblemEx, AcsJNarrowFailedEx {
ConsumerAdmin ret = null;
org.omg.CosNotifyChannelAdmin.ConsumerAdmin retBase = null;
boolean created = false;
int consumerAdminId = -1;
AdminReuseCompatibilityHack adminReuseCompatibilityHack = new AdminReuseCompatibilityHack(channelName, logger);
// while in real life we can have concurrent admin creation requests from different processes.
synchronized (NCSubscriber.class) {
// Check if we can reuse an already existing consumer admin
for (int adminId : channel.get_all_consumeradmins()) {
try {
org.omg.CosNotifyChannelAdmin.ConsumerAdmin tmpAdmin = channel.get_consumeradmin(adminId);
if (adminReuseCompatibilityHack.isSharedAdmin(tmpAdmin)) {
// (the -1 goes because of the dummy proxy that is attached to the shared admin)
if (tmpAdmin.push_suppliers().length - 1 < PROXIES_PER_ADMIN) {
retBase = tmpAdmin;
consumerAdminId = adminId;
break;
}
}
} catch (AdminNotFound e) {
logger.log(AcsLogLevel.NOTICE, "Consumer admin with ID='" + adminId + "' not found for channel '" + channelName + "', " + "will continue anyway to search for shared consumer admins", e);
}
}
// If no suitable consumer admin was found, we create a new one
if (retBase == null) {
// create a new consumer admin
IntHolder consumerAdminIDHolder = new IntHolder();
// We use filters only on proxy objects, not on admin objects.
// An admin object without filters will opt to pass all events.
// We need a logical AND to be used when comparing the event passing decisions
// made by the set of proxy supplier filters and by the admin object.
InterFilterGroupOperator adminProxyFilterLogic = InterFilterGroupOperator.AND_OP;
retBase = channel.new_for_consumers(adminProxyFilterLogic, consumerAdminIDHolder);
consumerAdminId = consumerAdminIDHolder.value;
created = true;
}
}
try {
// cast to TAO extension type
ret = ConsumerAdminHelper.narrow(retBase);
} catch (BAD_PARAM ex) {
if (created) {
retBase.destroy();
}
LOG_NC_TaoExtensionsSubtypeMissing.log(logger, "ConsumerAdmin for channel " + channelName, ConsumerAdminHelper.id(), org.omg.CosNotifyChannelAdmin.ConsumerAdminHelper.id());
AcsJNarrowFailedEx ex2 = new AcsJNarrowFailedEx(ex);
ex2.setNarrowType(ConsumerAdminHelper.id());
throw ex2;
}
if (created) {
// @TODO: Remove this workaround once it is no longer needed.
adminReuseCompatibilityHack.markAsSharedAdmin(ret);
}
LOG_NC_ConsumerAdminObtained_OK.log(logger, consumerAdminId, (created ? "created" : "reused"), clientName, channelName, getNotificationFactoryName());
return ret;
}
Aggregations