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

Examples of org.jboss.errai.bus.client.api.messaging.Message


*/
public class StatsTest {

    @Test
    public void testTotalWaitTime() throws InterruptedException {
        Message message = MessageBuilder.createMessage()
            .toSubject("fake")
            .withValue("a fake value")
            .getMessage();

        Stats stats = new Stats();
View Full Code Here


            stats.getTotalWaitTime() >= 200);
    }

    @Test
    public void testAverageWaitTime() throws InterruptedException {
        Message message = MessageBuilder.createMessage()
            .toSubject("fake")
            .withValue("a fake value")
            .getMessage();

        Stats stats = new Stats();
View Full Code Here

  }

  @Override
  public void receive(final org.jgroups.Message msg) {
    try {
      final Message erraiMessage = getErraiMessage(msg);
      erraiMessage.setResource(JGROUPS_MESSAGE_RESOURCE, msg);

      if (busId.equals(erraiMessage.get(String.class, BusId))) {
        return;
      }
      erraiMessage.setFlag(RoutingFlag.FromPeer);

      serverMessageBus.sendGlobal(erraiMessage);
    }
    catch (Exception e) {
      e.printStackTrace();
View Full Code Here

            return;
          }

          final org.jgroups.Message jgroupsMessage = message.getResource(org.jgroups.Message.class, JGROUPS_MESSAGE_RESOURCE);

          final Message replyMsg = CommandMessage.create()
              .set(ToSubject, CLUSTER_SERVICE)
              .set(CommandType, ClusterCommands.NotifyOwner.name())
              .set(BusId, busId)
              .copy(MessageId, message)
              .set(ClusterParts.SessId, sessionIdRequested);

          try {
            jchannel.send(jgroupsMessage.getSrc(), ErraiProtocol.encodePayload(replyMsg.getParts()));
          }
          catch (Exception e) {
            e.printStackTrace();
          }
        }
      }
      break;

      case NotifyOwner: {
        final String messageId = message.get(String.class, MessageId);
        final String sessId = message.get(String.class, SessId);
        final Message deferredMessage = serverMessageBus.getDeadLetterMessage(messageId);
        serverMessageBus.removeDeadLetterMessage(messageId);

        final org.jgroups.Message jgroupsMessage
            = message.getResource(org.jgroups.Message.class, JGROUPS_MESSAGE_RESOURCE);

        sessionToNodeCache.put(sessId, jgroupsMessage.getSrc());

        if (deferredMessage != null) {
          final Message dMessage = createForwardMessageFor(deferredMessage, messageId);

          try {
            jchannel.send(jgroupsMessage.getSrc(), ErraiProtocol.encodePayload(dMessage.getParts()));
          }
          catch (Exception e) {
            e.printStackTrace();
          }
        }
      }
      break;

      case InvalidRoute: {
        final String sessionId = message.get(String.class, SessId);
        sessionToNodeCache.invalidate(sessionId);

        final String messageId = message.get(String.class, MessageId);
        final String subject = message.get(String.class, Subject);

        final Message whoMessage = createWhoHandlesMessage(sessionId, subject, messageId);

        try {
          jchannel.send(getJGroupsMessage(whoMessage));
        }
        catch (Exception e) {
          e.printStackTrace();
        }

        break;
      }

      case MessageForward: {
        final String payload = message.get(String.class, Payload);
        final Message forwardMessage = MessageFactory.createCommandMessage(IntrabusQueueSession.INSTANCE, payload);
        forwardMessage.setFlag(RoutingFlag.FromPeer);

        final String sessId = message.get(String.class, SessId);
        if (sessId == null) {
          serverMessageBus.sendGlobal(forwardMessage);
        }
        else {
          final MessageQueue messageQueue;

          try {
            messageQueue = serverMessageBus.getQueueBySession(sessId);
          }
          catch (QueueUnavailableException e) {
            final org.jgroups.Message jgroupsMessage
                = message.getResource(org.jgroups.Message.class, JGROUPS_MESSAGE_RESOURCE);

            final String messageId = message.get(String.class, MessageId);
            final Message invalidRoute = createInvalidRouteMessage(sessId, forwardMessage.getSubject(), messageId);

            try {
              jchannel.send(jgroupsMessage.getSrc(), ErraiProtocol.encodePayload(invalidRoute.getParts()));
            }
            catch (Exception e2) {
              e2.printStackTrace();
            }
            return;
View Full Code Here

  @Override
  public void clusterTransmit(final String sessionId, final String subject, final String messageId) {
    final Address knownAddress = sessionToNodeCache.getIfPresent(sessionId);
    if (knownAddress != null) {
      final Message forwardMessage = createForwardMessageFor(serverMessageBus.getDeadLetterMessage(messageId), messageId);
      try {
        jchannel.send(knownAddress, ErraiProtocol.encodePayload(forwardMessage.getParts()));
      }
      catch (Exception e) {
        e.printStackTrace();
      }
    }
    else {
      final Message whoHandlesMessage = createWhoHandlesMessage(sessionId, subject, messageId);
      try {
        jchannel.send(getJGroupsMessage(whoHandlesMessage));
      }
      catch (Exception e) {
        e.printStackTrace();
View Full Code Here

      }
    }
  }

  private Message createForwardMessageFor(final Message message, final String messageId) {
    final Message forward = CommandMessage.create()
        .set(ToSubject, CLUSTER_SERVICE)
        .set(CommandType, ClusterCommands.MessageForward.name())
        .set(Payload, ErraiProtocol.encodePayload(message.getParts()))
        .set(BusId, busId);

    if (message.hasPart(SessionID)) {
      final String value = message.get(String.class, SessionID);
      if (!IntrabusQueueSession.INSTANCE.getSessionId().equals(value)) {
        forward.set(SessId, value);
      }
    }

    if (messageId != null) {
      forward.set(MessageId, messageId);
    }

    return forward;
  }
View Full Code Here

        }
      }

      @Override
      public void reply() {
        final Message incomingMessage = getIncomingMessage();

        if (incomingMessage == null) {
          throw new IllegalStateException("Cannot reply.  Cannot find incoming message.");
        }

        if (!incomingMessage.hasResource(RequestDispatcher.class.getName())) {
          throw new IllegalStateException("Cannot reply.  Cannot find RequestDispatcher resource.");
        }

        final RequestDispatcher dispatcher = (RequestDispatcher)
                incomingMessage.getResource(ResourceProvider.class, RequestDispatcher.class.getName()).get();

        if (dispatcher == null) {
          throw new IllegalStateException("Cannot reply.  Cannot find RequestDispatcher resource.");
        }

        final Message msg = getIncomingMessage();

        message.copyResource("Session", msg);
        message.copyResource(RequestDispatcher.class.getName(), msg);

        try {
          dispatcher.dispatch(message);
        }
        catch (Exception e) {
          throw new MessageDeliveryFailure("unable to deliver message: " + e.getMessage(), e);
        }
      }

      @Override
      public AsyncTask replyRepeating(final TimeUnit unit, final int interval) {
        final Message msg = getIncomingMessage();
        message.copyResource("Session", msg);
        final RequestDispatcher dispatcher = (RequestDispatcher) msg.getResource(ResourceProvider.class, RequestDispatcher.class.getName()).get();
        return _sendRepeatingWith(message, dispatcher, unit, interval);
      }

      @Override
      public AsyncTask replyDelayed(final TimeUnit unit, final int interval) {
        final Message msg = getIncomingMessage();
        message.copyResource("Session", msg);
        final RequestDispatcher dispatcher = (RequestDispatcher) msg.getResource(ResourceProvider.class, RequestDispatcher.class.getName()).get();
        return _sendDelayedWith(message, dispatcher, unit, interval);
      }

      private Message getIncomingMessage() {
        return ((ConversationMessageWrapper) message).getIncomingMessage();
      }

      @Override
      public AsyncTask sendRepeatingWith(final RequestDispatcher viaThis, final TimeUnit unit, final int interval) {
        return _sendRepeatingWith(message, viaThis, unit, interval);
      }

      @Override
      public AsyncTask sendDelayedWith(final RequestDispatcher viaThis, final TimeUnit unit, final int interval) {
        return _sendDelayedWith(message, viaThis, unit, interval);
      }

      private AsyncTask _sendRepeatingWith(final Message message, final RequestDispatcher viaThis, final TimeUnit unit, final int interval) {
        final boolean isConversational = message instanceof ConversationMessageWrapper;

        final AsyncTask task = TaskManagerFactory.get().scheduleRepeating(unit, interval, new HasAsyncTaskRef() {
          AsyncTask task;
          AsyncDelegateErrorCallback errorCallback;

          final Runnable sender;

          {
            errorCallback = new AsyncDelegateErrorCallback(this, message.getErrorCallback());

            if (isConversational) {
              final Message incomingMsg = ((ConversationMessageWrapper) message).getIncomingMessage();

              if (incomingMsg.hasPart(MessageParts.ReplyTo)) {
                sender = new Runnable() {
                  final String replyTo = incomingMsg
                          .get(String.class, MessageParts.ReplyTo);

                  @Override
                  public void run() {
                    try {
View Full Code Here

      }
    }
    else {
      // this is an active session. send the message.;

      final Message msg = MessageFactory.createCommandMessage(cometSession, text);
      msg.setResource(HttpServletRequest.class.getName(), socket.getServletRequest());
      service.store(msg);
    }
  }
View Full Code Here

      synchronized (queue) {
        if (deferredQueue.containsKey(queue)) {
          final List<Message> deferredMessages = deferredQueue.get(queue);
          final Iterator<Message> dmIter = deferredMessages.iterator();

          Message m;
          while (dmIter.hasNext()) {
            if ((m = dmIter.next()).hasPart(MessageParts.PriorityProcessing.toString())) {
              queue.offer(m);
              dmIter.remove();
            }
View Full Code Here

            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());

            msg.set(ConnectionSessionKey, queue.getSession().getSessionId());
            send(msg, false);

            queue.finishInit();
            drainDeferredDeliveryQueue(queue);
            break;
View Full Code Here

TOP

Related Classes of org.jboss.errai.bus.client.api.messaging.Message

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.