use of alma.acsnc.EventDescription in project ACS by ACS-Community.
the class NCSubscriberTest method testAddSubscription.
/**
*/
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testAddSubscription() throws Exception {
// Invalid receiver (returns null)
try {
m_subscriber.addSubscription(new EventReceiver1() {
public Class<statusBlockEvent1> getEventType() {
return null;
}
});
fail("Event receiver is invalid, as it returns a null event type");
} catch (AcsJEventSubscriptionEx e) {
}
// Invalid receiver (returns String.class)
try {
m_subscriber.addSubscription(new Callback() {
public void receive(Object event, EventDescription eventDescrip) {
}
public Class getEventType() {
return String.class;
}
});
fail("Event receiver is invalid, as it returns a java.lang.String as the event type");
} catch (AcsJEventSubscriptionEx e) {
}
// Several receiver subscriptions for the same type overwrite the previous one
m_subscriber.addSubscription(new EventReceiver1());
m_subscriber.addSubscription(new EventReceiver1());
m_subscriber.addSubscription(new EventReceiver1());
m_subscriber.addSubscription(new EventReceiver1());
assertEquals(1, m_subscriber.subscriptionsFilters.size());
assertEquals(1, m_subscriber.getNumberOfReceivers());
assertFalse(m_subscriber.hasGenericReceiver());
assertEquals(2, m_subscriber.proxySupplier.get_all_filters().length);
m_subscriber.addSubscription(new EventReceiver2());
m_subscriber.addSubscription(new EventReceiver2());
m_subscriber.addSubscription(new EventReceiver2());
m_subscriber.addSubscription(new EventReceiver2());
assertEquals(2, m_subscriber.subscriptionsFilters.size());
assertEquals(2, m_subscriber.getNumberOfReceivers());
assertFalse(m_subscriber.hasGenericReceiver());
assertEquals(3, m_subscriber.proxySupplier.get_all_filters().length);
m_subscriber.addGenericSubscription(new GenericEventReceiver());
m_subscriber.addGenericSubscription(new GenericEventReceiver());
m_subscriber.addGenericSubscription(new GenericEventReceiver());
m_subscriber.addGenericSubscription(new GenericEventReceiver());
assertEquals(3, m_subscriber.subscriptionsFilters.size());
assertEquals(2, m_subscriber.getNumberOfReceivers());
assertTrue(m_subscriber.hasGenericReceiver());
assertEquals(4, m_subscriber.proxySupplier.get_all_filters().length);
}
use of alma.acsnc.EventDescription in project ACS by ACS-Community.
the class EventSupplierImpl method sendEvents.
/**
* Sends some events to an event channel.
*
* @param param
* number of events to send
*/
@Override
public void sendEvents(short param) {
System.out.println("Now sending simplesupplier events...");
try {
// first send out some number of events.
EventDescription t_block = new EventDescription("no name", 32L, 64L);
for (short i = 0; i < param; i++) {
m_supplier.publishEvent(t_block);
Thread.sleep(1);
}
} catch (Exception e) {
System.err.println(e);
}
}
use of alma.acsnc.EventDescription in project ACS by ACS-Community.
the class EventSupplierCDBChannel method sendEvents.
/**
* Sends some events to an event channel.
*
* @param param
* number of events to send
*/
public void sendEvents(short param) {
System.out.println("Now sending simplesupplier events...");
try {
// first send out some number of events.
EventDescription t_block = new EventDescription("no name", 32L, 64L);
for (short i = 0; i < param; i++) {
m_supplier.publishEvent(t_block);
}
//fake a subscription change notification (should be disabled on the proxy consumer in the real system)
try {
m_supplier.subscription_change(new org.omg.CosNotification.EventType[] {}, new org.omg.CosNotification.EventType[] {});
m_logger.warning("Call to 'subscription_change' did not produce the expected NO_IMPLEMENT exception.");
} catch (NO_IMPLEMENT ex) {
// expected
}
} catch (Exception e) {
System.err.println(e);
}
}
use of alma.acsnc.EventDescription 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.acsnc.EventDescription in project ACS by ACS-Community.
the class SimpleConsumerReconnClient method sendEvents.
public void sendEvents(int numEvents, int sleepTimeMs) {
EventDescription ed = new EventDescription();
ed.count = 0;
ed.name = "description";
ed.timestamp = new Date().getTime();
m_logger.info("Start publishing " + String.valueOf(numEvents) + " events");
// publish events
for (int j = 0; j < numEvents; j++) {
try {
ed.count = j;
m_publisher.publishEvent(ed);
try {
Thread.sleep(sleepTimeMs);
} catch (InterruptedException e) {
}
} catch (Throwable e) {
m_cbObj.exceptionThrown(e);
}
m_logger.info(":::[TestSubscriberReconn] Published events at iteration " + String.valueOf(j));
}
}
Aggregations