use of com.ibm.streams.operator.OperatorContext in project streamsx.kafka by IBMStreams.
the class AbstractKafkaProducerOperator method checkErrorPortSchema.
@ContextCheck(compile = true)
public static void checkErrorPortSchema(OperatorContextChecker checker) {
final OperatorContext opCtx = checker.getOperatorContext();
final int nOPorts = opCtx.getNumberOfStreamingOutputs();
if (nOPorts == 0)
return;
StreamSchema inPortSchema = opCtx.getStreamingInputs().get(0).getStreamSchema();
StreamSchema outSchema = opCtx.getStreamingOutputs().get(0).getStreamSchema();
if (outSchema.getAttributeCount() > 2) {
// $NON-NLS-1$
checker.setInvalidContext(Messages.getString("PRODUCER_INVALID_OPORT_SCHEMA", opCtx.getKind()), new Object[0]);
}
// check attribute types
int nTupleAttrs = 0;
int nStringAttrs = 0;
for (String outAttrName : outSchema.getAttributeNames()) {
Attribute attr = outSchema.getAttribute(outAttrName);
Type attrType = attr.getType();
MetaType metaType = attrType.getMetaType();
switch(metaType) {
case TUPLE:
++nTupleAttrs;
TupleType tupleType = (TupleType) attr.getType();
StreamSchema tupleSchema = tupleType.getTupleSchema();
if (!tupleSchema.equals(inPortSchema)) {
// $NON-NLS-1$
checker.setInvalidContext(Messages.getString("PRODUCER_INVALID_OPORT_SCHEMA", opCtx.getKind()), new Object[0]);
}
break;
case RSTRING:
case USTRING:
++nStringAttrs;
break;
case OPTIONAL:
MetaType optionalValueMeta = ((OptionalType) attrType).getValueType().getMetaType();
switch(optionalValueMeta) {
case RSTRING:
case USTRING:
++nStringAttrs;
break;
default:
// $NON-NLS-1$
checker.setInvalidContext(Messages.getString("PRODUCER_INVALID_OPORT_SCHEMA", opCtx.getKind()), new Object[0]);
}
break;
default:
// $NON-NLS-1$
checker.setInvalidContext(Messages.getString("PRODUCER_INVALID_OPORT_SCHEMA", opCtx.getKind()), new Object[0]);
}
}
if (nTupleAttrs > 1 || nStringAttrs > 1)
// $NON-NLS-1$
checker.setInvalidContext(Messages.getString("PRODUCER_INVALID_OPORT_SCHEMA", opCtx.getKind()), new Object[0]);
}
use of com.ibm.streams.operator.OperatorContext in project streamsx.kafka by IBMStreams.
the class AbstractKafkaProducerOperator method checkDefaultKeyAttribute.
@ContextCheck(compile = true)
public static void checkDefaultKeyAttribute(OperatorContextChecker checker) {
/*
* When we specify a key attribute via `keyAttribute` parameter, the Streams compiler
* checks for presence of the given attribute and for the right type.
* When we do not specify the attribute, 'key' would be the default key attribute in the input schema.
* We check the type of this default attribute if present.
*/
final OperatorContext operatorContext = checker.getOperatorContext();
if (!operatorContext.getParameterNames().contains(KEYATTR_PARAM_NAME)) {
// no keyAttribute parameter - check presence of 'key' attribute in the schema
StreamSchema schema = operatorContext.getStreamingInputs().get(0).getStreamSchema();
// $NON-NLS-1$
Attribute keyAttribute = schema.getAttribute(DEFAULT_KEY_ATTR_NAME);
if (keyAttribute != null) {
if (!checker.checkAttributeType(keyAttribute, SUPPORTED_ATTR_TYPES)) {
final String msg = Messages.getString("UNSUPPORTED_ATTR_TYPE", operatorContext.getKind(), keyAttribute.getType().getLanguageType(), keyAttribute.getName());
checker.setInvalidContext(msg, new Object[0]);
}
}
}
}
use of com.ibm.streams.operator.OperatorContext in project streamsx.kafka by IBMStreams.
the class AbstractKafkaProducerOperator 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 synchronized void shutdown() throws Exception {
OperatorContext context = getOperatorContext();
Logger.getLogger(this.getClass()).trace(// $NON-NLS-1$ //$NON-NLS-2$
"Operator " + context.getName() + " shutting down in PE: " + context.getPE().getPEId() + " in Job: " + // $NON-NLS-1$
context.getPE().getJobId());
producer.flush();
producer.close(AbstractKafkaProducerClient.CLOSE_TIMEOUT_MS);
if (this.errorPortSubmitter != null)
this.errorPortSubmitter.stop();
// Must call super.shutdown()
super.shutdown();
}
use of com.ibm.streams.operator.OperatorContext in project streamsx.kafka by IBMStreams.
the class AbstractKafkaProducerOperator method checkDefaultMessageAttribute.
@ContextCheck(compile = true)
public static void checkDefaultMessageAttribute(OperatorContextChecker checker) {
/*
* When we specify a message attribute via `messageAttribute` parameter, the Streams compiler
* checks for presence of the given attribute and for the right type.
* When we do not specify the attribute, 'message' must be present in the input schema.
* We can check presence and type of this default attribute.
*/
final OperatorContext operatorContext = checker.getOperatorContext();
if (!operatorContext.getParameterNames().contains(MESSAGEATTR_PARAM_NAME)) {
// no messageAttribute parameter - check presence of 'message' attribute in the schema
StreamSchema schema = operatorContext.getStreamingInputs().get(0).getStreamSchema();
// $NON-NLS-1$
Attribute messageAttribute = schema.getAttribute(DEFAULT_MESSAGE_ATTR_NAME);
if (messageAttribute == null) {
checker.setInvalidContext(Messages.getString("MESSAGE_ATTRIBUTE_NOT_FOUND"), new Object[0]);
return;
}
if (!checker.checkAttributeType(messageAttribute, SUPPORTED_ATTR_TYPES)) {
final String msg = Messages.getString("UNSUPPORTED_ATTR_TYPE", operatorContext.getKind(), messageAttribute.getType().getLanguageType(), messageAttribute.getName());
checker.setInvalidContext(msg, new Object[0]);
}
}
}
use of com.ibm.streams.operator.OperatorContext in project streamsx.topology by IBMStreams.
the class FunctionalOpUtils method checkNotConsistentRegionSource.
/**
* Verify a functional operator is not the start of a consistent region.
* @param checker Context checker.
*/
static void checkNotConsistentRegionSource(OperatorContextChecker checker) {
OperatorContext context = checker.getOperatorContext();
ConsistentRegionContext crc = context.getOptionalContext(ConsistentRegionContext.class);
if (crc == null)
return;
if (crc.isStartOfRegion() || crc.isTriggerOperator())
checker.setInvalidContext(Messages.getString("CONSISTENT_CHECK_1"), new String[] { context.getKind() });
}
Aggregations