Search in sources :

Example 6 with OperatorContext

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

the class AbstractKafkaConsumerOperator method shutdown.

/**
 * Shutdown this operator, which will interrupt the thread executing the
 * <code>produceTuples()</code> method.
 *
 * @throws Exception
 *             Operator failure, will cause the enclosing PE to terminate.
 */
public void shutdown() throws Exception {
    synchronized (monitor) {
        final OperatorContext context = getOperatorContext();
        logger.info(// $NON-NLS-1$ //$NON-NLS-2$
        "Operator " + context.getName() + " shutting down in PE: " + context.getPE().getPEId() + " in Job: " + // $NON-NLS-1$
        context.getPE().getJobId());
        shutdown.set(true);
        if (processThreadEndedLatch != null) {
            processThreadEndedLatch.await(SHUTDOWN_TIMEOUT, SHUTDOWN_TIMEOUT_TIMEUNIT);
            processThreadEndedLatch = null;
        }
        final ConsumerClient consumer = consumerRef.get();
        if (consumer.isProcessing()) {
            consumer.onShutdown(SHUTDOWN_TIMEOUT, SHUTDOWN_TIMEOUT_TIMEUNIT);
        }
        logger.info("Operator " + context.getName() + ": shutdown done");
        // Must call super.shutdown()
        super.shutdown();
    }
}
Also used : DummyConsumerClient(com.ibm.streamsx.kafka.clients.consumer.DummyConsumerClient) NonCrKafkaConsumerClient(com.ibm.streamsx.kafka.clients.consumer.NonCrKafkaConsumerClient) CrKafkaStaticAssignConsumerClient(com.ibm.streamsx.kafka.clients.consumer.CrKafkaStaticAssignConsumerClient) ConsumerClient(com.ibm.streamsx.kafka.clients.consumer.ConsumerClient) OperatorContext(com.ibm.streams.operator.OperatorContext)

Example 7 with OperatorContext

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

the class AbstractKafkaConsumerOperator method checkStartOffsetRequiresPartition.

@ContextCheck(compile = true)
public static void checkStartOffsetRequiresPartition(OperatorContextChecker checker) {
    // parameters startOffset and partition must have the same size - can be checked only at runtime.
    // This implies that partition parameter is required when startOffset is specified - can be checked at compile time.
    OperatorContext operatorContext = checker.getOperatorContext();
    Set<String> parameterNames = operatorContext.getParameterNames();
    if (parameterNames.contains(START_OFFSET_PARAM) && !parameterNames.contains(PARTITION_PARAM)) {
        // $NON-NLS-1$
        checker.setInvalidContext(Messages.getString("PARAM_X_REQUIRED_WHEN_PARAM_Y_USED", PARTITION_PARAM, START_OFFSET_PARAM), new Object[0]);
    }
}
Also used : OperatorContext(com.ibm.streams.operator.OperatorContext) RString(com.ibm.streams.operator.types.RString) ContextCheck(com.ibm.streams.operator.OperatorContext.ContextCheck)

Example 8 with OperatorContext

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

the class AbstractKafkaConsumerOperator method allPortsReady.

@Override
public void allPortsReady() throws Exception {
    synchronized (monitor) {
        OperatorContext context = getOperatorContext();
        logger.info(// $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());
        // start the thread that produces the tuples out of the message queue. The thread runs the produceTuples() method.
        if (processThread != null) {
            processThread.start();
        }
    }
}
Also used : OperatorContext(com.ibm.streams.operator.OperatorContext)

Example 9 with OperatorContext

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

the class QRSDetector method shutdown.

/**
	 * Shutdown this operator.
	 * 
	 * @throws Exception
	 *             Operator failure, will cause the enclosing PE to terminate.
	 */
public synchronized void shutdown() throws Exception {
    OperatorContext context = getOperatorContext();
    logger.trace("Operator " + context.getName() + " shutting down in PE: " + context.getPE().getPEId() + " in Job: " + context.getPE().getJobId());
    super.shutdown();
}
Also used : OperatorContext(com.ibm.streams.operator.OperatorContext)

Example 10 with OperatorContext

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

the class AbstractKafkaConsumerOperator method checkTriggerCommitCount.

@ContextCheck(compile = true)
public static void checkTriggerCommitCount(OperatorContextChecker checker) {
    OperatorContext operatorContext = checker.getOperatorContext();
    ConsistentRegionContext crContext = operatorContext.getOptionalContext(ConsistentRegionContext.class);
    Set<String> parameterNames = operatorContext.getParameterNames();
    if (crContext != null) {
        if (parameterNames.contains(COMMIT_COUNT_PARAM)) {
            System.err.println(Messages.getString("PARAM_IGNORED_IN_CONSITENT_REGION", COMMIT_COUNT_PARAM));
        }
        if (parameterNames.contains(COMMIT_PERIOD_PARAM)) {
            System.err.println(Messages.getString("PARAM_IGNORED_IN_CONSITENT_REGION", COMMIT_PERIOD_PARAM));
        }
        if (crContext.isStartOfRegion()) {
            if (crContext.isTriggerOperator()) {
                // 'triggerCount' parameter required
                if (!parameterNames.contains(TRIGGER_COUNT_PARAM)) {
                    // $NON-NLS-1$
                    checker.setInvalidContext(Messages.getString("TRIGGER_PARAM_MISSING"), new Object[0]);
                }
            } else {
                // periodic CR; 'triggerCount' ignored
                if (parameterNames.contains(TRIGGER_COUNT_PARAM)) {
                    System.err.println(Messages.getString("PARAM_IGNORED_FOR_PERIODIC_CR", TRIGGER_COUNT_PARAM));
                }
            }
        }
    } else {
        // not in a CR ...
        if (parameterNames.contains(TRIGGER_COUNT_PARAM)) {
            System.err.println(Messages.getString("PARAM_IGNORED_NOT_IN_CONSITENT_REGION", TRIGGER_COUNT_PARAM));
        }
        if (parameterNames.contains(COMMIT_COUNT_PARAM) && parameterNames.contains(COMMIT_PERIOD_PARAM)) {
            // $NON-NLS-1$
            checker.setInvalidContext(Messages.getString("PARAMETERS_EXCLUDE_EACH_OTHER", COMMIT_COUNT_PARAM, COMMIT_PERIOD_PARAM), new Object[0]);
        }
    }
}
Also used : ConsistentRegionContext(com.ibm.streams.operator.state.ConsistentRegionContext) OperatorContext(com.ibm.streams.operator.OperatorContext) RString(com.ibm.streams.operator.types.RString) ContextCheck(com.ibm.streams.operator.OperatorContext.ContextCheck)

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