org.apache.reef.wake.EventHandler Java Examples

The following examples show how to use org.apache.reef.wake.EventHandler. 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: HandlerContainer.java    From reef with Apache License 2.0 6 votes vote down vote up
/**
 * Subscribe for events from a given source and message type.
 * @param sourceIdentifier An identifier of an event source.
 * @param messageType Java class of messages to dispatch.
 * @param theHandler Message handler.
 * @return A new subscription object that will cancel its subscription on .close()
 */
@SuppressWarnings("checkstyle:diamondoperatorforvariabledefinition")
public AutoCloseable registerHandler(
    final RemoteIdentifier sourceIdentifier,
    final Class<? extends T> messageType,
    final EventHandler<? super T> theHandler) {

  final Tuple2<RemoteIdentifier, Class<? extends T>> tuple =
      new Tuple2<RemoteIdentifier, Class<? extends T>>(sourceIdentifier, messageType);

  this.tupleToHandlerMap.put(tuple, theHandler);

  LOG.log(Level.FINER,
      "Add handler for tuple: {0},{1}",
      new Object[] {tuple.getT1(), tuple.getT2().getCanonicalName()});

  return new SubscriptionHandler<>(tuple, this.unsubscribeTuple);
}
 
Example #2
Source File: Control.java    From reef with Apache License 2.0 6 votes vote down vote up
public void run() throws Exception {

    LOG.log(Level.INFO, "command: {0} task: {1} port: {2}",
        new Object[]{this.command, this.taskId, this.port});

    final ObjectSerializableCodec<String> codec = new ObjectSerializableCodec<>();

    final EStage<TransportEvent> stage = new ThreadPoolStage<>("suspend-control-client",
        new LoggingEventHandler<TransportEvent>(), 1, new EventHandler<Throwable>() {
          @Override
          public void onNext(final Throwable throwable) {
            throw new RuntimeException(throwable);
          }
        });

    try (Transport transport = tpFactory.newInstance("localhost", 0, stage, stage, 1, 10000)) {
      final Link link = transport.open(new InetSocketAddress("localhost", this.port), codec, null);
      link.write(this.command + " " + this.taskId);
    }
  }
 
Example #3
Source File: SuspendClientControl.java    From reef with Apache License 2.0 6 votes vote down vote up
@Inject
public SuspendClientControl(
    @Parameter(SuspendClientControl.Port.class) final int port,
    final TransportFactory tpFactory) throws IOException {

  LOG.log(Level.INFO, "Listen to control port {0}", port);

  final EStage<TransportEvent> stage = new ThreadPoolStage<>(
      "suspend-control-server", new ControlMessageHandler(), 1, new EventHandler<Throwable>() {
        @Override
        public void onNext(final Throwable throwable) {
          throw new RuntimeException(throwable);
        }
      });

  this.transport = tpFactory.newInstance("localhost", port, stage, stage, 1, 10000);
}
 
Example #4
Source File: ResourceManagerTest.java    From reef with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Before
public void setUp() throws InjectionException {
  final JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
  cb.bindNamedParameter(RootFolder.class, "target/REEF_LOCAL_RUNTIME");
  injector = Tang.Factory.getTang().newInjector(cb.build());
  remoteManager = injector.getInstance(RemoteManager.class);
  mockRuntimeResourceStatusHandler = mock(EventHandler.class);
  injector.bindVolatileParameter(RuntimeParameters.ResourceStatusHandler.class, mockRuntimeResourceStatusHandler);
  mockNodeDescriptorHandler = mock(EventHandler.class);
  injector.bindVolatileParameter(RuntimeParameters.NodeDescriptorHandler.class, mockNodeDescriptorHandler);
  mockResourceAllocationHandler = mock(EventHandler.class);
  injector.bindVolatileParameter(RuntimeParameters.ResourceAllocationHandler.class, mockResourceAllocationHandler);
  mockRuntimeStatusHandler = mock(EventHandler.class);
  injector.bindVolatileParameter(RuntimeParameters.RuntimeStatusHandler.class, mockRuntimeStatusHandler);
  configurationSerializer = injector.getInstance(ConfigurationSerializer.class);
  filenames = injector.getInstance(REEFFileNames.class);
  loggingScopeFactory = injector.getInstance(LoggingScopeFactory.class);
}
 
