use of org.omg.CORBA.portable.IDLEntity 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 org.omg.CORBA.portable.IDLEntity in project ACS by ACS-Community.
the class NCSubscriberAdminReuseTest method runConcurrentSubscribersCreation.
private void runConcurrentSubscribersCreation(int numRealSubscribersDefinedTotal) throws Exception {
m_logger.info("Setting up " + numRealSubscribersDefinedTotal + " concurrent subscriber creations...");
final List<AcsEventSubscriber<IDLEntity>> subscribers = Collections.synchronizedList(new ArrayList<AcsEventSubscriber<IDLEntity>>());
// Create all the tasks first
ThreadBurstExecutorService executor = new ThreadBurstExecutorService(getContainerServices().getThreadFactory());
for (int i = 0; i < numRealSubscribersDefinedTotal; i++) {
Runnable r = new Runnable() {
public void run() {
try {
// create subscriber, and add it to the list
subscribers.add(getContainerServices().createNotificationChannelSubscriber(CHANNEL_NAME, IDLEntity.class));
} catch (Exception e) {
m_logger.log(Level.WARNING, "Failed to create a subscriber.", e);
}
}
};
try {
executor.submit(r, 100, TimeUnit.SECONDS);
} catch (InterruptedException e1) {
fail("Failed to submit the subscriber creator thread to the executor service");
}
}
// and now run'em all at the same time! (concurrently)
m_logger.info("Will run " + numRealSubscribersDefinedTotal + " concurrent subscriber creations...");
try {
boolean startOK = executor.executeAllAndWait(100, TimeUnit.SECONDS);
assertTrue("Not all subscribers started within the alotted 100 seconds window.", startOK);
} catch (InterruptedException e) {
fail("Got InterruptedException while running all my threads");
}
// After all the show, we should have all requested subscribers in the local list
assertEquals(numRealSubscribersDefinedTotal, subscribers.size());
m_logger.info("Successfully created " + numRealSubscribersDefinedTotal + " subscribers semi-concurrently. Will now check their NC admin links...");
// Check if these subscribers are distributed correctly over several admin objects,
// allowing for some overbooking due to concurrent requests (see comment about concurrency in c'tor of NCSubscriber)
final int allowedAdminOverbooking = 2;
int numRealSubscribersFoundTotal = 0;
int[] adminIDs = channel.get_all_consumeradmins();
for (int i = 0; i < adminIDs.length; i++) {
int adminID = adminIDs[i];
String msgBase = "Subscriber admin #" + (i + 1) + " (of " + adminIDs.length + ") ";
try {
int subs = channel.get_consumeradmin(adminID).push_suppliers().length;
// minus 1 for the 'management' subscriber
int numRealSubscribersThisAdmin = subs - 1;
m_logger.info(msgBase + "has " + numRealSubscribersThisAdmin + " proxy objects (subscribers) attached.");
if (i < adminIDs.length - 1) {
// This is not the last of the admin objects. It should be filled to the brim with proxies.
assertThat(msgBase + "should be full with " + NCSubscriber.PROXIES_PER_ADMIN + " proxies.", numRealSubscribersThisAdmin, greaterThanOrEqualTo(NCSubscriber.PROXIES_PER_ADMIN));
assertThat(msgBase + "has more proxies than allowed by 'allowedAdminOverbooking'=" + allowedAdminOverbooking + ", which may be OK.", numRealSubscribersThisAdmin, lessThanOrEqualTo(NCSubscriber.PROXIES_PER_ADMIN + allowedAdminOverbooking));
} else {
// We should be at the last of the admin objects, which may be only partially filled
assertThat(msgBase + "has more proxies than allowed by 'allowedAdminOverbooking'=" + allowedAdminOverbooking + ", which may be OK.", numRealSubscribersThisAdmin, lessThanOrEqualTo(NCSubscriber.PROXIES_PER_ADMIN + allowedAdminOverbooking));
assertThat(msgBase + "should contain all remaining proxies.", numRealSubscribersThisAdmin, equalTo(numRealSubscribersDefinedTotal - numRealSubscribersFoundTotal));
}
numRealSubscribersFoundTotal += numRealSubscribersThisAdmin;
} catch (AdminNotFound ex) {
fail("Can't get information about consumer admin #" + (i + 1) + " (ID=" + adminID + "): " + ex.toString());
}
}
destroyConsumers();
}
use of org.omg.CORBA.portable.IDLEntity in project ACS by ACS-Community.
the class AnyAide method objectToCorbaAny.
/**
* Converts a generic Java object to a CORBA Any. May fail.
*
* @param obj
* Object to be converted to a CORBA any
* @return A CORBA any with obj's data embedded within it.
* @throws AcsJException
* Thrown if there's some problem converting the object to an
* any. TODO: make sure this works with enumerations.
*/
public Any objectToCorbaAny(Object obj) throws AcsJException {
if (obj != null && obj.getClass().isArray()) {
return internalArrayToCorbaAny(obj);
}
Any retVal = m_containerServices.getAdvancedContainerServices().getAny();
// null case
if (obj == null) {
retVal.insert_Object(null);
} else // check against string
if (obj instanceof String) {
retVal.insert_string((String) obj);
} else // check against double
if (obj instanceof Double) {
double value = ((Double) obj).doubleValue();
retVal.insert_double(value);
} else // check against long - CORBA long long and unsigned long long
if (obj instanceof Long) {
long value = ((Long) obj).longValue();
retVal.insert_longlong(value);
} else // check against integer - CORBA long or unsigned long
if (obj instanceof Integer) {
int value = ((Integer) obj).intValue();
retVal.insert_long(value);
} else // check against float
if (obj instanceof Float) {
float value = ((Float) obj).floatValue();
retVal.insert_float(value);
} else if (obj instanceof IDLEntity) {
// and that this method will work.
return complexObjectToCorbaAny((IDLEntity) obj);
} else {
Throwable cause = new Throwable("Bad arg of type " + obj.getClass().getName());
throw new AcsJBadParameterEx(cause);
}
return retVal;
}
use of org.omg.CORBA.portable.IDLEntity in project ACS by ACS-Community.
the class EventSupplierImpl method initialize.
/** Sets up the NCPublisher.
* @param containerServices Services to components.
* @throws ComponentLifecycleException Not thrown.
*/
public void initialize(ContainerServices containerServices) throws ComponentLifecycleException {
super.initialize(containerServices);
try {
//Instantiate our supplier
AcsEventPublisher<IDLEntity> pubIF = containerServices.createNotificationChannelPublisher("blar", IDLEntity.class);
// For special testing, we cast to the expected publisher impl class (normally not needed)
m_supplier = (NCPublisher<IDLEntity>) pubIF;
m_logger.info("NCPublisher for 'blar' channel created.");
} catch (Exception e) {
throw new ComponentLifecycleException(e);
}
}
Aggregations