Search in sources :

Example 1 with ConstraintExp

use of org.omg.CosNotifyFilter.ConstraintExp 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)

Example 2 with ConstraintExp

use of org.omg.CosNotifyFilter.ConstraintExp in project ACS by ACS-Community.

the class Consumer method addFilter.

/**
	 * Adds a single filter to this consumer. With ALMA's use of IDL structs for
	 * ICD events, this method is no longer useful. May become deprecated in
	 * future ACS releases.
	 * 
	 * @return The filter ID of the newly created filter. This is only useful for
	 *         removing filters. Returns -1 on failure.
	 * @param structClassName
	 *           IDL struct Java class filter is to be applied to.
	 * @param filter
	 *           The filter string in extended trader constraint language.
	 * @throws AcsJException
	 *            Thrown if there is some CORBA problem (like the filter is not
	 *            using the correct grammar).
	 */
public int addFilter(Class<? extends IDLEntity> structClassName, String filter) throws AcsJException {
    String type = structClassName.getName().substring(structClassName.getName().lastIndexOf('.') + 1);
    try {
        FilterFactory t_filterFactory = m_channel.default_filter_factory();
        // create the filter
        Filter t_filter = t_filterFactory.create_filter(getFilterLanguage());
        EventType[] t_eType = { new EventType(getChannelDomain(), type) };
        ConstraintExp[] t_cexp = { new ConstraintExp(t_eType, filter) };
        t_filter.add_constraints(t_cexp);
        // add the filter to the proxy
        return m_proxySupplier.add_filter(t_filter);
    } catch (org.omg.CosNotifyFilter.InvalidGrammar e) {
        String msg = "'" + filter + "' filter is invalid for the '" + m_channelName + "' channel: ";
        throw new alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx(msg + e.getMessage());
    } catch (org.omg.CosNotifyFilter.InvalidConstraint e) {
        String msg = "'" + filter + "' filter is invalid for the '" + m_channelName + "' channel: ";
        throw new alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx(msg + e.getMessage());
    }
}
Also used : 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)2 EventType (org.omg.CosNotification.EventType)2 ConstraintExp (org.omg.CosNotifyFilter.ConstraintExp)2 Filter (org.omg.CosNotifyFilter.Filter)2 FilterFactory (org.omg.CosNotifyFilter.FilterFactory)2 InvalidEventType (org.omg.CosNotifyComm.InvalidEventType)1