use of org.apache.samza.context.ContainerContext in project samza by apache.
the class TestLocalTableWrite method createTable.
private LocalTable createTable(boolean isTimerDisabled) {
Map<String, String> config = new HashMap<>();
if (isTimerDisabled) {
config.put(MetricsConfig.METRICS_TIMER_ENABLED, "false");
}
Context context = mock(Context.class);
JobContext jobContext = mock(JobContext.class);
when(context.getJobContext()).thenReturn(jobContext);
when(jobContext.getConfig()).thenReturn(new MapConfig(config));
ContainerContext containerContext = mock(ContainerContext.class);
when(context.getContainerContext()).thenReturn(containerContext);
when(containerContext.getContainerMetricsRegistry()).thenReturn(metricsRegistry);
LocalTable table = new LocalTable("t1", kvStore);
table.init(context);
return table;
}
use of org.apache.samza.context.ContainerContext in project samza by apache.
the class OperatorImpl method init.
/**
* 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 LinkedHashSet<>();
prevOperators = new LinkedHashSet<>();
inputStreams = new LinkedHashSet<>();
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);
this.elasticityFactor = new JobConfig(context.getJobContext().getConfig()).getElasticityFactor();
initialized = true;
}
Aggregations