Example #5
Source File: TimerStage.java    From reef with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs a timer stage.
 *
 * @param name         the stage name
 * @param handler      an event handler
 * @param initialDelay an initial delay
 * @param period       a period in milli-seconds
 */
@Inject
public TimerStage(@Parameter(StageName.class) final String name,
                  @Parameter(StageHandler.class) final EventHandler<PeriodicEvent> handler,
                  @Parameter(TimerInitialDelay.class) final long initialDelay,
                  @Parameter(TimerPeriod.class) final long period) {
  this.executor = Executors.newScheduledThreadPool(1, new DefaultThreadFactory(name));
  executor.scheduleAtFixedRate(new Runnable() {

    @Override
    public void run() {
      if (LOG.isLoggable(Level.FINEST)) {
        LOG.log(Level.FINEST, "{0} {1}", new Object[]{name, event});
      }
      handler.onNext(event);
    }

  }, initialDelay, period, TimeUnit.MILLISECONDS);
  StageManager.instance().register(this);
}
 
Example #6
Source File: ForkPoolStageTest.java    From reef with Apache License 2.0 6 votes vote down vote up
@Test
public void testMeter() throws Exception {
  System.out.println(LOG_PREFIX + name.getMethodName());
  final WakeSharedPool p = new WakeSharedPool(10);
  final EventHandler<TestEvent> eventHandler = new TestEventHandler();
  final ForkPoolStage<TestEvent> stage = new ForkPoolStage<>(eventHandler, p);

  final TestEvent e = new TestEvent();
  for (int i = 0; i < 1000000; ++i) {
    stage.onNext(e);
  }
  stage.close();
  System.out.println("Note this is not a real test of throughput");
  System.out.println("mean input throughput: " + stage.getInMeter().getMeanThp() + " events/sec");
  System.out.println("mean output throughput: " + stage.getOutMeter().getMeanThp() + " events/sec");
}
 
Example #7
Source File: ClientManager.java    From reef with Apache License 2.0 6 votes vote down vote up
@Inject
ClientManager(@Parameter(ClientCloseHandlers.class)
              final InjectionFuture<Set<EventHandler<Void>>> clientCloseHandlers,
              @Parameter(ClientCloseWithMessageHandlers.class)
              final InjectionFuture<Set<EventHandler<byte[]>>> clientCloseWithMessageHandlers,
              @Parameter(ClientMessageHandlers.class)
              final InjectionFuture<Set<EventHandler<byte[]>>> clientMessageHandlers,
              @Parameter(ClientRemoteIdentifier.class) final String clientRID,
              final RemoteManager remoteManager,
              final DriverStatusManager driverStatusManager) {
  this.driverStatusManager = driverStatusManager;
  this.clientCloseHandlers = clientCloseHandlers;
  this.clientCloseWithMessageHandlers = clientCloseWithMessageHandlers;
  this.clientMessageHandlers = clientMessageHandlers;

  if (!clientRID.equals(ClientRemoteIdentifier.NONE)) {
    remoteManager.registerHandler(clientRID, ClientRuntimeProtocol.JobControlProto.class, this);
  } else {
    LOG.log(Level.FINE, "Not registering a handler for JobControlProto, as there is no client.");
  }
}
 
Example #8
Source File: ThreadPoolStageTest.java    From reef with Apache License 2.0 6 votes vote down vote up
@Test
public void testThreadPoolStage() throws Exception {
  System.out.println(LOG_PREFIX + name.getMethodName());

  final Set<TestEvent> procSet = Collections.synchronizedSet(new HashSet<TestEvent>());
  final Set<TestEvent> orgSet = Collections.synchronizedSet(new HashSet<TestEvent>());

  final EventHandler<TestEventA> eventHandler = new TestEventHandlerA(procSet);

  final EStage<TestEventA> stage = new ThreadPoolStage<>(eventHandler, 10);

  for (int i = 0; i < 10; ++i) {
    final TestEventA a = new TestEventA();
    orgSet.add(a);

    stage.onNext(a);
  }

  while (procSet.size() < 10) {
    //
  }

  stage.close();

  Assert.assertEquals(orgSet, procSet);
}
 
