本文整理汇总了Java中org.osgi.framework.BundleActivator类的典型用法代码示例。如果您正苦于以下问题:Java BundleActivator类的具体用法?Java BundleActivator怎么用?Java BundleActivator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BundleActivator类属于org.osgi.framework包,在下文中一共展示了BundleActivator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadActivators
import org.osgi.framework.BundleActivator; //导入依赖的package包/类
private Set<BundleActivator> loadActivators() {
String serviceFile =
_SERVICES + "/" + BundleActivator.class.getCanonicalName();
Set<BundleActivator> activators = new LinkedHashSet<>();
ClassLoader classLoader = getClass().getClassLoader();
try {
Enumeration<URL> enumeration = classLoader.getResources(
serviceFile);
while (enumeration.hasMoreElements()) {
addBundleActivatorToActivatorsListFromURL(
activators, enumeration.nextElement());
}
}
catch (Exception e) {
throw new RuntimeException("Could not load bundle activators", e);
}
return activators;
}
示例2: bundleB
import org.osgi.framework.BundleActivator; //导入依赖的package包/类
@Deployment(name = BUNDLE_B, testable = false, managed = false)
public static Archive<?> bundleB() {
final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, BUNDLE_B);
archive.addClasses(SimpleBundleActivator.class);
archive.setManifest(new Asset() {
@Override
public InputStream openStream() {
OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
builder.addBundleManifestVersion(2);
builder.addBundleSymbolicName(archive.getName());
builder.addBundleVersion("1.0.0");
builder.addImportPackages(BundleActivator.class);
builder.addBundleActivator(SimpleBundleActivator.class);
return builder.openStream();
}
});
return archive;
}
示例3: prepareFramework
import org.osgi.framework.BundleActivator; //导入依赖的package包/类
private void prepareFramework() {
fileInstall = new FileInstall();
propertiesDictionary = new Hashtable<String, String>();
StartupProperties startupProperties = CommunoteRuntime.getInstance()
.getConfigurationManager().getStartupProperties();
propertiesDictionary.put(DirectoryWatcher.DIR, startupProperties.getPluginDir()
.getAbsolutePath());
propertiesDictionary.put(DirectoryWatcher.NO_INITIAL_DELAY, Boolean.TRUE.toString());
propertiesDictionary.put(DirectoryWatcher.START_NEW_BUNDLES, Boolean.TRUE.toString());
propertiesDictionary.put(DirectoryWatcher.LOG_LEVEL, Integer.toString(4));
Properties frameworkProperties = loadFrameworkProperties();
List<BundleActivator> activatorList = new ArrayList<BundleActivator>();
activatorList.add(fileInstall);
frameworkProperties.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, activatorList);
// TODO better add a setSystemBundlesLocation method
String pathToWebInf = CommunoteRuntime.getInstance().getApplicationInformation()
.getApplicationRealPath()
+ "WEB-INF" + File.separator;
initSystemBundles(frameworkProperties, pathToWebInf + "plugins");
frameworkProperties.put(Constants.FRAMEWORK_STORAGE, OSGiHelper.getBundleBasePath()
.getAbsolutePath() + File.separator + "bundle-cache");
try {
framework = new Felix(frameworkProperties);
framework.init();
AutoProcessor.process(frameworkProperties, framework.getBundleContext());
framework.getBundleContext().addBundleListener(this);
} catch (BundleException e) {
throw new BeanCreationException(
"Starting OSGi framework failed because of a BundleException.", e);
}
LOG.info("OSGi Framework initialized.");
}
示例4: testStartupExtension
import org.osgi.framework.BundleActivator; //导入依赖的package包/类
@Test
public void testStartupExtension() {
Extension extension = getEarlyStartup();
IStartup startup = extension.createExecutableExtension( "class", IStartup.class );
assertThat( startup ).isInstanceOf( DynamicWorkingSetStartup.class );
assertThat( startup ).isNotInstanceOf( BundleActivator.class );
}
示例5: testStartupExtension
import org.osgi.framework.BundleActivator; //导入依赖的package包/类
@Test
public void testStartupExtension() {
Extension extension = getEarlyStartup();
IStartup startup = extension.createExecutableExtension( "class", IStartup.class );
assertThat( startup ).isInstanceOf( LaunchExtrasStartup.class );
assertThat( startup ).isNotInstanceOf( BundleActivator.class );
}
示例6: startBundle
import org.osgi.framework.BundleActivator; //导入依赖的package包/类
public synchronized void startBundle() throws BundleException {
if (this.state == 1) {
throw new IllegalStateException("Cannot start uninstalled bundle " + toString());
} else if (this.state != 32) {
if (this.state == 2) {
resolveBundle(true);
}
this.state = 8;
try {
this.context.isValid = true;
if (!(this.classloader.activatorClassName == null || StringUtils.isBlank(this.classloader.activatorClassName))) {
Class loadClass = this.classloader.loadClass(this.classloader.activatorClassName);
if (loadClass == null) {
throw new ClassNotFoundException(this.classloader.activatorClassName);
}
this.classloader.activator = (BundleActivator) loadClass.newInstance();
this.classloader.activator.start(this.context);
}
this.state = 32;
Framework.notifyBundleListeners(2, this);
if (Framework.DEBUG_BUNDLES && log.isInfoEnabled()) {
log.info("Framework: Bundle " + toString() + " started.");
}
} catch (Throwable th) {
Throwable th2 = th;
Framework.clearBundleTrace(this);
this.state = 4;
String str = "Error starting bundle " + toString();
if (th2.getCause() != null) {
th2 = th2.getCause();
}
BundleException bundleException = new BundleException(str, th2);
}
}
}
示例7: HostApplication
import org.osgi.framework.BundleActivator; //导入依赖的package包/类
public HostApplication() throws IOException {
// Create a configuration property map.
Map<String, Object> config = new HashMap<String, Object>();
// Create host activator;
m_activator = new HostActivator();
List<BundleActivator> list = new ArrayList<BundleActivator>();
list.add(m_activator);
config.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, list);
config.put(FelixConstants.FRAMEWORK_STORAGE, "target/felix");
config.put(FelixConstants.LOG_LEVEL_PROP, "5");
cleanUp("target/felix");
try
{
// Now create an instance of the framework with
// our configuration properties.
m_felix = new Felix(config);
// Now start Felix instance.
m_felix.start();
}
catch (Exception ex)
{
System.err.println("Could not create framework: " + ex);
ex.printStackTrace();
}
}
示例8: start
import org.osgi.framework.BundleActivator; //导入依赖的package包/类
@Override
public void start(final BundleContext context) throws Exception {
final TestClassLoader testClassLoader = new TestClassLoader() {
@Override
public Class<?> loadTestClass(String className)
throws ClassNotFoundException {
return context.getBundle().loadClass(className);
}
};
// Execute all activators
bundleActivators = loadActivators();
for (BundleActivator bundleActivator : bundleActivators) {
bundleActivator.start(context);
}
// Register the JMXTestRunner
MBeanServer mbeanServer = findOrCreateMBeanServer();
testRunner = new JMXTestRunner(testClassLoader) {
@Override
public byte[] runTestMethod(String className, String methodName) {
BundleAssociation.setBundle(context.getBundle());
BundleContextAssociation.setBundleContext(context);
return super.runTestMethod(className, methodName);
}
};
testRunner.registerMBean(mbeanServer);
}
示例9: stop
import org.osgi.framework.BundleActivator; //导入依赖的package包/类
@Override
public void stop(BundleContext context) throws Exception {
// Execute all activators
for (BundleActivator bundleActivator : bundleActivators) {
bundleActivator.stop(context);
}
// Unregister the JMXTestRunner
MBeanServer mbeanServer = findOrCreateMBeanServer();
testRunner.unregisterMBean(mbeanServer);
}
示例10: addBundleActivatorToActivatorsListFromStringLine
import org.osgi.framework.BundleActivator; //导入依赖的package包/类
private void addBundleActivatorToActivatorsListFromStringLine(
Set<BundleActivator> activators, String line) {
ClassLoader classLoader = getClass().getClassLoader();
if (line.startsWith("!")) {
return;
}
try {
Class<?> aClass = classLoader.loadClass(line);
Class<? extends BundleActivator> bundleActivatorClass =
aClass.asSubclass(BundleActivator.class);
activators.add(bundleActivatorClass.newInstance());
}
catch (ClassNotFoundException cnfe) {
throw new IllegalStateException(
"Activator " + line + " class not found", cnfe);
}
catch (ClassCastException cce) {
throw new IllegalStateException(
"Activator " + line + " does not implement expected type " +
BundleActivator.class.getCanonicalName(),
cce);
}
catch (Exception e) {
throw new IllegalStateException(
"Activator " + line + " can't be created ", e);
}
}
示例11: addBundleActivatorToActivatorsListFromURL
import org.osgi.framework.BundleActivator; //导入依赖的package包/类
private void addBundleActivatorToActivatorsListFromURL(
Set<BundleActivator> activators, URL url)
throws IOException {
final InputStream is = url.openStream();
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
String line = reader.readLine();
while (null != line) {
line = skipCommentAndTrim(line);
addBundleActivatorToActivatorsListFromStringLine(
activators, line);
line = reader.readLine();
}
}
finally {
if (reader != null) {
reader.close();
}
}
}
示例12: ChainActivator
import org.osgi.framework.BundleActivator; //导入依赖的package包/类
public ChainActivator() {
final LoggingActivator logStatus = new LoggingActivator();
final JavaBeansCacheActivator activateJavaBeansCache = new JavaBeansCacheActivator();
final NamespaceHandlerActivator activateCustomNamespaceHandling = new NamespaceHandlerActivator();
final NamespaceHandlerActivator activateBlueprintspecificNamespaceHandling = new BlueprintNamespaceHandlerActivator();
final ExtenderConfiguration initializeExtenderConfiguration = new ExtenderConfiguration();
final ListenerServiceActivator activateListeners = new ListenerServiceActivator(initializeExtenderConfiguration);
final ContextLoaderListener listenForSpringDmBundles = new ContextLoaderListener(initializeExtenderConfiguration);
final BlueprintLoaderListener listenForBlueprintBundles = new BlueprintLoaderListener(initializeExtenderConfiguration, activateListeners);
if (OsgiPlatformDetector.isR42()) {
if (BLUEPRINT_AVAILABLE) {
log.info("Blueprint API detected; enabling Blueprint Container functionality");
CHAIN = new BundleActivator[] {
logStatus,
activateJavaBeansCache,
activateCustomNamespaceHandling,
activateBlueprintspecificNamespaceHandling,
initializeExtenderConfiguration,
activateListeners,
listenForSpringDmBundles,
listenForBlueprintBundles
};
}
else {
log.warn("Blueprint API not found; disabling Blueprint Container functionality");
CHAIN = new BundleActivator[] {
logStatus,
activateJavaBeansCache,
activateCustomNamespaceHandling,
initializeExtenderConfiguration,
activateListeners,
listenForSpringDmBundles
};
}
} else {
log.warn("Pre-4.2 OSGi platform detected; disabling Blueprint Container functionality");
CHAIN = new BundleActivator[] {
logStatus,
activateJavaBeansCache,
activateCustomNamespaceHandling,
initializeExtenderConfiguration,
activateListeners,
listenForSpringDmBundles
};
}
}
示例13: createActivator
import org.osgi.framework.BundleActivator; //导入依赖的package包/类
@Override
public BundleActivator createActivator() {
return this;
}
示例14: configHostActivator
import org.osgi.framework.BundleActivator; //导入依赖的package包/类
protected void configHostActivator(Map<String, Object> config) {
List<BundleActivator> activators = new ArrayList<BundleActivator>();
activators.add(this.hostActivator);
config.put(SYSTEMBUNDLE_ACTIVATORS_PROP, activators);
}
示例15: createHostActivator
import org.osgi.framework.BundleActivator; //导入依赖的package包/类
private BundleActivator createHostActivator() {
this.hostActivator = new HostActivator(
this.containerConfiguration.areRemoteShellBundlesEnabled(), this.containerConfiguration.isSlf4jBridgeActivated());
return this.hostActivator;
}