Search in sources :

Example 1 with AcsJCORBAProblemEx

use of alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx 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 AcsJCORBAProblemEx

use of alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx in project ACS by ACS-Community.

the class Helper method createNotificationChannel.

/**
	 * Tries to create a notification channel (using quality of service and administrative properties 
	 * specified by configQofS() and configAdminProps() respectively).
	 * If this succeeds, then registers this channel with the naming service.
	 * <p>
	 * Should only be invoked when the channel that this supplier or consumer is attempting to connect to
	 * does not exist.
	 * However even with prior check for the existence of this channel, a race condition with other suppliers or consumers
	 * can lead to multiple attempts to create the same channel, which will result in <code>NameAlreadyUsed</code> exception.
	 * <p>
	 * Design note: Currently the TAO notification extensions are used to synch channel creation with other clients
	 * by supplying the channel name to the factory.
	 * If we want to use only standard NC factories then we'd have to implement our own locking mechanisms in all 
	 * ACS consumer and supplier classes, see http://jira.alma.cl/browse/COMP-2808
	 * 
	 * @return Reference to the newly created channel.
	 * @param channelKind
	 *           Kind of the channel as registered with the CORBA naming service.
	 * @param notifyFactoryName
	 *           Name of the notification service as registered with the CORBA naming service.
	 * @throws AcsJException
	 *            Standard ACS Java exception.
	 * @throws NameAlreadyUsed thrown if the channel of this name already exists.
	 */
protected EventChannel createNotificationChannel(String channelKind, String notifyFactoryName) throws AcsJException, NameAlreadyUsed {
    LOG_NC_ChannelCreated_ATTEMPT.log(m_logger, channelName, notifyFactoryName);
    // return value
    EventChannel retValue = null;
    // to be assigned by factory
    channelId = -1;
    StopWatch stopwatch = new StopWatch();
    try {
        initializeNotifyFactory(notifyFactoryName);
        // create the channel
        // here we use the channel properties taken directly from our channel properties helper object. 
        // presumably these values come from the ACS configuration database.
        IntHolder channelIdHolder = new IntHolder();
        retValue = createNotifyChannel_internal(m_channelProperties.configQofS(channelName), m_channelProperties.configAdminProps(channelName), channelIdHolder);
        // sanity check
        if (retValue == null) {
            // a null reference implies we cannot go any further
            Throwable cause = new Throwable("Null reference obtained for the '" + channelName + "' channel!");
            // TODO: more specific ex type
            throw new alma.ACSErrTypeJavaNative.wrappers.AcsJJavaLangEx(cause);
        }
        channelId = channelIdHolder.value;
        // register our new channel with the naming service
        try {
            NameComponent[] t_NameChannel = { new NameComponent(combineChannelAndDomainName(channelName, domainName), channelKind) };
            getNamingService().rebind(t_NameChannel, retValue);
            // Create an entry into the Naming Service to store the timestamp of the channel in order to allow
            // subscribers to reconnect to the channel (ICT-4730)
            int maxNumAttempts = 10;
            int nAttempts = maxNumAttempts;
            boolean timestampCreated = setChannelTimestamp(retValue);
            while (false == timestampCreated && nAttempts > 0) {
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException ex1) {
                // too bad
                }
                nAttempts--;
                timestampCreated = setChannelTimestamp(retValue);
            }
            if (false == timestampCreated) {
                Throwable cause = new Throwable("Failed to register the timestamp of the channel '" + channelName + "' into the Naming Service after " + String.valueOf(maxNumAttempts) + " attempts");
                // TODO: more specific ex type
                throw new alma.ACSErrTypeJavaNative.wrappers.AcsJJavaLangEx(cause);
            }
        } catch (org.omg.CosNaming.NamingContextPackage.NotFound ex) {
            // Corba spec: "If already bound, the previous binding must be of type nobject; 
            //              otherwise, a NotFound exception with a why reason of not_object is raised."
            String reason = "Failed to register the new channel '" + channelName + "' with the Naming Service: " + ex.why.toString();
            AcsJCORBAProblemEx ex2 = new AcsJCORBAProblemEx(ex);
            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);
    } catch (org.omg.CosNotification.UnsupportedQoS e) {
        Throwable cause = new Throwable("The quality of service properties specified for the '" + channelName + "' channel are unsupported: " + e.getMessage());
        throw new alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx(cause);
    }
    LOG_NC_ChannelCreated_OK.log(m_logger, channelName, channelId, notifyFactoryName, stopwatch.getLapTimeMillis());
    return retValue;
}
Also used : AcsJCORBAProblemEx(alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx) NameComponent(org.omg.CosNaming.NameComponent) UnsupportedQoS(org.omg.CosNotification.UnsupportedQoS) StopWatch(alma.acs.util.StopWatch) EventChannel(gov.sandia.NotifyMonitoringExt.EventChannel) IntHolder(org.omg.CORBA.IntHolder) AcsJCORBAProblemEx(alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx)

Example 3 with AcsJCORBAProblemEx

use of alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx 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 4 with AcsJCORBAProblemEx

use of alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx in project ACS by ACS-Community.

the class NCSubscriber method notifyFirstSubscription.

/**
	 * Adds a filter on the server-side supplier proxy that lets the given event type pass through.
	 * <p>
	 * Note that we derive the event type name from the simple class name of <code>struct</code>, 
	 * as done in other parts of ACS, which requires IDL event structs to have globally unique names 
	 * across IDL name spaces.
	 * <p>
	 * If <code>structClass</code> is <code>null</code> (generic subscription), 
	 * then "<code>*</code>" is used as the event type name,
	 * which in ETCL is understood as a wildcard for all event type names. 
	 * 
	 * @param structClass
	 * @throws AcsJEventSubscriptionEx
	 */