Example #9
Source File: BlockingEventHandlerTest.java    From reef with Apache License 2.0 6 votes vote down vote up
@Test
public void testSingle() {
  final AtomicInteger i = new AtomicInteger(0);
  final AtomicInteger cnt = new AtomicInteger(0);

  final BlockingEventHandler<Integer> h = new BlockingEventHandler<>(1, new EventHandler<Iterable<Integer>>() {
    @Override
    public void onNext(final Iterable<Integer> value) {
      for (final int x : value) {
        i.getAndAdd(x);
        cnt.incrementAndGet();
      }
    }
  });
  h.onNext(0xBEEF);
  assertEquals(0xBEEF, i.get());
  assertEquals(1, cnt.get());
}
 
Example #10
Source File: ThreadPoolStageTest.java    From reef with Apache License 2.0 6 votes vote down vote up
@Test
public void testSingleThreadStage() throws Exception {
  System.out.println(LOG_PREFIX + name.getMethodName());

  final Set<TestEvent> procSet = Collections.synchronizedSet(new HashSet<TestEvent>());
  final Set<TestEvent> orgSet = Collections.synchronizedSet(new HashSet<TestEvent>());

  final EventHandler<TestEventA> eventHandler = new TestEventHandlerA(procSet);
  final EStage<TestEventA> stage = new SingleThreadStage<>(eventHandler, 20);

  for (int i = 0; i < 10; ++i) {
    final TestEventA a = new TestEventA();
    orgSet.add(a);

    stage.onNext(a);
  }

  while (procSet.size() < 10) {
    //
  }

  stage.close();

  Assert.assertEquals(orgSet, procSet);
}
 
Example #11
Source File: RuntimeClock.java    From reef with Apache License 2.0 6 votes vote down vote up
@Inject
private RuntimeClock(
    final Timer timer,
    @Parameter(Clock.StartHandler.class)
        final InjectionFuture<Set<EventHandler<StartTime>>> startHandler,
    @Parameter(Clock.StopHandler.class)
        final InjectionFuture<Set<EventHandler<StopTime>>> stopHandler,
    @Parameter(Clock.RuntimeStartHandler.class)
        final InjectionFuture<Set<EventHandler<RuntimeStart>>> runtimeStartHandler,
    @Parameter(Clock.RuntimeStopHandler.class)
        final InjectionFuture<Set<EventHandler<RuntimeStop>>> runtimeStopHandler,
    @Parameter(Clock.IdleHandler.class)
        final InjectionFuture<Set<EventHandler<IdleClock>>> idleHandler) {

  this.timer = timer;
  this.startHandler = startHandler;
  this.stopHandler = stopHandler;
  this.runtimeStartHandler = runtimeStartHandler;
  this.runtimeStopHandler = runtimeStopHandler;
  this.idleHandler = idleHandler;

  LOG.log(Level.FINE, "RuntimeClock instantiated.");
}
 
Example #12
Source File: RunningJobImpl.java    From reef with Apache License 2.0 6 votes vote down vote up
@Inject
RunningJobImpl(final RemoteManager remoteManager,
               @Parameter(DriverIdentifier.class) final String driverIdentifier,
               @Parameter(REEFImplementation.DriverRemoteIdentifier.class) final String driverRID,
               @Parameter(JobRunningHandler.class) final EventHandler<RunningJob> runningJobEventHandler,
               @Parameter(JobCompletedHandler.class) final EventHandler<CompletedJob> completedJobEventHandler,
               @Parameter(JobFailedHandler.class) final EventHandler<FailedJob> failedJobEventHandler,
               @Parameter(JobMessageHandler.class) final EventHandler<JobMessage> jobMessageEventHandler,
               final ExceptionCodec exceptionCodec) {

  this.jobId = driverIdentifier;
  this.runningJobEventHandler = runningJobEventHandler;
  this.completedJobEventHandler = completedJobEventHandler;
  this.failedJobEventHandler = failedJobEventHandler;
  this.jobMessageEventHandler = jobMessageEventHandler;
  this.exceptionCodec = exceptionCodec;
  this.jobControlHandler = remoteManager.getHandler(driverRID, JobControlProto.class);

  this.runningJobEventHandler.onNext(this);
  LOG.log(Level.FINE, "Instantiated 'RunningJobImpl'");
}
 
Example #13
Source File: RemoteReceiverStage.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a remote receiver stage.
 *
 * @param handler      the handler of remote events
 * @param errorHandler the exception handler
 * @param numThreads   the number of threads
 */
