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

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


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

    final QueueSession session = sessionProvider.getSession(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.getSession(request.getSession(),
            request.getHeader(ClientMessageBus.REMOTE_QUEUE_ID_HEADER));
    try {
      service.store(createCommandMessage(session, request));
    }
    catch (Exception e) {
View Full Code Here

              .getName()));
    }

    @SuppressWarnings("unchecked") EJObject val = JSONDecoder.decode(((TextWebSocketFrame) frame).getText()).isObject();

    QueueSession session;

    // this is not an active channel.
    if (!activeChannels.containsKey(ctx.getChannel())) {
      String commandType =  val.get(MessageParts.CommandType.name()).isString().stringValue();
View Full Code Here

  protected void onSocketOpened(WebSocket socket) throws IOException {
  }

  @Override
  protected void onSocketClosed(WebSocket socket) throws IOException {
    final QueueSession session = sessionProvider.getSession(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

@Override
  protected void onReceivedTextFrame(final WebSocket socket) throws IOException {
    final String text = socket.readTextFrame();

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

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

    @SuppressWarnings("unchecked") 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) {
      String commandType = val.get(MessageParts.CommandType.name()).isString().stringValue();

      // this client apparently wants to connect.
      if (BusCommands.ConnectToQueue.name().equals(commandType)) {
        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) {
          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.
            service.getBus().getQueue(cometSession).setDirectSocketChannel(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

    messageBus.subscribe("ServerOTEngine", new MessageCallback() {

      @Override
      public void callback(final Message message) {
        final OpDto value = message.getValue(OpDto.class);
        final QueueSession queueSession = message.getResource(QueueSession.class, "Session");
        final String session = queueSession.getSessionId();
        final OTPeer peer = engine.getPeerState().getPeer(session);

        if (peer == null) {
          System.out.println("SessionID: " + session);
          System.out.println("No session for: " + message.getParts());
          return;
        }

        if (value == null && message.hasPart("PurgeHint")) {
          final Integer purgeHint = message.get(Integer.class, "PurgeHint");
          final Integer entityId = message.get(Integer.class, "EntityId");

          peer.setLastKnownRemoteSequence(entityId, purgeHint);
        }
        else if (value != null) {
          final OTEntity entity = engine.getEntityStateSpace().getEntity(value.getEntityId());
          if (entity == null) {
            return;
          }
          synchronized (entity) {
            ClientDemuxer demux = LocalContext.get(queueSession).getAttribute(ClientDemuxer.class);
            if (demux == null) {
              LocalContext.get(queueSession).setAttribute(ClientDemuxer.class, demux = new ClientDemuxer());
            }

         //   final Collection<OpDto> enginePlanFor = demux.getEnginePlanFor(value);
            for (final OpDto operation : Collections.singletonList(value)) {

              final OTOperation remoteOp = operation.otOperation(engine);

              OTLogUtil.log("RECV", "<<from: " + remoteOp.getAgentId() + ">>" ,
                  "REMOTE", "Server", operation.getRevision(),
                  "\"" + String.valueOf(entity.getState().get()) + "\"");

              if (!engine.receive(session, remoteOp)) {
                System.out.println("*** WARNING: CORRUPT PATHS - MUST RESYNC ALL ***");
                engine.getPeerState().forceResyncAll(entity);
              }
            }
          }
        }
      }
    });

    messageBus.subscribe("ServerOTEngineSyncService", new MessageCallback() {
      @Override
      public void callback(final Message message) {
        final Integer entityId = message.getValue(Integer.class);

        final QueueSession queueSession = message.getResource(QueueSession.class, "Session");
        final String session = queueSession.getSessionId();

        OTPeer peer = engine.getPeerState().getPeer(session);
        if (peer == null) {
          engine.getPeerState().registerPeer(peer = new ServerOTPeerImpl(session, messageBus));

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(true),
            httpServletRequest.getHeader(ClientMessageBus.REMOTE_QUEUE_ID_HEADER));

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

    pollForMessages(session, httpServletRequest, httpServletResponse, false);
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).setDirectSocketChannel(null);
  }
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 (BusCommands.ConnectToQueue.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.
            service.getBus().getQueue(cometSession).setDirectSocketChannel(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

    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

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.