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

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


    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


    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 {
    QueueSession session = activeChannels.remove(socket);
    service.getBus().getQueue(session).setDeliveryHandlerToDefault();
  }
View Full Code Here

    }

    final EJValue val = JSONDecoder.decode(((TextFrame) frame).getText());
    // this is not an active channel.
    if (!activeChannels.containsKey(socket)) {
      final QueueSession queueSession =
              WebSocketNegotiationHandler.establishNegotiation(val, new SimpleEventChannelWrapped(socket), service);
     
      if (queueSession != null) {
        activeChannels.put(socket, queueSession);
      }
    }
    else {
      QueueSession queueSession = activeChannels.get(socket);
      // this is an active session. send the message.
      for (final Message msg : MessageFactory.createCommandMessage(queueSession, val)) {
        msg.setResource(HttpServletRequest.class.getName(), socket.getServletRequest());
        service.store(msg);
      }
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"})
    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());
              final String webSocketURL;
              final HttpServletRequest request = message.getResource(HttpServletRequest.class,
                      HttpServletRequest.class.getName());
 
              String websocketScheme = "ws";
              if (request.getScheme().equals("https") || useSecureWebsocket) {
                websocketScheme = "wss";
                log.debug("use secure websocket");
              }

              if (webSocketServlet) {
                webSocketURL = websocketScheme + "://" + request.getHeader("Host") + webSocketPath;
              }
              else {
                webSocketURL = websocketScheme + "://" + 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

    SessionsContainer sc = (SessionsContainer) externSessRef.getAttribute(HTTP_SESS);
    if (sc == null) {
      externSessRef.setAttribute(HTTP_SESS, sc = new SessionsContainer());
    }

    QueueSession qs = sc.getSession(remoteQueueID);
    if (qs == null) {
      qs = sc.createSession(externSessRef.getId(), remoteQueueID);
      qs.setAttribute(HttpSession.class.getName(), externSessRef);
    }

    return qs;
  }
View Full Code Here

  public static class SessionsContainer implements Serializable {
    private final Map<String, Object> sharedAttributes = new HashMap<String, Object>();
    private 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

   */
  @Override
  protected void doPost(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
          throws ServletException, IOException {

    final QueueSession session = sessionProvider.getSession(httpServletRequest.getSession(),
            httpServletRequest.getHeader(ClientMessageBus.REMOTE_QUEUE_ID_HEADER));

    try {
      service.store(createCommandMessage(session, httpServletRequest));
    }
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.