Package com.alibaba.wasp.session

Examples of com.alibaba.wasp.session.ExecutionEngineSession$QueryExecutor


    protected SessionListener(final String n) {
      this.sessionName = n;
    }

    public void leaseExpired() {
      ExecutionEngineSession s = sessions.remove(this.sessionName);
      if (s != null) {
        LOG.info("Session " + this.sessionName + " lease expired.");
        try {
          s.close();
          s = null;
        } catch (IOException e) {
          LOG.error("Closing session for " + sessionName, e);
        }
      } else {
View Full Code Here


      if (sessionId != null) {
        sessionName = sessionId;
      }

      Leases.Lease lease = null;
      ExecutionEngineSession session = null;

      boolean lastScan = false;
      if (StringUtils.isNotEmpty(sessionId)) {
        session = sessions.get(sessionName);
        if (!closeSession) {
          if (session == null) {
            throw new UnknownSessionException("Name: " + sessionName
                + ", already closed? sessions size is " + sessions.size());
          }
        }
      } else {
        session = addSession();
        sessionName = session.getSessionId();
        if (plan instanceof LocalQueryPlan) {
          LocalQueryPlan localQueryPlan = (LocalQueryPlan) plan;
          if (localQueryPlan.getScanAction() != null) {
            session.setExecutor(new LocalScanExecutor(localQueryPlan));
          } else if (localQueryPlan.getGetAction() != null) {
            localQueryPlan.getGetAction().setSessionId(sessionName);
            session.setExecutor(new LocalGetExecutor(localQueryPlan));
          }
        } else if (plan instanceof GlobalQueryPlan) {
          session.setExecutor(new GlobalQueryExecutor((GlobalQueryPlan) plan,
              server));
        } else if (plan instanceof AggregateQueryPlan) {
          session.setExecutor(new AggregateQueryExecutor(
              (AggregateQueryPlan) plan, server));
        }
      }

      if (closeSession) {
        session = sessions.remove(sessionName);
        if (session != null) {
          session.close();
          try {
            leases.cancelLease(sessionName);
          } catch (LeaseException e) {
            LOG.warn("Lease " + sessionName
                + "does't exsit,may has been closed.");
          }
          session = null;
        }
        return new Pair<Boolean, Pair<String, Pair<List<ClientProtos.QueryResultProto>, List<ClientProtos.StringDataTypePair>>>>(
            lastScan,
            new Pair<String, Pair<List<ClientProtos.QueryResultProto>, List<ClientProtos.StringDataTypePair>>>(
                sessionName,
                new Pair<List<ClientProtos.QueryResultProto>, List<ClientProtos.StringDataTypePair>>(
                    new ArrayList<ClientProtos.QueryResultProto>(),
                    new ArrayList<ClientProtos.StringDataTypePair>())));
      } else {
        ExecutionEngineSession.QueryExecutor executor = null;
        try {
          lease = leases.removeLease(sessionName);
          executor = (ExecutionEngineSession.QueryExecutor) session
              .getExecutor();
          results = executor.execute();
          lastScan = executor.isLastScan();
          return new Pair<Boolean, Pair<String, Pair<List<ClientProtos.QueryResultProto>, List<ClientProtos.StringDataTypePair>>>>(
              lastScan,
              new Pair<String, Pair<List<ClientProtos.QueryResultProto>, List<ClientProtos.StringDataTypePair>>>(
                  sessionName, results));
        } finally {
          // We're done. On way out re-add the above removed lease.
          // Adding resets expiration time on lease.
          if (!lastScan) {
            if (sessions.containsKey(sessionName)) {
              if (lease != null) {
                leases.addLease(lease);
              }
            }
          } else {
            session = sessions.remove(sessionName);
            if (session != null) {
              session.close();
              session = null;
            }
          }
        }
      }
View Full Code Here

    }
  }

  private ExecutionEngineSession addSession() throws LeaseStillHeldException {
    long sessionId = -1;
    ExecutionEngineSession session;
    while (true) {
      sessionId = rand.nextLong();
      if (sessionId == -1) {
        continue;
      }
      String sessionName = String.valueOf(sessionId);
      session = SessionFactory.createExecutionEngineSession(sessionName, null);
      ExecutionEngineSession existing = sessions.putIfAbsent(sessionName,
          session);
      if (existing == null) {
        this.leases.createLease(sessionName, this.sessionLeaseTimeoutPeriod,
            new SessionListener(sessionName));
        break;
View Full Code Here

TOP

Related Classes of com.alibaba.wasp.session.ExecutionEngineSession$QueryExecutor

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.