Search in sources :

Example 1 with AcsJNarrowFailedEx

use of alma.ACSErrTypeCORBA.wrappers.AcsJNarrowFailedEx in project ACS by ACS-Community.

the class Helper method initializeNotifyFactory.

/**
	 * @param notifyFactoryName
	 * @throws AcsJException AcsJCORBAProblemEx if the NotifyService reference cannot be retrieved from the NamingService;
	 *                       AcsJNarrowFailedEx if the NotifyService is not of the required TAO extension type.
	 */
protected void initializeNotifyFactory(String notifyFactoryName) throws AcsJException {
    if (notifyFactory == null) {
        final String standardEventFactoryId = org.omg.CosNotifyChannelAdmin.EventChannelFactoryHelper.id();
        final String specialEventFactoryId = gov.sandia.NotifyMonitoringExt.EventChannelFactoryHelper.id();
        // get the Notification Factory first.
        NameComponent[] t_NameFactory = { new NameComponent(notifyFactoryName, "") };
        org.omg.CORBA.Object notifyFactoryObj = null;
        //notifyFactory = null;
        try {
            notifyFactoryObj = getNamingService().resolve(t_NameFactory);
        } catch (org.omg.CosNaming.NamingContextPackage.NotFound ex) {
            String reason = "The CORBA Notification Service '" + notifyFactoryName + "' is not registered in the Naming Service: " + ex.why.toString();
            AcsJCORBAProblemEx ex2 = new AcsJCORBAProblemEx();
            ex2.setInfo(reason);
            throw ex2;
        } catch (org.omg.CosNaming.NamingContextPackage.CannotProceed e) {
            // Think there is virtually no chance of this every happening but...
            Throwable cause = new Throwable(e.getMessage());
            throw new alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx(cause);
        } catch (org.omg.CosNaming.NamingContextPackage.InvalidName e) {
            // Think there is virtually no chance of this every happening but...
            Throwable cause = new Throwable(e.getMessage());
            throw new alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx(cause);
        }
        // narrow the notification factory to the TAO extension subtype
        try {
            notifyFactory = EventChannelFactoryHelper.narrow(notifyFactoryObj);
        } catch (BAD_PARAM ex) {
            if (notifyFactoryObj._is_a(standardEventFactoryId)) {
                LOG_NC_TaoExtensionsSubtypeMissing.log(m_logger, notifyFactoryName, specialEventFactoryId, standardEventFactoryId);
            } else {
                LOG_NC_TaoExtensionsSubtypeMissing.log(m_logger, notifyFactoryName, specialEventFactoryId, "???");
            }
            AcsJNarrowFailedEx ex2 = new AcsJNarrowFailedEx(ex);
            ex2.setNarrowType(specialEventFactoryId);
            throw ex2;
        }
    }
}
Also used : AcsJCORBAProblemEx(alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx) NameComponent(org.omg.CosNaming.NameComponent) BAD_PARAM(org.omg.CORBA.BAD_PARAM) AcsJNarrowFailedEx(alma.ACSErrTypeCORBA.wrappers.AcsJNarrowFailedEx) AcsJCORBAProblemEx(alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx)

Example 2 with AcsJNarrowFailedEx

use of alma.ACSErrTypeCORBA.wrappers.AcsJNarrowFailedEx in project ACS by ACS-Community.

the class NCPublisher method init.

/**
	 * Initializes NCPublisher
	 * @param namingService Naming service
	 * @throws AcsJException
	 *             There are literally dozens of CORBA exceptions that could be
	 *             thrown by the NCPublisher class. Instead, these are
	 *             converted into an ACS Error System exception for the
	 *             developer's convenience.
	 */
