Exemplo n.º 1
0
  private boolean processErrorEvent(DispatcherState curState, DbusEventInternalReadable nextEvent) {
    boolean success = false;
    DbusErrorEvent errorEvent = null;

    if (nextEvent.isErrorEvent()) {
      errorEvent = DbusEventSerializable.getErrorEventFromDbusEvent(nextEvent);

      if (null == errorEvent) {
        _log.error("Null error event received at dispatcher");
      } else {
        _log.info("Delivering error event to consumers: " + errorEvent);
        ConsumerCallbackResult callbackResult = ConsumerCallbackResult.ERROR;
        try {
          callbackResult = _asyncCallback.onError(errorEvent.returnActualException());
        } catch (RuntimeException e) {
          _log.error("Internal onError error: " + e.getMessage(), e);
        }
        success = ConsumerCallbackResult.isSuccess(callbackResult);
      }
    } else {
      _log.error("Unexcpected event received while DbusErrorEvent is expected! " + nextEvent);
    }

    return success;
  }
Exemplo n.º 2
0
  protected boolean storeCheckpoint(DispatcherState curState, Checkpoint cp, SCN winScn)
      throws IOException {
    boolean debugEnabled = _log.isDebugEnabled();

    if (debugEnabled) _log.debug("About to store checkpoint");

    boolean success = true;

    // processBatch - returns false ; then
    ConsumerCallbackResult callbackResult = getAsyncCallback().onCheckpoint(winScn);
    boolean persistCheckpoint =
        !ConsumerCallbackResult.isSkipCheckpoint(callbackResult)
            && ConsumerCallbackResult.isSuccess(callbackResult);
    if (persistCheckpoint) {
      if (null != getCheckpointPersistor()) {
        getCheckpointPersistor().storeCheckpointV3(getSubsciptionsList(), cp, _registrationId);
        ++_numCheckPoints;
      }
      curState.storeCheckpoint(cp, winScn);
      removeEvents(curState);
      if (debugEnabled) _log.debug("Checkpoint saved: " + cp.toString());
    } else {
      if (debugEnabled)
        _log.debug("Checkpoint " + cp + " not saved as callback returned " + callbackResult);
    }
    return success;
  }
Exemplo n.º 3
0
  protected void doStartDispatchEvents() {
    boolean debugEnabled = _log.isDebugEnabled();

    if (debugEnabled) _log.debug("Entered startDispatch");

    _asyncCallback.setSourceMap(_internalState.getSources());
    getStatus().start();

    ConsumerCallbackResult callbackResult = ConsumerCallbackResult.ERROR;
    try {
      callbackResult = _asyncCallback.onStartConsumption();
    } catch (RuntimeException e) {
      _log.error("Internal startConsumption error: " + e.getMessage(), e);
    }
    Boolean callSuccess = ConsumerCallbackResult.isSuccess(callbackResult);
    if (!callSuccess) {
      //      getStatus().suspendOnError(new RuntimeException("Unable to start processing of
      // events"));
      _log.error("StartConsumption failed.");
      _internalState.switchToStopDispatch();
      doStopDispatch(_internalState);
    } else {
      _stopDispatch.set(false);
      _internalState.switchToExpectEventWindow();
      doDispatchEvents();
    }
  }
Exemplo n.º 4
0
  protected boolean doEndStreamSource(DispatcherState curState) {
    boolean success = true;

    boolean debugEnabled = _log.isDebugEnabled();
    if (debugEnabled) _log.debug("Entered endSource");
    if (!curState.getStateId().equals(StateId.END_STREAM_SOURCE)) {
      success = false;
      _log.error("END_STREAM_SOURCE state expected but found :" + curState.getStateId());
    } else if (null == curState.getCurrentSource()) {
      success = false;
      _log.error("Missing source information in the current state");
    } else if (curState.getCurrentSource().getId() >= 0) {
      String sourceName = curState.getCurrentSource().getName();
      ConsumerCallbackResult callbackResult = ConsumerCallbackResult.ERROR;
      try {
        callbackResult =
            getAsyncCallback().onEndSource(sourceName, curState.getCurrentSourceSchema());
      } catch (RuntimeException e) {
        _log.error("Internal onEndSource error:" + e.getMessage(), e);
      }
      success = ConsumerCallbackResult.isSuccess(callbackResult);
      if (!success) {
        _log.error("Method endSource() failed for the source : " + sourceName);
      } else {
        if (debugEnabled) _log.debug("endSource succeeded:" + sourceName);
        curState.resetSourceInfo();
        curState.switchToExpectStreamDataEvents();
      }
    }

    return success;
  }
