Skip to content
Permalink
Browse files
Merge branch 'better-osgi-1' into 'ibm-trunk'
Better osgi 1

Initial changes to not use blueprint and set up project better.
  • Loading branch information
David Jencks committed Nov 13, 2014
2 parents 327b029 + 5c30ee9 commit 69641f31edc5db24db87e191159272cab45e349e
Show file tree
Hide file tree
Showing 12 changed files with 238 additions and 210 deletions.
@@ -1,5 +1,7 @@
*.i??
.project
.metadata
.idea
.classpath
.settings
target
12 pom.xml
@@ -197,6 +197,18 @@
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArguments>
<endorseddirs>${project.build.directory}/endorsed</endorseddirs>
</compilerArguments>
</configuration>
</plugin>

</plugins>

@@ -33,7 +33,7 @@
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>4.3.0</version>
<version>5.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -65,6 +65,19 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
<Bundle-Activator>org.apache.yoko.orb.activator.Activator</Bundle-Activator>
<Private-Package>
org.apache.yoko.orb.activator,
org.apache.yoko.osgi.locator.activator
</Private-Package>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
@@ -0,0 +1,16 @@
package org.apache.yoko.orb.activator;

import org.apache.yoko.osgi.locator.activator.AbstractBundleActivator;

public class Activator extends AbstractBundleActivator {

public Activator() {
super(new Info[] {new Info("org.apache.yoko.orb.CORBA.ORB", "org.apache.yoko.orb.CORBA.ORB", 1),
new Info("org.apache.yoko.orb.CORBA.ORBSingleton", "org.apache.yoko.orb.CORBA.ORBSingleton", 1)
},
new Info[] {new Info("org.omg.CORBA.ORBClass", "org.apache.yoko.orb.CORBA.ORB", 1),
new Info("org.omg.CORBA.ORBSingletonClass", "org.apache.yoko.orb.CORBA.ORBSingleton", 1)
});
}

}

This file was deleted.

@@ -36,7 +36,13 @@
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>4.3.0</version>
<version>5.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
<version>5.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
@@ -0,0 +1,107 @@
package org.apache.yoko.osgi.locator.activator;

import java.util.ArrayList;
import java.util.List;

import org.apache.yoko.osgi.locator.BundleProviderLoader;
import org.apache.yoko.osgi.locator.Register;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;

public abstract class AbstractBundleActivator implements BundleActivator {

public static class Info {
final String id;
final String className;
final int priority;

public Info(String id, String className, int priority) {
super();
this.id = id;
this.className = className;
this.priority = priority;
}

}
private final Info[] providerInfo;
private final Info[] serviceInfo;
private ServiceTracker<Register, Register> tracker;
private BundleContext context;
private boolean registered;
private final List<BundleProviderLoader> providerLoaders = new ArrayList<BundleProviderLoader>();
private final List<BundleProviderLoader> serviceLoaders = new ArrayList<BundleProviderLoader>();

public AbstractBundleActivator(Info[] providerInfo, Info[] serviceInfo) {
this.providerInfo = providerInfo;
this.serviceInfo = serviceInfo;
}

public void start(final BundleContext context) throws Exception {
this.context = context;
tracker = new ServiceTracker<Register, Register>(context, Register.class, new ServiceTrackerCustomizer<Register, Register>() {

public Register addingService(ServiceReference<Register> reference) {
Register register = context.getService(reference);
register(register);
return register;
}

public void modifiedService(ServiceReference<Register> reference,
Register service) {
// TODO Auto-generated method stub

}

public void removedService(ServiceReference<Register> reference,
Register service) {
// TODO Auto-generated method stub

}

});
tracker.open();
Register register = tracker.getService();
if (register != null) {
register(register);
}

}

private synchronized void register(Register register) {
if (!registered) {
registered = true;
Bundle bundle = context.getBundle();
for (Info classInfo: providerInfo) {
BundleProviderLoader loader = new BundleProviderLoader(classInfo.id, classInfo.className, bundle, classInfo.priority);
providerLoaders.add(loader);
register.registerProvider(loader);
}
for (Info classInfo: serviceInfo) {
BundleProviderLoader loader = new BundleProviderLoader(classInfo.id, classInfo.className, bundle, classInfo.priority);
serviceLoaders.add(loader);
register.registerService(loader);
}
}
}

public void stop(BundleContext context) throws Exception {
Register register = tracker.getService();
tracker.close();
synchronized (this) {
if (register != null && registered) {
for (BundleProviderLoader loader: providerLoaders) {
register.unregisterProvider(loader);
}
for (BundleProviderLoader loader: serviceLoaders) {
register.unregisterService(loader);
}
}
}

}

}
@@ -48,6 +48,12 @@
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.bcel</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>5.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -62,6 +68,7 @@
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
<Bundle-Activator>org.apache.yoko.rmi.osgi.activator.Activator</Bundle-Activator>
<Export-Package>
org.apache.yoko.osgi.locator,
org.apache.yoko.rmi.impl,
@@ -70,6 +77,13 @@
org.apache.yoko.rmi.util.corba,
org.apache.yoko.rmi.util.stub
</Export-Package>
<Import-Package>
!sun.*,*
</Import-Package>
<Private-Package>
org.apache.yoko.rmi.osgi.activator,
org.apache.yoko.osgi.locator.activator
</Private-Package>
</instructions>
</configuration>
</plugin>
@@ -0,0 +1,36 @@
package org.apache.yoko.rmi.osgi.activator;

import org.apache.yoko.osgi.locator.ProviderRegistryImpl;
import org.apache.yoko.osgi.locator.Register;
import org.apache.yoko.osgi.locator.activator.AbstractBundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;

public class Activator extends AbstractBundleActivator {

private ServiceRegistration<Register> sr;
private ProviderRegistryImpl register;

public Activator() {
super(new Info[] {new Info("javax.rmi.CORBA.UtilClass", "org.apache.yoko.rmi.impl.UtilImpl", 1)},
new Info[] {new Info("javax.rmi.CORBA.PortableRemoteObjectClass", "org.apache.yoko.rmi.impl.PortableRemoteObjectImpl", 1),
new Info("org.apache.yoko.rmi.PortableRemoteObjectExtClass", "org.apache.yoko.rmi.impl.PortableRemoteObjectExtImpl", 1),
new Info("javax.rmi.CORBA.StubClass", "org.apache.yoko.rmi.impl.StubImpl", 1)});
}

@Override
public void start(BundleContext context) throws Exception {
register = new ProviderRegistryImpl();
register.start();
sr = context.registerService(Register.class, register, null);
super.start(context);
}

@Override
public void stop(BundleContext context) throws Exception {
super.stop(context);
sr.unregister();
register.stop();
}

}

0 comments on commit 69641f3

Please sign in to comment.