public static void deploy(EPRuntime runtime, EPCompiled compiled) { try { runtime.getDeploymentService().deploy(compiled, new DeploymentOptions().setDeploymentId("stockticker")); } catch (EPDeployException ex) { throw new RuntimeException(ex); } } }
public static void deployAddListener(EPCompiled compiledStmt, String stmtName, UpdateListener listener, EPRuntime runtime) { try { EPDeployment deployed = runtime.getDeploymentService().deploy(compiledStmt, new DeploymentOptions().setStatementNameRuntime(ctx -> stmtName)); if (deployed.getStatements().length != 1) { throw new UnsupportedOperationException("This method is designed for a single statement"); } deployed.getStatements()[0].addListener(listener); } catch (EPDeployException e) { throw new RuntimeException(e); } }
private static void assertDeploy(RegressionEnvironment env, EPCompiled compiled, AtomicInteger milestone, Object userObject) { DeploymentOptions options = new DeploymentOptions(); options.setStatementUserObjectRuntime(new StatementUserObjectRuntimeOption() { public Object getUserObject(StatementUserObjectRuntimeContext env) { return userObject; } }); try { env.deployment().deploy(compiled, options); } catch (EPDeployException e) { fail(e.getMessage()); } env.undeployAll(); }
private static void deployWithResolver(RegressionEnvironment env, EPCompiled compiled, String statementName, StatementSubstitutionParameterOption resolver) { DeploymentOptions options = new DeploymentOptions().setStatementSubstitutionParameter(resolver); options.setStatementNameRuntime(context -> statementName); try { env.deployment().deploy(compiled, options); } catch (EPDeployException e) { throw new RuntimeException(e); } }
private static void compileDeployWSubstitution(RegressionEnvironment env, String epl, Map<String, Object> params) { EPCompiled compiled = env.compile("@name('s0') " + epl); StatementSubstitutionParameterOption resolver = ctx -> { for (Map.Entry<String, Object> entry : params.entrySet()) { ctx.setObject(entry.getKey(), entry.getValue()); } }; env.deploy(compiled, new DeploymentOptions().setStatementSubstitutionParameter(resolver)); env.addListener("s0"); }
private static EPStatement[] createStmts(RegressionEnvironment env, String[] deploymentIds, String[] statementNames) { assertEquals(deploymentIds.length, statementNames.length); EPStatement[] statements = new EPStatement[statementNames.length]; EPCompiled compiled = env.compile("select * from SupportBean"); for (int i = 0; i < statementNames.length; i++) { final int num = i; try { EPDeployment deployed = env.deployment().deploy(compiled, new DeploymentOptions().setDeploymentId(deploymentIds[i]).setStatementNameRuntime(new StatementNameRuntimeOption() { public String getStatementName(StatementNameRuntimeContext env) { return statementNames[num]; } })); statements[i] = deployed.getStatements()[0]; } catch (EPDeployException e) { throw new RuntimeException(e); } } return statements; } }
public void run(RegressionEnvironment env) { MySubstitutionOption.getContexts().clear(); EPCompiled compiled = env.compile("@name('s0') select ?:p0:int as c0 from SupportBean"); DeploymentOptions options = new DeploymentOptions().setStatementSubstitutionParameter(new MySubstitutionOption()); options.setDeploymentId("abc"); try { env.deployment().deploy(compiled, options); fail(); } catch (EPDeployException e) { // expected } assertEquals(1, MySubstitutionOption.getContexts().size()); StatementSubstitutionParameterContext ctx = MySubstitutionOption.getContexts().get(0); assertNotNull(ctx.getAnnotations()); assertEquals("abc", ctx.getDeploymentId()); assertNotNull(ctx.getEpl()); assertTrue(ctx.getStatementId() > 0); assertEquals("s0", ctx.getStatementName()); assertEquals(Integer.class, ctx.getSubstitutionParameterTypes()[0]); assertEquals((Integer) 1, ctx.getSubstitutionParameterNames().get("p0")); } }
public EPDeployment deploy(EPCompiled compiled) throws EPDeployException { return deploy(compiled, new DeploymentOptions()); }
options.getDeploymentLockStrategy().acquire(services.getEventProcessingRWLock()); } catch (Exception e) { throw new EPDeployLockException(e.getMessage(), e); if (options.getDeploymentId() == null) { deploymentId = UUID.randomUUID().toString(); } else { deploymentId = options.getDeploymentId(); deployerResult = Deployer.deployFresh(deploymentId, currentStatementId, compiled, options.getStatementNameRuntime(), options.getStatementUserObjectRuntime(), options.getStatementSubstitutionParameter(), runtime); statementIdRecovery.setCurrentStatementId(currentStatementId + deployerResult.getStatements().length); options.getDeploymentLockStrategy().release(services.getEventProcessingRWLock());
private static void tryInvalidResolver(RegressionEnvironment env, EPCompiled compiled, String expected, StatementSubstitutionParameterOption resolver) { DeploymentOptions options = new DeploymentOptions().setStatementSubstitutionParameter(resolver); try { env.deployment().deploy(compiled, options); fail(); } catch (EPDeploySubstitutionParameterException e) { SupportMessageAssertUtil.assertMessage(e.getMessage(), expected); } catch (EPDeployException e) { throw new RuntimeException(e); } }
public void run(RegressionEnvironment env) { env.advanceTime(0); String text = "select rstream theString from SupportBean#time(?::int)"; EPCompiled compiled = env.compile(text); env.deploy(compiled, new DeploymentOptions() .setStatementSubstitutionParameter(prepared -> prepared.setObject(1, 4)) .setStatementNameRuntime(ctx -> "s0")); env.deploy(compiled, new DeploymentOptions() .setStatementSubstitutionParameter(prepared -> prepared.setObject(1, 3)) .setStatementNameRuntime(ctx -> "s1")); env.addListener("s0").addListener("s1"); runAssertion(env); env.undeployAll(); } }
public void run(RegressionEnvironment env) { EPCompiled compiled = env.compile("select * from SupportBean"); env.deploy(compiled, new DeploymentOptions().setDeploymentId("ABC")); try { env.runtime().getDeploymentService().deploy(compiled, new DeploymentOptions().setDeploymentId("ABC")); fail(); } catch (EPDeployDeploymentExistsException ex) { SupportMessageAssertUtil.assertMessage(ex, "Deployment by id 'ABC' already exists"); } catch (EPDeployException ex) { throw new RuntimeException(ex); } env.undeployAll(); } }
public void run(RegressionEnvironment env) { String expression = "@name('s0') select * from pattern [every timer:at(?::int,?::int,*,*,[1,2,3,4,5])]"; Calendar cal = GregorianCalendar.getInstance(); cal.set(Calendar.MILLISECOND, 0); cal.set(2008, 7, 3, 10, 0, 0); // start on a Sunday at 6am, August 3 2008 sendTimer(cal.getTimeInMillis(), env); EPCompiled compiled = env.compile(expression); env.deploy(compiled, new DeploymentOptions().setStatementSubstitutionParameter(prepared -> { prepared.setObject(1, 0); prepared.setObject(2, 8); })); env.addListener("s0"); tryAssertion(env); env.undeployAll(); } }
private EPStatement compileDeploy(String expression, String statementName) { try { CompilerArguments args = new CompilerArguments(runtime.getRuntimePath()); EPCompiled compiled = EPCompilerProvider.getCompiler().compile(expression, args); DeploymentOptions options = new DeploymentOptions(); options.setStatementNameRuntime(env -> statementName); return runtime.getDeploymentService().deploy(compiled, options).getStatements()[0]; } catch (Exception ex) { throw new RuntimeException("Failed to compile and deploy: " + ex.getMessage(), ex); } } }
public void run(RegressionEnvironment env) { EPCompiled compiled = env.compile("expression myindex {pointregionquadtree(0, 0, 100, 100)}" + "select * from SupportSpatialAABB(point(?::int, ?::int, filterindex:myindex).inside(rectangle(x, y, width, height)))"); SupportUpdateListener listener = new SupportUpdateListener(); int count = 0; for (int x = 0; x < 10; x++) { for (int y = 0; y < 10; y++) { int finalX = x; int finalY = y; String name = x + "_" + y; DeploymentOptions options = new DeploymentOptions().setStatementSubstitutionParameter(prepared -> { prepared.setObject(1, finalX); prepared.setObject(2, finalY); }).setStatementNameRuntime(ctx -> name); env.deploy(compiled, options).statement(name).addListener(listener); // System.out.println("Deployed #" + count); count++; } } sendAssertSpatialAABB(env, listener, 10, 10, 1000); env.undeployAll(); } }
public void registerStatement(String epl, Object userObject) { // Compile statement. We simply use the provided configuration. CompilerArguments args = new CompilerArguments(runtime.getConfigurationDeepCopy()); args.getConfiguration().getCompiler().getByteCode().setAllowSubscriber(true); // using subcribers EPCompiled compiled; try { compiled = EPCompilerProvider.getCompiler().compile(epl, args); } catch (EPCompileException e) { throw new RuntimeException("Failed to compile: " + e.getMessage(), e); } EPStatement stmt; try { stmt = runtime.getDeploymentService().deploy(compiled, new DeploymentOptions().setStatementUserObjectRuntime(ctx -> userObject)).getStatements()[0]; } catch (EPDeployException e) { throw new RuntimeException("Failed to deploy: " + e.getMessage(), e); } if (System.getProperty("esper.benchmark.ul") != null) { stmt.addListener(updateListener); } else { stmt.setSubscriber(subscriber); } }
public static void setup(EPRuntime runtime, MatchAlertListener listener) { // Allocate a partition (session) that lasts for a mobile user until they sent a new event with new location String eplContext = "create context PerUser " + "initiated by MobileUserBean as mub " + "terminated by MobileUserBean(userId = mub.userId);\n"; // For each partition find a match within the location range String eplMatch = "@name('alert') context PerUser select mub as self, context.mub as other from MobileUserBean (" + "locationX in [(context.mub.locationX - 1) : (context.mub.locationX + 1)]," + "locationY in [(context.mub.locationY - 1) : (context.mub.locationY + 1)]," + "myGender = context.mub.preferredGender, " + "myAgeRange = context.mub.preferredAgeRange, " + "myHairColor = context.mub.preferredHairColor, " + "preferredGender = context.mub.myGender, " + "preferredAgeRange = context.mub.myAgeRange, " + "preferredHairColor = context.mub.myHairColor," + "userId != context.mub.userId" + ") as mub;\n"; try { EPCompiled compiled = EPCompilerProvider.getCompiler().compile(eplContext + eplMatch, new CompilerArguments(runtime.getRuntimePath())); runtime.getDeploymentService().deploy(compiled, new DeploymentOptions().setDeploymentId("matchmaker-deployment")); } catch (Exception ex) { throw new RuntimeException(ex); } runtime.getDeploymentService().getStatement("matchmaker-deployment", "alert").addListener(listener); } }
public void run(RegressionEnvironment env) { EPCompiled compiled; DeploymentOptions options; // numbered, typed compiled = env.compile("select * from SupportBean(theString=?::string)"); options = new DeploymentOptions().setStatementSubstitutionParameter(prepared -> { tryInvalidSetObject(prepared, stmt -> stmt.setObject(1, 10), "Failed to set substitution parameter 1, expected a value of type 'java.lang.String': " + SupportJavaVersionUtil.getCastMessage(Integer.class, String.class)); prepared.setObject(1, "abc"); }); deployWithOptionsWUndeploy(env, compiled, options); // name, typed compiled = env.compile("select * from SupportBean(theString=?:p0:string)"); options = new DeploymentOptions().setStatementSubstitutionParameter(prepared -> { tryInvalidSetObject(prepared, stmt -> stmt.setObject("p0", 10), "Failed to set substitution parameter 'p0', expected a value of type 'java.lang.String': " + SupportJavaVersionUtil.getCastMessage(Integer.class, String.class)); prepared.setObject("p0", "abc"); }); deployWithOptionsWUndeploy(env, compiled, options); // name, primitive compiled = env.compile("select * from SupportBean(intPrimitive=?:p0:int)"); options = new DeploymentOptions().setStatementSubstitutionParameter(prepared -> { // There is only boxed type consistent with all other column/variable/schema typing: // tryInvalidSetObject(prepared, stmt -> stmt.setObject("p0", null), "Failed to set substitution parameter 'p0', expected a value of type 'int': Received a null-value for a primitive type"); prepared.setObject("p0", 10); }); deployWithOptionsWUndeploy(env, compiled, options); } }
public void run(RegressionEnvironment env) { EPCompiled compiled = env.compile("select * from SupportBean;select * from SupportBean;"); try { env.deployment().deploy(compiled, new DeploymentOptions().setStatementNameRuntime(new StatementNameRuntimeOption() { public String getStatementName(StatementNameRuntimeContext env) { return "x"; } })); fail(); } catch (EPDeployException e) { assertMessage(e, "Duplicate statement name provide by statement name resolver for statement name 'x'"); } } }
public void run(RegressionEnvironment env) { MyUserObjectRuntimeOption.getContexts().clear(); String epl = "@name('s0') select * from SupportBean"; EPCompiled compiled = env.compile(epl); DeploymentOptions options = new DeploymentOptions(); options.setStatementUserObjectRuntime(new MyUserObjectRuntimeOption()); try { env.deployment().deploy(compiled, options); } catch (EPDeployException e) { fail(e.getMessage()); } StatementUserObjectRuntimeContext ctx = MyUserObjectRuntimeOption.getContexts().get(0); assertEquals("s0", ctx.getStatementName()); assertEquals(env.deploymentId("s0"), ctx.getDeploymentId()); assertSame(env.statement("s0").getAnnotations(), ctx.getAnnotations()); assertEquals(epl, ctx.getEpl()); env.undeployAll(); } }