Exemplo n.º 1
0
 @Override
 public Map<String, Reportable> getSubMetrics() {
   Map<String, Reportable> map = new HashMap<String, Reportable>();
   if (src != null) {
     map.put("source." + src.getName(), src);
   }
   if (snk != null) {
     map.put("sink." + snk.getName(), snk);
   }
   return map;
 }
Exemplo n.º 2
0
    public void run() {
      EventSink sink = null;
      EventSource source = null;
      synchronized (DirectDriver.this) {
        sink = DirectDriver.this.sink;
        source = DirectDriver.this.source;
      }
      try {
        synchronized (stateSignal) {
          state = DriverState.OPENING;
          stateSignal.notifyAll();
        }
        source.open();
        sink.open();
      } catch (Exception e) {
        // if open is interrupted or has an exception there was a problem.
        LOG.error("Closing down due to exception on open calls");
        errorCleanup(PumperThread.this.getName(), e);
        return;
      }

      synchronized (stateSignal) {
        lastExn = null;
        state = DriverState.ACTIVE;
        stateSignal.notifyAll();
      }

      LOG.debug("Starting driver " + DirectDriver.this);
      try {
        Event e = null;

        while (!stopped) {
          try {
            e = source.next();
          } catch (InterruptedException eIn) {
            // If we are interrupted then its time to go down. re-throw the exception.
            // Details are logged by the outer catch block
            throw eIn;
          } catch (Exception eI) {
            // If this is a chained or converted Interrupt then throw it back
            if (eI.getCause() instanceof InterruptedException) throw eI;

            // If there's an exception, try to reopen the source
            // if the open or close still raises an exception, then bail out
            LOG.warn("Exception in source: " + source.getName(), eI);
            LOG.warn("Retrying after Error in source: " + source.getName());
            source.close();
            source.open();
            LOG.info(" Source Retry successful");
            e = source.next(); // try to get the next event again
          }

          if (e == null) {
            LOG.warn("{}: Event is null or empty()", source.getName());
            if ("NullSource".equals(source.getName())) {
              break;
            } else {
              continue;
            }
          }

          if (e.getBody().length == 0) {
            LOG.warn("Event is empty; continue");
            continue;
          }
          nextCount++;

          try {
            sink.append(e);
          } catch (InterruptedException eIn) {
            // If we are interrupted then its time to go down. re-throw the exception.
            // Details are logged by the outer catch block
            throw eIn;
          } catch (Exception eI) {
            // If this is a chained or converted Interrupt then throw it back
            if (eI.getCause() instanceof InterruptedException) throw eI;

            // If there's an exception, try to reopen the source
            // if the open or close still raises an exception, then bail out
            LOG.warn("Exception in sink: " + sink.getName(), eI);
            LOG.warn("Retrying after Error in source: " + sink.getName());
            sink.close();
            sink.open();
            LOG.info("Sink Retry successful");
            sink.append(e); // try to sink the event again
          }
          appendCount++;
          appendBytes += e.getBody().length;
        }
      } catch (Exception e1) {
        // Catches all exceptions or throwables. This is a separate thread
        LOG.error("Closing down due to exception during append calls");
        errorCleanup(PumperThread.this.getName(), e1);
        return;
      }

      try {
        synchronized (stateSignal) {
          state = DriverState.CLOSING;
          stateSignal.notifyAll();
        }
        source.close();
        sink.close();
      } catch (Exception e) {
        LOG.error("Closing down due to exception during close calls");
        errorCleanup(PumperThread.this.getName(), e);
        return;
      }
      synchronized (stateSignal) {
        LOG.debug("Driver completed: " + DirectDriver.this);
        stopped = true;
        state = DriverState.IDLE;
        stateSignal.notifyAll();
      }
    }