Issue 82 in peaberry: Always getting the same instance. (Does single() mean singleton?).

20 views
Skip to first unread message

peab...@googlecode.com

unread,
Jun 7, 2013, 4:50:31 AM6/7/13
to guice...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 82 by bouhie...@gmail.com: Always getting the same instance.
(Does single() mean singleton?).
http://code.google.com/p/peaberry/issues/detail?id=82

When using peaberry, I always get the same instance of an object.
I don't specify the binding as being a Singleton Scope or use the
@Singleton annotation
on the class. The binding is however annotated (with @Server).

How do I get a unique instance? (A non-singleton).
Am I using Peaberry wrongly?

Bundle1:
--------
Module1:

bind(export(IDataProvider.class)).annotatedWith(Server.class)
.toProvider(service(ServerCDODataProvider.class).export());

Activator1:

@Inject
@Server
Export<IDataProvider> dataProvider;

.... start(BundleContext ctx){

createInjector(osgiModule(ctx), new Module1()).injectMembers();



Bundle2:
-------
Module2:
bind(IDataProvider.class).annotatedWith(Server.class).toProvider(
service(IDataProvider.class).single());

ConsumerClass1:

@Inject
@Server
IDataProvider provider1


ConsumerClass2:
@Inject
@Server
IDataProvider provider2

provider1 == provider2 => true







--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

peab...@googlecode.com

unread,
Jun 14, 2013, 8:23:06 AM6/14/13
to guice...@googlegroups.com

Comment #1 on issue 82 by mccu...@gmail.com: Always getting the same
instance. (Does single() mean singleton?).
http://code.google.com/p/peaberry/issues/detail?id=82

Peaberry works on top of OSGi services, so the reason you only see one
instance is because the service is a singleton and not a ServiceFactory:
http://www.osgi.org/javadoc/r4v43/core/org/osgi/framework/ServiceFactory.html

The multiple() method is for situations where there are multiple services
registered to the same interface and you want to see all these services.
Otherwise with single() you would only see the highest-ranked matching
service.

peab...@googlecode.com

unread,
Jun 14, 2013, 8:27:57 AM6/14/13
to guice...@googlegroups.com

Comment #2 on issue 82 by mccu...@gmail.com: Always getting the same
instance. (Does single() mean singleton?).
http://code.google.com/p/peaberry/issues/detail?id=82

If you want to get multiple copies of the same service then you need to
implement ServiceFactory - peaberry should then export the service as a
ServiceFactory and you should then be able to get a new instance
per-bundle. If you want to generate multiple instances per-bundle then you
need to write your own factory API and export that as a service for the
other bundles to consume.

peab...@googlecode.com

unread,
Jun 14, 2013, 9:35:26 AM6/14/13
to guice...@googlegroups.com

Comment #3 on issue 82 by bouhie...@gmail.com: Always getting the same
instance. (Does single() mean singleton?).
http://code.google.com/p/peaberry/issues/detail?id=82

Thanks Stuart. This clarifies!

peab...@googlecode.com

unread,
Jun 21, 2015, 9:55:44 PM6/21/15
to guice...@googlegroups.com
Updates:
Status: Duplicate

Comment #4 on issue 82 by mccu...@gmail.com: Always getting the same
instance. (Does single() mean singleton?).
https://code.google.com/p/peaberry/issues/detail?id=82

Moved to https://github.com/ops4j/peaberry/issues/80
Reply all
Reply to author
Forward
0 new messages