protected synchronized void init(NamingContext namingService) throws AcsJException {
    helper = new Helper(channelName, channelNotifyServiceDomainName, this.services, namingService);
    isTraceEventsEnabled = helper.getChannelProperties().isTraceEventsEnabled(this.channelName);
    // get the channel
    // @TODO: handle Corba TIMEOUT 
    channel = helper.getNotificationChannel(getNotificationFactoryName());
    // Corba NC spec about adminId: a unique identifier assigned by the target EventChannel instance that is unique among all 
    // SupplierAdmin instances currently associated with the channel.
    // We are currently not using it, but it could be logged to help with NC debugging.
    IntHolder adminIdHolder = new IntHolder();
    org.omg.CosNotifyChannelAdmin.SupplierAdmin supplierAdminBase = null;
    try {
        supplierAdminBase = channel.new_for_suppliers(InterFilterGroupOperator.AND_OP, adminIdHolder);
    } catch (TIMEOUT ex) {
        // found in http://jira.alma.cl/browse/COMP-6312
        throw new AcsJCORBAProblemEx(ex);
    }
    if (supplierAdminBase == null) {
        AcsJCORBAReferenceNilEx ex = new AcsJCORBAReferenceNilEx();
        ex.setVariable("supplierAdminBase");
        ex.setContext("Null reference obtained for the supplier admin for channel " + this.channelName);
        throw ex;
    }
    try {
        supplierAdmin = gov.sandia.NotifyMonitoringExt.SupplierAdminHelper.narrow(supplierAdminBase);
    } catch (BAD_PARAM ex) {
        // This should never happen, since we already enforced the presence of TAO extensions in Helper#initializeNotifyFactory
        String specialSupplierAdminId = gov.sandia.NotifyMonitoringExt.SupplierAdminHelper.id();
        String standardSupplierAdminId = org.omg.CosNotifyChannelAdmin.SupplierAdminHelper.id();
        LOG_NC_TaoExtensionsSubtypeMissing.log(logger, channelName + "-SupplierAdmin", specialSupplierAdminId, standardSupplierAdminId);
        AcsJNarrowFailedEx ex2 = new AcsJNarrowFailedEx(ex);
        ex2.setNarrowType(specialSupplierAdminId);
        throw ex2;
    }
    int proxyCreationAttempts = 0;
    while (proxyConsumer == null) {
        String randomizedClientName = Helper.createRandomizedClientName(services.getName());
        // Holder for the unique ID assigned by the admin object. It is different from the name we set, and will be discarded.
        IntHolder proxyIdHolder = new IntHolder();
        proxyCreationAttempts++;
        try {
            // Create the consumer proxy (to which the published events will be fed) with a name.
            // The client type parameter selects a StructuredProxyPushConsumer (based on Structured Events),
            // as opposed to ProxyPushConsumer (based on Anys), or SequenceProxyPushConsumer (based on sequences of Structured Events).
            org.omg.CORBA.Object tempCorbaObj = supplierAdmin.obtain_named_notification_push_consumer(ClientType.STRUCTURED_EVENT, proxyIdHolder, randomizedClientName.toString());
            if (tempCorbaObj == null) {
                AcsJCORBAReferenceNilEx ex = new AcsJCORBAReferenceNilEx();
                ex.setVariable("tempCorbaObj");
                ex.setContext("Null reference obtained for the Proxy Push Consumer for publisher " + services.getName());
                // @TODO destroy supplierAdmin
                throw ex;
            }
            proxyConsumer = StructuredProxyPushConsumerHelper.narrow(tempCorbaObj);
            LOG_NC_ConsumerProxyCreation_OK.log(logger, proxyIdHolder.value, randomizedClientName, proxyCreationAttempts, services.getName(), channelName, getNotificationFactoryName());
        } 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.
            logger.fine("Consumer proxy name '" + randomizedClientName + "' already in use. Will try again with different random number appended.");
        } catch (NameMapError ex) {
            // Default to the unnamed version
            try {
                proxyConsumer = StructuredProxyPushConsumerHelper.narrow(supplierAdmin.obtain_notification_push_consumer(ClientType.STRUCTURED_EVENT, proxyIdHolder));
                LOG_NC_ConsumerProxyCreation_OK.log(logger, proxyIdHolder.value, "-unknown-", proxyCreationAttempts, services.getName(), channelName, getNotificationFactoryName());
            } catch (AdminLimitExceeded ex2) {
                LOG_NC_ConsumerProxyCreation_FAIL.log(logger, services.getName(), channelName, getNotificationFactoryName(), ex2.getMessage());
                // @TODO destroy supplierAdmin
                throw new AcsJCORBAProblemEx(ex2);
            }
        } catch (AdminLimitExceeded e) {
            LOG_NC_ConsumerProxyCreation_FAIL.log(logger, services.getName(), channelName, getNotificationFactoryName(), e.getMessage());
            // @TODO destroy supplierAdmin
            throw new AcsJCORBAProblemEx(e);
        }
    }
    // Avoid future calls from the NC to #subscription_change(EventType[], EventType[]). See Corba spec 3.4.1.3
    // @TODO: If we use ALL_NOW_UPDATES_ON then we could actually suppress sending of event types that no consumer wants to get. 
    proxyConsumer.obtain_subscription_types(ObtainInfoMode.NONE_NOW_UPDATES_OFF);
    // see 3.4.4.1 of Notification Service, v1.1
    try {
        StructuredPushSupplier thisSps = StructuredPushSupplierHelper.narrow(this.services.activateOffShoot(this));
        proxyConsumer.connect_structured_push_supplier(thisSps);
    } catch (AcsJContainerServicesEx e) {
        // @TODO destroy supplierAdmin and proxyConsumer
        throw new AcsJCORBAProblemEx(e);
    } catch (AlreadyConnected e) {
        // @TODO destroy supplierAdmin and proxyConsumer
        throw new AcsJCORBAProblemEx(e);
    }
    reconnectCallback = new AcsNcReconnectionCallback(this, logger);
    reconnectCallback.registerForReconnect(services, helper.getNotifyFactory());
}
Also used : StructuredPushSupplier(org.omg.CosNotifyComm.StructuredPushSupplier) AcsJCORBAProblemEx(alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx) AdminLimitExceeded(org.omg.CosNotifyChannelAdmin.AdminLimitExceeded) AlreadyConnected(org.omg.CosEventChannelAdmin.AlreadyConnected) BAD_PARAM(org.omg.CORBA.BAD_PARAM) AcsJContainerServicesEx(alma.JavaContainerError.wrappers.AcsJContainerServicesEx) EventDescriptionHelper(alma.acsnc.EventDescriptionHelper) StructuredProxyPushConsumerHelper(org.omg.CosNotifyChannelAdmin.StructuredProxyPushConsumerHelper) StructuredPushSupplierHelper(org.omg.CosNotifyComm.StructuredPushSupplierHelper) AcsJCORBAReferenceNilEx(alma.ACSErrTypeCORBA.wrappers.AcsJCORBAReferenceNilEx) NameMapError(gov.sandia.NotifyMonitoringExt.NameMapError) IntHolder(org.omg.CORBA.IntHolder) NameAlreadyUsed(gov.sandia.NotifyMonitoringExt.NameAlreadyUsed) TIMEOUT(org.omg.CORBA.TIMEOUT) AcsJNarrowFailedEx(alma.ACSErrTypeCORBA.wrappers.AcsJNarrowFailedEx)

