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

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


  public static MessageInterceptor CONVERSATION_INTERCEPTOR = new ConversationInterceptor();

  public static void handleEvent(final Class<?> type, final EventHandler<Object> handler) {
    ErraiBus.get().subscribe("cdi.event:" + type.getName(), // by convention
            new MessageCallback() {
              public void callback(Message message) {
                Object response = message.get(type, CDIProtocol.OBJECT_REF);
                handler.handleEvent(response);
              }
            });
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);

            try {
              callMethod.invoke(targetBean, message);
            }
            catch (Exception e) {
              ErrorHelper.sendClientError(bus, message, "Error dispatching service", e);
            }
          }
        });
      }
    }

    for (final AnnotatedType<?> type : managedTypes.getServiceEndpoints()) {
      // Discriminate on @Command
      Map<String, Method> commandPoints = new HashMap<String, Method>();
      for (final AnnotatedMethod method : type.getMethods()) {
        if (method.isAnnotationPresent(Command.class)) {
          Command command = method.getAnnotation(Command.class);
          for (String cmdName : command.value()) {
            if (cmdName.equals(""))
              cmdName = method.getJavaMember().getName();
            commandPoints.put(cmdName, method.getJavaMember());
          }
        }
      }

      log.info("Register MessageCallback: " + type);
      final String subjectName = CDIServerUtil.resolveServiceName(type.getJavaClass());

      bus.subscribe(subjectName, new MessageCallback() {
        @Override
        public void callback(final Message message) {
          MessageCallback callback = (MessageCallback) CDIServerUtil.lookupBean(beanManager,
                  type.getJavaClass());
          callback.callback(message);
        }
      });

    }
View Full Code Here

        }
      }
    }

    final RemoteServiceCallback delegate = new RemoteServiceCallback(epts);
    bus.subscribe(remoteIface.getName() + ":RPC", new MessageCallback() {
      @Override
      public void callback(Message message) {
        delegate.callback(message);
      }
    });
