Package net.zschech.gwt.comet.server

Examples of net.zschech.gwt.comet.server.CometSession


  @Override
  public void login(String username) throws ChatException {
    // Get or create the HTTP session for the browser
    HttpSession httpSession = getThreadLocalRequest().getSession();
    // Get or create the Comet session for the browser
    CometSession cometSession = CometServlet.getCometSession(httpSession);
    // Remember the user name for the
    httpSession.setAttribute("username", username);
   
    // setup the mapping of user names to CometSessions
    if (users.putIfAbsent(username, cometSession) != null) {
View Full Code Here


      throw new ChatException("User: " + username + " is not logged in: no http session");
    }
   
    // check if there is a Comet session setup. In a larger application the HTTP session may have been
    // setup via other means.
    CometSession cometSession = CometServlet.getCometSession(httpSession, false);
    if (cometSession == null) {
      throw new ChatException("User: " + username + " is not logged in: no comet session");
    }
   
    // check the user name parameter matches the HTTP sessions user name
View Full Code Here

public class ConnectionTestServlet extends CometServlet {
 
  @Override
  protected void doComet(final CometServletResponse cometResponse) throws ServletException, IOException {
    final CometSession cometSession = cometResponse.getSession(false);
   
    HttpServletRequest request = cometResponse.getRequest();
    final int delay = Integer.parseInt(request.getParameter("delay"));
    new Thread() {
      public void run() {
        try {
          try {
            synchronized (cometResponse) {
              cometResponse.wait(delay);
            }
          }
          catch (InterruptedException e) {
            throw new InterruptedIOException();
          }
         
          if (cometSession != null) {
            cometSession.invalidate();
          }
          else {
            if (!cometResponse.isTerminated()) {
              log("Sending terminate");
              cometResponse.terminate();
View Full Code Here

    final boolean session = "true".equals(request.getParameter("session"));
    final int count = Integer.parseInt(request.getParameter("count"));
    final int batch = Integer.parseInt(request.getParameter("batch"));
    final int delay = Integer.parseInt(request.getParameter("delay"));
    final boolean string = "string".equals(request.getParameter("mode"));
    final CometSession cometSession = cometResponse.getSession(false);
    final boolean order = request.getRequestURI().endsWith("order");
   
    if (session && cometSession == null) {
      cometResponse.terminate();
      return;
    }
   
    if (session && connectionCount != 1) {
      return;
    }
   
    new Thread() {
      public void run() {
        try {
          if (cometSession == null) {
            for (int i = 0; i < count; i++) {
              if (!cometResponse.isTerminated()) {
               
                if (batch > 1) {
                  List<Serializable> messages = new ArrayList<Serializable>(batch);
                  for (int b = 0; b < batch; b++) {
                    messages.add(getMessage(string, order, i * batch + b));
                  }
                  synchronized (cometResponse) {
                    if (!cometResponse.isTerminated()) {
                      cometResponse.write(messages);
                    }
                  }
                }
                else {
                  synchronized (cometResponse) {
                    if (!cometResponse.isTerminated()) {
                      cometResponse.write(getMessage(string, order, i));
                    }
                  }
                }
               
                if (delay > 0) {
                  try {
                    sleep(delay);
                  }
                  catch (InterruptedException e) {
                    throw new InterruptedIOException();
                  }
                }
              }
            }
            cometResponse.terminate();
          }
          else {
            for (int i = 0; i < count; i++) {
              for (int b = 0; b < batch; b++) {
                cometSession.enqueue(getMessage(string, order, i * batch + b));
              }
             
              if (delay > 0) {
                try {
                  sleep(delay);
                }
                catch (InterruptedException e) {
                  throw new InterruptedIOException();
                }
              }
            }
            // there is no proper way to wait for the queue to drain :-(
            while (cometSession.isValid() && !cometSession.getQueue().isEmpty()) {
              try {
                sleep(1);
              }
              catch (InterruptedException e) {
                throw new InterruptedIOException();
              }
            }
            cometSession.invalidate();
          }
        }
        catch (IOException e) {
          log("Error writing data", e);
        }
View Full Code Here

public class CometTestServiceImpl extends RemoteServiceServlet implements CometTestService {
 
  @Override
  public boolean createSession() {
    HttpSession httpSession = getThreadLocalRequest().getSession();
    CometSession cometSession = CometServlet.getCometSession(httpSession, false);
    if (cometSession == null) {
      CometServlet.getCometSession(httpSession);
      return true;
    }
    return false;
View Full Code Here

    HttpSession httpSession = getThreadLocalRequest().getSession(false);
    if (httpSession == null) {
      return false;
    }
   
    CometSession cometSession = CometServlet.getCometSession(httpSession);
    if (cometSession == null) {
      return false;
    }
    cometSession.invalidate();
    return true;
  }
View Full Code Here

TOP

Related Classes of net.zschech.gwt.comet.server.CometSession

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.