Package com.espertech.esper.client

Examples of com.espertech.esper.client.EPStatement


        }

        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.debug("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

          .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 sinkName = epStatement.getOutput();
        final Sink sink = _sinksMap.get(sinkName);
        final String[] propertyNames = stmt.getEventType()
            .getPropertyNames();

        if (sink == null) {
          _log.warn(
              "Statement {} declares the sink {} "
                  + "but the corresponding Esper processor does not.",
              epStatement, sinkName);
        } else {
          final EsperStatementSubscriber subscriber = new EsperStatementSubscriber(
              sink, propertyNames);
          _log.info("Adding subscriber {} to statement {}", sink.getId(),
              epStatement);
          stmt.setSubscriber(subscriber);
        }
      }
    }
    _log.debug("Finished adding statements to Esper service");
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

                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);

                String[] types = statementEventTypeRef.getTypesForStatementName(stmt.getName());
                if (types != null) {
                    eventTypesReferenced.addAll(Arrays.asList(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>();
        if (undeploymentOptions.isDestroyStatements()) {
            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(Arrays.asList(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

        // 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

      final EPStatementObjectModel stmtModel = epAdmin
          .compileEPL(epStatement);

      // Create the actual statement in the current Esper engine from the
      // statement model.
      final EPStatement stmt = epAdmin.create(stmtModel);

      // Compute the hash value of the statement.
      // We use this to reference the statement's sink, if it declares
      // any.
      final String stmtName = Integer.toString(epStatement.hashCode());

      final Sink sink = _sinksMap.get(_statementSinksMap.get(stmtName));
      final String[] propertyNames = stmt.getEventType()
          .getPropertyNames();

      // Only add a subscriber, if the statement delcares to send its
      // output to a queue.
      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

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.