Search in sources :

Example 1 with OperatorContext

use of com.ibm.streams.operator.OperatorContext in project streamsx.health by IBMStreams.

the class QRSDetector method allPortsReady.

/**
	 * Notification that initialization is complete and all input and output
	 * ports are connected and ready to receive and submit tuples.
	 * 
	 * @throws Exception
	 *             Operator failure, will cause the enclosing PE to terminate.
	 */
@Override
public synchronized void allPortsReady() throws Exception {
    OperatorContext context = getOperatorContext();
    logger.trace("Operator " + context.getName() + " all ports are ready in PE: " + context.getPE().getPEId() + " in Job: " + context.getPE().getJobId());
}
Also used : OperatorContext(com.ibm.streams.operator.OperatorContext)

Example 2 with OperatorContext

use of com.ibm.streams.operator.OperatorContext in project streamsx.kafka by IBMStreams.

the class AbstractKafkaConsumerOperator method warnStartPositionParamRequiresJCP.

// @ContextCheck (compile = true)
public static void warnStartPositionParamRequiresJCP(OperatorContextChecker checker) {
    OperatorContext opCtx = checker.getOperatorContext();
    Set<String> paramNames = opCtx.getParameterNames();
    List<StreamingInput<Tuple>> inputPorts = opCtx.getStreamingInputs();
    if (opCtx.getOptionalContext(ConsistentRegionContext.class) == null && (paramNames.contains(START_POSITION_PARAM) || paramNames.contains(START_POSITION_STR_PARAM)) && inputPorts.size() == 0) {
        System.err.println(Messages.getString("WARN_ENSURE_JCP_ADDED_STARTPOS_NOT_DEFAULT", opCtx.getKind()));
    }
}
Also used : ConsistentRegionContext(com.ibm.streams.operator.state.ConsistentRegionContext) StreamingInput(com.ibm.streams.operator.StreamingInput) OperatorContext(com.ibm.streams.operator.OperatorContext) RString(com.ibm.streams.operator.types.RString)

Example 3 with OperatorContext

use of com.ibm.streams.operator.OperatorContext in project streamsx.kafka by IBMStreams.

the class AbstractKafkaProducerOperator method checkConsistentRegion.

@ContextCheck(compile = true)
public static void checkConsistentRegion(OperatorContextChecker checker) {
    // check that the operator is not the start of the consistent region
    OperatorContext opContext = checker.getOperatorContext();
    ConsistentRegionContext crContext = opContext.getOptionalContext(ConsistentRegionContext.class);
    if (crContext != null) {
        if (crContext.isStartOfRegion()) {
            // //$NON-NLS-1$
            checker.setInvalidContext(Messages.getString("OPERATOR_NOT_START_OF_CONSISTENT_REGION", opContext.getKind()), new Object[0]);
        }
    }
}
Also used : ConsistentRegionContext(com.ibm.streams.operator.state.ConsistentRegionContext) OperatorContext(com.ibm.streams.operator.OperatorContext) ContextCheck(com.ibm.streams.operator.OperatorContext.ContextCheck)

Example 4 with OperatorContext

use of com.ibm.streams.operator.OperatorContext in project streamsx.kafka by IBMStreams.

the class AbstractKafkaProducerOperator method checkTopicAttributeTypeOrTopicParameter.

/**
 * If the `topicAttribute` is not defined, then the operator will look
 * for an input attribute called "topic". Here, we need to check that this
 * input attribute is of type "rstring".
 * When the `topicAttribute`parameter is used, the Streams compiler will do the
 * attribute type check.
 * When neither the `topicAttribute` parameter is used nor a `topic` attribute with rstring type exists,
 * the `topic` parameter must be used.
 */
