version is 1.0.0 now and upgraded lwes-java to 0.2.4
[lwes-journaller-java.git] / src / main / java / org / lwes / journaller / SequenceDejournaller.java
blob0ef42428620e6c9baeb9b85a8f5e4626c1f4d331
1 package org.lwes.journaller;
2 /**
3 * @author fmaritato
4 */
6 import org.apache.commons.logging.Log;
7 import org.apache.commons.logging.LogFactory;
8 import org.apache.hadoop.conf.Configuration;
9 import org.apache.hadoop.fs.FileSystem;
10 import org.apache.hadoop.fs.Path;
11 import org.apache.hadoop.io.BytesWritable;
12 import org.apache.hadoop.io.NullWritable;
13 import org.apache.hadoop.io.SequenceFile;
14 import org.kohsuke.args4j.CmdLineException;
15 import org.lwes.Event;
16 import org.lwes.EventSystemException;
17 import org.lwes.db.EventTemplateDB;
19 import java.io.IOException;
21 public class SequenceDejournaller extends DeJournaller {
23 private static transient Log log = LogFactory.getLog(SequenceDejournaller.class);
25 public void run() {
26 Configuration conf = new Configuration();
27 FileSystem fs = null;
28 SequenceFile.Reader reader = null;
29 try {
30 if (log.isDebugEnabled()) {
31 log.debug("Opening file: " + getFileName());
33 fs = FileSystem.get(conf);
34 Path p = new Path(getFileName());
35 reader = new SequenceFile.Reader(fs, p, conf);
37 BytesWritable key = (BytesWritable) reader.getKeyClass().newInstance();
38 NullWritable value = NullWritable.get();
40 EventTemplateDB templ = new EventTemplateDB();
41 while (reader.next(key, value)) {
42 Event evt = new Event(key.getBytes(), false, templ);
43 if (log.isDebugEnabled()) {
44 log.debug("read a k/v: "+evt.toOneLineString());
46 handleEvent(evt);
49 catch (IOException e) {
50 log.error(e.getMessage(), e);
52 catch (InstantiationException e) {
53 log.error(e.getMessage(), e);
55 catch (IllegalAccessException e) {
56 log.error(e.getMessage(), e);
58 catch (EventSystemException e) {
59 log.error(e.getMessage(), e);
61 finally {
62 if (reader != null) {
63 try {
64 reader.close();
66 catch (IOException e) {
67 log.error(e.getMessage(), e);
73 public static void main(String[] args) {
74 SequenceDejournaller dj = new SequenceDejournaller();
75 try {
76 dj.parseArguments(args);
78 catch (CmdLineException e) {
79 log.error(e.getMessage(), e);
81 dj.run();