Search in sources :

Example 21 with DbusEventKey

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Random(java.util.Random) DbusEvent(com.linkedin.databus.core.DbusEvent) DbusEventInternalWritable(com.linkedin.databus.core.DbusEventInternalWritable) ArrayList(java.util.ArrayList) DbusEventKey(com.linkedin.databus.core.DbusEventKey) InternalDatabusEventsListener(com.linkedin.databus.core.InternalDatabusEventsListener) Checkpoint(com.linkedin.databus.core.Checkpoint)

Aggregations

DbusEventKey (com.linkedin.databus.core.DbusEventKey)21 DbusEventInfo (com.linkedin.databus.core.DbusEventInfo)11 ByteBuffer (java.nio.ByteBuffer)7 Checkpoint (com.linkedin.databus.core.Checkpoint)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 DbusEventBuffer (com.linkedin.databus.core.DbusEventBuffer)4 ArrayList (java.util.ArrayList)4 Test (org.testng.annotations.Test)4 DbusEventBufferAppendable (com.linkedin.databus.core.DbusEventBufferAppendable)3 DbusEventInternalReadable (com.linkedin.databus.core.DbusEventInternalReadable)3 KeyTypeNotImplementedException (com.linkedin.databus.core.KeyTypeNotImplementedException)3 ConditionCheck (com.linkedin.databus2.test.ConditionCheck)3 Logger (org.apache.log4j.Logger)3 NettyHttpDatabusRelayConnection (com.linkedin.databus.client.netty.NettyHttpDatabusRelayConnection)2 NettyHttpDatabusRelayConnectionInspector (com.linkedin.databus.client.netty.NettyHttpDatabusRelayConnectionInspector)2 DbusEventV2Factory (com.linkedin.databus.core.DbusEventV2Factory)2 DbusEventsStatisticsCollector (com.linkedin.databus.core.monitoring.mbean.DbusEventsStatisticsCollector)2 RegisterResponseEntry (com.linkedin.databus2.core.container.request.RegisterResponseEntry)2 SchemaId (com.linkedin.databus2.schemas.SchemaId)2 SimpleObjectCaptureHandler (com.linkedin.databus2.test.container.SimpleObjectCaptureHandler)2