public RemoteReceiverStage(final EventHandler<RemoteEvent<byte[]>> handler,
                           final EventHandler<Throwable> errorHandler, final int numThreads) {

  this.handler = new RemoteReceiverEventHandler(handler);

  this.executor = Executors.newFixedThreadPool(
      numThreads, new DefaultThreadFactory(RemoteReceiverStage.class.getName()));

  this.stage = new ThreadPoolStage<>(this.handler, this.executor, errorHandler);
}
 
Example #14
Source File: TaskLifeCycleHandlers.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * Sends the TaskStart event to the handlers for it.
 */
@SuppressWarnings("checkstyle:illegalcatch")
public void beforeTaskStart() throws TaskStartHandlerFailure {
  LOG.log(Level.FINEST, "Sending TaskStart event to the registered event handlers.");
  for (final EventHandler<TaskStart> startHandler : this.taskStartHandlers) {
    try {
      startHandler.onNext(this.taskStart);
    } catch (final Throwable throwable) {
      throw new TaskStartHandlerFailure(startHandler, throwable);
    }
  }
  LOG.log(Level.FINEST, "Done sending TaskStart event to the registered event handlers.");
}
 
Example #15
Source File: SyncStage.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a synchronous stage.
 *
 * @param name the stage name
 * @param handler      the event handler
 * @param errorHandler the error handler
 */
@Inject
public SyncStage(@Parameter(StageName.class) final String name,
                 @Parameter(StageHandler.class) final EventHandler<T> handler,
                 @Parameter(ErrorHandler.class) final EventHandler<Throwable> errorHandler) {
  super(name);
  this.handler = handler;
  this.errorHandler = errorHandler;
  StageManager.instance().register(this);
}
 
Example #16
Source File: ClientManager.java    From reef with Apache License 2.0 5 votes vote down vote up
private EventHandler<byte[]> getClientCloseWithMessageDispatcher() {
  if (clientCloseWithMessageDispatcher != null) {
    return clientCloseWithMessageDispatcher;
  } else {
    synchronized (this) {
      if (clientCloseWithMessageDispatcher == null) {
        clientCloseWithMessageDispatcher = new BroadCastEventHandler<>(clientCloseWithMessageHandlers.get());
      }
    }
    return clientCloseWithMessageDispatcher;
  }
}
 
Example #17
Source File: ClientManager.java    From reef with Apache License 2.0 5 votes vote down vote up
private synchronized EventHandler<Void> getClientCloseDispatcher() {
  if (clientCloseDispatcher != null) {
    return clientCloseDispatcher;
  } else {
    synchronized (this) {
      if (clientCloseDispatcher == null) {
        clientCloseDispatcher = new BroadCastEventHandler<>(clientCloseHandlers.get());
      }
    }
    return clientCloseDispatcher;
  }
}
 
Example #18
Source File: ThreadPoolStage.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a thread-pool stage.
 *
 * @param name         the stage name
 * @param handler      the event handler to execute
 * @param executor     the external executor service provided
 *                     for consistent tracking, it is recommended to create executor with {@link DefaultThreadFactory}
 * @param errorHandler the error handler
 */
@Inject
public ThreadPoolStage(@Parameter(StageName.class) final String name,
                       @Parameter(StageHandler.class) final EventHandler<T> handler,
                       @Parameter(StageExecutorService.class) final ExecutorService executor,
                       @Parameter(ErrorHandler.class) final EventHandler<Throwable> errorHandler) {
  super(name);
  this.handler = handler;
  this.errorHandler = errorHandler;
  this.numThreads = 0;
  this.executor = executor;
  StageManager.instance().register(this);
}
 
Example #19
Source File: DefaultRemoteManagerImplementation.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a proxy event handler for a remote identifier and a message type.
 */
@Override
public <T> EventHandler<T> getHandler(
    final RemoteIdentifier destinationIdentifier, final Class<? extends T> messageType) {

  if (LOG.isLoggable(Level.FINE)) {
    LOG.log(Level.FINE, "RemoteManager: {0} destinationIdentifier: {1} messageType: {2}",
        new Object[] {this.name, destinationIdentifier, messageType.getCanonicalName()});
  }

  return new ProxyEventHandler<>(this.myIdentifier, destinationIdentifier,
      "default", this.reSendStage.<T>getHandler(), this.seqGen);
}
 
