/** * Declares a stream populated by {@link JobRegistryService} events. * <p> * The job registry is passed as a runtime service. At startup * {@code JobRegistryService#addListener()} is called by the * runtime to subscribe an event listener. The listener invokes the given * {@code wrapper} function to construct a tuple from a job event * and submits the tuple on the returned stream.</p> * <p> * When the topology's execution is terminated, * {@code JobRegistryServic#removeListener()} in invoked to unsubscribe * the tuple source from the job registry. * </p> * * @param <T> Tuple type * @param topology the stream topology * @param wrapper constructs a tuple from a job event * @return new stream containing the tuples generated by the specified {@code wrapper}. * * @see Topology#getRuntimeServiceSupplier() * @see JobRegistryService#addListener(BiConsumer) * @see JobRegistryService#removeListener(BiConsumer) */ public static <T> TStream<T> source( Topology topology, BiFunction<JobRegistryService.EventType, Job, T> wrapper) { Supplier<RuntimeServices> rts = topology.getRuntimeServiceSupplier(); return topology.events(new JobEventsSetup<T>(wrapper, rts)); }
/** * Subscribe to a published topic. * This is a model that allows jobs to subscribe to * streams published by other jobs. * @param <T> Tuple type * @param te TopologyElement whose Topology to add to * @param topic Topic to subscribe to. * @param streamType Type of the stream. * @return Stream containing published tuples. * * @see #publish(TStream, String, Class) */ public static <T> TStream<T> subscribe(TopologyElement te, String topic, Class<T> streamType) { Topology topology = te.topology(); Supplier<RuntimeServices> rts = topology.getRuntimeServiceSupplier(); return te.topology().events(new SubscriberSetup<T>(topic, streamType, rts)); }
/** * Subscribe to a published topic. * This is a model that allows jobs to subscribe to * streams published by other jobs. * @param <T> Tuple type * @param te TopologyElement whose Topology to add to * @param topic Topic to subscribe to. * @param streamType Type of the stream. * @return Stream containing published tuples. * * @see #publish(TStream, String, Class) */ public static <T> TStream<T> subscribe(TopologyElement te, String topic, Class<T> streamType) { Topology topology = te.topology(); Supplier<RuntimeServices> rts = topology.getRuntimeServiceSupplier(); return te.topology().events(new SubscriberSetup<T>(topic, streamType, rts)); }
jobEvents.sink(new JobRestarter(t.getRuntimeServiceSupplier()));
jobEvents.sink(new JobRestarter(t.getRuntimeServiceSupplier()));
@Test public void testServiceRegistered() throws Exception { Topology t1 = newTopology(); StreamScopeRegistry rgy1 = t1.getRuntimeServiceSupplier().get() .getService(StreamScopeRegistry.class); assertNotNull(rgy1); Topology t2 = newTopology(); StreamScopeRegistry rgy2 = t2.getRuntimeServiceSupplier().get() .getService(StreamScopeRegistry.class); assertNotNull(rgy2); assertSame(rgy1, rgy2); }
static <T> void setPollFrequency(TStream<T> pollStream, long period, TimeUnit unit) { ControlService cs = pollStream.topology().getRuntimeServiceSupplier() .get().getService(ControlService.class); PeriodMXBean control = cs.getControl(TStream.TYPE, pollStream.getAlias(), PeriodMXBean.class); control.setPeriod(period, unit); }
t.getRuntimeServiceSupplier().get() .getService(StreamScopeRegistry.class); if (rgy == null)
@Test public void testRegistryControlRegistered() throws Exception { Topology t1 = newTopology(); ControlService cs1 = t1.getRuntimeServiceSupplier().get() .getService(ControlService.class); StreamScopeRegistryMXBean rgy1 = cs1.getControl(StreamScopeRegistryMXBean.TYPE, StreamScopeRegistryMXBean.TYPE, StreamScopeRegistryMXBean.class); assertNotNull(rgy1); Topology t2 = newTopology(); ControlService cs2 = t2.getRuntimeServiceSupplier().get() .getService(ControlService.class); StreamScopeRegistryMXBean rgy2 = cs2.getControl(StreamScopeRegistryMXBean.TYPE, StreamScopeRegistryMXBean.TYPE, StreamScopeRegistryMXBean.class); assertNotNull(rgy2); // The rgy1, rgy1 mbean instances may or may not be the same object // depending on the ControlService implementation. For JMXControlService, // each getControl() yields a different MXBeanProxy instance but they are // for the underlying bean (same objectname). //assertSame(rgy1, rgy2); }
StreamScopeRegistry rgy = t1.getRuntimeServiceSupplier().get() .getService(StreamScopeRegistry.class); assertNotNull(rgy); ControlService cs = t1.getRuntimeServiceSupplier().get() .getService(ControlService.class); StreamScopeRegistryMXBean rgyBean =
@Test public void testRuntimeServices() throws Exception { Topology t = newTopology(); TStream<String> s = t.strings("A"); Supplier<RuntimeServices> serviceGetter = t.getRuntimeServiceSupplier(); TStream<Boolean> b = s.map(tuple -> serviceGetter.get().getService(ThreadFactory.class) != null && serviceGetter.get().getService(ScheduledExecutorService.class) != null ); Condition<List<Boolean>> tc = t.getTester().streamContents(b, Boolean.TRUE); complete(t, tc); assertTrue(tc.valid()); }