Package com.espertech.esper.client

Examples of com.espertech.esper.client.EPStatement


            publisherInstances.put(streamConfig.getName(), updateListener);
        }

        // Add the stream in the Esper engine
        for (final String sqlStatement : streamConfig.getSql()) {
            final EPStatement epl = epService.getEPAdministrator().createEPL(sqlStatement);
            for (final String publisherType : publishers.keySet()) {
                log.info(String.format("Added publisher [%-50s] to [%s]", publisherType, sqlStatement));
                epl.addListener(publishers.get(publisherType));
            }
            epl.start();
        }
    }
View Full Code Here


    final EPAdministrator epAdmin = _epService.getEPAdministrator();
    for (String epStatement : _epStatements) {
      _log.debug("Compiling Esper statement {}", epStatement);
      final EPStatementObjectModel stmtModel = epAdmin
          .compileEPL(epStatement);
      final EPStatement stmt = epAdmin.create(stmtModel);
      final String stmtName = Integer.toString(epStatement.hashCode());
      // TODO fast hack disabling queues, since they are currently not
      // supported by Streams-Storm.
      final Sink sink = _sinksMap.get(_statementSinksMap.get(stmtName));
      final String[] propertyNames = stmt.getEventType()
          .getPropertyNames();
      if (sink != null) {
        final EsperStatementSubscriber subscriber = new EsperStatementSubscriber(
            sink, propertyNames);
        _log.debug("Adding subscriber to statement {}", stmtName);
        stmt.setSubscriber(subscriber);
      }
    }
    _log.debug("Finished adding statements to Esper service");

    _log.debug("Mapping event types to timestamp properties, if any");
View Full Code Here

    public EPStatement createEPL(String eplStatement, String statementName, Object userObject) 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);
        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 (options.getIsolatedServiceProvider() == null) {
                    stmt = epService.createEPL(item.getExpression());
                }
                else {
                    EPServiceProviderIsolated unit = statementIsolationService.getIsolationUnit(options.getIsolatedServiceProvider(), -1);
                    stmt = unit.getEPAdministrator().createEPL(item.getExpression(), null, null);
                }
                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);
                    }
                }
                undeployTypes(eventTypesReferenced);
            }
            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

        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

        }

        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

       
        Logger log = Logger.getLogger(IbEsper.class);
       
        EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider();
        String expressionString = "select avg(price) from com.squirrelhill.ibesper.event.TickPriceEvent.win:time(30 sec)";
        EPStatement statement = epService.getEPAdministrator().createEPL(expressionString);
        statement.addListener(new TickPriceEventListener());

        IbDataProducer dataProvider = new IbDataProducer();
        final SQLiteDataConsumer dataConsumer = new SQLiteDataConsumer("jdbc:sqlite:mktdata.db");
       
        try {
View Full Code Here

        // read all lines into the buffer.
        while ((line = reader.readLine()) != null) {
          buffer.append(line);
        }
        // Add the statement to the Esper engine.
        final EPStatement statement = _epService.getEPAdministrator()
            .createEPL(buffer.toString().trim());

        // Add a subscriber to the statement that logs all update
        // events to this statement.
        statement.setSubscriber(new LogSubscriber(statement));

        _log.info("Finished reading statement file {}.", statementFile);
      } catch (Exception e) {
        _log.error("Error reading statement file {}!", statementFile, e);
        assert false;
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.