-
1. Re: Using @Service annotation in eclipse; JBoss EJB 3.0 Serv
yantriki Dec 9, 2005 10:31 PM (in response to yantriki)Please help with writing EJB 3.0 Service. I can't get it to deploy.
I wrote the following EJB 3.0 Service:@Service(objectName = "ejb3:service=PollingService") @Management(PollingServiceManagement.class) public class PollingService implements PollingServiceManagement { Thread pollingThread = null; int pollingInterval = 30; boolean destroy; public int getPollInterval() { // TODO Auto-generated method stub return pollingInterval; } public void setPollInterval(int pollingInterval) { this.pollingInterval = pollingInterval; } // Lifecycle methods public void create() throws Exception { System.out.println("PollingService - Creating"); pollingThread = new PollingThread(); pollingThread.start(); } public void destroy() { System.out.println("PollingService - Destroying"); destroy = true; if(pollingThread != null && pollingThread.isAlive()) pollingThread.interrupt(); } public class PollingThread extends Thread { @Override public void run() { while(!destroy){ try{ sleep(pollingInterval*1000); System.out.println("Starting Poll..."); }catch(InterruptedException ex){ System.out.println("PollingThread interrupted: "+ex.getMessage()); } } } } }
I could not get it to deploy without the jboss-service.xml. So I created one to describe the MBean:<?xml version="1.0" encoding="UTF-8"?> <server> <mbean code="org.vss.jboss.service.PollingService" name="ejb3:service=PollingService"> </mbean> </server>
I am getting the following error while trying to deploy a Service "sar" file.
---------------------------------------------------22:23:30,000 ERROR [MainDeployer] Could not create deployment: file:/F:/java/jboss-4.0.3SP1/server/default/deploy/ejb3Service.sar org.jboss.deployment.DeploymentException: - nested throwable: (java.lang.reflect.UndeclaredThrowableException) at org.jboss.system.ServiceConfigurator.install(ServiceConfigurator.java:178) at org.jboss.system.ServiceController.install(ServiceController.java:215) at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141) at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80) at org.jboss.mx.server.Invocation.invoke(Invocation.java:72) at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245) at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644) at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:176) at $Proxy4.install(Unknown Source) at org.jboss.deployment.SARDeployer.create(SARDeployer.java:232) at org.jboss.deployment.MainDeployer.create(MainDeployer.java:935) at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:789) at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:753) at sun.reflect.GeneratedMethodAccessor8.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141) at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80) at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:118) at org.jboss.mx.server.Invocation.invoke(Invocation.java:74) at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:127) at org.jboss.mx.server.Invocation.invoke(Invocation.java:74) at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245) at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644) at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:176) at $Proxy6.deploy(Unknown Source) at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:319) at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:507) at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:192) at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:203) at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:182) Caused by: java.lang.reflect.UndeclaredThrowableException at org.jboss.system.ServiceCreator.install(ServiceCreator.java:203) at org.jboss.system.ServiceConfigurator.internalInstall(ServiceConfigurator.java:431) at org.jboss.system.ServiceConfigurator.install(ServiceConfigurator.java:153) ... 33 more Caused by: java.lang.Error: Unresolved compilation problems: Type mismatch: cannot convert from Service to Annotation Management cannot be resolved to a type at org.vss.jboss.service.PollingService.<init>(PollingService.java:19) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:494) at org.jboss.mx.server.MBeanServerImpl.instantiate(MBeanServerImpl.java:1218) at org.jboss.mx.server.MBeanServerImpl.instantiate(MBeanServerImpl.java:271) at org.jboss.mx.server.MBeanServerImpl.createMBean(MBeanServerImpl.java:329) at org.jboss.system.ServiceCreator.install(ServiceCreator.java:124) ... 35 more
-
2. Re: Using @Service annotation in eclipse; JBoss EJB 3.0 Serv
kabirkhan Dec 10, 2005 9:46 AM (in response to yantriki)In the ejb3 distribution there are some tutorials explaining the jboss extensions with code examples. They are under docs/tutorial/index.html.
As shown in the Service tutorial (docs/tutorial/service) there is no requirement for a jboss-service.xml when deploying -
3. Re: Using @Service annotation in eclipse; JBoss EJB 3.0 Serv
yantriki Dec 16, 2005 11:00 AM (in response to yantriki)Kabir,
I am unable to deploy the service. When I use the extension .sar, the SARDeployer expects to find jboss-service.xml file. However, if I deploy the file as .ejb3, the service never starts,although it deploys fine. Please, also note that I have renamed the PollingService to PollingServiceMBean, but that didn't help either. I have the lifecycle methods declared in the Management interface.
I looked at the tutorial, all that is there is that the Service is packaged in the ejb3 jar, along with other EJB beans etc. So I am not getting any clue as o what to do.
Regards
Vivek -
4. Re: Using @Service annotation in eclipse; JBoss EJB 3.0 Serv
yantriki Dec 16, 2005 4:43 PM (in response to yantriki)Amazingly, it was the jboss-ejb3.jar file, which apparently does not have org.jboss.annotation classes available. Once I got these files from the EJB3Trail tutorial, the service deployed smoothly.
The Eclipse IDE did not show any error at all about these missing annotation classes and compiled the classes. ????
Well, I checked the current development release of JBoss 5.0 alpha and also 4.0.3SP1 and it seems like it is missing from there too. I don't know it has been refractored, nothing whatsoever is mentioned about this package anywhere.
I would appreciate if someone can shed some light on how and why these classes in org.jboss.annotation are missing from jboss-ejb3.jar. It caused me days of miseries. -
5. Re: Using @Service annotation in eclipse; JBoss EJB 3.0 Serv
bill.burke Dec 16, 2005 5:24 PM (in response to yantriki)they are in jboss-annotations-ejb3.jar
-
6. Re: Using @Service annotation in eclipse; JBoss EJB 3.0 Serv
yantriki Dec 18, 2005 2:06 AM (in response to yantriki)Thanks Bill. I appreciate your help.
-
7. Re: Using @Service annotation in eclipse; JBoss EJB 3.0 Serv
lutfi123456 Dec 20, 2005 4:16 PM (in response to yantriki)is your Service tutorial application running well, yantriki? because I have some problems with
@Management(MyClass.class)
because the annotation for Management doesnt contains an argument. How can you solve that? -
8. Re: Using @Service annotation in eclipse; JBoss EJB 3.0 Serv
yantriki Jan 16, 2006 2:55 PM (in response to yantriki)Yes,
I have the Service tutorial running.
Following is my code:package org.vss.jboss.service; import org.jboss.annotation.ejb.Management; @Management public interface PollingServiceManagement { public int getPollInterval(); public void setPollInterval(int pollingInterval); // Life cycle method public void create() throws Exception; public void destroy() throws Exception; public void start() throws Exception; public void stop() throws Exception; }
Implementation codeimport java.util.Date; import org.jboss.logging.Logger; import org.jboss.annotation.ejb.Service; /** * @author VSrivastav * */ @Service(objectName = "ejb3:service=PollingService") public class PollingService implements PollingServiceManagement { Thread pollingThread = null; int pollingInterval = 30; boolean destroy; Logger log; public int getPollInterval() { // TODO Auto-generated method stub return pollingInterval; } public void setPollInterval(int pollingInterval) { this.pollingInterval = pollingInterval; } public class PollingThread extends Thread { @Override public void run() { while(!destroy){ try{ Date d = new Date(); log.info(d.toString()+": Sleeping for "+pollingInterval+" seconds"); sleep(pollingInterval*1000); log.info("Starting Poll..."); }catch(InterruptedException ex){ log.info("PollingThread interrupted: "+ex.getMessage()); } } log.info("PollingThread stopped."); } } public void create() throws Exception { log = Logger.getLogger(this.getClass()); log.info("PollingService - Creating"); } public void destroy() throws Exception { log.info("PollingService - Destroying"); } public void start() throws Exception { log.info("PollingService - Starting poll thread"); pollingThread = new PollingThread(); pollingThread.start(); } public void stop() throws Exception { log.info("PollingService - Stopping poll thread"); destroy = true; if(pollingThread != null && pollingThread.isAlive()) pollingThread.interrupt(); } }
The Service is deployed as ejb3Service.ejb3 file. It contains just a META-INF/Manifest.mf and my class files.