Java Code Examples for org.apache.samza.context.Context#getContainerContext()

The following examples show how to use org.apache.samza.context.Context#getContainerContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProjectTranslator.java    From samza with Apache License 2.0 6 votes vote down vote up
/**
 * initializes the ProjectMapFunction before any message is processed
 * @param context the {@link Context} for this task
 */
@Override
public void init(Context context) {
  this.context = context;
  this.translatorContext =
      ((SamzaSqlApplicationContext) context.getApplicationTaskContext()).getTranslatorContexts().get(queryId);
  this.project = (Project) this.translatorContext.getRelNode(projectId);
  this.expr = this.translatorContext.getExpressionCompiler().compile(project.getInputs(), project.getProjects());
  ContainerContext containerContext = context.getContainerContext();
  metricsRegistry = containerContext.getContainerMetricsRegistry();
  processingTime = new SamzaHistogram(metricsRegistry, logicalOpId, TranslatorConstants.PROCESSING_TIME_NAME);
  inputEvents = metricsRegistry.newCounter(logicalOpId, TranslatorConstants.INPUT_EVENTS_NAME);
  inputEvents.clear();
  outputEvents = metricsRegistry.newCounter(logicalOpId, TranslatorConstants.OUTPUT_EVENTS_NAME);
  outputEvents.clear();
}
 
Example 2
Source File: FilterTranslator.java    From samza with Apache License 2.0 6 votes vote down vote up
@Override
public void init(Context context) {
  this.context = context;
  this.translatorContext = ((SamzaSqlApplicationContext) context.getApplicationTaskContext()).getTranslatorContexts().get(queryId);
  this.filter = (LogicalFilter) this.translatorContext.getRelNode(filterId);
  this.expr = this.translatorContext.getExpressionCompiler().compile(filter.getInputs(), Collections.singletonList(filter.getCondition()));
  ContainerContext containerContext = context.getContainerContext();
  metricsRegistry = containerContext.getContainerMetricsRegistry();
  processingTime = new SamzaHistogram(metricsRegistry, logicalOpId, TranslatorConstants.PROCESSING_TIME_NAME);
  inputEvents = metricsRegistry.newCounter(logicalOpId, TranslatorConstants.INPUT_EVENTS_NAME);
  inputEvents.clear();
  filteredOutEvents = metricsRegistry.newCounter(logicalOpId, TranslatorConstants.FILTERED_EVENTS_NAME);
  filteredOutEvents.clear();
  outputEvents = metricsRegistry.newCounter(logicalOpId, TranslatorConstants.OUTPUT_EVENTS_NAME);
  outputEvents.clear();
}
 
Example 3
Source File: QueryTranslator.java    From samza with Apache License 2.0 6 votes vote down vote up
@Override
public void init(Context context) {
  TranslatorContext translatorContext =
      ((SamzaSqlApplicationContext) context.getApplicationTaskContext()).getTranslatorContexts().get(queryId);
  this.samzaMsgConverter = translatorContext.getMsgConverter(outputTopic);
  ContainerContext containerContext = context.getContainerContext();
  metricsRegistry = containerContext.getContainerMetricsRegistry();
  /* insert (SendToOutputStream) metrics */
  insertProcessingTime =
      new SamzaHistogram(metricsRegistry, insertLogicalId, TranslatorConstants.TOTAL_LATENCY_MILLIS_NAME);

  /* query metrics */
  totalLatencyMs = new SamzaHistogram(metricsRegistry, queryLogicalId, TranslatorConstants.TOTAL_LATENCY_MILLIS_NAME);

  queryLatencyNs = new SamzaHistogram(metricsRegistry, queryLogicalId, TranslatorConstants.QUERY_LATENCY_NANOS_NAME);
  queuingLatencyMS = new SamzaHistogram(metricsRegistry, queryLogicalId,
      TranslatorConstants.QUEUEING_LATENCY_MILLIS_NAME);
  queryOutputEvents = metricsRegistry.newCounter(queryLogicalId, TranslatorConstants.OUTPUT_EVENTS_NAME);
  queryOutputEvents.clear();
}
 
