/** * Prunes matches/partial matches based on the chosen strategy. * * @param matchesToPrune current partial matches * @param matchedResult already completed matches * @param sharedBufferAccessor accessor to corresponding shared buffer * @throws Exception thrown if could not access the state */ public void prune( Collection<ComputationState> matchesToPrune, Collection<Map<String, List<EventId>>> matchedResult, SharedBufferAccessor<?> sharedBufferAccessor) throws Exception { EventId pruningId = getPruningId(matchedResult); if (pruningId != null) { List<ComputationState> discardStates = new ArrayList<>(); for (ComputationState computationState : matchesToPrune) { if (computationState.getStartEventID() != null && shouldPrune(computationState.getStartEventID(), pruningId)) { sharedBufferAccessor.releaseNode(computationState.getPreviousBufferEntry()); discardStates.add(computationState); } } matchesToPrune.removeAll(discardStates); } }
sharedBufferAccessor.releaseNode(newComputationState.getPreviousBufferEntry()); } else { sharedBufferAccessor.releaseNode(state.getPreviousBufferEntry()); sharedBufferAccessor.releaseNode(match.getPreviousBufferEntry());
/** * Removes the {@code SharedBufferNode}, when the ref is decreased to zero, and also * decrease the ref of the edge on this node. * * @param node id of the entry * @param sharedBufferNode the node body to be removed * @throws Exception Thrown if the system cannot access the state. */ private void removeNode(NodeId node, SharedBufferNode sharedBufferNode) throws Exception { sharedBuffer.removeEntry(node); EventId eventId = node.getEventId(); releaseEvent(eventId); for (SharedBufferEdge sharedBufferEdge : sharedBufferNode.getEdges()) { releaseNode(sharedBufferEdge.getTarget()); } }
sharedBufferAccessor.releaseNode(computationState.getPreviousBufferEntry());
sharedBufferAccessor.releaseNode(earliestMatch.getPreviousBufferEntry()); earliestMatch = nfaState.getCompletedMatches().peek();
assertEquals(1L, patterns3.size()); assertEquals(expectedPattern3, sharedBufferAccessor.materializeMatch(patterns3.get(0))); sharedBufferAccessor.releaseNode(b3); assertEquals(1L, patterns2.size()); assertEquals(expectedPattern2, sharedBufferAccessor.materializeMatch(patterns2.get(0))); sharedBufferAccessor.releaseNode(b1); sharedBufferAccessor.releaseNode(b0);
sharedBufferAccessor.releaseNode(computationState.getPreviousBufferEntry());
@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()); }
/** * Prunes matches/partial matches based on the chosen strategy. * * @param matchesToPrune current partial matches * @param matchedResult already completed matches * @param sharedBufferAccessor accessor to corresponding shared buffer * @throws Exception thrown if could not access the state */ public void prune( Collection<ComputationState> matchesToPrune, Collection<Map<String, List<EventId>>> matchedResult, SharedBufferAccessor<?> sharedBufferAccessor) throws Exception { EventId pruningId = getPruningId(matchedResult); if (pruningId != null) { List<ComputationState> discardStates = new ArrayList<>(); for (ComputationState computationState : matchesToPrune) { if (computationState.getStartEventID() != null && shouldPrune(computationState.getStartEventID(), pruningId)) { sharedBufferAccessor.releaseNode(computationState.getPreviousBufferEntry()); discardStates.add(computationState); } } matchesToPrune.removeAll(discardStates); } }
/** * Prunes matches/partial matches based on the chosen strategy. * * @param matchesToPrune current partial matches * @param matchedResult already completed matches * @param sharedBufferAccessor accessor to corresponding shared buffer * @throws Exception thrown if could not access the state */ public void prune( Collection<ComputationState> matchesToPrune, Collection<Map<String, List<EventId>>> matchedResult, SharedBufferAccessor<?> sharedBufferAccessor) throws Exception { EventId pruningId = getPruningId(matchedResult); if (pruningId != null) { List<ComputationState> discardStates = new ArrayList<>(); for (ComputationState computationState : matchesToPrune) { if (computationState.getStartEventID() != null && shouldPrune(computationState.getStartEventID(), pruningId)) { sharedBufferAccessor.releaseNode(computationState.getPreviousBufferEntry()); discardStates.add(computationState); } } matchesToPrune.removeAll(discardStates); } }
/** * Removes the {@code SharedBufferNode}, when the ref is decreased to zero, and also * decrease the ref of the edge on this node. * * @param node id of the entry * @param sharedBufferNode the node body to be removed * @throws Exception Thrown if the system cannot access the state. */ private void removeNode(NodeId node, SharedBufferNode sharedBufferNode) throws Exception { sharedBuffer.removeEntry(node); EventId eventId = node.getEventId(); releaseEvent(eventId); for (SharedBufferEdge sharedBufferEdge : sharedBufferNode.getEdges()) { releaseNode(sharedBufferEdge.getTarget()); } }
/** * Removes the {@code SharedBufferNode}, when the ref is decreased to zero, and also * decrease the ref of the edge on this node. * * @param node id of the entry * @param sharedBufferNode the node body to be removed * @throws Exception Thrown if the system cannot access the state. */ private void removeNode(NodeId node, SharedBufferNode sharedBufferNode) throws Exception { sharedBuffer.removeEntry(node); EventId eventId = node.getEventId(); releaseEvent(eventId); for (SharedBufferEdge sharedBufferEdge : sharedBufferNode.getEdges()) { releaseNode(sharedBufferEdge.getTarget()); } }
sharedBufferAccessor.releaseNode(computationState.getPreviousBufferEntry());
sharedBufferAccessor.releaseNode(newComputationState.getPreviousBufferEntry()); } else { sharedBufferAccessor.releaseNode(state.getPreviousBufferEntry()); sharedBufferAccessor.releaseNode(match.getPreviousBufferEntry());
sharedBufferAccessor.releaseNode(newComputationState.getPreviousBufferEntry()); } else { sharedBufferAccessor.releaseNode(state.getPreviousBufferEntry()); sharedBufferAccessor.releaseNode(match.getPreviousBufferEntry());
sharedBufferAccessor.releaseNode(computationState.getPreviousBufferEntry());
sharedBufferAccessor.releaseNode(earliestMatch.getPreviousBufferEntry()); earliestMatch = nfaState.getCompletedMatches().peek();
sharedBufferAccessor.releaseNode(earliestMatch.getPreviousBufferEntry()); earliestMatch = nfaState.getCompletedMatches().peek();
sharedBufferAccessor.releaseNode(computationState.getPreviousBufferEntry());
sharedBufferAccessor.releaseNode(computationState.getPreviousBufferEntry());