Package org.persvr.remote

Examples of org.persvr.remote.EventStream


      }
      final CometSerializer serializer = getCometSerializer(request);
      eventStream.addCallback(new EventStream.EventCallback() {
 
        public synchronized void onEvent()  throws IOException{
          final EventStream eventStream = (Client) request.getSession().getAttribute(clientId);

         
         
          Notification notification= eventStream.eventAvailable() ? eventStream.take(0) : null;
          if (notification != null) { // we are resuming
            try {
             
              if (sendEvent(notification, eventStream, serializer)) {
                System.err.println("connection closed by server" + request);
                request.setAttribute("org.persvr.sent", true);
              }
            }
            catch (IOException e) {
              e.printStackTrace();
              eventStream.finished();
            }
          }
        }
       
      });
View Full Code Here


        prefix = prefix + "/";
    }
    //boolean streamingSupported = isHttpStreamAcceptable(req);
    CometSerializer serializer = getCometSerializer(req);
    serializer.setResponse(resp);
    final EventStream eventStream = getEventStream(req);
    if (eventStream == null) {
      resp.setStatus(404); // The client id was not found
      resp.getOutputStream().print("The client ID was not found");
      return;
    }
    Notification notification = eventStream.eventAvailable() ? eventStream.take(0) : null;
    if (notification != null) { // we are resuming
      try {
        if (sendEvent(notification, eventStream, serializer))
          return; // done
        else {
          org.mortbay.util.ajax.Continuation continuation = org.mortbay.util.ajax.ContinuationSupport.getContinuation(req, null);
          if (continuation.isResumed())
            continuation.suspend(req.getSession().getMaxInactiveInterval() * 500); // suspend again
          else
            notification = suspend(eventStream, req);
          continuation.suspend(req.getSession().getMaxInactiveInterval() * 500); // suspend again
        }
        throw new RuntimeException("Continuation failed");
      }
      catch (ConnectionConflictException e) {
        resp.setStatus(409);
      }
      catch (IOException e) {
        //e.printStackTrace();
        eventStream.finished();
      }
      return;
    }

    if (req.getHeader("xdomainrequest") == null) {
      // if it is not IE8, we do not want to have multiple connections
      HttpSession session = req.getSession(true);
      Client otherConnection = (Client) session.getAttribute("org.persvr.channel");
      if (otherConnection != null && otherConnection != eventStream) {
        //TODO: Send reconnect advice
        otherConnection.fire(new ConnectionConflict()); // if there is another connection, we need to notify it
      }
      session.setAttribute("org.persvr.channel",eventStream);
    }
    else
      resp.setHeader("XDomainRequestAllowed", "1"); // allow this so we can support streaming in IE8
   
    //final ServletOutputStream outStream = resp.getOutputStream();
//    System.err.println("eventStream.ping" + eventStream.pingCallback);
    boolean writtenTo = false;
    while (!writtenTo || serializer.isStreamingAvailable() || eventStream.eventAvailable()) {

      notification = suspend(eventStream, req); // implementation specific handling
      if (notification == null) // if the suspend returns null, the suspend will resume the operation
        return;
      serializer.sendNotification(notification, (Client) eventStream,!writtenTo);
View Full Code Here

    }     
    else if (event.getEventType() == CometEvent.EventType.READ) {
      //doPost(event.getHttpServletRequest(),event.getHttpServletResponse());
    }
    else if (event.getEventType() == CometEvent.EventType.END) {
      EventStream eventStream = getEventStream(request);
     
      if (eventStream != null && request.getAttribute("org.persvr.sent") == null){ // the connection was closed,
        System.err.println("connection closed by client " + request);
        eventStream.finished();
      }
      if (!eventStream.started) {
        event.getHttpServletResponse().setStatus(200);
        eventStream.started = true;
      }
View Full Code Here

TOP

Related Classes of org.persvr.remote.EventStream

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.