@ContextCheck(compile = true)
public static void checkTopicAttributeTypeOrTopicParameter(OperatorContextChecker checker) {
    /*
         * For topics, one of the following must be true: 
         *  * the 'topic' parameter is specified that lists topics to write to
         *  * the 'topicAttribute' parameter is specified that points to an input attribute containing the topic to write to
         *  * neither of the above parameters are specified but the input schema contains an attribute named "topic"
         *  
         * An invalid context is set if none of the above conditions are true
         */
    final OperatorContext operatorContext = checker.getOperatorContext();
    if (!operatorContext.getParameterNames().contains(TOPIC_PARAM_NAME)) {
        // no topic parameter - check presence of topicAttribute parameter
        if (!operatorContext.getParameterNames().contains(TOPICATTR_PARAM_NAME)) {
            // no topicAttribute parameter - check presence and type of 'topic' attribute
            StreamSchema schema = operatorContext.getStreamingInputs().get(0).getStreamSchema();
            // $NON-NLS-1$
            Attribute topicAttribute = schema.getAttribute(DEFAULT_TOPIC_ATTR_NAME);
            if (topicAttribute != null) {
                if (!checker.checkAttributeType(topicAttribute, MetaType.RSTRING, MetaType.BSTRING, MetaType.USTRING)) {
                    checker.setInvalidContext(Messages.getString("TOPIC_ATTRIBUTE_NOT_STRING"), new Object[0]);
                }
            } else {
                // no topic parameter, "topic" input attribute does not exist...set invalid context
                // $NON-NLS-1$
                checker.setInvalidContext(Messages.getString("TOPIC_NOT_SPECIFIED"), new Object[0]);
            }
        }
    }
}
Also used : Attribute(com.ibm.streams.operator.Attribute) DefaultAttribute(com.ibm.streams.operator.model.DefaultAttribute) TupleAttribute(com.ibm.streams.operator.TupleAttribute) OperatorContext(com.ibm.streams.operator.OperatorContext) StreamSchema(com.ibm.streams.operator.StreamSchema) ContextCheck(com.ibm.streams.operator.OperatorContext.ContextCheck)

Example 5 with OperatorContext

use of com.ibm.streams.operator.OperatorContext in project streamsx.kafka by IBMStreams.

the class AbstractKafkaProducerOperator method allPortsReady.

/**
 * Notification that initialization is complete and all input and output
 * ports are connected and ready to receive and submit tuples.
 *
 * @throws Exception
 *             Operator failure, will cause the enclosing PE to terminate.
 */
@Override
public synchronized void allPortsReady() throws Exception {
    OperatorContext context = getOperatorContext();
    logger.trace(// $NON-NLS-1$ //$NON-NLS-2$
    "Operator " + context.getName() + " all ports are ready in PE: " + context.getPE().getPEId() + " in Job: " + // $NON-NLS-1$
    context.getPE().getJobId());
    if (this.errorPortSubmitter != null)
        this.errorPortSubmitter.start();
}
Also used : OperatorContext(com.ibm.streams.operator.OperatorContext)

Aggregations

OperatorContext (com.ibm.streams.operator.OperatorContext)16 ContextCheck (com.ibm.streams.operator.OperatorContext.ContextCheck)7 Attribute (com.ibm.streams.operator.Attribute)4 StreamSchema (com.ibm.streams.operator.StreamSchema)4 TupleAttribute (com.ibm.streams.operator.TupleAttribute)4 DefaultAttribute (com.ibm.streams.operator.model.DefaultAttribute)4 ConsistentRegionContext (com.ibm.streams.operator.state.ConsistentRegionContext)4 RString (com.ibm.streams.operator.types.RString)3 StreamingInput (com.ibm.streams.operator.StreamingInput)1 Type (com.ibm.streams.operator.Type)1 MetaType (com.ibm.streams.operator.Type.MetaType)1 OptionalType (com.ibm.streams.operator.meta.OptionalType)1 TupleType (com.ibm.streams.operator.meta.TupleType)1 Checkpoint (com.ibm.streams.operator.state.Checkpoint)1 ConsumerClient (com.ibm.streamsx.kafka.clients.consumer.ConsumerClient)1 CrKafkaStaticAssignConsumerClient (com.ibm.streamsx.kafka.clients.consumer.CrKafkaStaticAssignConsumerClient)1 DummyConsumerClient (com.ibm.streamsx.kafka.clients.consumer.DummyConsumerClient)1 NonCrKafkaConsumerClient (com.ibm.streamsx.kafka.clients.consumer.NonCrKafkaConsumerClient)1