use of alma.JavaContainerError.wrappers.AcsJContainerServicesEx in project ACS by ACS-Community.
the class NCPublisher method init.
/**
* Initializes NCPublisher
* @param namingService Naming service
* @throws AcsJException
* There are literally dozens of CORBA exceptions that could be
* thrown by the NCPublisher class. Instead, these are
* converted into an ACS Error System exception for the
* developer's convenience.
*/
protected synchronized void init(NamingContext namingService) throws AcsJException {
helper = new Helper(channelName, channelNotifyServiceDomainName, this.services, namingService);
isTraceEventsEnabled = helper.getChannelProperties().isTraceEventsEnabled(this.channelName);
// get the channel
// @TODO: handle Corba TIMEOUT
channel = helper.getNotificationChannel(getNotificationFactoryName());
// Corba NC spec about adminId: a unique identifier assigned by the target EventChannel instance that is unique among all
// SupplierAdmin instances currently associated with the channel.
// We are currently not using it, but it could be logged to help with NC debugging.
IntHolder adminIdHolder = new IntHolder();
org.omg.CosNotifyChannelAdmin.SupplierAdmin supplierAdminBase = null;
try {
supplierAdminBase = channel.new_for_suppliers(InterFilterGroupOperator.AND_OP, adminIdHolder);
} catch (TIMEOUT ex) {
// found in http://jira.alma.cl/browse/COMP-6312
throw new AcsJCORBAProblemEx(ex);
}
if (supplierAdminBase == null) {
AcsJCORBAReferenceNilEx ex = new AcsJCORBAReferenceNilEx();
ex.setVariable("supplierAdminBase");
ex.setContext("Null reference obtained for the supplier admin for channel " + this.channelName);
throw ex;
}
try {
supplierAdmin = gov.sandia.NotifyMonitoringExt.SupplierAdminHelper.narrow(supplierAdminBase);
} catch (BAD_PARAM ex) {
// This should never happen, since we already enforced the presence of TAO extensions in Helper#initializeNotifyFactory
String specialSupplierAdminId = gov.sandia.NotifyMonitoringExt.SupplierAdminHelper.id();
String standardSupplierAdminId = org.omg.CosNotifyChannelAdmin.SupplierAdminHelper.id();
LOG_NC_TaoExtensionsSubtypeMissing.log(logger, channelName + "-SupplierAdmin", specialSupplierAdminId, standardSupplierAdminId);
AcsJNarrowFailedEx ex2 = new AcsJNarrowFailedEx(ex);
ex2.setNarrowType(specialSupplierAdminId);
throw ex2;
}
int proxyCreationAttempts = 0;
while (proxyConsumer == null) {
String randomizedClientName = Helper.createRandomizedClientName(services.getName());
// Holder for the unique ID assigned by the admin object. It is different from the name we set, and will be discarded.
IntHolder proxyIdHolder = new IntHolder();
proxyCreationAttempts++;
try {
// Create the consumer proxy (to which the published events will be fed) with a name.
// The client type parameter selects a StructuredProxyPushConsumer (based on Structured Events),
// as opposed to ProxyPushConsumer (based on Anys), or SequenceProxyPushConsumer (based on sequences of Structured Events).
org.omg.CORBA.Object tempCorbaObj = supplierAdmin.obtain_named_notification_push_consumer(ClientType.STRUCTURED_EVENT, proxyIdHolder, randomizedClientName.toString());
if (tempCorbaObj == null) {
AcsJCORBAReferenceNilEx ex = new AcsJCORBAReferenceNilEx();
ex.setVariable("tempCorbaObj");
ex.setContext("Null reference obtained for the Proxy Push Consumer for publisher " + services.getName());
// @TODO destroy supplierAdmin
throw ex;
}
proxyConsumer = StructuredProxyPushConsumerHelper.narrow(tempCorbaObj);
LOG_NC_ConsumerProxyCreation_OK.log(logger, proxyIdHolder.value, randomizedClientName, proxyCreationAttempts, services.getName(), channelName, getNotificationFactoryName());
} catch (NameAlreadyUsed e) {
// Hopefully we won't run into this situation. Still, try to go on in the loop,
// with a different client name next time.
logger.fine("Consumer proxy name '" + randomizedClientName + "' already in use. Will try again with different random number appended.");
} catch (NameMapError ex) {
// Default to the unnamed version
try {
proxyConsumer = StructuredProxyPushConsumerHelper.narrow(supplierAdmin.obtain_notification_push_consumer(ClientType.STRUCTURED_EVENT, proxyIdHolder));
LOG_NC_ConsumerProxyCreation_OK.log(logger, proxyIdHolder.value, "-unknown-", proxyCreationAttempts, services.getName(), channelName, getNotificationFactoryName());
} catch (AdminLimitExceeded ex2) {
LOG_NC_ConsumerProxyCreation_FAIL.log(logger, services.getName(), channelName, getNotificationFactoryName(), ex2.getMessage());
// @TODO destroy supplierAdmin
throw new AcsJCORBAProblemEx(ex2);
}
} catch (AdminLimitExceeded e) {
LOG_NC_ConsumerProxyCreation_FAIL.log(logger, services.getName(), channelName, getNotificationFactoryName(), e.getMessage());
// @TODO destroy supplierAdmin
throw new AcsJCORBAProblemEx(e);
}
}
// Avoid future calls from the NC to #subscription_change(EventType[], EventType[]). See Corba spec 3.4.1.3
// @TODO: If we use ALL_NOW_UPDATES_ON then we could actually suppress sending of event types that no consumer wants to get.
proxyConsumer.obtain_subscription_types(ObtainInfoMode.NONE_NOW_UPDATES_OFF);
// see 3.4.4.1 of Notification Service, v1.1
try {
StructuredPushSupplier thisSps = StructuredPushSupplierHelper.narrow(this.services.activateOffShoot(this));
proxyConsumer.connect_structured_push_supplier(thisSps);
} catch (AcsJContainerServicesEx e) {
// @TODO destroy supplierAdmin and proxyConsumer
throw new AcsJCORBAProblemEx(e);
} catch (AlreadyConnected e) {
// @TODO destroy supplierAdmin and proxyConsumer
throw new AcsJCORBAProblemEx(e);
}
reconnectCallback = new AcsNcReconnectionCallback(this, logger);
reconnectCallback.registerForReconnect(services, helper.getNotifyFactory());
}
use of alma.JavaContainerError.wrappers.AcsJContainerServicesEx 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());
}
use of alma.JavaContainerError.wrappers.AcsJContainerServicesEx in project ACS by ACS-Community.
the class NCSubscriber method reconnect.
/**
* Reconnect to the Notification Channel
*/
private void reconnect() throws AcsJException {
Date oldChannelTimestamp = helper.getLastRegisteredChannelTimestamp();
try {
// get the channel
channel = helper.getNotificationChannel(getNotificationFactoryName());
// get the admin object
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);
}
try {
// Clean up callback for reconnection requests
channelReconnectionCallback.disconnect();
} catch (org.omg.CORBA.OBJECT_NOT_EXIST ex1) {
// this is OK, because someone else has already destroyed the remote resources
}
channelReconnectionCallback = null;
try {
// 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 ex) {
AcsJException e = new AcsJGenericErrorEx(ex);
throw e;
} catch (org.omg.CosEventChannelAdmin.AlreadyConnected ex) {
AcsJException e = new AcsJGenericErrorEx(ex);
throw e;
} catch (org.omg.CosEventChannelAdmin.TypeError ex) {
AcsJException e = new AcsJGenericErrorEx(ex);
throw e;
} catch (AcsJIllegalArgumentEx ex) {
AcsJException e = new AcsJGenericErrorEx(ex);
throw e;
}
/* We only have to resume the connection when it has been suspended
try {
proxySupplier.resume_connection();
} catch (org.omg.CosNotifyChannelAdmin.ConnectionAlreadyActive ex) {
} catch (Exception ex) {
AcsJException e = new AcsJGenericErrorEx(ex);
throw e;
}*/
// In case any exception occurs, ensure the channel timestamp has not changed
} catch (Throwable e) {
helper.setLastRegisteredChannelTimestamp(oldChannelTimestamp);
throw e;
}
logger.log(Level.INFO, "Consumer reconnected to the channel '" + channelName + "'");
}
use of alma.JavaContainerError.wrappers.AcsJContainerServicesEx in project ACS by ACS-Community.
the class SimpleSupplierConsumerClient method createPublisherAndSubscriber.
public void createPublisherAndSubscriber() {
try {
m_client = new ComponentClient(m_logger, System.getProperty("ACS.manager"), "SimpleSupplierConsumerClient");
//m_subscriber = m_client.getContainerServices().createNotificationChannelSubscriber(CHANNEL_NAME, EventDescription.class);
//m_subscriber.addSubscription(this);
m_publisher = m_client.getContainerServices().createNotificationChannelPublisher(CHANNEL_NAME, IDLEntity.class);
} catch (AcsJContainerServicesEx e) {
// Silently ignore the errors
} catch (AcsJException e) {
// Shouldn't happen
} catch (Exception e) {
e.printStackTrace();
}
}
use of alma.JavaContainerError.wrappers.AcsJContainerServicesEx in project ACS by ACS-Community.
the class ComponentClientTestCase method getLogReceiver.
/**
* Gets a {@link LogReceiver} which can be used
* to verify log messages from both local and remote processes.
* The returned <code>LogReceiver</code> is already initialized.
* If initialization fails, an exception is thrown.
* <p>
* To receive logs from the log service, use either
* {@link LogReceiver#getLogQueue()} or {@link LogReceiver#startCaptureLogs(java.io.PrintWriter)}.
*
* @throws AcsJContainerServicesEx if the LogReceiver fails to initialize within 20 seconds.
*/
protected LogReceiver getLogReceiver() throws AcsJContainerServicesEx {
if (logReceiver == null) {
boolean initOk = false;
try {
logReceiver = new LogReceiver();
// logReceiver.setVerbose(true);
initOk = logReceiver.initialize(acsCorba.getORB(), m_acsManagerProxy.getManager(), 20);
} catch (Throwable thr) {
AcsJContainerServicesEx ex = new AcsJContainerServicesEx(thr);
ex.setContextInfo("Failed to obtain an initialized LogReceiver.");
throw ex;
}
if (!initOk) {
AcsJContainerServicesEx ex = new AcsJContainerServicesEx();
ex.setContextInfo("LogReceiver failed to initialize within 20 seconds.");
throw ex;
}
}
return logReceiver;
}
Aggregations