Package com.sun.hk2.component

Examples of com.sun.hk2.component.ExistingSingletonInhabitant


                addMetadata(buf, INDEX_KEY, contract);

            findInhabitantMetadata(d, buf);

            // for seed, capture the metadata for the actual companion object
            CompanionSeed seed = d.getAnnotation(CompanionSeed.class);
            if(seed!=null) {
                try {
                    seed.companion();
                } catch (MirroredTypeException e) {
                    ClassDeclaration companion = ((ClassType) e.getTypeMirror()).getDeclaration();
                    addMetadata(buf, COMPANION_CLASS_METADATA_KEY,
                        quote(getInhabitantDeclaration(find(companion, CompanionOf.class),companion)));
                }
View Full Code Here


      private final CopyOnWriteArrayList<HabitatListener> listeners =
          new CopyOnWriteArrayList<HabitatListener>();
      private volatile boolean released;

      protected ListenersByTypeInhabitant(String name) {
        super(new ExistingSingletonInhabitant(ListenersByTypeInhabitant.class, null));
        this.name = name;
      }
View Full Code Here

    }

    @SuppressWarnings("unchecked")
    public void initialize(T t, Inhabitant onBehalfOf) throws ComponentException {
        super.initialize(t, onBehalfOf);
        builder.onEntered(new ExistingSingletonInhabitant(t));
    }
View Full Code Here

        // create a habitat and initialize them
        Habitat habitat = registry.newHabitat();
        habitat.add(new ExistingSingletonInhabitant<StartupContext>(context));
        habitat.add(new ExistingSingletonInhabitant<Logger>(Logger.global));
        // the root registry must be added as other components sometimes inject it
        habitat.add(new ExistingSingletonInhabitant(ModulesRegistry.class, registry));
        final ClassLoader oldCL = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
            @Override
            public ClassLoader run() {
                ClassLoader cl = Thread.currentThread().getContextClassLoader();
                Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
View Full Code Here

        // Bootstrap a hk2 environment.
        ModulesRegistry registry = new StaticModulesRegistry(getClass().getClassLoader());
        habitat = registry.createHabitat("default");

        StartupContext startupContext = new StartupContext();
        habitat.add(new ExistingSingletonInhabitant(startupContext));

        habitat.addComponent(null, new ProcessEnvironment(ProcessEnvironment.ProcessType.Other));
    }
View Full Code Here

                    if (name == null) {
                        // let's get a name if possible, that will only work with Spring OSGi services
                        // we may need to find a better way to get a potential name.
                        name = (String) reference.getProperty("org.springframework.osgi.bean.name");
                    }
                    habitat.addIndex(new ExistingSingletonInhabitant(object), contractName, name);
                    if (logger.isLoggable(Level.FINE)) {
                        String objectDetails = object.toString();
                        logger.logp(Level.FINE, "HK2Main$HK2ServiceTrackerCustomizer",
                            "addingService", "registering service = {0}, contract = {1}, name = {2}", new Object[]{
                                    objectDetails, contractName, name});
                    }
                }
            } else {
                // this service does not implement a specific contract, let's register it by its type.
                habitat.add(new ExistingSingletonInhabitant(object));
                if (logger.isLoggable(Level.FINE)) {
                    String objectDetails = object.toString();
                    logger.logp(Level.FINE, "HK2Main$HK2ServiceTrackerCustomizer",
                        "addingService", "registering service = {0}", objectDetails);
                }
View Full Code Here

                    if (name == null) {
                        // let's get a name if possible, that will only work with Spring OSGi services
                        // we may need to find a better way to get a potential name.
                        name = (String) reference.getProperty("org.springframework.osgi.bean.name");
                    }
                    habitat.addIndex(new ExistingSingletonInhabitant(object), contractName, name);
                    if (logger.isLoggable(Level.FINE)) {
                        String objectDetails = object.getClass().getName()+"@"+
                            Integer.toHexString(
                                System.identityHashCode(object));
                        logger.logp(Level.FINE, "HK2Main$HK2ServiceTrackerCustomizer",
                            "addingService", "registering service = {0}, contract = {1}, name = {2}", new Object[]{
                                    objectDetails, contractName, name});
                    }
                }
            } else {
                // this service does not implement a specific contract, let's register it by its type.
                habitat.add(new ExistingSingletonInhabitant(object));
                if (logger.isLoggable(Level.FINE)) {
                    String objectDetails = object.getClass().getName()+"@"+
                        Integer.toHexString(System.identityHashCode(object));
                    logger.logp(Level.FINE, "HK2Main$HK2ServiceTrackerCustomizer",
                        "addingService", "registering service = {0}", objectDetails);
View Full Code Here

             * with the ACC one.
             */
            habitat.removeAllByType(StartupContext.class);
           
            StartupContext startupContext = new ACCStartupContext();
            habitat.add(new ExistingSingletonInhabitant(StartupContext.class, startupContext));
            /*
             * 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.
View Full Code Here

    }

    static private Habitat getHabitat() {
        Habitat habitat = Globals.getStaticHabitat();
        StartupContext startupContext = new StartupContext();
        habitat.add(new ExistingSingletonInhabitant(startupContext));

        habitat.addComponent(null, new ProcessEnvironment(ProcessEnvironment.ProcessType.Other));
        return habitat;
    }
View Full Code Here

        // for each FactoryFor component, insert inhabitant for components created by the factory
        if (index.equals(FactoryFor.class.getName())) {
            FactoryFor ff = i.type().getAnnotation(FactoryFor.class);
            Class<?> targetClass = ff.value();
            FactoryCreator target = new FactoryCreator(targetClass, i, habitat, MultiMap.<String,String>emptyMap());
            habitat.add(target);
            habitat.addIndex(target, targetClass.getName(), null);
        }
       
//        System.out.println("Habitat Index Changed: " + eventType + "; " + i + "; index=" + index + "; name=" + name);
View Full Code Here

TOP

Related Classes of com.sun.hk2.component.ExistingSingletonInhabitant

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.