@Override
protected void notifyFirstSubscription(Class<?> structClass) throws AcsJEventSubscriptionEx {
    String eventTypeNameShort = (structClass == null ? "*" : structClass.getSimpleName());
    try {
        int filterId = addFilter(eventTypeNameShort);
        subscriptionsFilters.put(eventTypeNameShort, filterId);
    } catch (AcsJCORBAProblemEx e) {
        throw new AcsJEventSubscriptionEx(e);
    }
}
Also used : AcsJEventSubscriptionEx(alma.acsErrTypeLifeCycle.wrappers.AcsJEventSubscriptionEx) AcsJCORBAProblemEx(alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx)

Example 5 with AcsJCORBAProblemEx

use of alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx in project ACS by ACS-Community.

the class NCSubscriber method addFilter.

/**
	 * This method manages the filtering capabilities used to control subscriptions.
	 * <p>
	 * A constraint evaluates to true when both of the following conditions are true:
	 *   A member of the constraint's EventTypeSeq matches the message's event type.
	 *   The constraint expression evaluates to true.
	 * 
	 * @return FilterID (see OMG NotificationService spec 3.2.4.1)
	 * @throws AcsJCORBAProblemEx
	 */
protected int addFilter(String eventTypeName) throws AcsJCORBAProblemEx {
    try {
        // Create the filter
        FilterFactory filterFactory = channel.default_filter_factory();
        Filter filter = filterFactory.create_filter(getFilterLanguage());
        // Information needed to construct the constraint expression object
        // (any domain, THE event type)
        // Note that TAO will internally convert the event type name 
        // to the expression "$type_name=='<our_eventTypeName>'", 
        // see orbsvcs/Notify/Notify_Constraint_Interpreter.cpp
        // The old Consumer class used 'getChannelDomain()' instead of "*"..?
        EventType[] t_info = { new EventType("*", eventTypeName) };
        // Add constraint expression object to the filter
        // no constraints other than the eventTypeName already given above
        String constraint_expr = "";
        ConstraintExp[] cexp = { new ConstraintExp(t_info, constraint_expr) };
        filter.add_constraints(cexp);
        // Add the filter to the proxy and return the filter ID
        int filterId = proxySupplier.add_filter(filter);
        if (logger.isLoggable(AcsLogLevel.DELOUSE)) {
            NcFilterInspector insp = new NcFilterInspector(proxySupplier, channelName + "::" + clientName + "::ProxySupplier", logger);
            logger.log(AcsLogLevel.DELOUSE, "Added filter for '" + eventTypeName + "'. Current " + insp.getFilterInfo());
        //				NcFilterInspector insp2 = new NcFilterInspector(
        //						sharedConsumerAdmin, channelName + "::" + clientName + "::Admin", logger);
        //				logger.log(AcsLogLevel.DEBUG, "Admin filters: " + insp2.getFilterInfo());
        }
        return filterId;
    } catch (org.omg.CosNotifyFilter.InvalidGrammar e) {
        Throwable cause = new Throwable("'" + eventTypeName + "' filter is invalid for the '" + channelName + "' channel: " + e.getMessage());
        throw new alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx(cause);
    } catch (org.omg.CosNotifyFilter.InvalidConstraint e) {
        Throwable cause = new Throwable("'" + eventTypeName + "' filter is invalid for the '" + channelName + "' channel: " + e.getMessage());
        throw new alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx(cause);
    }
}
Also used : InvalidEventType(org.omg.CosNotifyComm.InvalidEventType) EventType(org.omg.CosNotification.EventType) ConstraintExp(org.omg.CosNotifyFilter.ConstraintExp) FilterFactory(org.omg.CosNotifyFilter.FilterFactory) Filter(org.omg.CosNotifyFilter.Filter) AcsJCORBAProblemEx(alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx)

Aggregations

AcsJCORBAProblemEx (alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx)13 NameMapError (gov.sandia.NotifyMonitoringExt.NameMapError)4 BAD_PARAM (org.omg.CORBA.BAD_PARAM)4 IntHolder (org.omg.CORBA.IntHolder)4 AcsJNarrowFailedEx (alma.ACSErrTypeCORBA.wrappers.AcsJNarrowFailedEx)3 NameAlreadyUsed (gov.sandia.NotifyMonitoringExt.NameAlreadyUsed)3 AdminLimitExceeded (org.omg.CosNotifyChannelAdmin.AdminLimitExceeded)3 LogLevels (alma.Logging.LoggingConfigurablePackage.LogLevels)2 AcsJException (alma.acs.exceptions.AcsJException)2 StopWatch (alma.acs.util.StopWatch)2 EventChannel (gov.sandia.NotifyMonitoringExt.EventChannel)2 SystemException (org.omg.CORBA.SystemException)2 TIMEOUT (org.omg.CORBA.TIMEOUT)2 NameComponent (org.omg.CosNaming.NameComponent)2 AcsJCORBAReferenceNilEx (alma.ACSErrTypeCORBA.wrappers.AcsJCORBAReferenceNilEx)1 AcsJIllegalArgumentEx (alma.ACSErrTypeCommon.wrappers.AcsJIllegalArgumentEx)1 AcsJUnexpectedExceptionEx (alma.ACSErrTypeCommon.wrappers.AcsJUnexpectedExceptionEx)1 AcsJContainerServicesEx (alma.JavaContainerError.wrappers.AcsJContainerServicesEx)1 LoggerDoesNotExistEx (alma.Logging.LoggerDoesNotExistEx)1 AcsLogLevel (alma.acs.logging.AcsLogLevel)1