Example 3 with AcsJNarrowFailedEx

use of alma.ACSErrTypeCORBA.wrappers.AcsJNarrowFailedEx 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)

Example 4 with AcsJNarrowFailedEx

use of alma.ACSErrTypeCORBA.wrappers.AcsJNarrowFailedEx in project ACS by ACS-Community.

the class Helper method createNotifyChannel_internal.

/**
	 * Broken out from {@link #createNotificationChannel(String, String, String)}
	 * to give tests better control about the timing when this call to the event factory is made.
	 * @throws NameAlreadyUsed if the call to NotifyFactory#create_named_channel fails with this exception.
	 * @throws AcsJCORBAProblemEx if the TAO extension throws a NameMapError or if the QoS attributes cause a UnsupportedAdmin.
	 */
protected EventChannel createNotifyChannel_internal(Property[] initial_qos, Property[] initial_admin, IntHolder channelIdHolder) throws NameAlreadyUsed, UnsupportedQoS, AcsJNarrowFailedEx, AcsJCORBAProblemEx {
    EventChannel ret = null;
    StopWatch stopwatch = new StopWatch();
    try {
        // The TAO extension of the notify factory that we use declares only the plain EventChannel type, 
        // even though it creates the TAO-extension subtype.
        org.omg.CosNotifyChannelAdmin.EventChannel eventChannelBaseType = notifyFactory.create_named_channel(initial_qos, initial_admin, channelIdHolder, channelName);
        LOG_NC_ChannelCreatedRaw_OK.log(m_logger, channelName, channelIdHolder.value, stopwatch.getLapTimeMillis());
        // re-create the client side corba stub, to get the extension subtype
        ret = gov.sandia.NotifyMonitoringExt.EventChannelHelper.narrow(eventChannelBaseType);
    } catch (BAD_PARAM ex) {
        LOG_NC_TaoExtensionsSubtypeMissing.log(m_logger, channelName, EventChannel.class.getName(), org.omg.CosNotifyChannelAdmin.EventChannelHelper.id());
        AcsJNarrowFailedEx ex2 = new AcsJNarrowFailedEx(ex);
        ex2.setNarrowType(EventChannelHelper.id());
        throw ex2;
    } catch (NameMapError ex) {
        String msg = "Got a TAO extension-specific NameMapError exception that means the TAO NC extension is not usable. Bailing out since we need the extension.";
        m_logger.log(AcsLogLevel.ERROR, msg, ex);
        AcsJCORBAProblemEx ex2 = new AcsJCORBAProblemEx(ex);
        ex2.setInfo(msg);
        throw ex2;
    } catch (UnsupportedAdmin ex) {
        AcsJCORBAProblemEx ex2 = new AcsJCORBAProblemEx(ex);
        ex2.setInfo(createUnsupportedAdminLogMessage(ex));
        throw ex2;
    }
    return ret;
}
Also used : EventChannel(gov.sandia.NotifyMonitoringExt.EventChannel) AcsJCORBAProblemEx(alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx) NameMapError(gov.sandia.NotifyMonitoringExt.NameMapError) BAD_PARAM(org.omg.CORBA.BAD_PARAM) AcsJNarrowFailedEx(alma.ACSErrTypeCORBA.wrappers.AcsJNarrowFailedEx) UnsupportedAdmin(org.omg.CosNotification.UnsupportedAdmin) StopWatch(alma.acs.util.StopWatch)

