Package com.espertech.esper.client

Examples of com.espertech.esper.client.EPStatement


      for (EsperStatementBean esperStatementBean : _esperStatementBeansList) {
        // Add the statement to the Esper engine.
        _log.info(
            "Adding statement with name '{}' to Esper engine with URI '{}'",
            esperStatementBean.getName(), getEpService().getURI());
        final EPStatement statement = esperStatementBean.getName() == null ? _epService
            .getEPAdministrator().createEPL(
                esperStatementBean.getEsperStatement())
            : _epService.getEPAdministrator().createEPL(
                esperStatementBean.getEsperStatement(),
                esperStatementBean.getName());

        // Add a subscriber to the statement that logs all update
        // events to this statement.
        statement.setSubscriber(new LogSubscriber(statement));
      }
      _log.info("Finished parsing statements from {} .", statementsFile);

      _log.info("Finished adding statements from {} .", statementsFile);
    } catch (Exception e) {
View Full Code Here


        cepConfig.addEventType("StockTick", Tick.class.getName());
        EPServiceProvider cep = EPServiceProviderManager.getProvider("myCEPEngine", cepConfig);
        EPRuntime cepRT = cep.getEPRuntime();

        EPAdministrator cepAdm = cep.getEPAdministrator();
        EPStatement cepStatement = cepAdm.createEPL("select symbol,price,avg(price) from " + "StockTick(symbol='AAPL').win:length(10) "
                + "having avg(price) > 60.0");

        cepStatement.addListener(new CEPListener());

        // We generate a few ticks...
        for (int i = 0; i < 6000; i++) {
            generateRandomTick(cepRT);
            ThreadUtil.sleep(500);
View Full Code Here

        cepConfig.addEventType("Access", AccessRec.class);
        EPServiceProvider cep = EPServiceProviderManager.getProvider("myCEPEngine", cepConfig);
        EPRuntime cepRT = cep.getEPRuntime();

        EPAdministrator cepAdm = cep.getEPAdministrator();
        EPStatement cepStatement = cepAdm.createEPL("select ip, count(*) as cnt from Access.win:time(4 sec) group by ip"
                + " having count(*) > 50 output last every 2 seconds");

        cepStatement.setSubscriber(new SubscriberL());

        cepStatement = cepAdm.createEPL("select ip, rate(10) as cnt from Access.win:time(10 sec) group by ip");
        //cepStatement.setSubscriber(new SubscriberD());

        // We generate a few ticks...
View Full Code Here

          .compileEPL(epStatement.getEsperStatement());

      // Create the actual statement in the current Esper engine from the
      // statement model.
      final String stmtName = epStatement.getName();
      final EPStatement stmt = (stmtName == null ? epAdmin
          .create(stmtModel) : epAdmin.create(stmtModel, stmtName));

      // If an output sink was defined, then we add a subscriber.
      if (epStatement.getOutput() != null) {
        final String[] sinkNamesList = epStatement.getOutput();
        final List<Sink> sinksList = new ArrayList<Sink>();
        for (String sinkName : sinkNamesList) {
          final Sink sink = _sinksMap.get(sinkName);

          if (sink == null) {
            _log.warn(
                "Statement {} declares the sink {} "
                    + "but the corresponding Esper processor does not.",
                epStatement, sinkName);
          } else {
            sinksList.add(sink);
          }
        }
        final String[] propertyNames = stmt.getEventType()
            .getPropertyNames();

        final EsperStatementSubscriber subscriber = new EsperStatementSubscriber(
            sinksList, propertyNames);
        _log.info("Adding subscriber {} to statement {}",
            sinkNamesList, epStatement);
        stmt.setSubscriber(subscriber);

      }
    }
    _log.debug("Finished adding statements to Esper service");
View Full Code Here

    }

    // Create the actual statement in the current Esper engine from the
    // statement model.
    final String stmtName = epStatement.getName();
    final EPStatement stmt = (stmtName == null ? epAdmin.create(stmtModel)
        : epAdmin.create(stmtModel, stmtName));

    // If an output sink was defined, then we add a subscriber.
    if (epStatement.getOutput() != null) {
      final Sink[] sinksList = epStatement.getOutput();
      if (sinksList == null) {
        _log.warn("Statement {} has no sinks ");
      } else {
        final String[] propertyNames = stmt.getEventType()
            .getPropertyNames();

        final EsperStatementSubscriber subscriber = (epStatement
            .isRemoveBackticks() ? new EsperTrimmedStatementSubscriber(
            Arrays.asList(sinksList), propertyNames)
            : new EsperStatementSubscriber(
                Arrays.asList(sinksList), propertyNames));
        _log.info("Adding subscriber {} to statement {}", sinksList,
            epStatement);
        stmt.setSubscriber(subscriber);
      }

    }
    mapTimestampProperties();
    _log.info("Finished compiling statement {}", epStatement);
