/** Returns a new sink when the roller asks for a new one. */
  public synchronized EventSink newWritingSink(final Tagger tagger) throws IOException {
    File dir = getDir(State.WRITING);
    final String tag = tagger.newTag();
    EventSink curSink = new SeqfileEventSink(new File(dir, tag).getAbsoluteFile());
    writingQ.add(tag);
    DFOData data = new DFOData(tag);
    table.put(tag, data);
    writingCount.incrementAndGet();

    return new EventSinkDecorator<EventSink>(curSink) {
      @Override
      public synchronized void append(Event e) throws IOException, InterruptedException {
        synchronized (NaiveFileFailoverManager.this) {
          getSink().append(e);
          writingEvtCount.incrementAndGet();
        }
      }

      @Override
      public synchronized void close() throws IOException, InterruptedException {
        synchronized (NaiveFileFailoverManager.this) {
          super.close();
          if (!writingQ.contains(tag)) {
            LOG.warn("Already changed tag " + tag + " out of WRITING state");
            return;
          }
          LOG.info("File lives in " + getFile(tag));

          changeState(tag, State.WRITING, State.LOGGED);
          loggedCount.incrementAndGet();
        }
      }
    };
  }
Example #2
0
 @Override
 public CounterSink newSink(Tagger format) throws IOException {
   return new CounterSink(format.newTag());
 }