Package org.glassfish.hk2.api

Examples of org.glassfish.hk2.api.DynamicConfiguration


            Globals.setDefaultHabitat(habitat);
           
            ServiceLocator locator = habitat;
           
            DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
            DynamicConfiguration config = dcs.createDynamicConfiguration();
           
            /*
             * Remove any already-loaded startup context so we can replace it
             * with the ACC one.
             */
            config.addUnbindFilter(BuilderHelper.createContractFilter(StartupContext.class.getName()));
           
            /*
             * Following the example from AppServerStartup, remove any
             * pre-loaded lazy inhabitant for ProcessEnvironment that exists
             * from HK2's scan for services.  Then add in
             * an ACC ProcessEnvironment.
             */
            config.addUnbindFilter(BuilderHelper.createContractFilter(ProcessEnvironment.class.getName()));
           
            config.commit();
           
            config = dcs.createDynamicConfiguration();
           
            StartupContext startupContext = new ACCStartupContext();
            AbstractActiveDescriptor<?> startupContextDescriptor = BuilderHelper.createConstantDescriptor(startupContext);
            startupContextDescriptor.addContractType(StartupContext.class);
            config.addActiveDescriptor(startupContextDescriptor);
           
            ModulesRegistry modulesRegistry = new StaticModulesRegistry(ACCModulesManager.class.getClassLoader());
            config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(modulesRegistry));
           
            config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(
                    new ProcessEnvironment(ProcessEnvironment.ProcessType.ACC)));

            /*
             * Create the ClientNamingConfigurator used by naming.
             */
            ClientNamingConfigurator cnc = new ClientNamingConfiguratorImpl();
            config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(cnc));
           
            Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
            AbstractActiveDescriptor<Logger> di = BuilderHelper.createConstantDescriptor(logger);
            di.addContractType(Logger.class);
            config.addActiveDescriptor(di);
           
            config.commit();
       }
    }
View Full Code Here


        }
    }

    private static void atomicReplace(ServiceLocator locator, ProgramOptions options) {
        DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
        DynamicConfiguration config = dcs.createDynamicConfiguration();

        config.addUnbindFilter(BuilderHelper.createContractFilter(ProgramOptions.class.getName()));
        ActiveDescriptor<ProgramOptions> desc = BuilderHelper.createConstantDescriptor(
                options, null, ProgramOptions.class);
        config.addActiveDescriptor(desc);

        config.commit();
    }
View Full Code Here

    /**
     * Mallory cannot advertise the EvilService
     */
    public void tryToAdvertiseAService() {
        DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
        DynamicConfiguration config = dcs.createDynamicConfiguration();
       
        config.addActiveDescriptor(EvilService.class);
       
        config.commit()// This will throw a MultiException
    }
View Full Code Here

            }
           
        };
       
        DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
        DynamicConfiguration config = dcs.createDynamicConfiguration();
       
        config.addUnbindFilter(unbindFilter);
       
        config.commit()// This will throw a MultiException
    }
View Full Code Here

        return main.endsWith(".java");
    }

    private static void bind(ServiceLocator locator, Binder binder) {
        DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
        DynamicConfiguration dc = dcs.createDynamicConfiguration();

        locator.inject(binder);
        binder.bind(dc);

        dc.commit();
    }
View Full Code Here

        return main.endsWith(".java");
    }

    private static void bind(ServiceLocator locator, Binder binder) {
        DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
        DynamicConfiguration dc = dcs.createDynamicConfiguration();

        locator.inject(binder);
        binder.bind(dc);

        dc.commit();
    }
View Full Code Here

            logger.log(level, "Startup class : {0}", getClass().getName());
        }

        // prepare the global variables
        DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
        DynamicConfiguration config = dcs.createDynamicConfiguration();

        config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(this));
        config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(masterListener));
        config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(logger));

        config.addUnbindFilter(BuilderHelper.createContractFilter(ProcessEnvironment.class.getName()));

        config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(
                env.isEmbedded() ?
                new ProcessEnvironment(ProcessEnvironment.ProcessType.Embedded):
                new ProcessEnvironment(ProcessEnvironment.ProcessType.Server)));
        config.commit();

        // activate the run level services
        if (proceedTo(InitRunLevel.VAL, new InitActivator())) {
            if (proceedTo(StartupRunLevel.VAL, new StartupActivator())) {
                proceedTo(PostStartupRunLevel.VAL, new PostStartupActivator());
View Full Code Here

    public static void enablePerThreadScope(ServiceLocator locator) {
        Context<PerThread> perThreadContext = locator.getService((new TypeLiteral<Context<PerThread>>() {}).getType());
        if (perThreadContext != null) return;

        DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
        DynamicConfiguration config = dcs.createDynamicConfiguration();
        final DescriptorImpl descriptor = BuilderHelper.link(PerThreadContext.class).
                to(Context.class).
                in(Singleton.class.getName()).
                build();

        ClassLoader loader = ServiceLocatorUtilities.class.getClassLoader();
        final ClassLoader binderClassLoader = loader == null ? ClassLoader.getSystemClassLoader() : loader;
        descriptor.setLoader(new HK2Loader() {
            @Override
            public Class<?> loadClass(String className) throws MultiException {
                try {
                    return binderClassLoader.loadClass(className);
                } catch (ClassNotFoundException e) {
                    throw new MultiException(e);
                }

            }
        });

        config.bind(descriptor, false);
        config.commit();
    }
View Full Code Here

     * @param binders The non-null list of binders to be added to the locator
     * @throws MultiException if any error was encountered while binding services
     */
    public static void bind(ServiceLocator locator, Binder... binders) {
        DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
        DynamicConfiguration config = dcs.createDynamicConfiguration();

        for (Binder binder : binders) {
            binder.bind(config);
        }

        config.commit();
    }
View Full Code Here

     */
    @SuppressWarnings("unchecked")
    public static <T> ActiveDescriptor<T> addOneDescriptor(ServiceLocator locator, Descriptor descriptor,
            boolean requiresDeepCopy) {
        DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
        DynamicConfiguration config = dcs.createDynamicConfiguration();

        ActiveDescriptor<T> retVal;
        if (descriptor instanceof ActiveDescriptor) {
            ActiveDescriptor<T> active = (ActiveDescriptor<T>) descriptor;

            if (active.isReified()) {
                retVal = config.addActiveDescriptor(active, requiresDeepCopy);
            }
            else {
                retVal = config.bind(descriptor, requiresDeepCopy);
            }

        }
        else {
            retVal = config.bind(descriptor, requiresDeepCopy);
        }

        config.commit();

        return retVal;
    }
View Full Code Here

TOP

Related Classes of org.glassfish.hk2.api.DynamicConfiguration

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.