Search in sources :

Example 1 with AdminNotFound

use of org.omg.CosNotifyChannelAdmin.AdminNotFound 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;
}
Also used : EventChannel(org.omg.CosNotifyChannelAdmin.EventChannel) ProxyNotFound(org.omg.CosNotifyChannelAdmin.ProxyNotFound) ConsumerAdmin(org.omg.CosNotifyChannelAdmin.ConsumerAdmin) ProxySupplier(org.omg.CosNotifyChannelAdmin.ProxySupplier) AdminNotFound(org.omg.CosNotifyChannelAdmin.AdminNotFound)

Example 2 with AdminNotFound

use of org.omg.CosNotifyChannelAdmin.AdminNotFound 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();
}
Also used : ThreadBurstExecutorService(alma.acs.concurrent.ThreadBurstExecutorService) AcsEventSubscriber(alma.acs.nc.AcsEventSubscriber) IDLEntity(org.omg.CORBA.portable.IDLEntity) AdminNotFound(org.omg.CosNotifyChannelAdmin.AdminNotFound)

Example 3 with AdminNotFound

use of org.omg.CosNotifyChannelAdmin.AdminNotFound in project ACS by ACS-Community.

the class NCSubscriber method getSharedAdmin.

////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////// Helper methods  ////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
/**
	 * Creates or reuses a shared server-side NC consumer admin object.
	 * 
	 * @throws AcsJException
	 */
private ConsumerAdmin getSharedAdmin() throws AcsJCORBAProblemEx, AcsJNarrowFailedEx {
    ConsumerAdmin ret = null;
    org.omg.CosNotifyChannelAdmin.ConsumerAdmin retBase = null;
    boolean created = false;
    int consumerAdminId = -1;
    AdminReuseCompatibilityHack adminReuseCompatibilityHack = new AdminReuseCompatibilityHack(channelName, logger);
    // while in real life we can have concurrent admin creation requests from different processes.
    synchronized (NCSubscriber.class) {
        // Check if we can reuse an already existing consumer admin
        for (int adminId : channel.get_all_consumeradmins()) {
            try {
                org.omg.CosNotifyChannelAdmin.ConsumerAdmin tmpAdmin = channel.get_consumeradmin(adminId);
                if (adminReuseCompatibilityHack.isSharedAdmin(tmpAdmin)) {
                    // (the -1 goes because of the dummy proxy that is attached to the shared admin)
                    if (tmpAdmin.push_suppliers().length - 1 < PROXIES_PER_ADMIN) {
                        retBase = tmpAdmin;
                        consumerAdminId = adminId;
                        break;
                    }
                }
            } catch (AdminNotFound e) {
                logger.log(AcsLogLevel.NOTICE, "Consumer admin with ID='" + adminId + "' not found for channel '" + channelName + "', " + "will continue anyway to search for shared consumer admins", e);
            }
        }
        // If no suitable consumer admin was found, we create a new one 
        if (retBase == null) {
            // create a new consumer admin
            IntHolder consumerAdminIDHolder = new IntHolder();
            // We use filters only on proxy objects, not on admin objects.
            // An admin object without filters will opt to pass all events.
            // We need a logical AND to be used when comparing the event passing decisions
            // made by the set of proxy supplier filters and by the admin object.
            InterFilterGroupOperator adminProxyFilterLogic = InterFilterGroupOperator.AND_OP;
            retBase = channel.new_for_consumers(adminProxyFilterLogic, consumerAdminIDHolder);
            consumerAdminId = consumerAdminIDHolder.value;
            created = true;
        }
    }
    try {
        // cast to TAO extension type
        ret = ConsumerAdminHelper.narrow(retBase);
    } catch (BAD_PARAM ex) {
        if (created) {
            retBase.destroy();
        }
        LOG_NC_TaoExtensionsSubtypeMissing.log(logger, "ConsumerAdmin for channel " + channelName, ConsumerAdminHelper.id(), org.omg.CosNotifyChannelAdmin.ConsumerAdminHelper.id());
        AcsJNarrowFailedEx ex2 = new AcsJNarrowFailedEx(ex);
        ex2.setNarrowType(ConsumerAdminHelper.id());
        throw ex2;
    }
    if (created) {
        // @TODO: Remove this workaround once it is no longer needed.
        adminReuseCompatibilityHack.markAsSharedAdmin(ret);
    }
    LOG_NC_ConsumerAdminObtained_OK.log(logger, consumerAdminId, (created ? "created" : "reused"), clientName, channelName, getNotificationFactoryName());
    return ret;
}
Also used : ConsumerAdmin(gov.sandia.NotifyMonitoringExt.ConsumerAdmin) InterFilterGroupOperator(org.omg.CosNotifyChannelAdmin.InterFilterGroupOperator) BAD_PARAM(org.omg.CORBA.BAD_PARAM) IntHolder(org.omg.CORBA.IntHolder) AcsJNarrowFailedEx(alma.ACSErrTypeCORBA.wrappers.AcsJNarrowFailedEx) AdminNotFound(org.omg.CosNotifyChannelAdmin.AdminNotFound)

Aggregations

AdminNotFound (org.omg.CosNotifyChannelAdmin.AdminNotFound)3 AcsJNarrowFailedEx (alma.ACSErrTypeCORBA.wrappers.AcsJNarrowFailedEx)1 ThreadBurstExecutorService (alma.acs.concurrent.ThreadBurstExecutorService)1 AcsEventSubscriber (alma.acs.nc.AcsEventSubscriber)1 ConsumerAdmin (gov.sandia.NotifyMonitoringExt.ConsumerAdmin)1 BAD_PARAM (org.omg.CORBA.BAD_PARAM)1 IntHolder (org.omg.CORBA.IntHolder)1 IDLEntity (org.omg.CORBA.portable.IDLEntity)1 ConsumerAdmin (org.omg.CosNotifyChannelAdmin.ConsumerAdmin)1 EventChannel (org.omg.CosNotifyChannelAdmin.EventChannel)1 InterFilterGroupOperator (org.omg.CosNotifyChannelAdmin.InterFilterGroupOperator)1 ProxyNotFound (org.omg.CosNotifyChannelAdmin.ProxyNotFound)1 ProxySupplier (org.omg.CosNotifyChannelAdmin.ProxySupplier)1