本文整理汇总了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()));
}
}
示例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()));
}
}