Esempio n. 1
0
  @After
  public void tearDown() throws Exception {
    for (DelayedEventHandler delayedEventHandler : delayedEventHandlers) {
      delayedEventHandler.stopWaiting();
    }

    disruptor.halt();
    executor.joinAllThreads();
  }
Esempio n. 2
0
  private void ensureTwoEventsProcessedAccordingToDependencies(
      final CountDownLatch countDownLatch, final DelayedEventHandler... dependencies)
      throws InterruptedException {
    publishEvent();
    publishEvent();

    for (DelayedEventHandler dependency : dependencies) {
      assertThatCountDownLatchEquals(countDownLatch, 2L);
      dependency.processEvent();
      dependency.processEvent();
    }

    assertThatCountDownLatchIsZero(countDownLatch);
  }
Esempio n. 3
0
  @Test
  public void shouldBlockProducerUntilAllEventProcessorsHaveAdvanced() throws Exception {
    final DelayedEventHandler delayedEventHandler = createDelayedEventHandler();
    disruptor.handleEventsWith(delayedEventHandler);

    final RingBuffer<TestEvent> ringBuffer = disruptor.start();

    final StubPublisher stubPublisher = new StubPublisher(ringBuffer);
    try {
      executor.execute(stubPublisher);

      assertProducerReaches(stubPublisher, 4, true);

      delayedEventHandler.processEvent();
      delayedEventHandler.processEvent();
      delayedEventHandler.processEvent();
      delayedEventHandler.processEvent();
      delayedEventHandler.processEvent();

      assertProducerReaches(stubPublisher, 5, false);
    } finally {
      stubPublisher.halt();
    }
  }
Esempio n. 4
0
  /** The thread execution process. */
  public void run() {
    Logger.println("GameEngine now running");
    time = System.nanoTime() / 1000000000;

    eventHandler.add(
        new DelayedEvent(null, Config.GARBAGE_COLLECT_INTERVAL) { // Ran
          // every
          // 50*2
          // minutes
          @Override
          public void run() {
            new Thread(
                    new Runnable() {
                      public void run() {
                        garbageCollect();
                      }
                    })
                .start();
          }
        });
    eventHandler.add(
        new DelayedEvent(null, Config.SAVE_INTERVAL) {
          public void run() {
            long now = GameEngine.getTime();
            for (Player p : world.getPlayers()) {
              if (now - p.getLastSaveTime() >= Config.SAVE_INTERVAL) {
                p.save();
                p.setLastSaveTime(now);
              }
            }
            Instance.getServer().getLoginConnector().getActionSender().saveProfiles();
          }
        });
    while (running) {
      try {
        Thread.sleep(50);
      } catch (InterruptedException ie) {
      }
      long deltaTime = updateTime();
      processLoginServer();
      if ((deltaTime = getDeltaTime()) >= 1000)
        Logger.println(
            "processLoginServer is taking longer than it should, exactly " + deltaTime + "ms");
      processIncomingPackets();
      if ((deltaTime = getDeltaTime()) >= 1000)
        Logger.println(
            "processIncomingPackets is taking longer than it should, exactly " + deltaTime + "ms");
      processEvents();
      if ((deltaTime = getDeltaTime()) >= 1000)
        Logger.println(
            "processEvents is taking longer than it should, exactly " + deltaTime + "ms");
      processClients();
      if ((deltaTime = getDeltaTime()) >= 1000)
        Logger.println(
            "processClients is taking longer than it should, exactly " + deltaTime + "ms");
      cleanSnapshotDeque();
      if ((deltaTime = getDeltaTime()) >= 1000)
        Logger.println(
            "processSnapshotDeque is taking longer than it should, exactly " + deltaTime + "ms");
    }
  }
Esempio n. 5
0
 private void processEvents() {
   if (getTime() - lastEventTick >= 100) {
     eventHandler.doEvents();
     lastEventTick = getTime();
   }
 }