Package org.jboss.errai.bus.client.api

Examples of org.jboss.errai.bus.client.api.QueueSession


    }
  }

  @Override
  protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException {
    final QueueSession session = sessionProvider.createOrGetSession(request.getSession(), getClientId(request));
    session.setAttribute("NoSSE", Boolean.TRUE);
    try {
      try {
        service.store(createCommandMessage(session, request));
      }
      catch (QueueUnavailableException e) {
View Full Code Here


    else {
      sc = new SessionsContainer();
      externSessRef.setAttribute(SessionsContainer.class.getName(), sc);
    }

    QueueSession qs = sc.getSession(remoteQueueID);
    if (qs == null) {
      log.debug("queue session " + remoteQueueID + " started");
      qs = sc.createSession(externSessRef.getId(), remoteQueueID);
      qs.setAttribute(HttpSession.class.getName(), externSessRef);
      qs.addSessionEndListener(new SessionEndListener() {
        @Override
        public void onSessionEnd(SessionEndEvent event) {
          log.debug("queue session " + remoteQueueID + " ended");
          sc.removeSession(remoteQueueID);
        }
View Full Code Here

  public static class SessionsContainer implements Serializable {
    private transient final Map<String, Object> sharedAttributes = new HashMap<String, Object>();
    private transient final Map<String, QueueSession> queueSessions = new HashMap<String, QueueSession>();

    public QueueSession createSession(final String httpSessionId, final String remoteQueueId) {
      final QueueSession qs = new HttpSessionWrapper(this, httpSessionId, remoteQueueId);
      queueSessions.put(remoteQueueId, qs);
      return qs;
    }
View Full Code Here

  protected void onSocketOpened(final WebSocket socket) throws IOException {
  }

  @Override
  protected void onSocketClosed(final WebSocket socket) throws IOException {
    final QueueSession session = sessionProvider.createOrGetSession(socket.getHttpSession(),
            socket.getSocketID());

    final LocalContext localSessionContext = LocalContext.get(session);
    final QueueSession cometSession = localSessionContext.getAttribute(QueueSession.class, WEBSOCKET_SESSION_ALIAS);

    service.getBus().getQueue(cometSession).setDeliveryHandlerToDefault();
  }
View Full Code Here

        }
    }

    final String text = ((TextFrame) frame).getText();

    final QueueSession session = sessionProvider.createOrGetSession(socket.getHttpSession(),
            socket.getSocketID());

    if (text.length() == 0) return;

    @SuppressWarnings("unchecked") final EJObject val = JSONDecoder.decode(text).isObject();

    final LocalContext localSessionContext = LocalContext.get(session);

    QueueSession cometSession = localSessionContext.getAttribute(QueueSession.class, WEBSOCKET_SESSION_ALIAS);

    // this is not an active channel.
    if (cometSession == null) {
      final String commandType = val.get(MessageParts.CommandType.name()).isString().stringValue();

      // this client apparently wants to connect.
      if (BusCommand.Associate.name().equals(commandType)) {
        final String sessionKey = val.get(MessageParts.ConnectionSessionKey.name()).isString().stringValue();

        // has this client already attempted a connection, and is in a wait verify state
        if (sessionKey != null && (cometSession = service.getBus().getSessionBySessionId(sessionKey)) != null) {
          final LocalContext localCometSession = LocalContext.get(cometSession);

          if (localCometSession.hasAttribute(WebSocketServerHandler.SESSION_ATTR_WS_STATUS) &&
                  WebSocketServerHandler.WEBSOCKET_ACTIVE.equals(localCometSession.getAttribute(String.class, WebSocketServerHandler.SESSION_ATTR_WS_STATUS))) {

            // set the session queue into direct channel mode.

            final MessageQueue queue = service.getBus().getQueue(cometSession);
            queue.setDeliveryHandler(DirectDeliveryHandler.createFor(new SimpleEventChannelWrapped(socket)));

            localSessionContext.setAttribute(WEBSOCKET_SESSION_ALIAS, cometSession);
            cometSession.removeAttribute(WebSocketServerHandler.SESSION_ATTR_WS_STATUS);

            return;
          }

          // check the activation key matches.
View Full Code Here

   *     - if the request for the POST could not be handled
   */
  @Override
  protected void doPost(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException {

    final QueueSession session = sessionProvider.createOrGetSession(httpServletRequest.getSession(true),
        getClientId(httpServletRequest));

    session.setAttribute("NoSSE", Boolean.TRUE);

    try {
      service.store(createCommandMessage(session, httpServletRequest));
    }
    catch (IOException ioe) {
View Full Code Here

          .getName()));
    }

    @SuppressWarnings("unchecked") final EJValue val = JSONDecoder.decode(((TextWebSocketFrame) frame).text());

    final QueueSession session;

    // this is not an active channel.
    if (!activeChannels.containsKey(ctx.channel())) {
      if (val == null) {
        sendMessage(ctx, getFailedNegotiation("illegal handshake"));
View Full Code Here

    messageQueues.put(newSession, getQueue(oldSession));
  }

  @Override
  public MessageQueue getQueueBySession(final String sessionId) {
    final QueueSession session = sessionLookup.get(sessionId);
    if (session == null) {
      throw new QueueUnavailableException("no queue for sessionId=" + sessionId);
    }
    return getQueue(session);
  }
View Full Code Here

    @Override
    @SuppressWarnings({"unchecked", "SynchronizationOnLocalVariableOrMethodParameter"})
    public void callback(final Message message) {
      try {
        final QueueSession session = getSession(message);
        MessageQueueImpl queue = (MessageQueueImpl) messageQueues.get(session);

        switch (BusCommand.valueOf(message.getCommandType())) {
          case Heartbeat:
            if (queue != null) {
              queue.heartBeat();
            }
            break;

          case RemoteSubscribe:
            if (queue == null) return;

            if (message.hasPart(MessageParts.SubjectsList)) {
              for (final String subject : (List<String>) message.get(List.class, MessageParts.SubjectsList)) {
                remoteSubscribe(session, queue, subject);
              }
            }
            else if (message.hasPart(MessageParts.RemoteServices)) {
              for (final String subject : message.get(String.class, MessageParts.RemoteServices).split(",")) {
                remoteSubscribe(session, queue, subject);
              }
            }
            else {
              remoteSubscribe(session, messageQueues.get(session),
                  message.get(String.class, MessageParts.Subject));
            }

            break;

          case RemoteUnsubscribe:
            if (queue == null) return;

            remoteUnsubscribe(session, queue,
                message.get(String.class, MessageParts.Subject));
            break;

          case Disconnect:
            if (queue == null) return;

            synchronized (messageQueues) {
              queue.stopQueue();
              closeQueue(queue);
              session.endSession();
            }
            break;

          case Resend:
            if (queue == null) return;

          case Associate: {
            List<Message> deferred = null;
            synchronized (messageQueues) {
              if (messageQueues.containsKey(session)) {
                final MessageQueue q = messageQueues.get(session);
                synchronized (q) {
                  if (deferredQueue.containsKey(q)) {
                    deferred = deferredQueue.remove(q);
                  }
                }

                messageQueues.get(session).stopQueue();
              }

              queue = new MessageQueueImpl(transmissionbuffer, session, messageQueueTimeoutSecs);

              addQueue(session, queue);

              if (deferred != null) {
                deferredQueue.put(queue, deferred);
              }

              remoteSubscribe(session, queue, BuiltInServices.ClientBus.name());
            }

            for (final String svc : message.get(String.class, MessageParts.RemoteServices).split(",")) {
              remoteSubscribe(session, queue, svc);
            }

            if (isMonitor()) {
              busMonitor.notifyQueueAttached(session.getSessionId(), queue);
            }

            final Message msg = ConversationMessage.create(message)
                .toSubject(BuiltInServices.ClientBus.name())
                .command(BusCommand.FinishAssociation);

            final StringBuilder subjects = new StringBuilder();
            for (final String s : new HashSet<String>(globalSubscriptions)) {
              if (subjects.length() != 0) {
                subjects.append(',');
              }
              subjects.append(s);
            }

            msg.set(RemoteServices, subjects.toString());

            final StringBuilder capabilitiesBuffer = new StringBuilder(25);

            final boolean first;
            if (doLongPolling) {
              capabilitiesBuffer.append(Capabilities.LongPolling.name());
              first = false;
            }
            else {
              capabilitiesBuffer.append(Capabilities.ShortPolling.name());
              first = false;
              msg.set(MessageParts.PollFrequency, hostedModeTesting ? 50 : 250);
            }

            if (webSocketServer || webSocketServlet) {
              if (!first) {
                capabilitiesBuffer.append(',');
              }
              capabilitiesBuffer.append(Capabilities.WebSockets.name());
              /**
               * Advertise where the client can find a websocket.
               */

              final String webSocketURL;

              final HttpServletRequest request
                  = message.getResource(HttpServletRequest.class, HttpServletRequest.class.getName());

              if (webSocketServlet) {
                webSocketURL = "ws://" + request.getHeader("Host") + webSocketPath;
              }
              else {
                webSocketURL = "ws://" + request.getServerName() + ":" + webSocketPort + webSocketPath;
              }
              msg.set(MessageParts.WebSocketURL, webSocketURL);
              msg.set(MessageParts.WebSocketToken, WebSocketTokenManager.getNewOneTimeToken(session));
            }

            if (sseEnabled && !session.hasAttribute("NoSSE")) {
              capabilitiesBuffer.append(",").append(Capabilities.SSE.name());
            }

            msg.set(MessageParts.CapabilitiesFlags, capabilitiesBuffer.toString());

View Full Code Here

    else {
      sc = new SessionsContainer();
      externSessRef.setAttribute(SessionsContainer.class.getName(), sc);
    }

    QueueSession qs = sc.getSession(remoteQueueID);
    if (qs == null) {
      log.debug("queue session " + remoteQueueID + " started");
      qs = sc.createSession(externSessRef.getId(), remoteQueueID);
      qs.setAttribute(HttpSession.class.getName(), externSessRef);
      qs.addSessionEndListener(new SessionEndListener() {
        @Override
        public void onSessionEnd(SessionEndEvent event) {
          log.debug("queue session " + remoteQueueID + " ended");
          sc.removeSession(remoteQueueID);
        }
View Full Code Here

TOP

Related Classes of org.jboss.errai.bus.client.api.QueueSession

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.