use of alma.acs.exceptions.AcsJException in project ACS by ACS-Community.
the class NCSubscriberTest method publish.
/*===================================*/
/* Support methods */
/*===================================*/
private void publish(int nEvents, EventType type) {
IDLEntity event = null;
if (type.equals(EventType.statusBlock1)) {
event = new statusBlockEvent1();
((statusBlockEvent1) event).counter1 = 0;
((statusBlockEvent1) event).counter2 = 0;
((statusBlockEvent1) event).flipFlop = true;
((statusBlockEvent1) event).onOff = alma.ADMINTEST1.OnOffStates.ON;
} else if (type.equals(EventType.statusBlock2)) {
event = new statusBlockEvent2();
((statusBlockEvent2) event).counter1 = 0;
((statusBlockEvent2) event).counter2 = 0;
((statusBlockEvent2) event).flipFlop = true;
((statusBlockEvent2) event).onOff = alma.ADMINTEST2.OnOffStates.ON;
}
try {
for (int i = 0; i != nEvents; i++) m_publisher.publishEvent(event);
} catch (AcsJException e) {
e.printStackTrace();
}
}
use of alma.acs.exceptions.AcsJException in project ACS by ACS-Community.
the class NCPublisher method publishEvent.
/**
* Takes the given Java object and tries to pack it into a CORBA Any and
* publish it to the notification channel.
* This will fail if the parameter is not
* CORBA-generated from a user-defined IDL struct. In simple terms, trying
* to publish native Java types is impossible because they have no CORBA
* mapping to say Python or C++ types.
*
* @param customStruct
* An instance of the IDL struct (Java class) to be published.
* @throws AcsJPublishEventFailureEx If <code>customStruct</code> is not an IDL struct,
* for which it must be a subclass of IDLEntity.
* @throws AcsJException
* There are an enormous amount of possibilities pertaining to
* why an AcsJException would be thrown by publishEvent.
*/
@Override
public void publishEvent(T customStruct) throws AcsJException {
// Let's first verify that the use of generics between base class and here is OK also for the DDS side.
if (!(customStruct instanceof IDLEntity)) {
String msg = "ACS is using Corba NC as the underlying pub/sub framework. Event data must be IDL-defined structs that inherit from org.omg.CORBA.portable.IDLEntity.";
AcsJPublishEventFailureEx ex = new AcsJPublishEventFailureEx();
ex.setFailureDescription(msg);
ex.setChannelName(channelName);
ex.setEventName(customStruct.getClass().getName());
throw ex;
}
IDLEntity customStructEntity = (IDLEntity) customStruct;
String typeName = customStructEntity.getClass().getSimpleName();
// Event to send
// Header: domain_name = "ALMA", type_name = simple name of IDL struct, event_name = ""
StructuredEvent event = getCORBAEvent(typeName, "");
// Send event meta data (client name, timestamp, counter) in the accompanying EventDescription object,
// which we transmit as the Any field 'remainder_of_body'.
event.remainder_of_body = services.getAdvancedContainerServices().getAny();
EventDescription descrip = new EventDescription(services.getName(), alma.acs.util.UTCUtility.utcJavaToOmg(System.currentTimeMillis()), count.getAndIncrement());
EventDescriptionHelper.insert(event.remainder_of_body, descrip);
// In the 'filterable_data' field, we send our IDL struct coded as an Any
event.filterable_data = new Property[1];
event.filterable_data[0] = new Property(alma.acscommon.DEFAULTDATANAME.value, anyAide.complexObjectToCorbaAny(customStructEntity));
// Check the queue for events from previous failures.
synchronized (eventQueueSync) {
if (eventQueue != null) {
CircularQueue<T>.Data<T> tmp;
try {
while ((tmp = eventQueue.pop()) != null) {
publishCORBAEvent(tmp.corbaData, tmp.userData);
}
} catch (Exception ex) {
Level lev = (isTraceEventsEnabled ? Level.INFO : Level.FINEST);
logger.log(lev, "Failed to flush event queue.", ex);
// go on and try to send the new event, to at least have it inserted into the queue.
}
}
}
try {
publishCORBAEvent(event, customStruct);
} catch (AcsJCORBAProblemEx ex) {
String info = ex.getInfo();
if (false == info.contains("org.omg.CORBA.TRANSIENT")) {
throw ex;
}
}
}
use of alma.acs.exceptions.AcsJException 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.acs.exceptions.AcsJException in project ACS by ACS-Community.
the class AnyAideTest method testComplexObjectToCorbaAny.
public void testComplexObjectToCorbaAny() {
NestedEvent neVal = new NestedEvent();
neVal.sampVal = advancedCS.getAny();
neVal.sampVal.insert_long(15);
Any anyNe = null;
try {
anyNe = anyAide.complexObjectToCorbaAny(neVal);
} catch (AcsJException ex) {
}
assertNotNull(anyNe);
NestedEvent neVal2 = NestedEventHelper.extract(anyNe);
assertEquals(neVal.sampVal.extract_long(), neVal2.sampVal.extract_long());
try {
anyAide.complexObjectToCorbaAny(null);
fail();
} catch (AcsJException ex) {
}
}
use of alma.acs.exceptions.AcsJException in project ACS by ACS-Community.
the class AnyAideTest method testObjectToCorbaAny.
public void testObjectToCorbaAny() {
final String strVal = "str";
final Long lVal = 13L;
final Double dVal = 13.7;
final Float fVal = 13.3f;
final Integer iVal = 11;
final int[] intArr = new int[] { 1, 2, 3, 4 };
final NestedEvent neVal = new NestedEvent();
neVal.sampVal = advancedCS.getAny();
neVal.sampVal.insert_long(15);
Any anyNull = null, anyString = null, anyLong = null, anyDouble = null, anyFloat = null, anyInt = null;
Any anyNe = null, anyIntArr = null;
try {
anyNull = anyAide.objectToCorbaAny(null);
anyString = anyAide.objectToCorbaAny(strVal);
anyLong = anyAide.objectToCorbaAny(lVal);
anyDouble = anyAide.objectToCorbaAny(dVal);
anyFloat = anyAide.objectToCorbaAny(fVal);
anyInt = anyAide.objectToCorbaAny(iVal);
anyNe = anyAide.objectToCorbaAny(neVal);
anyIntArr = anyAide.objectToCorbaAny(intArr);
} catch (AcsJException ex) {
}
assertNotNull(anyNull);
assertNotNull(anyString);
assertNotNull(anyLong);
assertNotNull(anyDouble);
assertNotNull(anyFloat);
assertNotNull(anyInt);
assertNotNull(anyNe);
assertNotNull(anyIntArr);
assertNull(anyNull.extract_Object());
assertEquals(lVal.longValue(), anyLong.extract_longlong());
assertEquals(dVal.doubleValue(), anyDouble.extract_double());
assertEquals(fVal.floatValue(), anyFloat.extract_float());
assertEquals(iVal.intValue(), anyInt.extract_long());
assertEquals(strVal, anyString.extract_string());
NestedEvent neVal2 = NestedEventHelper.extract(anyNe);
assertEquals(neVal.sampVal.extract_long(), neVal2.sampVal.extract_long());
int[] intArr2 = longSeqHelper.extract(anyIntArr);
assertEquals(intArr.length, intArr2.length);
for (int i = 0; i < intArr2.length; ++i) {
assertEquals(intArr[i], intArr2[i]);
}
try {
Any anyVector = anyAide.objectToCorbaAny(new Vector());
fail();
} catch (AcsJException ex) {
}
}
Aggregations