Example #20
Source File: BlockingSignalEventHandlerTest.java    From reef with Apache License 2.0 5 votes vote down vote up
@Test
public void testTwoStreams() {
  final AtomicInteger cnt = new AtomicInteger(0);

  final int num = 1000;
  final BlockingSignalEventHandler<Integer> h =
      new BlockingSignalEventHandler<>(2 * num, new EventHandler<Integer>() {
        @Override
        public void onNext(final Integer value) {
          cnt.incrementAndGet();
        }
      });

  final Runnable r = new Runnable() {
    @Override
    public void run() {
      for (int i = 0; i < num; i++) {
        h.onNext(i);
      }
    }
  };
  final Thread a = new Thread(r);
  final Thread b = new Thread(r);
  a.start();
  b.start();
  try {
    a.join();
    b.join();
  } catch (final InterruptedException e) {
    fail(e.toString());
  }

  assertEquals(1, cnt.get());
}
 
Example #21
Source File: ProxyEventHandler.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a proxy event handler.
 *
 * @param myId           my identifier
 * @param remoteId       the remote identifier
 * @param remoteSinkName the remote sink name
 * @throws RemoteRuntimeException
 */
public ProxyEventHandler(final RemoteIdentifier myId, final RemoteIdentifier remoteId, final String remoteSinkName,
                         final EventHandler<RemoteEvent<T>> handler, final RemoteSeqNumGenerator seqGen) {
  LOG.log(Level.FINE, "ProxyEventHandler myId: {0} remoteId: {1} remoteSink: {2} handler: {3}",
      new Object[]{myId, remoteId, remoteSinkName, handler});
  if (!(myId instanceof SocketRemoteIdentifier && remoteId instanceof SocketRemoteIdentifier)) {
    throw new RemoteRuntimeException("Unsupported remote identifier type");
  }

  this.myId = (SocketRemoteIdentifier) myId;
  this.remoteId = (SocketRemoteIdentifier) remoteId;
  this.remoteSinkName = remoteSinkName;
  this.handler = handler;
  this.seqGen = seqGen;
}
 
Example #22
Source File: DefaultRemoteManagerFactory.java    From reef with Apache License 2.0 5 votes vote down vote up
@Override
public <T> RemoteManager getInstance(final String newRmName,
                                     final int newListeningPort,
                                     final Codec<T> newCodec,
                                     final EventHandler<Throwable> newErrorHandler) {
  return getInstance(newRmName, null, newListeningPort, newCodec, newErrorHandler, this.orderingGuarantee,
      this.numberOfTries, this.retryTimeout, this.localAddressProvider, this.tcpPortProvider);
}
 
Example #23
Source File: PubSubEventHandler.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * Subscribes an event handler for an event class type.
 *
 * @param clazz   an event class
 * @param handler an event handler
 */
public void subscribe(final Class<? extends T> clazz, final EventHandler<? extends T> handler) {
  lock.writeLock().lock();
  try {
    List<EventHandler<? extends T>> list = clazzToListOfHandlersMap.get(clazz);
    if (list == null) {
      list = new LinkedList<EventHandler<? extends T>>();
      clazzToListOfHandlersMap.put(clazz, list);
    }
    list.add(handler);
  } finally {
    lock.writeLock().unlock();
  }
}
 
Example #24
Source File: TaskRuntime.java    From reef with Apache License 2.0 5 votes vote down vote up
@Inject
private TaskRuntime(
    final HeartBeatManager heartBeatManager,
    final Task task,
    final TaskStatus currentStatus,
    @Parameter(TaskConfigurationOptions.CloseHandler.class)
    final InjectionFuture<EventHandler<CloseEvent>> fCloseHandler,
    @Parameter(TaskConfigurationOptions.SuspendHandler.class)
    final InjectionFuture<EventHandler<SuspendEvent>> fSuspendHandler,
    @Parameter(TaskConfigurationOptions.MessageHandler.class)
    final InjectionFuture<EventHandler<DriverMessage>> fMessageHandler,
    @Parameter(TaskConfigurationOptions.Memento.class) final String memento,
    final TaskLifeCycleHandlers taskLifeCycleHandlers) {

  this.heartBeatManager = heartBeatManager;
  this.task = task;
  this.taskLifeCycleHandlers = taskLifeCycleHandlers;

  this.memento = null == memento ? Optional.<byte[]>empty() :
      Optional.of(DatatypeConverter.parseBase64Binary(memento));

  this.fCloseHandler = fCloseHandler;
  this.fSuspendHandler = fSuspendHandler;
  this.fMessageHandler = fMessageHandler;

  this.currentStatus = currentStatus;
}
 