Aggregations

AcsJNarrowFailedEx (alma.ACSErrTypeCORBA.wrappers.AcsJNarrowFailedEx)4 BAD_PARAM (org.omg.CORBA.BAD_PARAM)4 AcsJCORBAProblemEx (alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx)3 NameMapError (gov.sandia.NotifyMonitoringExt.NameMapError)2 IntHolder (org.omg.CORBA.IntHolder)2 AcsJCORBAReferenceNilEx (alma.ACSErrTypeCORBA.wrappers.AcsJCORBAReferenceNilEx)1 AcsJContainerServicesEx (alma.JavaContainerError.wrappers.AcsJContainerServicesEx)1 StopWatch (alma.acs.util.StopWatch)1 EventDescriptionHelper (alma.acsnc.EventDescriptionHelper)1 ConsumerAdmin (gov.sandia.NotifyMonitoringExt.ConsumerAdmin)1 EventChannel (gov.sandia.NotifyMonitoringExt.EventChannel)1 NameAlreadyUsed (gov.sandia.NotifyMonitoringExt.NameAlreadyUsed)1 TIMEOUT (org.omg.CORBA.TIMEOUT)1 AlreadyConnected (org.omg.CosEventChannelAdmin.AlreadyConnected)1 NameComponent (org.omg.CosNaming.NameComponent)1 UnsupportedAdmin (org.omg.CosNotification.UnsupportedAdmin)1 AdminLimitExceeded (org.omg.CosNotifyChannelAdmin.AdminLimitExceeded)1 AdminNotFound (org.omg.CosNotifyChannelAdmin.AdminNotFound)1 InterFilterGroupOperator (org.omg.CosNotifyChannelAdmin.InterFilterGroupOperator)1 StructuredProxyPushConsumerHelper (org.omg.CosNotifyChannelAdmin.StructuredProxyPushConsumerHelper)1