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

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


        }
      }

      @Override
      public void reply() {
        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.");
        }

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

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

        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(TimeUnit unit, int interval) {
        Message msg = getIncomingMessage();
        message.copyResource("Session", msg);
        RequestDispatcher dispatcher = (RequestDispatcher) msg.getResource(ResourceProvider.class, RequestDispatcher.class.getName()).get();
        return _sendRepeatingWith(message, dispatcher, unit, interval);
      }

      @Override
      public AsyncTask replyDelayed(TimeUnit unit, int interval) {
        Message msg = getIncomingMessage();
        message.copyResource("Session", msg);
        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, TimeUnit unit, int interval) {
        return _sendRepeatingWith(message, viaThis, unit, interval);
      }

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

      private AsyncTask _sendRepeatingWith(final Message message, final RequestDispatcher viaThis, TimeUnit unit, 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


   * @return a <tt>MessageBuildSubject</tt> which essentially is a <tt>Message</tt>, but ensures that the user
   *         constructs messages properly
   */
  @SuppressWarnings({ "unchecked" })
  public static MessageBuildSubject<MessageReplySendable> createConversation(Message message) {
    Message newMessage = provider.get();
    newMessage.setFlag(RoutingFlag.NonGlobalRouting);
    if (newMessage instanceof HasEncoded) {
      return new DefaultMessageBuilder<MessageReplySendable>(new HasEncodedConvMessageWrapper(message, newMessage))
          .start();
    }
    else {
View Full Code Here

   * @return a <tt>MessageBuildSubject</tt> which essentially is a <tt>Message</tt>, but ensures that the user
   *         constructs messages properly
   */
  @SuppressWarnings({ "unchecked" })
  public static MessageBuildCommand<MessageReplySendable> createConversation(Message message, String subject) {
    Message newMessage = provider.get();
    if (newMessage instanceof HasEncoded) {
      return new DefaultMessageBuilder<MessageReplySendable>(new HasEncodedConvMessageWrapper(message, newMessage))
          .start()
          .toSubject(subject);
    }
View Full Code Here

      /**
       * Prepare to send a message back to the client, informing it that a successful login has
       * been performed.
       */
      Message successfulMsg = MessageBuilder.createConversation(message)
          .subjectProvided()
          .command(SecurityCommands.SuccessfulAuth)
          .with(SecurityParts.Roles, authSubject.toRolesString())
          .with(SecurityParts.Name, name).getMessage();

      try {
        // TODO: Still used? Take a look at MetaDataScanner.getProperties() instead
        ResourceBundle bundle = ResourceBundle.getBundle("errai");
        String motdText = bundle.getString("errai.login_motd");

        /**
         * If the MOTD is configured, then add it to the message.
         */
        if (motdText != null) {
          successfulMsg.set(MessageParts.MessageText, motdText);
        }
      }
      catch (Exception e) {
        // do nothing.
      }

      /**
       * Transmit the message back to the client.
       */
      successfulMsg.sendNowWith(bus);
    }
    catch (LoginException e) {
      /**
       * The login failed. How upsetting. Life must go on, and we must inform the client of the
       * unfortunate news.
View Full Code Here

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

      session = activeChannels.get(ctx.getChannel());
      Message msg = MessageFactory.createCommandMessage(session, ((TextWebSocketFrame) frame).getText());
      svc.store(msg);
    }
  }
View Full Code Here

        sb.append(buffer.get());
      }
      buffer.rewind();
    }

    Message msg = createCommandMessage(sessionProvider.getSession(request.getSession(),
        request.getHeader(REMOTE_QUEUE_ID_HEADER)), request, sb.toString());
    if (msg != null) {
      try {
        service.store(msg);
      }
View Full Code Here

  }

  public static Message createCommandMessage(QueueSession session, String json) {
    if (json.length() == 0) return null;

    Message msg = createWithParts(MapMarshaller.INSTANCE.demarshall( JSONDecoder.decode(json),
                new DecodingSession(MappingContextSingleton.get())))
            .setResource("Session", session)
            .setResource("SessionID", session.getSessionId());

    msg.setFlag(RoutingFlag.FromRemote);

    return msg;
  }
View Full Code Here

    return from(parts, session, request);
  }

  private static Message from(Map<String, Object> parts, QueueSession session, HttpServletRequest request) {
    Message msg = createWithParts(parts)
            .setResource("Session", session)
            .setResource("SessionID", session.getSessionId())
            .setResource(HttpServletRequest.class.getName(), request);

    msg.setFlag(RoutingFlag.FromRemote);

    return msg;
  }
View Full Code Here

  public void stop(boolean sendDisconnect) {
    try {
      if (sendDisconnect) {
        sendBuilder.setHeader("phase", "disconnect");

        Message m = MessageBuilder.createMessage()
                .toSubject(BuiltInServices.ServerBus.name())
                .command(BusCommands.Disconnect).getMessage();

        encodeAndTransmit(m);
      }
View Full Code Here

  private void sendAllDeferred() {
    log("transmitting deferred messages now ...");

    for (Iterator<Message> iter = deferredMessages.iterator(); iter.hasNext(); ) {
      Message m = iter.next();
      if (m.hasPart(MessageParts.PriorityProcessing)) {
        directStore(m);
        iter.remove();
      }
    }
View Full Code Here

TOP

Related Classes of org.jboss.errai.bus.client.api.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.