Example #25
Source File: DriverRPCServer.java    From incubator-nemo with Apache License 2.0 5 votes vote down vote up
/**
 * Registers handler for the given type of message.
 *
 * @param type    the type of message
 * @param handler handler implementation
 * @return {@code this}
 */
public DriverRPCServer registerHandler(final ControlMessage.DriverToClientMessageType type,
                                       final EventHandler<ControlMessage.DriverToClientMessage> handler) {
  // Registering a handler after running the server is considered not a good practice.
  ensureServerState(false);
  if (handlers.putIfAbsent(type, handler) != null) {
    throw new RuntimeException(String.format("A handler for %s already registered", type));
  }
  return this;
}
 
Example #26
Source File: DispatchingEStage.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * @param errorHandler used for exceptions thrown from the event handlers registered.
 * @param numThreads   number of threads to allocate to dispatch events.
 * @param stageName    the name to use for the underlying stage.
 *                     It will be carried over to name the Thread(s) spawned.
 */
public DispatchingEStage(final EventHandler<Throwable> errorHandler,
                         final int numThreads,
                         final String stageName) {
  this.errorHandler = errorHandler;
  this.stage = new ThreadPoolStage<>(stageName,
      new EventHandler<DelayedOnNext>() {
        @Override
        public void onNext(final DelayedOnNext promise) {
          promise.handler.onNext(promise.message);
        }
      }, numThreads
  );

}
 
Example #27
Source File: TaskLifeCycleHandlers.java    From reef with Apache License 2.0 5 votes vote down vote up
@Inject
TaskLifeCycleHandlers(@Parameter(TaskConfigurationOptions.StopHandlers.class)
                      final Set<EventHandler<TaskStop>> taskStopHandlers,
                      @Parameter(TaskConfigurationOptions.StartHandlers.class)
                      final Set<EventHandler<TaskStart>> taskStartHandlers,
                      final TaskStartImpl taskStart,
                      final TaskStopImpl taskStop) {
  this.taskStopHandlers = taskStopHandlers;
  this.taskStartHandlers = taskStartHandlers;
  this.taskStart = taskStart;
  this.taskStop = taskStop;
}
 
Example #28
Source File: SyncStageTest.java    From reef with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultiSyncStage() throws Exception {
  System.out.println(name.getMethodName());

  final Set<TestEvent> procSet = Collections.synchronizedSet(new HashSet<TestEvent>());
  final Set<TestEvent> orgSet = Collections.synchronizedSet(new HashSet<TestEvent>());

  final Map<Class<? extends TestEvent>, EventHandler<? extends TestEvent>> map = new HashMap<>();
  map.put(TestEventA.class, new TestEventHandlerA(procSet));
  map.put(TestEventB.class, new TestEventHandlerB(procSet));

  final EventHandler<TestEvent> eventHandler = new MultiEventHandler<>(map);

  final EStage<TestEvent> stage = new SyncStage<>(eventHandler);

  for (int i = 0; i < 10; ++i) {
    final TestEventA a = new TestEventA();
    final TestEventB b = new TestEventB();

    orgSet.add(a);
    orgSet.add(b);

    stage.onNext(a);
    stage.onNext(b);
  }

  stage.close();

  Assert.assertEquals(orgSet, procSet);
}
 
Example #29
Source File: ContextLifeCycle.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * Fires ContextStop to all registered event handlers.
 */
void close() {
  final ContextStop contextStop = new ContextStopImpl(this.identifier);
  for (final EventHandler<ContextStop> stopHandler : this.contextStopHandlers) {
    stopHandler.onNext(contextStop);
  }
}
 
Example #30
Source File: ContextLifeCycle.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * Fires ContextStart to all registered event handlers.
 */
void start() {
  final ContextStart contextStart = new ContextStartImpl(this.identifier);
  for (final EventHandler<ContextStart> startHandler : this.contextStartHandlers) {
    startHandler.onNext(contextStart);
  }
}