View Full Code Here

                statementName = options.getStatementNameResolver() != null ? options.getStatementNameResolver().getStatementName(ctx) : null;
                userObject = options.getStatementUserObjectResolver() != null ? options.getStatementUserObjectResolver().getUserObject(ctx) : null;
            }

            try {
                EPStatement stmt;
                if (optionalStatementIdGenerator == null) {
                    if (options.getIsolatedServiceProvider() == null) {
                        stmt = epService.createEPL(item.getExpression(), statementName, userObject);
                    }
                    else {
                        EPServiceProviderIsolated unit = statementIsolationService.getIsolationUnit(options.getIsolatedServiceProvider(), -1);
                        stmt = unit.getEPAdministrator().createEPL(item.getExpression(), statementName, userObject);
                    }
                }
                else {
                    String statementId = optionalStatementIdGenerator.getNextStatementId();
                    if (options.getIsolatedServiceProvider() == null) {
                        stmt = epService.createEPLStatementId(item.getExpression(), statementName, userObject, statementId);
                    }
                    else {
                        EPServiceProviderIsolated unit = statementIsolationService.getIsolationUnit(options.getIsolatedServiceProvider(), -1);
                        EPAdministratorIsolatedSPI spi = (EPAdministratorIsolatedSPI) unit.getEPAdministrator();
                        stmt = spi.createEPLStatementId(item.getExpression(), statementName, userObject, statementId);
                    }
                }
                statementNames.add(new DeploymentInformationItem(stmt.getName(), stmt.getText()));
                statements.add(stmt);

                Set<String> types = statementEventTypeRef.getTypesForStatementName(stmt.getName());
                if (types != null) {
                    eventTypesReferenced.addAll(types);
                }
            }
            catch (EPException ex) {
                exceptions.add(new DeploymentItemException(ex.getMessage(), item.getExpression(), ex, item.getLineNumber()));
                if (options.isFailFast()) {
                    break;
                }
            }
        }

        if (!exceptions.isEmpty()) {
            if (options.isRollbackOnFail()) {
                log.debug("Rolling back intermediate statements for deployment");
                for (EPStatement stmt : statements) {
                    try {
                        stmt.destroy();
                    }
                    catch (Exception ex) {
                        log.debug("Failed to destroy created statement during rollback: " + ex.getMessage(), ex);
                    }
                }
                EPLModuleUtil.undeployTypes(eventTypesReferenced, statementEventTypeRef, eventAdapterService, filterService);
            }
            String text = "Deployment failed";
            if (options.isValidateOnly()) {
                text = "Validation failed";
            }
            throw buildException(text, module, exceptions);
        }

        if (options.isValidateOnly()) {
            log.debug("Rolling back created statements for validate-only");
            for (EPStatement stmt : statements) {
                try {
                    stmt.destroy();
                }
                catch (Exception ex) {
                    log.debug("Failed to destroy created statement during rollback: " + ex.getMessage(), ex);
                }
            }
View Full Code Here

        }

        List<DeploymentInformationItem> revertedStatements = new ArrayList<DeploymentInformationItem>();
        Set<String> referencedTypes = new HashSet<String>();
        for (DeploymentInformationItem item : reverted) {
            EPStatement statement = epService.getStatement(item.getStatementName());
            if (statement == null) {
                log.debug("Deployment id '" + info.getDeploymentId() + "' statement name '" + item + "' not found");
                continue;
            }
            referencedTypes.addAll(statementEventTypeRef.getTypesForStatementName(statement.getName()));
            if (statement.isDestroyed()) {
                continue;
            }
            try {
                statement.destroy();
            }
            catch (RuntimeException ex) {
                log.warn("Unexpected exception destroying statement: " + ex.getMessage(), ex);
            }
            revertedStatements.add(item);
View Full Code Here

    public EPStatement createEPLStatementId(String eplStatement, String statementName, Object userObject, String statementId) throws EPException
    {
        SelectClauseStreamSelectorEnum defaultStreamSelector = SelectClauseStreamSelectorEnum.mapFromSODA(unisolatedServices.getConfigSnapshot().getEngineDefaults().getStreamSelection().getDefaultStreamSelector());
        StatementSpecRaw statementSpec = EPAdministratorHelper.compileEPL(eplStatement, eplStatement, true, statementName, unisolatedServices, defaultStreamSelector);
        EPStatement statement = unisolatedServices.getStatementLifecycleSvc().createAndStart(statementSpec, eplStatement, false, statementName, userObject, services, statementId, null);
        EPStatementSPI stmtSpi = (EPStatementSPI) statement;
        stmtSpi.getStatementContext().setInternalEventEngineRouteDest(isolatedRuntime);
        stmtSpi.setServiceIsolated(isolatedServiceName);
        statementNames.add(stmtSpi.getName());
        return statement;
View Full Code Here

    public void removeAllStatements()
    {
        List<EPStatement> statements = new ArrayList<EPStatement>();
        for (String stmtName : statementNames)
        {
            EPStatement stmt = unisolatedServices.getStatementLifecycleSvc().getStatementByName(stmtName);
            if (stmt == null)
            {
                log.error("Error returning statement '" + stmtName + "', the statement could not be found");
                continue;
            }

            if (stmt.getServiceIsolated() != null && (!stmt.getServiceIsolated().equals(isolatedServiceName)))
            {
                log.error("Error returning statement '" + stmtName + "', the internal isolation information is incorrect, isolated service for statement is currently '" +
                        stmt.getServiceIsolated() + "' and mismatches this isolated services named '" + isolatedServiceName + "'");
                continue;
            }

            statements.add(stmt);
        }
View Full Code Here

        Set<String> eventTypesReferenced = new HashSet<String>();

        for (ModuleItem item : module.getItems()) {
            try {

                EPStatement stmt;
                if (optionalStatementIdGenerator == null) {
                    if (options.getIsolatedServiceProvider() == null) {
                        stmt = epService.createEPL(item.getExpression());
                    }
                    else {
                        EPServiceProviderIsolated unit = statementIsolationService.getIsolationUnit(options.getIsolatedServiceProvider(), -1);
                        stmt = unit.getEPAdministrator().createEPL(item.getExpression(), null, null);
                    }
                }
                else {
                    String statementId = optionalStatementIdGenerator.getNextStatementId();
                    if (options.getIsolatedServiceProvider() == null) {
                        stmt = epService.createEPLStatementId(item.getExpression(), null, null, statementId);
                    }
                    else {
                        EPServiceProviderIsolated unit = statementIsolationService.getIsolationUnit(options.getIsolatedServiceProvider(), -1);
                        EPAdministratorIsolatedSPI spi = (EPAdministratorIsolatedSPI) unit.getEPAdministrator();
                        stmt = spi.createEPLStatementId(item.getExpression(), null, null, statementId);
                    }
                }
                statementNames.add(new DeploymentInformationItem(stmt.getName(), stmt.getText()));
                statements.add(stmt);

                Set<String> types = statementEventTypeRef.getTypesForStatementName(stmt.getName());
                if (types != null) {
                    eventTypesReferenced.addAll(types);
                }
            }
            catch (EPException ex) {
                exceptions.add(new DeploymentItemException(ex.getMessage(), item.getExpression(), ex, item.getLineNumber()));
                if (options.isFailFast()) {
                    break;
                }
            }
        }

        if (!exceptions.isEmpty()) {
            if (options.isRollbackOnFail()) {
                log.debug("Rolling back intermediate statements for deployment");
                for (EPStatement stmt : statements) {
                    try {
                        stmt.destroy();
                    }
                    catch (Exception ex) {
                        log.debug("Failed to destroy created statement during rollback: " + ex.getMessage(), ex);
                    }
                }
                EPLModuleUtil.undeployTypes(eventTypesReferenced, statementEventTypeRef, eventAdapterService, filterService);
            }
            String text = "Deployment failed";
            if (options.isValidateOnly()) {
                text = "Validation failed";
            }
            throw buildException(text, module, exceptions);
        }

        if (options.isValidateOnly()) {
            log.debug("Rolling back created statements for validate-only");
            for (EPStatement stmt : statements) {
                try {
                    stmt.destroy();
                }
                catch (Exception ex) {
                    log.debug("Failed to destroy created statement during rollback: " + ex.getMessage(), ex);
                }
            }
View Full Code Here

TOP

Related Classes of com.espertech.esper.client.EPStatement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.