java ee - EJB3 - Self Remote Injection / EJB Plugins -
i want implement kind of "plugin mechanism" using ejb3. have two+ war's, each containing own bean types using remote interfaces defined in separate project. basically, want main bean (product) deployed , provide mechanism other beans (n different project beans) register against. important arbitrary beans may register, long have knowledge of product's remote interface. sample code:
product bean
@singleton @concurrencymanagement(bean) public class productbean implements productremote, serializable { private static final long serialversionuid = 4686943363874502919l; private projectremote project; public void registerproject(projectremote project) { this.project = project; } public void something() { if(project != null) project.dosomething(); } }
project bean
@concurrencymanagement(bean) @singleton @startup public class projectbean implements projectremote, serializable { private static final long serialversionuid = -2034521486195622039l; @ejb(lookup="java:global/product/productbean") private productremote product; @postconstruct private void registerself() { product.registerproject(this); } public void dosomething() { system.err.println("foobar"); } }
product interface
@remote public interface productremote { public void registerproject(projectremote project); }
project interface
@remote public interface projectremote { public void dosomething(); }
unfortunately, when try deploy project classnotfoundexception:
22:56:33,146 error [org.jboss.as.controller.management-operation] (xnio-1 task-7) jbas014613: operation ("add") failed - address: ([{"deployment" => "project-0.1-snapshot.war"}]) - failure description: {"jbas014671: failed services" => {"jboss.deployment.unit.\"project-0.1-snapshot.war\".component.projectbean.start" => "org.jboss.msc.service.startexception in service jboss.deployment.unit.\"project-0.1-snapshot.war\".component.projectbean.start: java.lang.illegalstateexception: jbas011048: failed construct component instance caused by: java.lang.illegalstateexception: jbas011048: failed construct component instance caused by: javax.ejb.ejbexception: java.lang.runtimeexception: jbas014154: failed marshal ejb parameters caused by: java.lang.runtimeexception: jbas014154: failed marshal ejb parameters caused by: java.lang.classnotfoundexception: com.xxx.test.project.projectbean [module \"deployment.product-0.1-snapshot.war:main\" service module loader]"}}
so question is: there way realize such functionality? or entirely impossible because of different classpaths each war?
i think first problem though you're sharing interface, client implementation class still not available other project, , it's instance loaded different classloader (ie, war container).
you implement things using message bean (jms) design, allow separation of concerns, quasi-registration (to queue/topic), , allow deploy implementation want. check out how i'm working jms , activemq.
another solution use delegate pattern, such:
assuming went 2 separate war deployments single ear deployment, you're project have following modules.
mylibrary
ejb interface:
@local public interface mybeanlocal public void dosomething(string something);
myclient annotation:
@documented @qualifier @retention(retentionpolicy.runtime) @target({elementtype.method, elementtype.field, elementtype.parameter, elementtype.type}) public @interface myclient { }
mydefault annotation:
@documented @qualifier @retention(retentionpolicy.runtime) @target({elementtype.method, elementtype.field, elementtype.parameter, elementtype.type}) public @interface mydefault { }
myclientejb
@stateless @myclient public class mybean implements mybeanlocal { @inject @mydefault private mybeanlocal mydefault; @override public void dosomething(string something) { mydefault.dosomething(something); } }
mydefaultejb
@stateless @mydefault public class mybean implements mybeanlocal { @override public void dosomething(string something) { // } }
myweb
@named @request public class myrequestbean { @inject @myclient private mybeanlocal myclient; public void something() { myclient.dosomething("..."); } }
lastly, might want consider osgi. haven't done that, might you're looking far registering resources. of course, consider resource adapter depending on problem domain.
Comments
Post a Comment