Package org.infinispan.cli.interpreter.session

Examples of org.infinispan.cli.interpreter.session.Session


   }

   void expireSessions() {
      long timeBoundary = System.nanoTime() - sessionTimeout * 1000000l;
      for (Iterator<Session> i = sessions.values().iterator(); i.hasNext();) {
         Session session = i.next();
         if (session.getTimestamp() < timeBoundary) {
            i.remove();
            if (log.isDebugEnabled()) {
               log.debugf("Removed expired interpreter session %s", session.getId());
            }
         }
      }
   }
View Full Code Here


      }
   }

   @ManagedOperation(description = "Parses and executes IspnQL statements")
   public Map<String, String> execute(final String sessionId, final String s) throws Exception {
      Session session = null;
      ClassLoader oldCL = SysPropertyActions.setThreadContextClassLoader(cacheManager.getCacheManagerConfiguration().classLoader());
      Map<String, String> response = new HashMap<String, String>();
      try {
         session = validateSession(sessionId);

         CharStream stream = new ANTLRStringStream(s);
         IspnQLLexer lexer = new IspnQLLexer(stream);
         CommonTokenStream tokens = new CommonTokenStream(lexer);
         IspnQLParser parser = new IspnQLParser(tokens);

         parser.statements();
         session = sessions.get(sessionId);
         StringBuilder output = new StringBuilder();
         for (Statement stmt : parser.statements) {
            Result result = stmt.execute(session);
            if (result != EmptyResult.RESULT) {
               output.append(result.getResult());
            }
         }
         if (output.length() > 0) {
            response.put(ResultKeys.OUTPUT.toString(), output.toString());
         }
      } catch (Throwable t) {
         log.interpreterError(t);
         response.put(ResultKeys.ERROR.toString(), t.getMessage());
         StringWriter sw = new StringWriter();
         PrintWriter pw = new PrintWriter(sw);
         t.printStackTrace(pw);
         response.put(ResultKeys.STACKTRACE.toString(), sw.toString());
      } finally {
         if (session != null) {
            session.reset();
            response.put(ResultKeys.CACHE.toString(), session.getCurrentCacheName());
         }
         SysPropertyActions.setThreadContextClassLoader(oldCL);

      }
      return response;
View Full Code Here

   }

   void expireSessions() {
      long timeBoundary = timeService.time() - sessionTimeout * 1000000l;
      for (Iterator<Session> i = sessions.values().iterator(); i.hasNext();) {
         Session session = i.next();
         if (session.getTimestamp() < timeBoundary) {
            i.remove();
            if (log.isDebugEnabled()) {
               log.debugf("Removed expired interpreter session %s", session.getId());
            }
         }
      }
   }
View Full Code Here

      }
   }

   @ManagedOperation(description = "Parses and executes IspnQL statements")
   public Map<String, String> execute(final String sessionId, final String s) throws Exception {
      Session session = null;
      ClassLoader oldCL = SysPropertyActions.setThreadContextClassLoader(cacheManager.getCacheManagerConfiguration().classLoader());
      Map<String, String> response = new HashMap<String, String>();
      try {
         session = validateSession(sessionId);

         CharStream stream = new ANTLRStringStream(s);
         IspnQLLexer lexer = new IspnQLLexer(stream);
         CommonTokenStream tokens = new CommonTokenStream(lexer);
         IspnQLParser parser = new IspnQLParser(tokens);

         parser.statements();

         if (parser.hasParserErrors()) {
            throw new ParseException(parser.getParserErrors());
         }

         StringBuilder output = new StringBuilder();
         for (Statement stmt : parser.statements) {
            Result result = stmt.execute(session);
            if (result != EmptyResult.RESULT) {
               output.append(result.getResult());
            }
         }
         if (output.length() > 0) {
            response.put(ResultKeys.OUTPUT.toString(), output.toString());
         }
      } catch (Throwable t) {
         log.interpreterError(t);
         response.put(ResultKeys.ERROR.toString(), t.getMessage());
         StringWriter sw = new StringWriter();
         PrintWriter pw = new PrintWriter(sw);
         t.printStackTrace(pw);
         response.put(ResultKeys.STACKTRACE.toString(), sw.toString());
      } finally {
         if (session != null) {
            session.reset();
            response.put(ResultKeys.CACHE.toString(), session.getCurrentCacheName());
         }
         SysPropertyActions.setThreadContextClassLoader(oldCL);

      }
      return response;
View Full Code Here

      return response;
   }

   private Session validateSession(final String sessionId) {
      if (sessionId == null) {
         Session session = new SessionImpl(codecRegistry, cacheManager, null, timeService);
         session.setCurrentCache(BasicCacheContainer.DEFAULT_CACHE_NAME);
         return session;
      }
      if (!sessions.containsKey(sessionId)) {
         throw log.invalidSession(sessionId);
      }
View Full Code Here

   }

   void expireSessions() {
      long timeBoundary = System.nanoTime() - sessionTimeout * 1000000l;
      for (Iterator<Session> i = sessions.values().iterator(); i.hasNext();) {
         Session session = i.next();
         if (session.getTimestamp() < timeBoundary) {
            i.remove();
            if (log.isDebugEnabled()) {
               log.debugf("Removed expired interpreter session %s", session.getId());
            }
         }
      }
   }
