/**
   * Method cleans up all events that either outnumber queue size or exceeds time-to-live value. It
   * does none if someone else cleans up queue (lock is locked) or if there are queue readers
   * (readersNum > 0).
   */
  private void cleanupQueue() {
    long now = U.currentTimeMillis();

    long queueOversize = evts.sizex() - expireCnt;

    for (int i = 0; i < queueOversize && evts.sizex() > expireCnt; i++) {
      GridEvent expired = evts.poll();

      if (log.isDebugEnabled()) log.debug("Event expired by count: " + expired);
    }

    while (true) {
      ConcurrentLinkedDeque8.Node<GridEvent> node = evts.peekx();

      if (node == null) // Queue is empty.
      break;

      GridEvent evt = node.item();

      if (evt == null) // Competing with another thread.
      continue;

      if (now - evt.timestamp() < expireAgeMs) break;

      if (evts.unlinkx(node) && log.isDebugEnabled())
        log.debug("Event expired by age: " + node.item());
    }
  }
Exemplo n.º 2
0
  private void applyEvent(GridEvent event) {

    String fullJobId = event.getJobId();
    GridJob job = state.getJobByFullId(fullJobId);

    // Update the run state
    state.applyEvent(event);

    // Update the actor state
    switch (event.getType()) {
      case SUB:
        if (job == null) {
          job = new GridJob(event.getSnapshotJob());
        }
        applySub(job);
        break;
      case START:
        if (job == null) {
          log.error("Cannot start null job");
        } else {
          applyStart(job);
        }
        break;
      case END:
        if (job == null) {
          log.error("Cannot end null job");
        } else {
          applyEnd(job, event.getOffset());
        }
        break;
      default:
        log.warn("Unrecognized event type: {}", event.getType());
        break;
    }
  }
  /** {@inheritDoc} */
  @Override
  public void record(GridEvent evt) throws GridSpiException {
    assert evt != null;

    // Filter out events.
    if (filter == null || filter.apply(evt)) {
      cleanupQueue();

      evts.add(evt);

      // Make sure to filter out metrics updates to prevent log from flooding.
      if (evt.type() != EVT_NODE_METRICS_UPDATED && log.isDebugEnabled())
        log.debug("Event recorded: " + evt);
    }
  }