Exemple #1
0
 /** Add session. */
 public void addSession(Session session) {
   synchronized (mutex) {
     sessions.put(session.getId(), session);
     sessionCacheDirty = true;
   }
   // log(session.getId() + " at " + session.getAddress() + " adding ");
   info(session.getId() + " at " + session.getAddress() + " added ");
 }
Exemple #2
0
 /** Register session for removal. */
 public Session removeSession(Session aSession) {
   synchronized (mutex) {
     Session session = (Session) sessions.remove(aSession.getId());
     if (session != null) {
       info(session.getId() + " at " + session.getAddress() + " removed ");
     }
     sessionCacheDirty = true;
     return session;
   }
 }
  @OnOpen
  public void open(Session session) {
    peers.add(session);
    Tweet tweet = new Tweet();
    tweet.setAuthor("THE SERVER");
    tweet.setMessage("Welcome! We will provide you with data " + "as soon as we have it available");
    List<Tweet> tweets = Arrays.asList(tweet);
    session.getAsyncRemote().sendText(Tweet.listToJsonArray(tweets).toString());

    logger.info("opened session with id " + session.getId());
  }
 protected void createSessionsTable(List<Session> sessions) {
   table().attr("cellpadding", "0", "cellspacing", "0", "border", "0", "class", "display");
   thead();
   tr();
   createThs("Id", "Last Used");
   end();
   end();
   tbody();
   for (Session s : sessions) {
     tr();
     createTds(s.getId(), formatDurationHMS(System.currentTimeMillis() - s.getLastUsed()));
     end();
   }
   end();
   end();
 }
  /**
   * Method declaration
   *
   * @param c
   * @param s
   * @throws SQLException
   */
  void write(Session c, String s) throws SQLException {

    if (bRestoring || s == null || s.length() == 0) {
      return;
    }

    if (!bReadOnly) {
      int id = 0;

      if (c != null) {
        id = c.getId();
      }

      if (id != mLastId) {
        s = "/*C" + id + "*/" + s;
        mLastId = id;
      }

      try {
        writeLine(wScript, s);

        if (bWriteDelay) {
          bNeedFlush = true;
        } else {
          wScript.flush();
        }
      } catch (IOException e) {
        throw Trace.error(Trace.FILE_IO_ERROR, sFileScript);
      }

      // fredt@users - todo - eliminate new File() calls
      if (iLogSize > 0 && iLogCount++ > 100) {
        iLogCount = 0;

        if (scriptChecker.length() > iLogSize * 1024 * 1024) {
          checkpoint(false);
        }
      }
    }
  }
  /**
   * Method declaration
   *
   * @throws SQLException
   */
  private void runScript() throws SQLException {

    if (Trace.TRACE) {
      Trace.trace();
    }

    if (!(new File(sFileScript)).exists()) {
      return;
    }

    bRestoring = true;

    dDatabase.setReferentialIntegrity(false);

    HsqlArrayList session = new HsqlArrayList();

    session.add(sysSession);

    Session current = sysSession;

    try {
      long time = 0;

      if (Trace.TRACE) {
        time = System.currentTimeMillis();
      }

      LineNumberReader r = new LineNumberReader(new FileReader(sFileScript));

      while (true) {
        String s = readLine(r);

        if (s == null) {
          break;
        }

        if (s.startsWith("/*C")) {
          int id = Integer.parseInt(s.substring(3, s.indexOf('*', 4)));

          if (id >= session.size()) {
            session.setSize(id + 1);
          }

          current = (Session) session.get(id);

          if (current == null) {
            current = new Session(sysSession, id);

            session.set(id, current);
            dDatabase.registerSession(current);
          }

          s = s.substring(s.indexOf('/', 1) + 1);
        }

        if (s.length() != 0) {
          Result result = dDatabase.execute(s, current);

          if ((result != null) && (result.iMode == Result.ERROR)) {
            throw (Trace.getError(result.errorCode, result.sError));
          }
        }

        if (s.equals("DISCONNECT")) {
          int id = current.getId();

          current = new Session(sysSession, id);

          session.set(id, current);
        }
      }

      r.close();

      for (int i = 0; i < session.size(); i++) {
        current = (Session) session.get(i);

        if (current != null) {
          current.rollback();
        }
      }

      if (Trace.TRACE) {
        Trace.trace(time - System.currentTimeMillis());
      }
    } catch (IOException e) {
      throw Trace.error(Trace.FILE_IO_ERROR, sFileScript + " " + e);
    }

    dDatabase.setReferentialIntegrity(true);

    bRestoring = false;
  }