public static PolicyStreamHandler createHandler(PolicyDefinition.Definition definition, Map<String, StreamDefinition> sds) { if (SIDDHI_ENGINE.equals(definition.getType())) { return new SiddhiPolicyHandler(sds, 0);// // FIXME: 8/2/16 } else if (NO_DATA_ALERT_ENGINE.equals(definition.getType())) { // no data for an entire stream won't trigger gap alert (use local time & batch window instead) return new NoDataPolicyTimeBatchHandler(sds); } else if (ABSENCE_ALERT_ENGINE.equals(definition.getType())) { return new AbsencePolicyHandler(sds); } else if (CUSTOMIZED_ENGINE.equals(definition.getType())) { try { Class<?> handlerClz = Class.forName(definition.getHandlerClass()); PolicyStreamHandler handler = (PolicyStreamHandler) handlerClz.getConstructor(Map.class).newInstance(sds); return handler; } catch (Exception e) { LOG.error("Not able to create policy handler for handler class " + definition.getHandlerClass(), e); throw new IllegalArgumentException("Illegal extended policy handler class!" + definition.getHandlerClass()); } } throw new IllegalArgumentException("Illegal policy stream handler type " + definition.getType()); }
public void test(PolicyDefinition pd) throws Exception { Map<String, StreamDefinition> sds = new HashMap<>(); StreamDefinition sd = buildStreamDef(); sds.put("testInputStream", sd); AbsencePolicyHandler handler = new AbsencePolicyHandler(sds); PolicyHandlerContext context = new PolicyHandlerContext(); context.setPolicyDefinition(pd); handler.prepare(new TestCollector(), context); handler.send(buildStreamEvt(0, "job1", "running")); }