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

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


    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 {
    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

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

          switch (BusCommands.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 {
                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 FinishStateSync:
              if (queue == null) return;
              queue.finishInit();

              drainDeferredDeliveryQueue(queue);
              break;

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

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

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

            case ConnectToQueue: {
              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);

                addQueue(session, queue);

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

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

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

              createConversation(message)
                  .toSubject(BuiltInServices.ClientBus.name())
                  .command(BusCommands.RemoteSubscribe)
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

   * @throws ServletException - if the request for the POST could not be handled
   */
  @Override
  protected void doPost(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
          throws ServletException, IOException {
    final QueueSession session = sessionProvider.createOrGetSession(httpServletRequest.getSession(),
            httpServletRequest.getHeader(ClientMessageBus.REMOTE_QUEUE_ID_HEADER));

    service.store(createCommandMessage(session, httpServletRequest));

    pollForMessages(session, httpServletRequest, httpServletResponse, false);
View Full Code Here

  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,
      IOException {

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

    final MessageQueue queue = service.getBus().getQueue(session);
    if (queue == null) {
      switch (getConnectionPhase(request)) {
View Full Code Here

    });
  }

  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    final QueueSession session = sessionProvider.createOrGetSession(request.getSession(),
            request.getHeader(ClientMessageBus.REMOTE_QUEUE_ID_HEADER));
    try {
      service.store(createCommandMessage(session, request));
    }
    catch (Exception e) {
View Full Code Here

      e.printStackTrace();
    }
  }

  private void addAuthenticationToken(Message message, AuthSubject loginSubject) {
    QueueSession session = message.getResource(QueueSession.class, "Session");
    session.setAttribute(ErraiService.SESSION_AUTH_DATA, loginSubject);
  }
View Full Code Here

  protected void onSocketOpened(WebSocket socket) throws IOException {
  }

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

    final LocalContext localSessionContext = LocalContext.get(session);
    QueueSession cometSession = localSessionContext.getAttribute(QueueSession.class, WEBSOCKET_SESSION_ALIAS);
    service.getBus().getQueue(cometSession).setDirectSocketChannel(null);
  }
View Full Code Here

    QueueSession session = message.getResource(QueueSession.class, "Session");
    session.setAttribute(ErraiService.SESSION_AUTH_DATA, loginSubject);
  }

  public boolean isAuthenticated(Message message) {
    QueueSession session = message.getResource(QueueSession.class, "Session");
    return session != null && session.hasAttribute(ErraiService.SESSION_AUTH_DATA);
  }
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.