int appendMatches(PatternExtractor pe, MatchedHandler[] matches, int jin) { Object p = pe.extractPattern(); int j = jin; MatchedHandler[] handlers = subscriptions.get(p); if (handlers != null) { for (int k = 0; k < handlers.length; k++) { matches[j] = handlers[k]; j++; } } return j; } }
public static Object peelAllLayers(PatternExtractor obj) { PatternExtractor o = obj; while (o.extractValue() instanceof PatternExtractor) { o = (PatternExtractor) o.extractValue(); } return o.extractValue(); }
public static Optional<PatternExtractor> peelToLayer(PatternExtractor obj, Object patternType) { PatternExtractor o = obj; while(true) { if(o.extractPattern().equals(patternType)) { return Optional.of(o); } Object value = o.extractValue(); if(!(value instanceof PatternExtractor)) { return Optional.empty(); } o = (PatternExtractor)value; } } }
public static Object peelOneLayer(PatternExtractor obj) { return obj.extractValue(); }
boolean matches(PatternExtractor pe) { Object p = pe.extractPattern(); return subscriptions.containsKey(p); }
@SuppressWarnings("unchecked") private boolean executeEvent(PatternExtractor<?, ?> event, MatchedHandler<?, ?, ?> handler) { try { PatternExtractor<?, Object> pe = (PatternExtractor<?, Object>) event; MatchedHandler<?, Object, PatternExtractor<?, Object>> h = (MatchedHandler<?, Object, PatternExtractor<?, Object>>) handler; h.handle(pe.extractValue(), pe); return false; // no state change } catch (Throwable throwable) { logger().error("Handling an event caused a fault! Might be handled later...", throwable); markSubtreeAs(State.FAULTY); escalateFault(new Fault(throwable, this, event)); return true; // state changed } }