Skip to content

Commit 5e43999

Browse files
committed
[aggregate] Immediate
The service needs to be immediate
1 parent 1bb26b4 commit 5e43999

File tree

22 files changed

+280
-2
lines changed

22 files changed

+280
-2
lines changed

biz.aQute.aggregate.provider/src/main/java/biz/aQute/aggregate/provider/AggregateState.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
@SuppressWarnings({
3333
"rawtypes", "unchecked"
3434
})
35-
@Component(property = "condition=true", service = AggregateState.class)
35+
@Component(property = "condition=true", service = AggregateState.class, immediate = true)
3636
@AggregateImplementation
3737
public class AggregateState {
3838
final static Class ARCHETYPE = Aggregate.class;

biz.aQute.aggregate.provider/src/main/java/biz/aQute/aggregate/provider/TrackedService.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import java.util.stream.Collectors;
1010

1111
import org.osgi.framework.Bundle;
12+
import org.osgi.framework.BundleContext;
13+
import org.osgi.framework.FrameworkUtil;
1214
import org.osgi.framework.ServiceReference;
1315
import org.osgi.framework.ServiceRegistration;
1416
import org.osgi.util.tracker.ServiceTracker;
@@ -116,7 +118,9 @@ private void register() {
116118
logger.debug("registering %s", actualType);
117119
try {
118120
ActualTypeFactory instance = new ActualTypeFactory(this, state, serviceType);
119-
ServiceRegistration reg = state.context.registerService(actualType.getName(), instance, null);
121+
BundleContext context = FrameworkUtil.getBundle(actualType)
122+
.getBundleContext();
123+
ServiceRegistration reg = context.registerService(actualType.getName(), instance, null);
120124
synchronized (state) {
121125
instance.reg = reg;
122126
if (!state.closed) {

biz.aQute.aggregate.test/.classpath

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
4+
<classpathentry kind="con" path="aQute.bnd.classpath.container"/>
5+
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
6+
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
7+
<attributes>
8+
<attribute name="test" value="true"/>
9+
</attributes>
10+
</classpathentry>
11+
</classpath>

biz.aQute.aggregate.test/.project

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>biz.aQute.aggregate.test</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>bndtools.core.bndbuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
21+
<nature>bndtools.core.bndnature</nature>
22+
</natures>
23+
</projectDescription>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
eclipse.preferences.version=1
2+
encoding/.classpath=UTF-8
3+
encoding//src/test/java/biz/aQute/aggregate/test/AggregateTest.java=UTF-8
4+
encoding/<project>=UTF-8
5+
encoding/bnd.bnd=UTF-8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.8
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11+
org.eclipse.jdt.core.compiler.release=enabled
12+
org.eclipse.jdt.core.compiler.source=1.8

biz.aQute.aggregate.test/b1.bnd

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-includepackage: biz.aQute.aggregate.test.b1

biz.aQute.aggregate.test/b2.bnd

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-includepackage: biz.aQute.aggregate.test.b2

biz.aQute.aggregate.test/b3.bnd

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-includepackage: biz.aQute.aggregate.test.b3

biz.aQute.aggregate.test/bnd.bnd

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#
2+
# biz.aQute.aggregate.test PROVIDER BUNDLE
3+
#
4+
5+
-buildpath: \
6+
osgi.annotation,\
7+
org.osgi.service.component.annotations,\
8+
org.osgi.framework,\
9+
org.osgi.resource,\
10+
slf4j.api,\
11+
biz.aQute.api.aggregate,\
12+
biz.aQute.osgi.diverse.util;version=snapshot
13+
14+
-testpath: \
15+
biz.aQute.wrapper.junit,\
16+
biz.aQute.wrapper.hamcrest,\
17+
org.assertj.core,\
18+
biz.aQute.launchpad,\
19+
org.osgi.util.tracker,\
20+
org.osgi.dto,\
21+
org.awaitility,\
22+
slf4j.simple
23+
24+
-sub: *.bnd

biz.aQute.aggregate.test/main.bnd

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-includepackage: biz.aQute.aggregate.test
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package biz.aQute.aggregate.test;
2+
3+
public interface Foo {
4+
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package biz.aQute.aggregate.test;
2+
3+
import org.osgi.service.component.annotations.Activate;
4+
import org.osgi.service.component.annotations.Component;
5+
import org.osgi.service.component.annotations.Deactivate;
6+
import org.osgi.service.component.annotations.Reference;
7+
import org.slf4j.Logger;
8+
import org.slf4j.LoggerFactory;
9+
10+
import biz.aQute.aggregate.api.Aggregate;
11+
import biz.aQute.osgi.service.util.ObjectClass;
12+
13+
@Component
14+
public class Server {
15+
Logger logger = LoggerFactory.getLogger(Server.class);
16+
17+
@Activate
18+
public Server() {
19+
logger.info("activated {}", guard.getServices());
20+
}
21+
22+
@Deactivate
23+
public void deactivate() {
24+
logger.info("deactivated {}", guard.getServices());
25+
}
26+
27+
@ObjectClass
28+
interface AgFoo extends Aggregate<Foo> {
29+
}
30+
31+
@Reference
32+
AgFoo guard;
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package biz.aQute.aggregate.test.b1;
2+
3+
import org.osgi.service.component.annotations.Component;
4+
5+
import biz.aQute.aggregate.test.Foo;
6+
7+
@Component(immediate=true)
8+
public class B1 implements Foo {
9+
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package biz.aQute.aggregate.test.b2;
2+
3+
import org.osgi.service.component.annotations.Component;
4+
5+
import biz.aQute.aggregate.test.Foo;
6+
7+
@Component(immediate=true)
8+
public class B3 implements Foo {
9+
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package biz.aQute.aggregate.test.b3;
2+
3+
import org.osgi.service.component.annotations.Component;
4+
5+
import biz.aQute.aggregate.test.Foo;
6+
7+
@Component(immediate=true)
8+
public class B2 implements Foo {
9+
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@org.osgi.annotation.bundle.Export
2+
@Version("1.0.0")
3+
package biz.aQute.aggregate.test;
4+
5+
import org.osgi.annotation.versioning.Version;
6+
7+
/**
8+
* An API to do thread based stuff
9+
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package biz.aQute.aggregate.test;
2+
3+
import org.junit.Ignore;
4+
import org.junit.Test;
5+
import org.osgi.framework.Constants;
6+
7+
import aQute.launchpad.Launchpad;
8+
import aQute.launchpad.LaunchpadBuilder;
9+
import biz.aQute.aggregate.api.Aggregate;
10+
11+
public class AggregateTest {
12+
static {
13+
System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "debug");
14+
}
15+
16+
static LaunchpadBuilder builder = new LaunchpadBuilder().nostart()
17+
.bndrun("test.bndrun")
18+
.set(Constants.FRAMEWORK_BEGINNING_STARTLEVEL, "2");
19+
20+
interface T1Agg extends Aggregate<String> {}
21+
22+
23+
@Ignore
24+
@Test
25+
public void simple() throws Exception {
26+
try (Launchpad lp = builder.create()) {
27+
lp.start();
28+
29+
System.out.println();
30+
}
31+
32+
}
33+
34+
}

biz.aQute.aggregate.test/test.bndrun

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
-runpath: slf4j.simple, slf4j.api
2+
-resolve: cache
3+
-runfw: org.apache.felix.framework;version='[6.0.2,6.0.2]'
4+
-runee: JavaSE-1.8
5+
-runrequires: \
6+
osgi.identity;filter:='(osgi.identity=org.apache.felix.scr)',\
7+
osgi.identity;filter:='(osgi.identity=org.apache.felix.webconsole.plugins.scriptconsole)',\
8+
osgi.identity;filter:='(osgi.identity=org.apache.felix.log)',\
9+
osgi.identity;filter:='(osgi.identity=biz.aQute.aggregate.provider)',\
10+
osgi.identity;filter:='(osgi.identity=biz.aQute.aggregate.test.b1)',\
11+
osgi.identity;filter:='(osgi.identity=biz.aQute.aggregate.test.b2)',\
12+
osgi.identity;filter:='(osgi.identity=biz.aQute.aggregate.test.b3)',\
13+
osgi.identity;filter:='(osgi.identity=biz.aQute.aggregate.test.main)',\
14+
osgi.identity;filter:='(osgi.identity=biz.aQute.gogo.commands.provider)'
15+
-runbundles: \
16+
org.apache.commons.fileupload;version='[1.3.2,1.3.3)',\
17+
org.apache.commons.io;version='[2.5.0,2.5.1)',\
18+
org.apache.felix.configadmin;version='[1.9.12,1.9.13)',\
19+
org.apache.felix.gogo.command;version='[1.1.0,1.1.1)',\
20+
org.apache.felix.http.servlet-api;version='[1.1.2,1.1.3)',\
21+
org.apache.felix.log;version='[1.2.4,1.2.5)',\
22+
org.apache.felix.scr;version='[2.1.30,2.1.31)',\
23+
org.apache.felix.webconsole;version='[4.3.8,4.3.9)',\
24+
org.apache.felix.webconsole.plugins.scriptconsole;version='[1.0.2,1.0.3)',\
25+
org.json;version='[1.0.0,1.0.1)',\
26+
org.osgi.service.http;version='[1.2.1,1.2.2)',\
27+
org.osgi.util.function;version='[1.1.0,1.1.1)',\
28+
org.osgi.util.promise;version='[1.1.1,1.1.2)',\
29+
biz.aQute.aggregate.provider;version=snapshot,\
30+
biz.aQute.aggregate.test.b1;version=snapshot,\
31+
biz.aQute.aggregate.test.b2;version=snapshot,\
32+
biz.aQute.aggregate.test.b3;version=snapshot,\
33+
biz.aQute.aggregate.test.main;version=snapshot,\
34+
biz.aQute.api.aggregate;version=snapshot,\
35+
biz.aQute.osgi.diverse.util;version=snapshot,\
36+
org.apache.felix.gogo.runtime;version='[1.1.2,1.1.3)',\
37+
org.apache.felix.gogo.shell;version='[1.1.2,1.1.3)'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package biz.aQute.osgi.service.util;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
import org.osgi.annotation.bundle.Attribute;
9+
import org.osgi.annotation.bundle.Capability;
10+
11+
/**
12+
* Add a service capability to the bundle
13+
*
14+
*/
15+
@Capability(namespace = "osgi.service", effective = "active")
16+
@Retention(RetentionPolicy.CLASS)
17+
@Target(ElementType.TYPE)
18+
public @interface AddServiceCapability {
19+
@Attribute("objectClass")
20+
Class<?>[] value();
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package biz.aQute.osgi.service.util;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
import org.osgi.annotation.bundle.Capability;
9+
10+
/**
11+
* Add the marked type as a service capability
12+
*
13+
*/
14+
@Capability(namespace = "osgi.service", effective = "active", attribute = "objectClass=${@class}")
15+
@Retention(RetentionPolicy.CLASS)
16+
@Target(ElementType.TYPE)
17+
public @interface ObjectClass {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@org.osgi.annotation.bundle.Export
2+
@Version("1.0.0")
3+
package biz.aQute.osgi.service.util;
4+
5+
import org.osgi.annotation.versioning.Version;
6+
7+
/**
8+
* An API to do thread based stuff
9+
*/

0 commit comments

Comments
 (0)