use of org.omg.CosNotifyChannelAdmin.ConsumerAdmin in project ACS by ACS-Community.
the class NCSubscriberAdminReuseTest method testNewAndOldNCsTogether.
/**
* TODO: Write a similar test with an old-style C++ Consumer,
* once we remove the deprecated Java NC Consumer.
*/
public void testNewAndOldNCsTogether() throws Exception {
List<Consumer> consumers = new ArrayList<Consumer>();
for (int i = 1; i <= 10; i++) {
// Create the maximum number of proxies per admin
// Also, per every NCSubscriber, create an old Consumer
AcsEventSubscriber[] subscribers = new AcsEventSubscriber[NCSubscriber.PROXIES_PER_ADMIN];
for (int j = 0; j != NCSubscriber.PROXIES_PER_ADMIN; j++) {
subscribers[j] = getContainerServices().createNotificationChannelSubscriber(CHANNEL_NAME, IDLEntity.class);
Consumer c = new Consumer(CHANNEL_NAME, getContainerServices());
consumers.add(c);
}
assertEquals(i * (1 + NCSubscriber.PROXIES_PER_ADMIN), channel.get_all_consumeradmins().length);
}
// Now, let's examine the consumer admins, and see whether they are shared or not
int sharedAdmins = 0;
int lonelyAdmins = 0;
for (int adminID : channel.get_all_consumeradmins()) {
ConsumerAdmin admin = channel.get_consumeradmin(adminID);
boolean isSharedAdmin = false;
for (int proxyID : admin.push_suppliers()) {
ProxySupplier proxy = admin.get_proxy_supplier(proxyID);
if (ProxyType.PUSH_ANY.equals(proxy.MyType())) {
isSharedAdmin = true;
break;
}
}
if (isSharedAdmin) {
assertEquals(NCSubscriber.PROXIES_PER_ADMIN, admin.push_suppliers().length - 1);
sharedAdmins++;
} else
lonelyAdmins++;
}
assertEquals(10, sharedAdmins);
assertEquals(10 * NCSubscriber.PROXIES_PER_ADMIN, lonelyAdmins);
// Manually free these old filthy consumers
for (Consumer c : consumers) c.disconnect();
}
use of org.omg.CosNotifyChannelAdmin.ConsumerAdmin in project ACS by ACS-Community.
the class EventModel method getChannelStatistics.
/**
* Called by NotifyServiceUpdateJob (single/periodic refresh of service summary / channel tree).
*/
public synchronized boolean getChannelStatistics() {
if (false == discoverNotifyServicesAndChannels()) {
return false;
}
for (NotifyServiceData nsData : notifyServices.values()) {
if (!nsData.isReachable()) {
// we skip services that were unreachable already in the above discoverNotifyServicesAndChannels call
continue;
}
// especially if we don't want to display the admin objects as tree nodes to show consumer allocation to the shared admins.
for (ChannelData channelData : nsData.getChannels()) {
String channelName = channelData.getQualifiedName();
EventChannel ec = channelData.getCorbaRef();
// initial or previous count of consumers / suppliers
int[] consAndSupp = { 0, 0 };
if (channelData.isNewNc()) {
lastConsumerAndSupplierCount.put(channelName, consAndSupp);
} else if (lastConsumerAndSupplierCount.containsKey(channelName)) {
consAndSupp = lastConsumerAndSupplierCount.get(channelName);
}
// for consumers we must count the proxies, cannot just deduce their number from the consumer admins
int consumerCount = 0;
for (int consumerAdminId : ec.get_all_consumeradmins()) {
try {
ConsumerAdmin consumerAdmin = ec.get_consumeradmin(consumerAdminId);
int[] push_suppliers_ids = consumerAdmin.push_suppliers();
for (int proxyID : push_suppliers_ids) {
try {
ProxySupplier proxy = consumerAdmin.get_proxy_supplier(proxyID);
if (!NCSubscriber.AdminReuseCompatibilityHack.isDummyProxy(proxy)) {
consumerCount++;
}
} catch (ProxyNotFound ex) {
m_logger.log(AcsLogLevel.NOTICE, "Proxy with ID='" + proxyID + "' not found for consumer admin with ID='" + consumerAdminId + "', " + "even though this Id got listed a moment ago.", ex);
}
}
} catch (AdminNotFound ex) {
ex.printStackTrace();
}
}
final String[] roleNames = { "consumer", "supplier" };
int[] proxyCounts = new int[2];
int[] proxyDeltas = new int[2];
proxyCounts[0] = consumerCount;
// currently for suppliers we have 1 admin object per supplier
proxyCounts[1] = ec.get_all_supplieradmins().length;
// same code for consumer and supplier
for (int i = 0; i < proxyCounts.length; i++) {
String cstr = channelName;
int cdiff = proxyCounts[i] - consAndSupp[i];
if (cdiff != 0) {
if (cdiff > 0) {
cstr += " has added " + cdiff + " " + roleNames[i];
} else if (cdiff < 0) {
cstr += " has removed " + (-cdiff) + " " + roleNames[i];
}
cstr += (Math.abs(cdiff) != 1 ? "s." : ".");
m_logger.info(cstr);
}
proxyDeltas[i] = cdiff;
}
lastConsumerAndSupplierCount.put(channelName, proxyCounts);
//m_logger.info("Channel: " + channelName + " has " + adminCounts[0] + " consumers and " + adminCounts[1] + " suppliers.");
channelData.setNumberConsumers(proxyCounts[0]);
channelData.setNumberSuppliers(proxyCounts[1]);
channelData.setDeltaConsumers(proxyDeltas[0]);
channelData.setDeltaSuppliers(proxyDeltas[1]);
}
}
return true;
}
Aggregations