From ebdab671afd3c66ad261f425cba72ffeea92abf9 Mon Sep 17 00:00:00 2001
From: Jonathan Hsieh <jon@cloudera.com>
Date: Tue, 3 May 2011 21:02:41 -0700
Subject: [PATCH] FLUME-644: Remove unused parts of the Tagger

---
 .../flume/handlers/rolling/ProcessTagger.java      |   63 +-------------------
 .../cloudera/flume/handlers/rolling/Tagger.java    |    7 --
 .../flume/reporter/history/DumbTagger.java         |    6 --
 3 files changed, 1 insertions(+), 75 deletions(-)

diff --git a/flume-core/src/main/java/com/cloudera/flume/handlers/rolling/ProcessTagger.java b/flume-core/src/main/java/com/cloudera/flume/handlers/rolling/ProcessTagger.java
index a7b9faa..481900d 100644
--- a/flume-core/src/main/java/com/cloudera/flume/handlers/rolling/ProcessTagger.java
+++ b/flume-core/src/main/java/com/cloudera/flume/handlers/rolling/ProcessTagger.java
@@ -17,15 +17,10 @@
  */
 package com.cloudera.flume.handlers.rolling;
 
-import java.nio.ByteBuffer;
 import java.text.DateFormat;
-import java.text.ParsePosition;
 import java.text.SimpleDateFormat;
 import java.util.Date;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
 
-import com.cloudera.flume.core.Event;
 import com.cloudera.util.Clock;
 
 /**
@@ -33,58 +28,15 @@ import com.cloudera.util.Clock;
  * files. It uses a file name convention and to tag on batches of events.
  */
 public class ProcessTagger implements Tagger {
-  private final static Pattern p = Pattern
-      .compile(".*\\.(\\d+)\\.(\\d+-\\d+-\\d+)\\.seq");
-  private final static String DATE_FORMAT = "yyyyMMdd-HHmmssSSSZ";
 
-  /**
-   * These event attributes names are used to keep some group information on
-   * events.
-   */
-  public final static String A_TID = "tid";
-  public final static String A_EXE = "exe";
+  private final static String DATE_FORMAT = "yyyyMMdd-HHmmssSSSZ";
 
   String lastTag;
   Date last;
 
-  String exe;
-  long pid;
-
   public ProcessTagger() {
   }
 
-  public String createTag(String name, int pid) {
-    SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
-    String f;
-    f = dateFormat.format(new Date(Clock.unixTime()));
-
-    if (name.length() > 200) {
-      name = name.substring(0, 200); // concatenate long prefixes
-    }
-
-    long nanos = Clock.nanos();
-    // formatted so that lexigraphical and chronological can use same sort
-    // yyyyMMdd-HHmmssSSSz.0000000nanos.00000pid
-    String fname = String.format("%s.%012d.%08d", f, nanos, pid);
-    return fname;
-  }
-
-  public static Date extractDate(String s) {
-    DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
-    if (s == null)
-      return null;
-
-    Matcher m = p.matcher(s);
-
-    if (!m.find()) {
-      return null;
-    }
-    String date = m.group(2);
-
-    Date d = dateFormat.parse(date, new ParsePosition(0));
-    return d;
-  }
-
   @Override
   public String getTag() {
     return lastTag;
@@ -95,7 +47,6 @@ public class ProcessTagger implements Tagger {
     DateFormat dateFormat2 = new SimpleDateFormat(DATE_FORMAT);
 
     long pid = Thread.currentThread().getId();
-    String prefix = "log";
     Date now = new Date(Clock.unixTime());
     long nanos = Clock.nanos();
     String f;
@@ -103,16 +54,11 @@ public class ProcessTagger implements Tagger {
     synchronized (dateFormat2) {
       f = dateFormat2.format(now);
     }
-    if (prefix.length() > 200) {
-      prefix = prefix.substring(0, 200); // concatenate long prefixes
-    }
 
     // formatted so that lexigraphical and chronological can use same sort
     // yyyyMMdd-HHmmssSSSz.0000000nanos.00000pid
     lastTag = String.format("%s.%012d.%08d", f, nanos, pid);
 
-    this.pid = pid;
-    this.exe = prefix;
     this.last = now;
     return lastTag;
   }
@@ -125,11 +71,4 @@ public class ProcessTagger implements Tagger {
     return new Date(last.getTime()); // Defensive copy
   }
 
-  @Override
-  public void annotate(Event e) {
-    // ByteBuffer one liners are to convert longs to byte[8]s.
-    e.set(A_TID, ByteBuffer.allocate(8).putLong(pid).array());
-    e.set(A_EXE, exe.getBytes());
-    e.set(A_TXID, ByteBuffer.allocate(8).putLong(last.getTime()).array());
-  }
 }
diff --git a/flume-core/src/main/java/com/cloudera/flume/handlers/rolling/Tagger.java b/flume-core/src/main/java/com/cloudera/flume/handlers/rolling/Tagger.java
index e143f08..699cc73 100644
--- a/flume-core/src/main/java/com/cloudera/flume/handlers/rolling/Tagger.java
+++ b/flume-core/src/main/java/com/cloudera/flume/handlers/rolling/Tagger.java
@@ -19,8 +19,6 @@ package com.cloudera.flume.handlers.rolling;
 
 import java.util.Date;
 
-import com.cloudera.flume.core.Event;
-
 /**
  * A tagger is a mechanism that creates unique names for groups of events and
  * adds annotation data to events. It keeps some state -- the name for most
@@ -42,9 +40,4 @@ public interface Tagger {
 
   Date getDate();
 
-  /**
-   * This allows the tagger to add structured data or metadata to an event
-   */
-  void annotate(Event e);
-
 }
diff --git a/flume-core/src/main/java/com/cloudera/flume/reporter/history/DumbTagger.java b/flume-core/src/main/java/com/cloudera/flume/reporter/history/DumbTagger.java
index a5b0656..33d043d 100644
--- a/flume-core/src/main/java/com/cloudera/flume/reporter/history/DumbTagger.java
+++ b/flume-core/src/main/java/com/cloudera/flume/reporter/history/DumbTagger.java
@@ -19,7 +19,6 @@ package com.cloudera.flume.reporter.history;
 
 import java.util.Date;
 
-import com.cloudera.flume.core.Event;
 import com.cloudera.flume.handlers.rolling.Tagger;
 import com.cloudera.util.Clock;
 
@@ -51,9 +50,4 @@ public class DumbTagger implements Tagger {
     return getTag();
   }
 
-  @Override
-  public void annotate(Event e) {
-    // Do nothing
-  }
-
 }
-- 
1.7.1

