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

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


        /**
         * Declare a local service to receive messages on the subject
         * "BroadCastReceiver".
         */
        bus.subscribe("BroadcastReceiver", new MessageCallback() {
            public void callback(Message message) {
                /**
                 * When a message arrives, extract the "BroadcastText" field and
                 * update the broadcastReceive Label widget with the contents.
                 */
 
View Full Code Here


      }
    };

    bus.addPostInitTask(busReadyEvent);

    bus.subscribe(CDI.CLIENT_DISPATCHER_SUBJECT, new MessageCallback() {
      public void callback(Message message) {
        switch (BusCommands.valueOf(message.getCommandType())) {
          case RemoteSubscribe:
            CDI.addRemoteEventTypes(message.get(String[].class, MessageParts.Value));
View Full Code Here


  private boolean directSubscribe(final String subject, final MessageCallback callback) {
    boolean isNew = !isSubscribed(subject);

    addSubscription(subject, _subscribe(subject, new MessageCallback() {
      public void callback(Message message) {
        try {
          // TODO: performance impact? might be better when decoding the message from the wire
          executeInterceptorStack(true, message);
          callback.callback(message);
View Full Code Here

  public void conversationWith(final Message message, final MessageCallback callback) {
    final String tempSubject = "temp:Reply:" + (++conversationCounter);

    message.set(ReplyTo, tempSubject);

    subscribe(tempSubject, new MessageCallback() {
      public void callback(Message message) {
        unsubscribeAll(tempSubject);
        callback.callback(message);
      }
    });
View Full Code Here

     */
    for (InitializationListener listener : onInitializationListeners) {
      listener.onInitilization();
    }

    directSubscribe("ClientBus", new MessageCallback() {
      @SuppressWarnings({"unchecked"})
      public void callback(final Message message) {
        switch (BusCommands.valueOf(message.getCommandType())) {
          case RemoteSubscribe:
            if (message.hasPart("SubjectsList")) {
              for (String subject : (List<String>) message.get(List.class, "SubjectsList")) {
                remoteSubscribe(subject);
              }
            }
            else {
              String subject = message.get(String.class, Subject);
              remoteSubscribe(subject);

            }
            break;

          case RemoteUnsubscribe:
            unsubscribeAll(message.get(String.class, Subject));
            break;

          case CapabilitiesNotice:
            String[] capabilites = message.get(String.class, "Flags").split(",");

            for (String capability : capabilites) {
              switch (Capabilities.valueOf(capability)) {
                case LongPollAvailable:
                  COMM_CALLBACK = new LongPollRequestCallback();
                  break;
                case NoLongPollAvailable:
                  COMM_CALLBACK = new ShortPollRequestCallback();
                  if (message.hasPart("PollFrequency")) {
                    POLL_FREQUENCY = message.get(Integer.class, "PollFrequency");
                  }
                  else {
                    POLL_FREQUENCY = 500;
                  }
                  break;
              }
            }

            break;

          case RemoteMonitorAttach:
            break;

          case FinishStateSync:
            if (isInitialized()) {
              return;
            }

            List<String> subjects = new ArrayList<String>();
            for (String s : subscriptions.keySet()) {
              if (s.startsWith("local:")) continue;
              if (!remotes.containsKey(s)) subjects.add(s);
            }

            remoteSubscribe("ServerBus");

            MessageBuilder.createMessage()
                    .toSubject("ServerBus")
                    .command(RemoteSubscribe)
                    .with("SubjectsList", subjects)
                    .with(PriorityProcessing, "1")
                    .noErrorHandling()
                    .sendNowWith(ClientMessageBusImpl.this);


            MessageBuilder.createMessage()
                    .toSubject("ServerBus")
                    .command(BusCommands.FinishStateSync)
                    .with(PriorityProcessing, "1")
                    .noErrorHandling().sendNowWith(ClientMessageBusImpl.this);

            /**
             * ... also send RemoteUnsubscribe signals.
             */

            addSubscribeListener(new SubscribeListener() {
              public void onSubscribe(SubscriptionEvent event) {
                if (event.isLocalOnly() || event.getSubject().startsWith("local:")
                        || remotes.containsKey(event.getSubject())) {
                  return;
                }

                MessageBuilder.getMessageProvider().get().command(RemoteSubscribe)
                        .toSubject("ServerBus")
                        .set(Subject, event.getSubject())
                        .set(PriorityProcessing, "1")
                        .sendNowWith(ClientMessageBusImpl.this);
              }
            });

            addUnsubscribeListener(new UnsubscribeListener() {
              public void onUnsubscribe(SubscriptionEvent event) {
                MessageBuilder.getMessageProvider().get().command(BusCommands.RemoteUnsubscribe)
                        .toSubject("ServerBus")
                        .set(Subject, event.getSubject())
                        .set(PriorityProcessing, "1")
                        .sendNowWith(ClientMessageBusImpl.this);
              }
            });

            subscribe(DefaultErrorCallback.CLIENT_ERROR_SUBJECT, new MessageCallback() {
              public void callback(Message message) {
                String errorTo = message.get(String.class, MessageParts.ErrorTo);
                if (errorTo == null) {
                  logError(message.get(String.class, "ErrorMessage"),
                          message.get(String.class, "AdditionalDetails"), null);
View Full Code Here

    }

    /**
     * Define the default ServerBus service used for intrabus communication.
     */
    subscribe(BuiltInServices.ServerBus.name(), new MessageCallback() {
      @Override
      @SuppressWarnings({"unchecked", "SynchronizationOnLocalVariableOrMethodParameter"})
      public void callback(Message message) {
        try {
          QueueSession session = getSession(message);
View Full Code Here


  private boolean directSubscribe(final String subject, final MessageCallback callback, boolean local) {
    boolean isNew = !isSubscribed(subject);

    MessageCallback cb = new MessageCallback() {
      @Override
      public void callback(Message message) {
        try {
          executeInterceptorStack(true, message);
          callback.callback(message);
View Full Code Here

  public void conversationWith(final Message message, final MessageCallback callback) {
    final String tempSubject = "temp:Reply:" + (++conversationCounter);

    message.set(ReplyTo, tempSubject);

    subscribe(tempSubject, new MessageCallback() {
      @Override
      public void callback(Message message) {
        unsubscribeAll(tempSubject);
        callback.callback(message);
      }
View Full Code Here

    for (PreInitializationListener listener : preInitializationListeners) {
      listener.beforeInitialization();
    }

    remoteSubscribe(BuiltInServices.ServerEchoService.name());
    directSubscribe(BuiltInServices.ClientBus.name(), new MessageCallback() {
      @Override
      @SuppressWarnings({"unchecked"})
      public void callback(final Message message) {
        switch (BusCommands.valueOf(message.getCommandType())) {
          case RemoteSubscribe:
            if (message.hasPart(MessageParts.SubjectsList)) {
              for (String subject : (List<String>) message.get(List.class, MessageParts.SubjectsList)) {
                remoteSubscribe(subject);
              }
            }
            else {
              String subject = message.get(String.class, Subject);
              remoteSubscribe(subject);
            }
            break;

          case RemoteUnsubscribe:
            unsubscribeAll(message.get(String.class, Subject));
            break;

          case CapabilitiesNotice:
            LogUtil.log("received capabilities notice from server. supported capabilities of remote: "
                    + message.get(String.class, MessageParts.CapabilitiesFlags));

            String[] capabilites = message.get(String.class, MessageParts.CapabilitiesFlags).split(",");

            for (String capability : capabilites) {
              switch (Capabilities.valueOf(capability)) {
                case WebSockets:
                  webSocketUrl = message.get(String.class, MessageParts.WebSocketURL);
                  webSocketToken = message.get(String.class, MessageParts.WebSocketToken);

                  LogUtil.log("attempting web sockets connection at URL: " + webSocketUrl);

                  Object o = ClientWebSocketChannel.attemptWebSocketConnect(ClientMessageBusImpl.this, webSocketUrl);

                  if (o instanceof String) {
                    LogUtil.log("could not use web sockets. reason: " + o);
                  }
                  break;
                case LongPollAvailable:

                  LogUtil.log("initializing long poll subsystem");
                  receiveCommCallback = new LongPollRequestCallback();
                  break;
                case NoLongPollAvailable:
                  receiveCommCallback = new ShortPollRequestCallback();
                  if (message.hasPart(MessageParts.PollFrequency)) {
                    POLL_FREQUENCY = message.get(Integer.class, MessageParts.PollFrequency);
                  }
                  else {
                    POLL_FREQUENCY = 500;
                  }
                  break;
              }
            }

            break;

          case RemoteMonitorAttach:
            break;

          case FinishStateSync:
            if (isInitialized()) {
              return;
            }

            LogUtil.log("received FinishStateSync message. preparing to bring up the federation");

            List<String> subjects = new ArrayList<String>();
            for (String s : subscriptions.keySet()) {
              if (s.startsWith("local:")) continue;
              if (!remotes.containsKey(s)) subjects.add(s);
            }

            sessionId = message.get(String.class, MessageParts.ConnectionSessionKey);

            remoteSubscribe(BuiltInServices.ServerBus.name());

            MessageBuilder.createMessage()
                    .toSubject(BuiltInServices.ServerBus.name())
                    .command(RemoteSubscribe)
                    .with(MessageParts.SubjectsList, subjects)
                    .with(PriorityProcessing, "1")
                    .noErrorHandling()
                    .sendNowWith(ClientMessageBusImpl.this);


            MessageBuilder.createMessage()
                    .toSubject(BuiltInServices.ServerBus.name())
                    .command(BusCommands.FinishStateSync)
                    .with(PriorityProcessing, "1")
                    .noErrorHandling().sendNowWith(ClientMessageBusImpl.this);

            /**
             * ... also send RemoteUnsubscribe signals.
             */
            addSubscribeListener(new SubscribeListener() {
              @Override
              public void onSubscribe(SubscriptionEvent event) {
                if (event.isLocalOnly() || event.getSubject().startsWith("local:")
                        || remotes.containsKey(event.getSubject())) {
                  return;
                }

                if (event.isNew()) {
                  MessageBuilder.getMessageProvider().get().command(RemoteSubscribe)
                          .toSubject(BuiltInServices.ServerBus.name())
                          .set(Subject, event.getSubject())
                          .set(PriorityProcessing, "1")
                          .sendNowWith(ClientMessageBusImpl.this);
                }
              }
            });

            addUnsubscribeListener(new UnsubscribeListener() {
              @Override
              public void onUnsubscribe(SubscriptionEvent event) {
                MessageBuilder.getMessageProvider().get().command(BusCommands.RemoteUnsubscribe)
                        .toSubject(BuiltInServices.ServerBus.name())
                        .set(Subject, event.getSubject())
                        .set(PriorityProcessing, "1")
                        .sendNowWith(ClientMessageBusImpl.this);
              }
            });

            subscribe(DefaultErrorCallback.CLIENT_ERROR_SUBJECT, new MessageCallback() {
              @Override
              public void callback(Message message) {
                String errorTo = message.get(String.class, MessageParts.ErrorTo);
                if (errorTo == null) {
                  logError(message.get(String.class, MessageParts.ErrorMessage),
View Full Code Here

        Service svc = method.getAnnotation(Service.class);
        String svcName = svc.value().equals("") ? method.getJavaMember().getName() : svc.value();

        final Method callMethod = method.getJavaMember();

        bus.subscribe(svcName, new MessageCallback() {

          @Override
          public void callback(Message message) {
            Object targetBean = CDIServerUtil.lookupBean(beanManager, type);
View Full Code Here

TOP

Related Classes of org.jboss.errai.bus.client.api.MessageCallback

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.