View Full Code Here

      IspnQLLexer lexer = new IspnQLLexer(stream);
      CommonTokenStream tokens = new CommonTokenStream(lexer);
      IspnQLParser parser = new IspnQLParser(tokens);
      ClassLoader oldCL = SysPropertyActions.setThreadContextClassLoader(cacheManager.getCacheManagerConfiguration()
            .classLoader());
      Session session = null;
      try {
         parser.statements();
         session = sessions.get(sessionId);
         StringBuilder output = new StringBuilder();
         for (Statement stmt : parser.statements) {
            Result result = stmt.execute(session);
            if (result != EmptyResult.RESULT) {
               output.append(result.getResult());
            }
         }
         return output.length() == 0 ? null : output.toString();
      } catch (Exception e) {
         log.interpreterError(e);
         // Rewrap the exception into a plain exception to avoid the need for custom classes to travel via RMI
         Exception exception = new Exception(e.getMessage());
         exception.setStackTrace(e.getStackTrace());
         throw exception;
      } finally {
         if (session != null) {
            session.reset();
         }
         SysPropertyActions.setThreadContextClassLoader(oldCL);
      }
   }
View Full Code Here

   }

   void expireSessions() {
      long timeBoundary = System.nanoTime() - sessionTimeout * 1000000l;
      for (Iterator<Session> i = sessions.values().iterator(); i.hasNext();) {
         Session session = i.next();
         if (session.getTimestamp() < timeBoundary) {
            i.remove();
            if (log.isDebugEnabled()) {
               log.debugf("Removed expired interpreter session %s", session.getId());
            }
         }
      }
   }
View Full Code Here

      }
   }

   @ManagedOperation(description = "Parses and executes IspnQL statements")
   public Map<String, String> execute(final String sessionId, final String s) throws Exception {
      Session session = null;
      ClassLoader oldCL = SysPropertyActions.setThreadContextClassLoader(cacheManager.getCacheManagerConfiguration().classLoader());
      Map<String, String> response = new HashMap<String, String>();
      try {
         session = validateSession(sessionId);

         CharStream stream = new ANTLRStringStream(s);
         IspnQLLexer lexer = new IspnQLLexer(stream);
         CommonTokenStream tokens = new CommonTokenStream(lexer);
         IspnQLParser parser = new IspnQLParser(tokens);

         parser.statements();
         session = sessions.get(sessionId);
         StringBuilder output = new StringBuilder();
         for (Statement stmt : parser.statements) {
            Result result = stmt.execute(session);
            if (result != EmptyResult.RESULT) {
               output.append(result.getResult());
            }
         }
         if (output.length() > 0) {
            response.put("OUTPUT", output.toString());
         }
      } catch (Exception e) {
         log.interpreterError(e);
         response.put("ERROR", e.getMessage());
         StringWriter sw = new StringWriter();
         PrintWriter pw = new PrintWriter(sw);
         e.printStackTrace(pw);
         response.put("STACKTRACE", sw.toString());
      } finally {
         if (session != null) {
            session.reset();
            response.put("CACHE", session.getCurrentCacheName());
         }
         SysPropertyActions.setThreadContextClassLoader(oldCL);

      }
      return response;
View Full Code Here

   }

   void expireSessions() {
      long timeBoundary = System.nanoTime() - sessionTimeout * 1000000l;
      for (Iterator<Session> i = sessions.values().iterator(); i.hasNext();) {
         Session session = i.next();
         if (session.getTimestamp() < timeBoundary) {
            i.remove();
            if (log.isDebugEnabled()) {
               log.debugf("Removed expired interpreter session %s", session.getId());
            }
         }
      }
   }
View Full Code Here

TOP

Related Classes of org.infinispan.cli.interpreter.session.Session

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.