Package org.cometd.bayeux.server

Examples of org.cometd.bayeux.server.ServerSession


                            throw new ServletException(x);
                        }
                    }
                    // Remove the client, so that the CometD implementation will send
                    // "unknown client" and the JavaScript will re-handshake
                    ServerSession session = bayeuxServer.getSession(clientId);
                    if (session != null)
                        bayeuxServer.removeServerSession(session, false);
                }
            }
            else
View Full Code Here


            consumer.getProcessor().process(exchange);

            if (ExchangeHelper.isOutCapable(exchange)) {
                ServerChannel channel = getBayeux().getChannel(channelName);
                ServerSession serverSession = getServerSession();

                ServerMessage.Mutable outMessage = binding.createCometdMessage(channel, serverSession, exchange.getOut());
                remote.deliver(serverSession, outMessage);
            }
        }
View Full Code Here

    } catch (Exception e) {
      e.printStackTrace();
    }
   
    this.sessionModerator = sessionHandler.getSessionModerator();
    ServerSession moderator = this.sessionModerator.getServerSession();

    // make sure the moderator has joined the conference and has a site
    // id before anyone joins.  User slot 0 for moderator.
    this.siteids.set(0, moderator.getId());
    this.sessionModerator.setSessionAttribute("siteid", new Integer(0));
    this.clientids.put(moderator.getId(), moderator);
  }
View Full Code Here

      this.sessionHandler.removeBadClient(client);
      return;
    }

    /* Now, we have a validated token. Find the updatee. */
    ServerSession updatee = this.updatees.get(token);
    if (updatee == null)
      return;

    this.updatees.remove(token);
    /* Should we cache the state? */
    if (this.cacheState) {
      this.lastState = (Object[]) data.get("state");
      log.fine("Cached state from updater.");
      log.fine(JSON.toString(this.lastState));
    }

    ServerMessage.Mutable msg = this.sessionManager.getBayeux()
        .newMessage();

    msg.setChannel("/service/session/join/state");
    if (this.cacheState) {
      log.info("sending cached state");
      msg.setData(this.lastState);
    } else {
      log.info("sending state from updater");
      msg.setData((Object[]) data.get("state"));
    }
    msg.setLazy(false);

    updatee.deliver(this.sessionManager.getServerSession(), msg);
  }
View Full Code Here

   * Let all clients know that another client has been added to the roster.
   * @param client The new client.
   */
  private void sendRosterAvailable(ServerSession client) {
    log.info("sending roster available");
    ServerSession from = this.sessionManager.getServerSession();

    Integer siteId = (Integer) client.getAttribute("siteid");
    String username = (String) client.getAttribute("username");

    Map<String, Object> data = new HashMap<String, Object>();
View Full Code Here

    ServerChannel channel = server.getChannel(rosterUnavailableChannel);
    if (channel == null) {
      return;
    }

    ServerSession from = this.sessionManager.getServerSession();

    Integer siteId = (Integer) client.getAttribute("siteid");
    String username = (String) client.getAttribute("username");

    Map<String, Object> data = new HashMap<String, Object>();
View Full Code Here

  protected Map<Integer, String> getRosterList(ServerSession client) {

    Map<Integer, String> roster = new HashMap<Integer, String>();

    for (String clientId : this.updaters.keySet()) {
      ServerSession c = this.clientids.get(clientId);
      Integer siteId = (Integer) c.getAttribute("siteid");
      roster.put(siteId, (String) c.getAttribute("username"));
    }

    return roster;
  }
View Full Code Here

   * @param updatee The newly joined client.
   * @param updaterType Updater type as specified by the OCW application.
   */
  private void assignUpdater(ServerSession updatee, String updaterType) {
    log.info("assignUpdater *****************");
    ServerSession from = this.sessionManager.getServerSession();
    if (this.updaters.isEmpty()) {
      this.addUpdater(updatee, false);
      ((ServerSession)updatee).deliver(from, "/service/session/join/state",
          new ArrayList<String>(), null);
      return;
    }

    String updaterId = null;
    ServerSession updater = null;
    if (!updaterType.equals("default")) {
      /* Try to find a custom updater. */
      String matchedType = updaterTypeMatcher.match(updaterType,
          getAvailableUpdaterTypes());
      if (matchedType != null) {
        for (String id : this.updaters.keySet()) {
          updater = this.clientids.get(id);
          if (updater.getAttribute("updaterType").equals(matchedType)) {
            updaterId = id;
            log.fine("found an updater type matched to [" + matchedType + "]");
            break;
          }
        }
      }
    }
    if (updaterId == null) {
      /* Choose random updater for default types or if a custom updater wasn't
       * found. */
      Random r = new Random();
      int idx = r.nextInt(this.updaters.size());

      log.fine("using default updater type");
      Object[] keys = this.updaters.keySet().toArray();
      updaterId = (String) keys[idx];
      updater = this.clientids.get(updaterId);
    }

    /* Now we've found an updater, so generate a token and ask the updater to
     * provide full application state. */
    log.fine("assigning updater " + updater.getAttribute("siteid") + " to "
        + updatee.getAttribute("siteid"));
    SecureRandom s = new SecureRandom();
    String token = new BigInteger(130, s).toString(32);

    this.updaters.get(updaterId).add(token);
    this.updatees.put(token, updatee);

    updater.deliver(from, "/service/session/updater", token, null);
  }
View Full Code Here

    List<String> tokenList = this.updaters.get(client.getId());
    this.updaters.remove(client.getId());
    if (tokenList == null) {
      for (String token : this.updatees.keySet()) {
        ServerSession updatee = this.updatees.get(token);
        if (updatee.getId().equals(client.getId())) {
          this.updatees.remove(token);
        }
      }
    } else {
      log.fine("sending roster unavailable");
      this.sendRosterUnavailable(client);
      if (!tokenList.isEmpty()) {
        log.fine("this updater was updating someone");
        for (String token : tokenList) {
          ServerSession updatee = this.updatees.get(token);
          if (updatee == null)
            continue;

          // this.updatees.remove(token);
          String updaterType = (String) client
View Full Code Here

  }

  private List<String> getAvailableUpdaterTypes() {
    List<String> availableUpdaterTypes = new ArrayList<String>();
    for (String id : this.updaters.keySet()) {
      ServerSession updater = this.clientids.get(id);
      availableUpdaterTypes.add((String) updater
          .getAttribute("updaterType"));
    }
    return availableUpdaterTypes;
  }
View Full Code Here

TOP

Related Classes of org.cometd.bayeux.server.ServerSession

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.