Export Singleton EventBus

163 views
Skip to first unread message

Cristian Rinaldi

unread,
Nov 7, 2012, 12:03:58 PM11/7/12
to guice...@googlegroups.com
Hello comunity, I have a two osgi modules:
* core
* client

In the Core module, I export a implemtantion of EventBus (Guava EventBus):

public class ActivationModule extends PeaberryActivationModule {

@Override
protected void configure() {
/* Export CoreModule*/
bind(export(Module.class)).toProvider(service(CoreModule.class).export());
bind(CoreModule.class).in(Singleton.class);

/* Export Events */


/* Bind Watcher */
bind(WatcherCore.class).in(Singleton.class);
bindService(Module.class).out(Key.get(WatcherCore.class)).multiple();


/* Export EventBus */
bind(EventBus.class).in(Singleton.class);
bind(export(EventBus.class)).toProvider(service(EventBus.class).export());

requestInjection(this);
}
}

With this EventBus I throw events when a module is loaded, removed, etc.

In the client module, I record these events in the EventBus, to handle them.

Client Code:

public class ActivationModule extends PeaberryActivationModule {

@Override
protected void configure() {

bind(ClientModule.class).in(Singleton.class);

bind(iterable(Module.class)).toProvider(service(Module.class).multiple());

bind(EventBus.class).toProvider(service(EventBus.class).single());

//bind(ModuleInitializeEventHandler.class).toProvider(service(ModuleInitializeEventHandler.class).single());

install(new ServletModule());

requestInjection(this);
}
}

....
....

public class ClientModule implements Module {

@Inject
EventBus eventBus;

@Singleton
private ModuleInitializeEventHandlerImpl handler = new ModuleInitializeEventHandlerImpl();

@Override
public String getName() {
return this.getClass().getName();
}

@Override
@Start
public Boolean initialize() {

this.eventBus.register(handler);

return true;
}

...
}

In the initialize method the eventBus variable is null, below the error:

[#|2012-11-07T13:57:38.357-0300|WARNING|glassfish3.1.2|com.google.inject.servlet.GuiceFilter|_ThreadID=16;_ThreadName=Thread-2;|Multiple Servlet injectors detected. This is a warning indicating that you have more than one GuiceFilter running in your web application. If this is deliberate, you may safely ignore this message. If this is NOT deliberate however, your application may not work as expected.|#]

[#|2012-11-07T13:57:38.380-0300|SEVERE|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=16;_ThreadName=Thread-2;|org.ops4j.peaberry.activation.PeaberryActivationException: Error invoking com.logikas.kratos.client.module.ClientModule@e560aa5#public java.lang.Boolean com.logikas.kratos.client.module.ClientModule.initialize()
at org.ops4j.peaberry.activation.internal.Reflection.invoke(Reflection.java:82)
at org.ops4j.peaberry.activation.internal.SingletonBundleRoot.activate(SingletonBundleRoot.java:43)
at org.ops4j.peaberry.activation.internal.InstanceBundleRoot.activate(InstanceBundleRoot.java:46)
at org.ops4j.peaberry.activation.internal.BundleActivation.activate(BundleActivation.java:185)
at org.ops4j.peaberry.activation.internal.BundleActivation.update(BundleActivation.java:157)
at org.ops4j.peaberry.activation.internal.StateBundleActivationTracker.start(StateBundleActivationTracker.java:38)
at org.ops4j.peaberry.activation.internal.BundleActivation.start(BundleActivation.java:136)
at org.ops4j.peaberry.activation.internal.BundleTracker.start(BundleTracker.java:103)
at org.ops4j.peaberry.activation.internal.BundleTracker.bundleChanged(BundleTracker.java:82)
at org.apache.felix.framework.util.EventDispatcher.invokeBundleListenerCallback(EventDispatcher.java:868)
at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:789)
at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:514)
at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4244)
at org.apache.felix.framework.Felix.startBundle(Felix.java:1923)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:944)
at org.glassfish.extras.osgicontainer.OSGiDeployedBundle.startBundle(OSGiDeployedBundle.java:107)
at org.glassfish.extras.osgicontainer.OSGiDeployedBundle.resume(OSGiDeployedBundle.java:83)
at org.glassfish.extras.osgicontainer.OSGiDeployedBundle.start(OSGiDeployedBundle.java:67)
at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130)
at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269)
at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:301)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:391)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)
at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.ops4j.peaberry.activation.internal.Reflection.invoke(Reflection.java:80)
... 48 more
Caused by: org.ops4j.peaberry.ServiceUnavailableException
at com.google.common.eventbus.EventBus$pbryglu.register(Unknown Source)
at com.logikas.kratos.client.module.ClientModule.initialize(ClientModule.java:45)
... 53 more
|#]

Any Idea?

Thanks for your time!!

Reply all
Reply to author
Forward
0 new messages