Package org.atmosphere.cpr

Examples of org.atmosphere.cpr.Meteor


        return null;
    }

    public ActionForward openCometChannel(ActionMapping mapping, ActionForm _form, HttpServletRequest req, HttpServletResponse res) throws Exception {
        logger.info("BEGIN SimpleAction.openCometChannel()");
        Meteor m = Meteor.build(req, list, null);
        m.setBroadcaster(b);
        req.getSession().setAttribute("meteor", m);
        m.suspend(-1);
        m.broadcast(req.getServerName()
                + "__has suspended a connection from " + req.getRemoteAddr());
        return null;
    }
View Full Code Here


        return null;
    }

    public ActionForward sendCometMsg(ActionMapping mapping, ActionForm _form, HttpServletRequest req, HttpServletResponse res) throws Exception {
        logger.info("BEGIN SimpleAction.sendCometMsg()");
        Meteor m = (Meteor) req.getSession().getAttribute("meteor");
        logger.info("meteor: " + m);
        res.setCharacterEncoding("UTF-8");
        String value = req.getParameter("value");
        logger.debug("value: " + value);

        m.broadcast("<script>parent.cometMsg('Broadcast: " + value + "');</script>");
        res.getWriter().write("{message:'success'}");
        res.getWriter().flush();
        return null;
    }
View Full Code Here

    }
   
    public static class Meteor1 extends HttpServlet {
        @Override
        public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
            final Meteor m = Meteor.build(req);
            req.getSession().setAttribute("meteor", m);
            m.suspend(5000, false);
           
            m.broadcast("resume");
            m.addListener(new AtmosphereResourceEventListener(){

                @Override
                public void onSuspend(final AtmosphereResourceEvent<HttpServletRequest, HttpServletResponse> event){
                }
View Full Code Here

    }

    public static class Meteor1 extends HttpServlet {
        @Override
        public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
            final Meteor m = Meteor.build(req);
            m.getBroadcaster().setScope(Broadcaster.SCOPE.REQUEST);
            req.getSession().setAttribute("meteor", m);
           
            m.suspend(5000, false);
            broadcasterId.set(m.getBroadcaster().getID());

            res.getOutputStream().write("resume".getBytes());
            m.addListener(new AtmosphereResourceEventListener(){

                @Override
                public void onSuspend(final AtmosphereResourceEvent<HttpServletRequest, HttpServletResponse> event){
                     event.getResource().getRequest().setAttribute(AtmosphereServlet.RESUME_ON_BROADCAST, "true");
                }
View Full Code Here

     * @param req An {@link HttpServletRequest}
     * @param res An {@link HttpServletResponse}
     */
    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
        Meteor m = Meteor.build(req, list, null);

        // Log all events on the concole.
        m.addListener(new EventsLogger());

        req.getSession().setAttribute("meteor", m);

        res.setContentType("text/html;charset=ISO-8859-1");

        m.suspend(-1);
        m.broadcast(req.getServerName() + "__has suspended a connection from " + req.getRemoteAddr());
    }
View Full Code Here

     * @param req An {@link HttpServletRequest}
     * @param res An {@link HttpServletResponse}
     */
    @Override
    public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException {
        Meteor m = (Meteor)req.getSession().getAttribute("meteor");
        res.setCharacterEncoding("UTF-8");
        String action = req.getParameterValues("action")[0];
        String name = req.getParameterValues("name")[0];

        if ("login".equals(action)) {
            req.getSession().setAttribute("name", name);
            m.broadcast("System Message from " + req.getServerName() + "__" + name + " has joined.");
            res.getWriter().write("success");
            res.getWriter().flush();
        } else if ("post".equals(action)) {
            String message = req.getParameterValues("message")[0];
            m.broadcast(name + "__" + message);
            res.getWriter().write("success");
            res.getWriter().flush();
        } else {
            res.setStatus(422);

View Full Code Here

    public PushPage() {
        HttpServletRequest req = getWebRequestCycle().getWebRequest().getHttpServletRequest();

        // Grap a Meteor
        Meteor meteor = Meteor.build(req);

        // Start scheduling update.
        if (!scheduleStarted.getAndSet(true)) {
            meteor.schedule(new Callable<String>() {
                public String call() {
                    String s = new Date().toString();
                    return s;
                }
            }, 1); // One second
        }

        // Add us to the listener list.
        meteor.addListener(this);

        // Depending on the connection
        String transport = req.getHeader("X-Atmosphere-Transport");

        // Suspend the connection. Could be long-polling, streaming or websocket.
        meteor.suspend(-1, !(transport != null && transport.equalsIgnoreCase("long-polling")));
    }
View Full Code Here

        logger.info("onBroadcast(): {}", event.getMessage());

        // If we are using long-polling, resume the connection as soon as we get an event.
        String transport = event.getResource().getRequest().getHeader("X-Atmosphere-Transport");
        if (transport != null && transport.equalsIgnoreCase("long-polling")) {
            Meteor meteor = Meteor.lookup(event.getResource().getRequest());

            meteor.removeListener(this);
            meteor.resume();
        }
    }
View Full Code Here

  {
    RequestCycle requestCycle = RequestCycle.get();
    ServletWebRequest request = (ServletWebRequest)requestCycle.getRequest();

    // Grab a Meteor
    Meteor meteor = Meteor.build(request.getContainerRequest());
    String uuid = getUUID(meteor.getAtmosphereResource());
    component.getPage().setMetaData(ATMOSPHERE_UUID, uuid);
    EventBus.get().registerPage(uuid, component.getPage());

    // Add us to the listener list.
    meteor.addListener(this);

    String transport = request.getHeader(HeaderConfig.X_ATMOSPHERE_TRANSPORT);
    if (HeaderConfig.LONG_POLLING_TRANSPORT.equalsIgnoreCase(transport))
    {
      // request.getContainerRequest().setAttribute(ApplicationConfig.RESUME_ON_BROADCAST,
      // Boolean.TRUE);
      meteor.suspend(-1, false);
    }
    else
    {
      meteor.suspend(-1);
    }
  }
View Full Code Here

      .getRequest()
      .getHeader(HeaderConfig.X_ATMOSPHERE_TRANSPORT);

    if (HeaderConfig.LONG_POLLING_TRANSPORT.equalsIgnoreCase(transport))
    {
      Meteor meteor = Meteor.lookup(event.getResource().getRequest());
      meteor.resume();
    }
  }
View Full Code Here

TOP

Related Classes of org.atmosphere.cpr.Meteor

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.