package com.cloudera.flume.handlers.avro;
import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang.NotImplementedException;
import org.apache.commons.lang.StringEscapeUtils;
import com.cloudera.flume.core.Event;
import com.cloudera.flume.core.EventImpl;
import com.google.common.base.Preconditions;
AvroFlumeEvent evt = null;
super();
this.evt = evt;
}
@Override
return evt.body.array();
}
@Override
return convert(evt.priority);
}
@Override
return evt.timestamp;
}
public static Priority
convert(com.cloudera.flume.handlers.avro.Priority p) {
Preconditions.checkNotNull(p, "Prioirity argument must be valid.");
switch (p) {
case FATAL:
return Priority.FATAL;
case ERROR:
return Priority.ERROR;
case WARN:
return Priority.WARN;
case INFO:
return Priority.INFO;
case DEBUG:
return Priority.DEBUG;
case TRACE:
return Priority.TRACE;
default:
throw new IllegalStateException("Unknown value " + p);
}
}
public static com.cloudera.flume.handlers.avro.Priority
convert(Priority p) {
Preconditions.checkNotNull(p, "Argument must not be null.");
switch (p) {
case FATAL:
return com.cloudera.flume.handlers.avro.Priority.FATAL;
case ERROR:
return com.cloudera.flume.handlers.avro.Priority.ERROR;
case WARN:
return com.cloudera.flume.handlers.avro.Priority.WARN;
case INFO:
return com.cloudera.flume.handlers.avro.Priority.INFO;
case DEBUG:
return com.cloudera.flume.handlers.avro.Priority.DEBUG;
case TRACE:
return com.cloudera.flume.handlers.avro.Priority.TRACE;
default:
throw new IllegalStateException("Unknown value " + p);
}
}
@Override
String mbody = StringEscapeUtils.escapeJava(new String(getBody()));
return "[" + getPriority().toString() + " " + new Date(getTimestamp())
+ "] " + mbody;
}
@Override
return evt.nanos;
}
@Override
return evt.host.toString();
}
public static AvroFlumeEvent
convert(Event e) {
AvroFlumeEvent tempAvroEvt = new AvroFlumeEvent();
tempAvroEvt.timestamp = e.getTimestamp();
tempAvroEvt.priority = convert(e.getPriority());
ByteBuffer bbuf = ByteBuffer.wrap(e.getBody());
tempAvroEvt.body = bbuf;
tempAvroEvt.nanos = e.getNanos();
tempAvroEvt.host = e.getHost();
tempAvroEvt.fields = new HashMap<CharSequence, ByteBuffer>();
for (String s : e.getAttrs().keySet()) {
ByteBuffer temp = ByteBuffer.wrap(e.getAttrs().get(s));
tempAvroEvt.fields.put(s, temp);
}
return tempAvroEvt;
}
Preconditions.checkNotNull(evt, "AvroFlumeEvent is not initialized");
return new EventImpl(this.getBody(), this.getTimestamp(), this
.getPriority(), this.getNanos(), this.getHost(), this.getAttrs());
}
@Override
public byte[]
get(String attr) {
return evt.fields.get(attr).array();
}
@Override
if (evt.fields == null) {
return Collections.<String, byte[]> emptyMap();
}
HashMap<String, byte[]> tempMap = new HashMap<String, byte[]>();
for (CharSequence u : evt.fields.keySet()) {
tempMap.put(u.toString(), evt.fields.get(u).array());
}
return tempMap;
}
@Override
public void set(String attr,
byte[] value) {
if (evt.fields.get(attr) != null) {
throw new IllegalArgumentException(
"Event already had an event with attribute " + attr);
}
ByteBuffer bbuf = ByteBuffer.wrap(value);
evt.fields.put(attr, bbuf);
}
@Override
throw new NotImplementedException();
}
@Override
public void merge(Event e) {
throw new NotImplementedException();
}
}