/** * Creates an instance of the application-defined {@link ApplicationContainerContext}. * <p> * Applications should implement this to provide a context for container initialization. * * @param externalContext external context provided for the application; null if it was not provided * @param jobContext framework-provided job context * @param containerContext framework-provided container context * @return a new instance of the application-defined {@link ApplicationContainerContext} */ default T create(ExternalContext externalContext, JobContext jobContext, ContainerContext containerContext) { return create(jobContext, containerContext); }
/** * Creates an instance of the application-defined {@link ApplicationTaskContext}. * <p> * Applications should implement this to provide a context for task initialization. * * @param externalContext external context provided for the application; null if it was not provided * @param jobContext framework-provided job context * @param containerContext framework-provided container context * @param taskContext framework-provided task context * @param applicationContainerContext application-defined container context; null if it was not provided * @return a new instance of the application-defined {@link ApplicationTaskContext} */ default T create(ExternalContext externalContext, JobContext jobContext, ContainerContext containerContext, TaskContext taskContext, ApplicationContainerContext applicationContainerContext) { return create(jobContext, containerContext, taskContext, applicationContainerContext); }
@Override public void init(Context context) { String rightStoreName = joinOpSpec.getRightOpId(); rightStreamState = (KeyValueStore<Object, TimestampedValue<Object>>) context.getTaskContext().getStore(rightStoreName); // user-defined joinFn should only be initialized once, // so we do it only in left partial join function and not here again. }
@Before public void setup() { this.context = new MockContext(); // individual tests can override this config if necessary when(this.context.getJobContext().getConfig()).thenReturn(mock(Config.class)); TaskModel taskModel = mock(TaskModel.class); when(taskModel.getTaskName()).thenReturn(new TaskName("task 0")); when(this.context.getTaskContext().getTaskModel()).thenReturn(taskModel); when(this.context.getTaskContext().getTaskMetricsRegistry()).thenReturn(new MetricsRegistryMap()); when(this.context.getContainerContext().getContainerMetricsRegistry()).thenReturn(new MetricsRegistryMap()); }
@Before public void setup() { this.context = new MockContext(); when(this.context.getTaskContext().getTaskMetricsRegistry()).thenReturn(new MetricsRegistryMap()); when(this.context.getTaskContext().getTaskModel()).thenReturn(mock(TaskModel.class)); when(this.context.getContainerContext().getContainerMetricsRegistry()).thenReturn(new MetricsRegistryMap()); }
BroadcastOperatorImpl(BroadcastOperatorSpec<M> broadcastOpSpec, SystemStream systemStream, Context context) { this.broadcastOpSpec = broadcastOpSpec; this.systemStream = systemStream; this.taskName = context.getTaskContext().getTaskModel().getTaskName().getTaskName(); }
SendToTableOperatorImpl(SendToTableOperatorSpec<K, V> sendToTableOpSpec, Context context) { this.sendToTableOpSpec = sendToTableOpSpec; this.table = context.getTaskContext().getTable(sendToTableOpSpec.getTableId()); }
/** * 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(); }
@Override public void init(Context context) throws Exception { Config config = context.getJobContext().getConfig(); this.expectedMessageCount = config.getInt("app.messageCount"); this.outputTopic = config.get("app.outputTopic", "output"); this.outputSystem = config.get("app.outputSystem", "test-system"); }
/** * Given no concrete context, getApplicationTaskContext should throw an exception. */ @Test(expected = IllegalStateException.class) public void testGetMissingApplicationTaskContext() { Context context = buildWithApplicationTaskContext(null); context.getApplicationTaskContext(); }
/** * Given no concrete context, getExternalContext should throw an exception. */ @Test(expected = IllegalStateException.class) public void testGetMissingExternalContext() { Context context = buildWithExternalContext(null); context.getExternalContext(); }
/** * Given no concrete context, getApplicationContainerContext should throw an exception. */ @Test(expected = IllegalStateException.class) public void testGetMissingApplicationContainerContext() { Context context = buildWithApplicationContainerContext(null); context.getApplicationContainerContext(); }
@Override public void init(Context context) { String rightStoreName = joinOpSpec.getRightOpId(); rightStreamState = (KeyValueStore<Object, TimestampedValue<Object>>) context.getTaskContext().getStore(rightStoreName); // user-defined joinFn should only be initialized once, // so we do it only in left partial join function and not here again. }
BroadcastOperatorImpl(BroadcastOperatorSpec<M> broadcastOpSpec, SystemStream systemStream, Context context) { this.broadcastOpSpec = broadcastOpSpec; this.systemStream = systemStream; this.taskName = context.getTaskContext().getTaskModel().getTaskName().getTaskName(); }
StreamTableJoinOperatorImpl(StreamTableJoinOperatorSpec<K, M, R, JM> joinOpSpec, Context context) { this.joinOpSpec = joinOpSpec; this.table = context.getTaskContext().getTable(joinOpSpec.getTableId()); }
@Override public void init(Context context) { String rightStoreName = joinOpSpec.getRightOpId(); rightStreamState = (KeyValueStore<Object, TimestampedValue<Object>>) context.getTaskContext().getStore(rightStoreName); // user-defined joinFn should only be initialized once, // so we do it only in left partial join function and not here again. }
BroadcastOperatorImpl(BroadcastOperatorSpec<M> broadcastOpSpec, SystemStream systemStream, Context context) { this.broadcastOpSpec = broadcastOpSpec; this.systemStream = systemStream; this.taskName = context.getTaskContext().getTaskModel().getTaskName().getTaskName(); }
@Override public void init(Context context) { String rightStoreName = joinOpSpec.getRightOpId(); rightStreamState = (KeyValueStore<Object, TimestampedValue<Object>>) context.getTaskContext().getStore(rightStoreName); // user-defined joinFn should only be initialized once, // so we do it only in left partial join function and not here again. }
@Override public void init(Context context) { String rightStoreName = joinOpSpec.getRightOpId(); rightStreamState = (KeyValueStore<Object, TimestampedValue<Object>>) context.getTaskContext().getStore(rightStoreName); // user-defined joinFn should only be initialized once, // so we do it only in left partial join function and not here again. }
@Override public void init(Context context) { String leftStoreName = joinOpSpec.getLeftOpId(); leftStreamState = (KeyValueStore<Object, TimestampedValue<Object>>) context.getTaskContext().getStore(leftStoreName); // user-defined joinFn should only be initialized once, so we do it only in left partial join function. joinFn.init(context); }