当前位置: 首页>>代码示例>>Java>>正文


Java Component.setImplementation方法代码示例

本文整理汇总了Java中org.apache.felix.dm.Component.setImplementation方法的典型用法代码示例。如果您正苦于以下问题:Java Component.setImplementation方法的具体用法?Java Component.setImplementation怎么用?Java Component.setImplementation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.felix.dm.Component的用法示例。


在下文中一共展示了Component.setImplementation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: containerCreate

import org.apache.felix.dm.Component; //导入方法依赖的package包/类
/**
 * Method of IContainerAware called when a new container is available
 *
 * @param containerName Container being created
 */
@Override
public void containerCreate(String containerName) {
    try {
        Object[] imps = getImplementations();
        logger.trace("Creating instance {}", containerName);
        if (imps != null) {
            for (int i = 0; i < imps.length; i++) {
                ImmutablePair<String, Object> key = new ImmutablePair<String, Object>(
                        containerName, imps[i]);
                Component c = this.dbInstances.get(key);
                if (c == null) {
                    c = this.dm.createComponent();
                    c.addStateListener(new ListenerComponentStates());
                    // Now let the derived class to configure the
                    // dependencies it wants
                    configureInstance(c, imps[i], containerName);
                    // Set the implementation so the component can manage
                    // its lifecycle
                    if (c.getService() == null) {
                        logger.trace("Setting implementation to: {}",
                                      imps[i]);
                        c.setImplementation(imps[i]);
                    }

                    //Set the service properties to include the containerName
                    //in the service, that is fundamental for supporting
                    //multiple services just distinguished via a container
                    Dictionary<String, String> serviceProps = c
                            .getServiceProperties();
                    if (serviceProps != null) {
                        logger.trace("Adding new property for container");
                        serviceProps.put("containerName", containerName);
                    } else {
                        logger
                                .trace("Create a new properties for the service");
                        serviceProps = new Hashtable<String, String>();
                        serviceProps.put("containerName", containerName);
                    }
                    c.setServiceProperties(serviceProps);

                    // Now add the component to the dependency Manager
                    // which will immediately start tracking the dependencies
                    this.dm.add(c);

                    //Now lets keep track in our shadow database of the
                    //association
                    this.dbInstances.put(key, c);
                } else {
                    logger
                            .error("I have been asked again to create an instance "
                                    + "on: "
                                    + containerName
                                    + "for object: "
                                    + imps[i]
                                    + "when i already have it!!");
                }
            }
        }
    } catch (Exception ex) {
        logger
                .error("During containerDestroy invocation caught exception: "
                        + ex
                        + "\nStacktrace:"
                        + stackToString(ex.getStackTrace()));
    }
}
 
开发者ID:lbchen,项目名称:ODL,代码行数:72,代码来源:ComponentActivatorAbstractBase.java

示例2: start

import org.apache.felix.dm.Component; //导入方法依赖的package包/类
/**
 * Method called by the OSGi framework when the OSGi bundle
 * starts. The functionality we want to perform here are:
 *
 * 1) Register with the OSGi framework, that we are a provider of
 * IContainerAware service and so in case of startup of a container we
 * want to be called
 *
 * 2) Create data structures that allow to keep track of all the
 * instances created per-container given the derived class of
 * ComponentActivatorAbstractBase will act as a Factory manager
 *
 * @param context OSGi bundle context to interact with OSGi framework
 */
@Override
public void start(BundleContext context) {
    try {
        this.dm = new DependencyManager(context);

        logger.trace("Activating");

        // Now create Global components
        Object[] imps = getGlobalImplementations();
        if (imps != null) {
            for (int i = 0; i < imps.length; i++) {
                Object key = imps[i];
                Component c = this.dbGlobalInstances.get(key);
                if (c == null) {
                    try {
                        c = this.dm.createComponent();
                        c.addStateListener(new ListenerComponentStates());
                        // Now let the derived class to configure the
                        // dependencies it wants
                        configureGlobalInstance(c, imps[i]);
                        // Set the implementation so the component
                        // can manage its lifesycle
                        if (c.getService() == null) {
                            logger.trace("Setting implementation to: {}",
                                    imps[i]);
                            c.setImplementation(imps[i]);
                        }

                        // Now add the component to the dependency
                        // Manager which will immediately start
                        // tracking the dependencies
                        this.dm.add(c);
                    } catch (Exception nex) {
                        logger.error("During creation of a Global "
                                + "instance caught exception: " + nex
                                + "\nStacktrace:"
                                + stackToString(nex.getStackTrace()));
                    }

                    //Now lets keep track in our shadow database of the
                    //association
                    if (c != null)
                        this.dbGlobalInstances.put(key, c);
                } else {
                    logger.error("I have been asked again to create an "
                            + "instance " + " Global for object: "
                            + imps[i] + "when i already have it!!");
                }
            }
        }

        // Register with OSGi the provider for the service IContainerAware
        context.registerService(
                IContainerAware.class.getName(), this, null);

        // Now call the derived class init function
        this.init();

        logger.trace("Activation DONE!");
    } catch (Exception ex) {
        logger.error("During Activator start caught exception: " + ex
                + "\nStacktrace:" + stackToString(ex.getStackTrace()));
    }
}
 
开发者ID:lbchen,项目名称:ODL,代码行数:79,代码来源:ComponentActivatorAbstractBase.java


注:本文中的org.apache.felix.dm.Component.setImplementation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。