Examples of ErraiServiceConfiguratorImpl


Examples of org.jboss.errai.bus.server.service.ErraiServiceConfiguratorImpl

   *
   * @param queueSize The size of the underlying worker queue.
   */
  public PooledExecutorService(int queueSize) {
    this(queueSize, SaturationPolicy.valueOf(
            ErraiConfigAttribs.SATURATION_POLICY.get(new ErraiServiceConfiguratorImpl())));
  }
View Full Code Here

Examples of org.jboss.errai.bus.server.service.ErraiServiceConfiguratorImpl

class DefaultComponents implements BootstrapExecution {
  private Logger log = LoggerFactory.getLogger(DefaultComponents.class);

  public void execute(final BootstrapContext context) {

    final ErraiServiceConfiguratorImpl config = (ErraiServiceConfiguratorImpl) context.getConfig();

   // MessageBuilder.setMessageProvider(JSONMessageServer.PROVIDER);

    /*** Authentication Adapter ***/

    if (config.hasProperty("errai.authentication_adapter")) {
      try {
        final Class<? extends AuthenticationAdapter> authAdapterClass = Class.forName(config.getProperty("errai.authentication_adapter"))
            .asSubclass(AuthenticationAdapter.class);

        log.info("authentication adapter configured: " + authAdapterClass.getName());

        final Runnable create = new Runnable() {
          public void run() {
            final AuthenticationAdapter authAdapterInst = Guice.createInjector(new AbstractModule() {
              @Override
              protected void configure() {
                bind(AuthenticationAdapter.class).to(authAdapterClass);
                bind(ErraiServiceConfigurator.class).toInstance(context.getConfig());
                bind(MessageBus.class).toInstance(context.getBus());
                bind(ServerMessageBus.class).toInstance(context.getBus());
              }
            }).getInstance(AuthenticationAdapter.class);

            config.getExtensionBindings().put(AuthenticationAdapter.class, new ResourceProvider() {
              public Object get() {
                return authAdapterInst;
              }
            });
          }
        };

        try {
          create.run();
        }
        catch (Throwable e) {
          log.info("authentication adapter " + authAdapterClass.getName() + " cannot be bound yet, deferring ...");
          context.defer(create);
        }

      }
      catch (ErraiBootstrapFailure e) {
        throw e;
      }
      catch (Exception e) {
        throw new ErraiBootstrapFailure("cannot configure authentication adapter", e);
      }
    }


    /*** Dispatcher ***/

    RequestDispatcher dispatcher = createInjector(new AbstractModule() {

      @Override
      protected void configure() {
        Class<? extends RequestDispatcher> dispatcherImplementation = SimpleDispatcher.class;

        if (config.hasProperty(ErraiServiceConfigurator.ERRAI_DISPATCHER_IMPLEMENTATION)) {
          try {
            dispatcherImplementation = Class.forName(config.getProperty(ErraiServiceConfigurator.ERRAI_DISPATCHER_IMPLEMENTATION))
                .asSubclass(RequestDispatcher.class);
          }
          catch (Exception e) {
            throw new ErraiBootstrapFailure("could not load request dispatcher implementation class", e);
          }
        }

        log.info("using dispatcher implementation: " + dispatcherImplementation.getName());

        bind(RequestDispatcher.class).to(dispatcherImplementation);
        bind(ErraiService.class).toInstance(context.getService());
        bind(MessageBus.class).toInstance(context.getBus());
        bind(ErraiServiceConfigurator.class).toInstance(config);
      }
    }).getInstance(RequestDispatcher.class);

    context.getService().setDispatcher(dispatcher);

    /*** Session Provider ***/

    SessionProvider sessionProvider = createInjector(new AbstractModule() {
      @Override
      protected void configure() {
        Class<? extends SessionProvider> sessionProviderImplementation = HttpSessionProvider.class;

        if (config.hasProperty(ErraiServiceConfigurator.ERRAI_SESSION_PROVIDER_IMPLEMENTATION)) {
          try {
            sessionProviderImplementation = Class.forName(config.getProperty(ErraiServiceConfigurator.ERRAI_SESSION_PROVIDER_IMPLEMENTATION))
                .asSubclass(SessionProvider.class);
          }
          catch (Exception e) {
            throw new ErraiBootstrapFailure("could not load session provider implementation class", e);
          }
View Full Code Here

Examples of org.jboss.errai.bus.server.service.ErraiServiceConfiguratorImpl

class DiscoverServices implements BootstrapExecution {
  private Logger log = LoggerFactory.getLogger(DiscoverServices.class);

  @Override
  public void execute(final BootstrapContext context) {
    final ErraiServiceConfiguratorImpl config = (ErraiServiceConfiguratorImpl) context.getConfig();

    if (isAutoScanEnabled(config)) {
      log.debug("begin meta data scanning ...");

      // meta data scanner
View Full Code Here

Examples of org.jboss.errai.bus.server.service.ErraiServiceConfiguratorImpl

* @date: May 3, 2010
* @see org.jboss.errai.common.client.api.ResourceProvider
*/
class DefaultResources implements BootstrapExecution {
  public void execute(BootstrapContext context) {
    final ErraiServiceConfiguratorImpl config = (ErraiServiceConfiguratorImpl) context
        .getConfig();

    config.getResourceProviders().put(MessageBus.class.getName(),
        new BusProvider(context.getBus()));
    config.getResourceProviders().put(RequestDispatcher.class.getName(),
        new DispatcherProvider(context.getService().getDispatcher()));

    // configure the server-side taskmanager

    final TaskManager taskManager = resolveTaskManager(config);
View Full Code Here

Examples of org.jboss.errai.bus.server.service.ErraiServiceConfiguratorImpl

*/
public class LoadExtensions implements BootstrapExecution {
  private Logger log = LoggerFactory.getLogger(LoadExtensions.class);

  public void execute(final BootstrapContext context) {
    final ErraiServiceConfiguratorImpl config = (ErraiServiceConfiguratorImpl) context.getConfig();

    boolean autoScanModules = true;

    final Set<String> loadedComponents = new HashSet<String>();

    /*** Extensions  ***/
    if (config.hasProperty("errai.auto_load_extensions")) {
      autoScanModules = Boolean.parseBoolean(config.getProperty("errai.auto_load_extensions"));
    }
    if (autoScanModules) {

      log.info("searching for errai extensions ...");

      final ErraiConfig erraiConfig = new ErraiConfig() {
        public void addBinding(Class<?> type, ResourceProvider provider) {
          config.getExtensionBindings().put(type, provider);
        }

        public void addResourceProvider(String name, ResourceProvider provider) {
          config.getResourceProviders().put(name, provider);
        }

        public void addSerializableType(Class<?> type) {
          log.debug("marked " + type + " as serializable.");
          loadedComponents.add(type.getName());
          config.getSerializableTypes().add(type);
        }
      };

      // Search for Errai extensions.
      MetaDataScanner scanner = context.getScanner();

      Set<Class<?>> extensionComponents = scanner.getTypesAnnotatedWith(ExtensionComponent.class);
      for (Class<?> loadClass : extensionComponents) {
        if (ErraiConfigExtension.class.isAssignableFrom(loadClass)) {
          // We have an annotated ErraiConfigExtension.  So let's configure it.
          final Class<? extends ErraiConfigExtension> clazz =
              loadClass.asSubclass(ErraiConfigExtension.class);


          log.info("found extension " + clazz.getName());

          try {

            final Runnable create = new Runnable() {
              public void run() {
                AbstractModule module = new AbstractModule() {
                  @Override
                  protected void configure() {
                    bind(ErraiConfigExtension.class).to(clazz);
                    bind(ErraiServiceConfigurator.class).toInstance(config);
                    bind(MessageBus.class).toInstance(context.getBus());

                    // Add any extension bindings.
                    for (Map.Entry<Class<?>, ResourceProvider> entry : config.getExtensionBindings().entrySet()) {
                      bind(entry.getKey()).toProvider(new GuiceProviderProxy(entry.getValue()));
                    }
                  }
                };
                Guice.createInjector(module)
View Full Code Here

Examples of org.jboss.errai.bus.server.service.ErraiServiceConfiguratorImpl

* @author: Heiko Braun <hbraun@redhat.com>
* @date: May 3, 2010
*/
class RegisterEntities implements BootstrapExecution {
  public void execute(BootstrapContext context) {
    final ErraiServiceConfiguratorImpl config = (ErraiServiceConfiguratorImpl) context.getConfig();
  }
View Full Code Here

Examples of org.jboss.errai.bus.server.service.ErraiServiceConfiguratorImpl

        return ErraiServiceSingleton.getService();
      }

      final ServletContext context = config.getServletContext();

      final ErraiServiceConfigurator configurator = new ErraiServiceConfiguratorImpl();

      final String autoDiscoverServices
              = ServletInitAttribs.AUTO_DISCOVER_SERVICES.getInitOrContextValue(config, "false");

      if (autoDiscoverServices != null) {
View Full Code Here

Examples of org.jboss.errai.bus.server.service.ErraiServiceConfiguratorImpl

* @date: May 3, 2010
* @see org.jboss.errai.bus.server.io.JSONEncoder
*/
class RegisterTypes implements BootstrapExecution {
    public void execute(BootstrapContext context) {
        final ErraiServiceConfiguratorImpl config = (ErraiServiceConfiguratorImpl) context.getConfig();
        JSONEncoder.setSerializableTypes(config.getSerializableTypes());
    }
View Full Code Here

Examples of org.jboss.errai.bus.server.service.ErraiServiceConfiguratorImpl

class DefaultComponents implements BootstrapExecution {
    private Logger log = LoggerFactory.getLogger(DefaultComponents.class);

    public void execute(final BootstrapContext context) {

        final ErraiServiceConfiguratorImpl config = (ErraiServiceConfiguratorImpl) context.getConfig();
        final NoopModelAdapter adapter = new NoopModelAdapter();

        final ResourceProvider<ModelAdapter> modelAdapterProvider = new ResourceProvider<ModelAdapter>() {
            public ModelAdapter get() {
                return adapter;
            }
        };

        /*** ModelAdapter ***/
        config.getExtensionBindings().put(ModelAdapter.class, modelAdapterProvider);

        MessageBuilder.setMessageProvider(JSONMessageServer.PROVIDER);

        /*** Authentication Adapter ***/

        if (config.hasProperty("errai.authentication_adapter")) {
            try {
                final Class<? extends AuthenticationAdapter> authAdapterClass = Class.forName(config.getProperty("errai.authentication_adapter"))
                        .asSubclass(AuthenticationAdapter.class);

                log.info("authentication adapter configured: " + authAdapterClass.getName());

                final Runnable create = new Runnable() {
                    public void run() {
                        final AuthenticationAdapter authAdapterInst = Guice.createInjector(new AbstractModule() {
                            @Override
                            protected void configure() {
                                bind(AuthenticationAdapter.class).to(authAdapterClass);
                                bind(ErraiServiceConfigurator.class).toInstance(context.getConfig());
                                bind(MessageBus.class).toInstance(context.getBus());
                                bind(ServerMessageBus.class).toInstance(context.getBus());
                            }
                        }).getInstance(AuthenticationAdapter.class);

                        config.getExtensionBindings().put(AuthenticationAdapter.class, new ResourceProvider() {
                            public Object get() {
                                return authAdapterInst;
                            }
                        });
                    }
                };

                try {
                    create.run();
                }
                catch (Throwable e) {
                    log.info("authentication adapter " + authAdapterClass.getName() + " cannot be bound yet, deferring ...");
                    context.defer(create);
                }

            }
            catch (ErraiBootstrapFailure e) {
                throw e;
            }
            catch (Exception e) {
                throw new ErraiBootstrapFailure("cannot configure authentication adapter", e);
            }
        }


        /*** Dispatcher ***/

        RequestDispatcher dispatcher = createInjector(new AbstractModule() {
            @Override
            protected void configure() {
                Class<? extends RequestDispatcher> dispatcherImplementation = SimpleDispatcher.class;

                if (config.hasProperty(ErraiServiceConfigurator.ERRAI_DISPATCHER_IMPLEMENTATION)) {
                    try {
                        dispatcherImplementation = Class.forName(config.getProperty(ErraiServiceConfigurator.ERRAI_DISPATCHER_IMPLEMENTATION))
                                .asSubclass(RequestDispatcher.class);
                    }
                    catch (Exception e) {
                        throw new ErraiBootstrapFailure("could not load request dispatcher implementation class", e);
                    }
                }

                log.info("using dispatcher implementation: " + dispatcherImplementation.getName());

                bind(RequestDispatcher.class).to(dispatcherImplementation);
                bind(ErraiService.class).toInstance(context.getService());
                bind(MessageBus.class).toInstance(context.getBus());
                bind(ErraiServiceConfigurator.class).toInstance(config);
            }
        }).getInstance(RequestDispatcher.class);

        context.getService().setDispatcher(dispatcher);

        /*** Session Provider ***/

        SessionProvider sessionProvider = createInjector(new AbstractModule() {
            @Override
            protected void configure() {
                Class<? extends SessionProvider> sessionProviderImplementation = HttpSessionProvider.class;

                if (config.hasProperty(ErraiServiceConfigurator.ERRAI_SESSION_PROVIDER_IMPLEMENTATION)) {
                    try {
                        sessionProviderImplementation = Class.forName(config.getProperty(ErraiServiceConfigurator.ERRAI_SESSION_PROVIDER_IMPLEMENTATION))
                                .asSubclass(SessionProvider.class);
                    }
                    catch (Exception e) {
                        throw new ErraiBootstrapFailure("could not load session provider implementation class", e);
                    }
View Full Code Here

Examples of org.jboss.errai.bus.server.service.ErraiServiceConfiguratorImpl

*/
public class ServiceProcessor implements MetaDataProcessor {
    private Logger log = LoggerFactory.getLogger(ServiceProcessor.class);

    public void process(final BootstrapContext context, MetaDataScanner reflections) {
        final ErraiServiceConfiguratorImpl config = (ErraiServiceConfiguratorImpl) context.getConfig();
        final Set<Class<?>> services = reflections.getTypesAnnotatedWithExcluding(Service.class, MetaDataScanner.CLIENT_PKG_REGEX);

        for (Class<?> loadClass : services) {
            Object svc = null;
            String svcName = loadClass.getAnnotation(Service.class).value();
            // If no name is specified, just use the class name as the service
            // by default.
            if ("".equals(svcName)) {
                svcName = loadClass.getSimpleName();
            }

            Map<String, Method> commandPoints = new HashMap<String, Method>();
            for (final Method method : loadClass.getDeclaredMethods()) {
                if (method.isAnnotationPresent(Command.class)) {
                    Command command = method.getAnnotation(Command.class);
                    for (String cmdName : command.value()) {
                        if (cmdName.equals("")) cmdName = method.getName();
                        commandPoints.put(cmdName, method);
                    }
                }
            }

            Class remoteImpl = getRemoteImplementation(loadClass);
            if (remoteImpl != null) {
                createRPCScaffolding(remoteImpl, loadClass, context);
            } else if (MessageCallback.class.isAssignableFrom(loadClass)) {
                final Class<? extends MessageCallback> clazz = loadClass.asSubclass(MessageCallback.class);

                //loadedComponents.add(loadClass.getName());


                log.info("discovered service: " + clazz.getName());
                try {
                    svc = Guice.createInjector(new AbstractModule() {
                        @Override
                        protected void configure() {
                            bind(MessageCallback.class).to(clazz);
                            bind(MessageBus.class).toInstance(context.getBus());
                            bind(RequestDispatcher.class).toInstance(context.getService().getDispatcher());

                            // Add any extension bindings.
                            for (Map.Entry<Class<?>, ResourceProvider> entry : config.getExtensionBindings().entrySet()) {
                                bind(entry.getKey()).toProvider(new GuiceProviderProxy(entry.getValue()));
                            }
                        }
                    }).getInstance(MessageCallback.class);
                }
                catch (Throwable t) {
                    t.printStackTrace();
                }


                if (commandPoints.isEmpty()) {
                    // Subscribe the service to the bus.
                    context.getBus().subscribe(svcName, (MessageCallback) svc);
                }

                RolesRequiredRule rule = null;
                if (clazz.isAnnotationPresent(RequireRoles.class)) {
                    rule = new RolesRequiredRule(clazz.getAnnotation(RequireRoles.class).value(), context.getBus());
                } else if (clazz.isAnnotationPresent(RequireAuthentication.class)) {
                    rule = new RolesRequiredRule(new HashSet<Object>(), context.getBus());
                }
                if (rule != null) {
                    context.getBus().addRule(svcName, rule);
                }
            }

            if (svc == null) {
                svc = Guice.createInjector(new AbstractModule() {
                    @Override
                    protected void configure() {
                        bind(MessageBus.class).toInstance(context.getBus());
                        bind(RequestDispatcher.class).toInstance(context.getService().getDispatcher());

                        // Add any extension bindings.
                        for (Map.Entry<Class<?>, ResourceProvider> entry : config.getExtensionBindings().entrySet()) {
                            bind(entry.getKey()).toProvider(new GuiceProviderProxy(entry.getValue()));
                        }
                    }
                }).getInstance(loadClass);
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.