public static Object peelAllLayers(PatternExtractor obj) { PatternExtractor o = obj; while (o.extractValue() instanceof PatternExtractor) { o = (PatternExtractor) o.extractValue(); } return o.extractValue(); }
public static Object peelOneLayer(PatternExtractor obj) { return obj.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; } } }
@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 } }