Search in sources :

Example 1 with ProxySupplier

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

the class NCSubscriber method createProxySupplier.

/**
	 * Creates the proxy supplier (push-style, for structured events) 
	 * that lives in the Notify server process, managed by the consumer admin object, and
	 * will later be connected to this client-side subscriber object.
	 * 
	 * @throws AcsJCORBAProblemEx If creation of the proxy supplier failed.
	 */
private StructuredProxyPushSupplier createProxySupplier() throws AcsJCORBAProblemEx {
    StructuredProxyPushSupplier ret = null;
    String errMsg = null;
    // will get assigned "a numeric identifier [...] that is unique among all proxy suppliers [the admin object] has created"
    IntHolder proxyIdHolder = new IntHolder();
    String randomizedClientName = null;
    try {
        ProxySupplier proxy = null;
        while (proxy == null) {
            // See the comments on Consumer#createConsumer() for a nice explanation of why this randomness is happening here
            randomizedClientName = Helper.createRandomizedClientName(clientName);
            try {
                proxy = sharedConsumerAdmin.obtain_named_notification_push_supplier(ClientType.STRUCTURED_EVENT, proxyIdHolder, randomizedClientName);
            } catch (NameAlreadyUsed e) {
            // Hopefully we won't run into this situation. Still, try to go on in the loop,
            // with a different client name next time.
            } catch (NameMapError e) {
                // Default to the unnamed version
                proxy = sharedConsumerAdmin.obtain_notification_push_supplier(ClientType.STRUCTURED_EVENT, proxyIdHolder);
            }
        }
        ret = StructuredProxyPushSupplierHelper.narrow(proxy);
    } catch (AdminLimitExceeded ex) {
        // See NC spec 3.4.15.10
        // If the number of consumers currently connected to the channel with which the target ConsumerAdmin object is associated 
        // exceeds the value of the MaxConsumers administrative property, the AdminLimitExceeded exception is raised.
        String limit = ex.admin_property_err.value.extract_string();
        errMsg = "NC '" + channelName + "' is configured for a maximum of " + limit + " subscribers, which does not allow this client to subscribe.";
    }
    if (ret != null) {
        LOG_NC_SupplierProxyCreation_OK.log(logger, proxyIdHolder.value, clientName, randomizedClientName, channelName, getNotificationFactoryName());
    } else {
        LOG_NC_SupplierProxyCreation_FAIL.log(logger, clientName, channelName, getNotificationFactoryName(), errMsg);
        AcsJCORBAProblemEx ex2 = new AcsJCORBAProblemEx();
        ex2.setInfo("Failed to create proxy supplier on NC '" + channelName + "' for client '" + clientName + "': " + errMsg);
        throw ex2;
    }
    return ret;
}
Also used : AcsJCORBAProblemEx(alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx) NameMapError(gov.sandia.NotifyMonitoringExt.NameMapError) AdminLimitExceeded(org.omg.CosNotifyChannelAdmin.AdminLimitExceeded) IntHolder(org.omg.CORBA.IntHolder) ProxySupplier(org.omg.CosNotifyChannelAdmin.ProxySupplier) NameAlreadyUsed(gov.sandia.NotifyMonitoringExt.NameAlreadyUsed) StructuredProxyPushSupplier(org.omg.CosNotifyChannelAdmin.StructuredProxyPushSupplier)

Example 2 with ProxySupplier

use of org.omg.CosNotifyChannelAdmin.ProxySupplier 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();
}
Also used : ConsumerAdmin(org.omg.CosNotifyChannelAdmin.ConsumerAdmin) AcsEventSubscriber(alma.acs.nc.AcsEventSubscriber) ArrayList(java.util.ArrayList) ProxySupplier(org.omg.CosNotifyChannelAdmin.ProxySupplier) IDLEntity(org.omg.CORBA.portable.IDLEntity)

Example 3 with ProxySupplier

use of org.omg.CosNotifyChannelAdmin.ProxySupplier 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 4 with ProxySupplier

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

the class ACSStructuredPushConsumer method initialize.

/**
	 * Initializes the parser.
	 * Creation date: (10/24/2001 12:48:32 PM)
	 */
private void initialize() {
    org.omg.CORBA.IntHolder proxyId = new org.omg.CORBA.IntHolder();
    ProxySupplier proxySupplier = null;
    try {
        proxySupplier = acsra.getConsumerAdmin().obtain_named_notification_push_supplier(ClientType.STRUCTURED_EVENT, proxyId, createUniqueClientName());
    } catch (Exception e) {
        listenersDispatcher.publishReport("Exception occurred when obtaining notification push supplier.");
        System.out.println("Exception in ACSStructuredPushConsumer::initialize(): " + e);
        return;
    }
    structuredProxyPushSupplier = StructuredProxyPushSupplierHelper.narrow(proxySupplier);
    isInitialized = true;
}
Also used : ProxySupplier(org.omg.CosNotifyChannelAdmin.ProxySupplier)

Aggregations

ProxySupplier (org.omg.CosNotifyChannelAdmin.ProxySupplier)4 ConsumerAdmin (org.omg.CosNotifyChannelAdmin.ConsumerAdmin)2 AcsJCORBAProblemEx (alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx)1 AcsEventSubscriber (alma.acs.nc.AcsEventSubscriber)1 NameAlreadyUsed (gov.sandia.NotifyMonitoringExt.NameAlreadyUsed)1 NameMapError (gov.sandia.NotifyMonitoringExt.NameMapError)1 ArrayList (java.util.ArrayList)1 IntHolder (org.omg.CORBA.IntHolder)1 IDLEntity (org.omg.CORBA.portable.IDLEntity)1 AdminLimitExceeded (org.omg.CosNotifyChannelAdmin.AdminLimitExceeded)1 AdminNotFound (org.omg.CosNotifyChannelAdmin.AdminNotFound)1 EventChannel (org.omg.CosNotifyChannelAdmin.EventChannel)1 ProxyNotFound (org.omg.CosNotifyChannelAdmin.ProxyNotFound)1 StructuredProxyPushSupplier (org.omg.CosNotifyChannelAdmin.StructuredProxyPushSupplier)1