View Full Code Here

        final String errorTo =
            message.getSubject() + "." + message.getCommandType() + ":Errors:" + ((id == null) ? uniqueNumber() : id);

        if (remoteCallback != null) {
          bus.subscribe(replyTo,
              new MessageCallback() {
                @Override
                public void callback(Message message) {
                  bus.unsubscribeAll(replyTo);
                  if (DefaultRemoteCallBuilder.this.message.getErrorCallback() != null) {
                    bus.unsubscribeAll(errorTo);
                  }
                  remoteCallback.callback(message.get(responseType, "MethodReply"));
                }
              }
          );
          message.set(MessageParts.ReplyTo, replyTo);
        }

        if (message.getErrorCallback() != null) {
          bus.subscribe(errorTo,
              new MessageCallback() {
                @Override
                public void callback(Message m) {
                  bus.unsubscribeAll(errorTo);
                  if (remoteCallback != null) {
                    bus.unsubscribeAll(replyTo);
View Full Code Here


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

    addShadowSubscription(subject, 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:
            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);

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

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

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

                  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;
            }

            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

    }

    /**
     * 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

    final boolean authenticationConfigured =
        context.getConfig().getResource(AuthenticationAdapter.class) != null;



    bus.subscribe(ErraiService.AUTHORIZATION_SVC_SUBJECT, new MessageCallback() {
      public void callback(Message message) {
        switch (SecurityCommands.valueOf(message.getCommandType())) {
          case AuthenticationScheme:
            if (authenticationConfigured) {

              /**
               * Respond with what credentials the authentication system requires.
               */
              //todo: we only support login/password for now

              createConversation(message)
                  .subjectProvided()
                  .command(SecurityCommands.AuthenticationScheme)
                  .with(SecurityParts.CredentialsRequired, "Name,Password")
                  .with(MessageParts.ReplyTo, ErraiService.AUTHORIZATION_SVC_SUBJECT)
                  .noErrorHandling().sendNowWith(bus);
            }
            else {
              createConversation(message)
                  .subjectProvided()
                  .command(SecurityCommands.AuthenticationNotRequired)
                  .noErrorHandling().sendNowWith(bus);
            }

            break;

          case AuthRequest:
            /**
             * Receive a challenge.
             */

            if (authenticationConfigured) {
              try {
                context.getConfig().getResource(AuthenticationAdapter.class)
                    .challenge(message);
              }
              catch (AuthenticationFailedException a) {
              }
            }
            break;

          case EndSession:
            if (authenticationConfigured) {
              context.getConfig().getResource(AuthenticationAdapter.class)
                  .endSession(message);
            }

            // reply in any case
            createConversation(message)
                .toSubject("LoginClient")
                .command(SecurityCommands.EndSession)
                .noErrorHandling()
                .sendNowWith(bus);

            break;
        }
      }
    });

    /**
     * The standard ServerEchoService.
     */
    bus.subscribe(ErraiService.SERVER_ECHO_SERVICE, new MessageCallback() {
      public void callback(Message c) {
        MessageBuilder.createConversation(c)
            .subjectProvided().noErrorHandling()
            .sendNowWith(bus);
      }
    });

    bus.subscribe(ErraiService.AUTHORIZATION_SERVICE, new MessageCallback() {
      public void callback(Message message) {
        AuthSubject subject = message.getResource(QueueSession.class, "Session")
            .getAttribute(AuthSubject.class, ErraiService.SESSION_AUTH_DATA);

        Message reply = MessageBuilder.createConversation(message).getMessage();
View Full Code Here

    public void execute(final BootstrapContext context) {
        final ServerMessageBus bus = context.getBus();
        final boolean authenticationConfigured =
                context.getConfig().getResource(AuthenticationAdapter.class) != null;

        bus.subscribe(ErraiService.AUTHORIZATION_SVC_SUBJECT, new MessageCallback() {
            public void callback(Message message) {
                switch (SecurityCommands.valueOf(message.getCommandType())) {
                    case AuthenticationScheme:
                        if (authenticationConfigured) {

                            /**
                             * Respond with what credentials the authentication system requires.
                             */
                            //todo: we only support login/password for now

                            createConversation(message)
                                    .subjectProvided()
                                    .command(SecurityCommands.AuthenticationScheme)
                                    .with(SecurityParts.CredentialsRequired, "Name,Password")
                                    .with(MessageParts.ReplyTo, ErraiService.AUTHORIZATION_SVC_SUBJECT)
                                    .noErrorHandling().sendNowWith(bus);
                        } else {
                            createConversation(message)
                                    .subjectProvided()
                                    .command(SecurityCommands.AuthenticationNotRequired)
                                    .noErrorHandling().sendNowWith(bus);
                        }

                        break;

                    case AuthRequest:
                        /**
                         * Receive a challenge.
                         */

                        if (authenticationConfigured) {
                            try {
                                context.getConfig().getResource(AuthenticationAdapter.class)
                                        .challenge(message);
                            }
                            catch (AuthenticationFailedException a) {
                            }
                        }
                        break;

                    case EndSession:
                        if (authenticationConfigured) {
                            context.getConfig().getResource(AuthenticationAdapter.class)
                                    .endSession(message);
                        }

                        // reply in any case
                        createConversation(message)
                                .toSubject("LoginClient")
                                .command(SecurityCommands.EndSession)
                                .noErrorHandling()
                                .sendNowWith(bus);

                        break;
                }
            }
        });

        /**
         * The standard ServerEchoService.
         */
        bus.subscribe(ErraiService.SERVER_ECHO_SERVICE, new MessageCallback() {
            public void callback(Message c) {
                MessageBuilder.createConversation(c)
                        .subjectProvided().noErrorHandling()
                        .sendNowWith(bus);
            }
        });

        bus.subscribe(ErraiService.AUTHORIZATION_SERVICE, new MessageCallback() {
            public void callback(Message message) {
                AuthSubject subject = message.getResource(QueueSession.class, "Session")
                        .getAttribute(AuthSubject.class, ErraiService.SESSION_AUTH_DATA);

                Message reply = MessageBuilder.createConversation(message).getMessage();
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.