/** * Adds another unique event to the shared buffer and assigns a unique id for it. It automatically creates a * lock on this event, so it won't be removed during processing of that event. Therefore the lock should be removed * after processing all {@link org.apache.flink.cep.nfa.ComputationState}s * * <p><b>NOTE:</b>Should be called only once for each unique event! * * @param value event to be registered * @return unique id of that event that should be used when putting entries to the buffer. * @throws Exception Thrown if the system cannot access the state. */ public EventId registerEvent(V value, long timestamp) throws Exception { return sharedBuffer.registerEvent(value, timestamp); }
@Test public void testSharedBufferCountersClearing() throws Exception { SharedBuffer<Event> sharedBuffer = TestSharedBuffer.createTestBuffer(Event.createTypeSerializer()); int numberEvents = 4; Event[] events = new Event[numberEvents]; for (int i = 0; i < numberEvents; i++) { events[i] = new Event(i + 1, "e" + (i + 1), i); sharedBuffer.registerEvent(events[i], i); } sharedBuffer.advanceTime(3); Iterator<Map.Entry<Long, Integer>> counters = sharedBuffer.getEventCounters(); Map.Entry<Long, Integer> entry = counters.next(); assertEquals(3, entry.getKey().longValue()); assertEquals(1, entry.getValue().intValue()); assertFalse(counters.hasNext()); }
eventIds[i] = sharedBuffer.registerEvent(events[i], timestamp);
eventIds[i] = sharedBuffer.registerEvent(events[i], timestamp);
@Test public void testClearingSharedBufferWithMultipleEdgesBetweenEntries() throws Exception { SharedBuffer<Event> sharedBuffer = TestSharedBuffer.createTestBuffer(Event.createTypeSerializer()); int numberEvents = 8; Event[] events = new Event[numberEvents]; EventId[] eventIds = new EventId[numberEvents]; final long timestamp = 1L; for (int i = 0; i < numberEvents; i++) { events[i] = new Event(i + 1, "e" + (i + 1), i); eventIds[i] = sharedBuffer.registerEvent(events[i], timestamp); } try (SharedBufferAccessor<Event> sharedBufferAccessor = sharedBuffer.getAccessor()) { NodeId start = sharedBufferAccessor.put("start", eventIds[1], null, DeweyNumber.fromString("1")); NodeId b0 = sharedBufferAccessor.put("branching", eventIds[2], start, DeweyNumber.fromString("1.0")); NodeId b1 = sharedBufferAccessor.put("branching", eventIds[3], start, DeweyNumber.fromString("1.1")); NodeId b00 = sharedBufferAccessor.put("branching", eventIds[3], b0, DeweyNumber.fromString("1.0.0")); sharedBufferAccessor.put("branching", eventIds[4], b00, DeweyNumber.fromString("1.0.0.0")); NodeId b10 = sharedBufferAccessor.put("branching", eventIds[4], b1, DeweyNumber.fromString("1.1.0")); //simulate IGNORE (next event can point to events[2]) sharedBufferAccessor.lockNode(b0); sharedBufferAccessor.releaseNode(b10); for (EventId eventId : eventIds) { sharedBufferAccessor.releaseEvent(eventId); } } //There should be still events[1] and events[2] in the buffer assertFalse(sharedBuffer.isEmpty()); }
/** * Adds another unique event to the shared buffer and assigns a unique id for it. It automatically creates a * lock on this event, so it won't be removed during processing of that event. Therefore the lock should be removed * after processing all {@link org.apache.flink.cep.nfa.ComputationState}s * * <p><b>NOTE:</b>Should be called only once for each unique event! * * @param value event to be registered * @return unique id of that event that should be used when putting entries to the buffer. * @throws Exception Thrown if the system cannot access the state. */ public EventId registerEvent(V value, long timestamp) throws Exception { return sharedBuffer.registerEvent(value, timestamp); }
/** * Adds another unique event to the shared buffer and assigns a unique id for it. It automatically creates a * lock on this event, so it won't be removed during processing of that event. Therefore the lock should be removed * after processing all {@link org.apache.flink.cep.nfa.ComputationState}s * * <p><b>NOTE:</b>Should be called only once for each unique event! * * @param value event to be registered * @return unique id of that event that should be used when putting entries to the buffer. * @throws Exception Thrown if the system cannot access the state. */ public EventId registerEvent(V value, long timestamp) throws Exception { return sharedBuffer.registerEvent(value, timestamp); }