mathieuancelin / weld-osgi

This project aims to provide an OSGi integration for Weld. This project is no longer updated, see https://github.com/weld/core for updates
https://github.com/weld/core
12 stars 10 forks source link

Singleton Provider for OSGi #14

Closed mathieuancelin closed 13 years ago

mathieuancelin commented 13 years ago

The title speaks for itself

mathieuancelin commented 13 years ago

Started something here :

https://github.com/mathieuancelin/core/commit/bccdd3323bd9f687de16b59179cd37be29e5b079

arcane86 commented 13 years ago

Calling a method on a application scoped service bean obtain using the Service interface give me a "Singleton is not set for bundle 7"

Here the service interface and implementation:

public interface ContextualService {
    long getId();
}

@Publish
@Name("Application")
@ApplicationScoped
public class ApplicationScopedContextualService implements ContextualService {
    private final long id = System.nanoTime();
    @Override
    public long getId() {
        return id;
    }
}

The way the service is obtained:

@Inject
@Name("Application")
private Service<ContextualService> applicationScopedContextualService;

public ContextualService getApplicationScopedContextualService() {
    return applicationScopedContextualService.get();
}

The test code:

ContextualService applicationScopedContextualService = provider.getApplicationScopedContextualService();
Assert.assertNotNull("The application scoped contextual service was null", applicationScopedContextualService); //Okay
long applicationScopedContextualServiceId = applicationScopedContextualService.getId(); //throws the exception

The same thing work just fine using a @Dependent service bean. I'm going to commit the test code on my fork.

mathieuancelin commented 13 years ago

Did you try with the patched version of Weld ? If so, it's always the same Weld issue and we need to fix it (at least for OSGi environment).

If you want to start investigations about that, I can show you some tests I ran and you can also speak with @pmuir on how to do it the best way.

If I remember well, last time we spoke about it, one of the solution was to patch SingletonProviders so they can use some kind of contextual ID (a String) to target the right Weld container and embed this ID in beans or proxy.

Let me know.

mathieuancelin commented 13 years ago

Should be fixed with https://github.com/mathieuancelin/core/commit/8f7b618ebbb5d18f315d4c18a02f7cfb52381189 and https://github.com/mathieuancelin/core/commit/d11c7a1c9c27a87b297f053520709033b6b3ceab