use of com.linkedin.databus.core.DbusEventKey in project databus by linkedin.
the class DummySuccessfulErrorCountingConsumer method writeEventsToBuffer.
static WriteEventsResult writeEventsToBuffer(DbusEventBuffer buf, DbusEventInfo[] eventInfos, int winSize) throws UnsupportedEncodingException {
Random rng = new Random(100);
final List<Integer> eventOfs = new ArrayList<Integer>(eventInfos.length);
final List<DbusEventKey> eventKeys = new ArrayList<DbusEventKey>(eventInfos.length);
InternalDatabusEventsListener ofsTracker = new InternalDatabusEventsListener() {
@Override
public void close() throws IOException {
}
@Override
public void onEvent(DbusEvent event, long offset, int size) {
DbusEventInternalWritable e = (DbusEventInternalWritable) event;
assertTrue("endEvents() gave us an invalid event! (offset = " + offset + ", size = " + size + ")", e.isValid(true));
// FIXME: is this correct? position() == offset; why subtract size?
eventOfs.add(e.getRawBytes().position() - e.size());
}
};
buf.addInternalListener(ofsTracker);
for (int i = 0; i < eventInfos.length; ++i) {
if (i % winSize == 0) {
if (i > 0)
buf.endEvents(i);
buf.startEvents();
}
DbusEventKey key = new DbusEventKey(RngUtils.randomString(rng, rng.nextInt(50)).getBytes("UTF-8"));
buf.appendEvent(key, eventInfos[i], null);
eventKeys.add(key);
}
buf.endEvents(eventInfos.length);
buf.removeInternalListener(ofsTracker);
return new WriteEventsResult(eventOfs, eventKeys);
}
Aggregations