Exemplo n.º 5
0
  protected boolean doEndStreamEventWindow(DispatcherState curState) {
    boolean success = true;

    boolean debugEnabled = _log.isDebugEnabled();
    if (debugEnabled) _log.debug("Entered endDataEventSequence");
    if (!curState.getStateId().equals(StateId.END_STREAM_EVENT_WINDOW)) {
      success = false;
      _log.error("END_STREAM_EVENT_WINDOW state expected but found :" + curState.getStateId());
    } else {
      ConsumerCallbackResult callbackResult = ConsumerCallbackResult.ERROR;
      try {
        callbackResult = getAsyncCallback().onEndDataEventSequence(curState.getEndWinScn());
      } catch (RuntimeException e) {
        _log.error("Internal onEndDataEventSequence error: " + e.getMessage(), e);
      }
      success = ConsumerCallbackResult.isSuccess(callbackResult);
      if (success) {
        if (debugEnabled)
          _log.debug("endDataEventSequence callback succeeded:" + curState.getEndWinScn());
      } else {
        _log.error(
            "endDataEventSequence callback failed, the end window scn is: "
                + curState.getEndWinScn());
      }
    }

    return success;
  }
Exemplo n.º 6
0
  protected boolean processDataEventsBatch(DispatcherState curState) {
    DbusPrettyLogUtils.logExceptionAtDebug("Flushing batched events", null, _log);

    ConsumerCallbackResult callbackResult = getAsyncCallback().flushCallQueue(-1);
    boolean success = ConsumerCallbackResult.isSuccess(callbackResult);
    if (!success) {
      _log.error("Error dispatching events, the consumer callback returned an error");
    }

    return success;
  }
Exemplo n.º 7
0
  protected boolean processDataEvent(DispatcherState curState, DbusEvent event) {
    ConsumerCallbackResult callbackResult =
        getAsyncCallback().onDataEvent(event, curState.getEventDecoder());
    boolean success = ConsumerCallbackResult.isSuccess(callbackResult);

    if (!success) {
      _log.error("Method onDataEvent failed on consumer callback returned an error.");
    } else {
      _log.debug("Event queued: " + event.toString());
    }

    return success;
  }
Exemplo n.º 8
0
  protected void doRollback(
      DispatcherState curState, SCN rollbackScn, boolean checkRetries, boolean regressItr) {
    boolean success = true;

    boolean debugEnabled = _log.isDebugEnabled();

    if (!curState.getStateId().equals(StateId.ROLLBACK)) {
      success = false;
      _log.error(
          "ROLLBACK state is expected by the dispatcher, but the current state is:"
              + curState.getStateId());
    }

    int retriesLeft = Integer.MAX_VALUE;

    if (checkRetries) {
      retriesLeft = getStatus().getRetriesLeft();
      _log.info(
          "Rolling back the dispatcher to last successful checkpoint. Number of remaining retries for dispatcher to replay events = "
              + retriesLeft);
      success = success && (retriesLeft > 0);

      if (success) {
        if (0 == getStatus().getRetriesNum()) getStatus().retryOnError("rollback");
        else getStatus().retryOnLastError();
      }
    }

    if (success) {
      Checkpoint lastCp = curState.getLastSuccessfulCheckpoint();

      if ((null != lastCp) || (!regressItr)) {
        ConsumerCallbackResult callbackResult = ConsumerCallbackResult.ERROR;
        try {
          _log.info("Rolling back to SCN : " + rollbackScn);
          callbackResult = getAsyncCallback().onRollback(rollbackScn);
        } catch (RuntimeException e) {
          _log.error("Internal onRollback error: " + e.getMessage(), e);
        }

        success = ConsumerCallbackResult.isSuccess(callbackResult);
        if (success) {
          if (debugEnabled) _log.debug("Rollback consumer callback succeeded");
        } else {
          _log.error("Rollback consumer callback failed");
        }
      }

      if (regressItr) {
        if (null != curState.getLastSuccessfulIterator()) {
          _log.info(
              "Rolled back to last successful checkpoint position in the buffer: "
                  + curState.getLastSuccessfulIterator());
          _currentWindowSizeInBytes = 0;
          curState.switchToReplayDataEvents();
        } else {
          _log.fatal(
              "Unable to rollback, this usually means that the events belonging to the last checkpoint"
                  + " are no longer to be found in the buffer. Please checkpoint more frequently to avoid this. Restarting the client "
                  + "will fix this problem, last checkpoint found: \n"
                  + lastCp);
          curState.switchToClosed();
        }
      }
    } else {
      DispatcherRetriesExhaustedException exp = new DispatcherRetriesExhaustedException();
      _log.info("Invoke onError callback as dispatcher retries have exhausted");
      getAsyncCallback().onError(exp);
      curState.switchToClosed();
    }
  }