Example 4
Source File: OperatorImpl.java    From samza with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize this {@link OperatorImpl} and its user-defined functions.
 *
 * @param internalTaskContext the {@link InternalTaskContext} for the task
 */
public final void init(InternalTaskContext internalTaskContext) {
  final Context context = internalTaskContext.getContext();

  String opId = getOpImplId();

  if (initialized) {
    throw new IllegalStateException(String.format("Attempted to initialize Operator %s more than once.", opId));
  }

  if (closed) {
    throw new IllegalStateException(String.format("Attempted to initialize Operator %s after it was closed.", opId));
  }

  this.highResClock = createHighResClock(context.getJobContext().getConfig());
  registeredOperators = new HashSet<>();
  prevOperators = new HashSet<>();
  inputStreams = new HashSet<>();

  final ContainerContext containerContext = context.getContainerContext();
  final MetricsRegistry metricsRegistry = containerContext.getContainerMetricsRegistry();
  this.numMessage = metricsRegistry.newCounter(METRICS_GROUP, opId + "-messages");
  this.handleMessageNs = metricsRegistry.newTimer(METRICS_GROUP, opId + "-handle-message-ns");
  this.handleTimerNs = metricsRegistry.newTimer(METRICS_GROUP, opId + "-handle-timer-ns");

  final TaskContext taskContext =  context.getTaskContext();
  this.taskName = taskContext.getTaskModel().getTaskName();
  this.eosStates = (EndOfStreamStates) internalTaskContext.fetchObject(EndOfStreamStates.class.getName());
  this.watermarkStates = (WatermarkStates) internalTaskContext.fetchObject(WatermarkStates.class.getName());
  this.controlMessageSender = new ControlMessageSender(internalTaskContext.getStreamMetadataCache());
  this.taskModel = taskContext.getTaskModel();
  this.callbackScheduler = taskContext.getCallbackScheduler();
  handleInit(context);

  initialized = true;
}
 
Example 5
Source File: ScanTranslator.java    From samza with Apache License 2.0 5 votes vote down vote up
@Override
public void init(Context context) {
  TranslatorContext translatorContext =
      ((SamzaSqlApplicationContext) context.getApplicationTaskContext()).getTranslatorContexts().get(queryId);
  this.msgConverter = translatorContext.getMsgConverter(streamName);
  ContainerContext containerContext = context.getContainerContext();
  metricsRegistry = containerContext.getContainerMetricsRegistry();
  processingTime = new SamzaHistogram(metricsRegistry, logicalOpId, TranslatorConstants.PROCESSING_TIME_NAME);
  queryInputEvents = metricsRegistry.newCounter(queryLogicalId, TranslatorConstants.INPUT_EVENTS_NAME);
  queryInputEvents.clear();
}
 
Example 6
Source File: TranslatorInputMetricsMapFunction.java    From samza with Apache License 2.0 5 votes vote down vote up
/**
 * initializes the TranslatorOutputMetricsMapFunction before any message is processed
 * @param context the {@link Context} for this task
 */
@Override
public void init(Context context) {
  ContainerContext containerContext = context.getContainerContext();
  metricsRegistry = containerContext.getContainerMetricsRegistry();
  inputEvents = metricsRegistry.newCounter(logicalOpId, TranslatorConstants.INPUT_EVENTS_NAME);
  inputEvents.clear();
}
 
Example 7
Source File: TranslatorOutputMetricsMapFunction.java    From samza with Apache License 2.0 5 votes vote down vote up
/**
 * initializes the TranslatorOutputMetricsMapFunction before any message is processed
 * @param context the {@link Context} for this task
 */
@Override
public void init(Context context) {
  ContainerContext containerContext = context.getContainerContext();
  metricsRegistry = containerContext.getContainerMetricsRegistry();
  processingTime = new SamzaHistogram(metricsRegistry, logicalOpId, TranslatorConstants.PROCESSING_TIME_NAME);
  outputEvents = metricsRegistry.newCounter(logicalOpId, TranslatorConstants.OUTPUT_EVENTS_NAME);
  outputEvents.clear();
}