5 Replies Latest reply on Sep 28, 2007 10:38 AM by Oskar Carlstedt

    How do I invoke a method just after an ear-deploy?

    Oskar Carlstedt Novice

      Hello!

      Does any of you out there know how to invoke an ejb3 method just after deploy of the ear file? (i.e. not the @PostConstruct, @PostActivate because these methods are called once per ejb instance).

      There is a way to use an mbean and do something in the start method. But for me this is like using the big cannon for just a simple thing.


      Best regards
      /Oskar

        • 1. Re: How do I invoke a method just after an ear-deploy?
          Andrew Rubinger Master

          A bit hacky, but maybe synchronize access to a static boolean flag on your EJB signaling whether your action has been completed?

          S,
          ALR

          • 2. Re: How do I invoke a method just after an ear-deploy?
            Andrew Rubinger Master

            Actually, that's a lot hacky, and could create an immediate bottleneck. I'd personally make a quick @Service with a "start" and be done with it.

            S,
            ALR

            • 3. Re: How do I invoke a method just after an ear-deploy?
              Kestas ruks Newbie

              But if you want to do something for each entity (but you do not have lsit of entities?) one time just after deploy of the ear file?
              Is some way to add listener or something to catch event of new entity was parsed?

              • 4. Re: How do I invoke a method just after an ear-deploy?
                Oskar Carlstedt Novice

                Thank you all for quick replies. I tried the service annotoation as describen in the ejb tutorial. I think it must be the simplest way to go by simply adding the @Service-annotation.

                Doing is will make the deployment to fail in JBoss 4.2.1.GA also having JBossWS 2.0.1.GA installed. I get the following error:

                11:16:25,931 INFO [EJBContainer] STARTED EJB: se.my.service.test.soapmessage.ServiceReg ejbName: ServiceReg
                11:16:25,944 ERROR [STDERR] java.lang.RuntimeException: Problem registering @Management interface for @Service class se.my.service.test.soapmessage.ServiceReg
                11:16:25,946 ERROR [STDERR] at org.jboss.ejb3.service.ServiceContainer.registerManagementInterface(ServiceContainer.java:560)
                11:16:25,948 ERROR [STDERR] at org.jboss.ejb3.service.ServiceContainer.start(ServiceContainer.java:155)
                11:16:25,949 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                11:16:25,950 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                11:16:25,952 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                11:16:25,953 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
                11:16:25,953 ERROR [STDERR] at org.jboss.ejb3.ServiceDelegateWrapper.startService(ServiceDelegateWrapper.java:103)
                11:16:25,954 ERROR [STDERR] at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
                11:16:25,955 ERROR [STDERR] at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
                11:16:25,956 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
                11:16:25,956 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                11:16:25,967 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
                11:16:25,968 ERROR [STDERR] at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                11:16:25,969 ERROR [STDERR] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                11:16:25,970 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
                11:16:25,980 ERROR [STDERR] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                11:16:25,981 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                11:16:25,986 ERROR [STDERR] at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
                11:16:25,987 ERROR [STDERR] at $Proxy0.start(Unknown Source)
                11:16:25,988 ERROR [STDERR] at org.jboss.system.ServiceController.start(ServiceController.java:417)
                11:16:25,988 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
                11:16:25,989 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                11:16:25,989 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
                11:16:25,990 ERROR [STDERR] at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                11:16:25,990 ERROR [STDERR] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                11:16:25,991 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
                11:16:25,991 ERROR [STDERR] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                11:16:25,992 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                11:16:25,992 ERROR [STDERR] at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
                11:16:25,993 ERROR [STDERR] at $Proxy80.start(Unknown Source)
                11:16:25,993 ERROR [STDERR] at org.jboss.ejb3.JmxKernelAbstraction.install(JmxKernelAbstraction.java:120)
                11:16:25,994 ERROR [STDERR] at org.jboss.ejb3.Ejb3Deployment.registerEJBContainer(Ejb3Deployment.java:301)
                11:16:25,994 ERROR [STDERR] at org.jboss.ejb3.Ejb3Deployment.start(Ejb3Deployment.java:362)
                11:16:25,995 ERROR [STDERR] at org.jboss.ejb3.Ejb3Module.startService(Ejb3Module.java:91)
                11:16:25,995 ERROR [STDERR] at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
                11:16:25,996 ERROR [STDERR] at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
                11:16:25,996 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
                11:16:25,997 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                11:16:25,997 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
                11:16:25,998 ERROR [STDERR] at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                11:16:25,999 ERROR [STDERR] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                11:16:25,999 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
                11:16:26,000 ERROR [STDERR] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                11:16:26,001 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                11:16:26,002 ERROR [STDERR] at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
                11:16:26,003 ERROR [STDERR] at $Proxy0.start(Unknown Source)
                11:16:26,004 ERROR [STDERR] at org.jboss.system.ServiceController.start(ServiceController.java:417)
                11:16:26,004 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
                11:16:26,005 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                11:16:26,005 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
                11:16:26,006 ERROR [STDERR] at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                11:16:26,007 ERROR [STDERR] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                11:16:26,007 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
                11:16:26,008 ERROR [STDERR] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                11:16:26,009 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                11:16:26,009 ERROR [STDERR] at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
                11:16:26,010 ERROR [STDERR] at $Proxy33.start(Unknown Source)
                11:16:26,010 ERROR [STDERR] at org.jboss.ejb3.EJB3Deployer.start(EJB3Deployer.java:512)
                11:16:26,011 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                11:16:26,011 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                11:16:26,011 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                11:16:26,012 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
                11:16:26,013 ERROR [STDERR] at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                11:16:26,013 ERROR [STDERR] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                11:16:26,013 ERROR [STDERR] at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
                11:16:26,014 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                11:16:26,015 ERROR [STDERR] at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
                11:16:26,016 ERROR [STDERR] at org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:97)
                11:16:26,016 ERROR [STDERR] at org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServiceMBeanSupport.java:238)
                11:16:26,017 ERROR [STDERR] at org.jboss.wsf.container.jboss42.DeployerInterceptor.start(DeployerInterceptor.java:87)
                11:16:26,017 ERROR [STDERR] at org.jboss.deployment.SubDeployerInterceptorSupport$XMBeanInterceptor.start(SubDeployerInterceptorSupport.java:188)
                11:16:26,018 ERROR [STDERR] at org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:95)
                11:16:26,019 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                11:16:26,019 ERROR [STDERR] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                11:16:26,020 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                11:16:26,020 ERROR [STDERR] at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
                11:16:26,021 ERROR [STDERR] at $Proxy34.start(Unknown Source)
                11:16:26,021 ERROR [STDERR] at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
                11:16:26,021 ERROR [STDERR] at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1015)
                11:16:26,022 ERROR [STDERR] at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
                11:16:26,023 ERROR [STDERR] at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
                11:16:26,023 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor20.invoke(Unknown Source)
                11:16:26,024 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                11:16:26,024 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
                11:16:26,025 ERROR [STDERR] at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                11:16:26,025 ERROR [STDERR] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                11:16:26,026 ERROR [STDERR] at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
                11:16:26,026 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                11:16:26,027 ERROR [STDERR] at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
                11:16:26,028 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                11:16:26,028 ERROR [STDERR] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                11:16:26,029 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                11:16:26,029 ERROR [STDERR] at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
                11:16:26,030 ERROR [STDERR] at $Proxy9.deploy(Unknown Source)
                11:16:26,030 ERROR [STDERR] at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:421)
                11:16:26,031 ERROR [STDERR] at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:634)
                11:16:26,031 ERROR [STDERR] at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:263)
                11:16:26,033 ERROR [STDERR] at org.jboss.deployment.scanner.AbstractDeploymentScanner.startService(AbstractDeploymentScanner.java:336)
                11:16:26,034 ERROR [STDERR] at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
                11:16:26,035 ERROR [STDERR] at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
                11:16:26,035 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
                11:16:26,036 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                11:16:26,036 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
                11:16:26,037 ERROR [STDERR] at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                11:16:26,037 ERROR [STDERR] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                11:16:26,038 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
                11:16:26,038 ERROR [STDERR] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                11:16:26,039 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                11:16:26,039 ERROR [STDERR] at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
                11:16:26,040 ERROR [STDERR] at $Proxy0.start(Unknown Source)
                11:16:26,041 ERROR [STDERR] at org.jboss.system.ServiceController.start(ServiceController.java:417)
                11:16:26,041 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
                11:16:26,042 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                11:16:26,042 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
                11:16:26,043 ERROR [STDERR] at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                11:16:26,043 ERROR [STDERR] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                11:16:26,044 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
                11:16:26,044 ERROR [STDERR] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                11:16:26,045 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                11:16:26,045 ERROR [STDERR] at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
                11:16:26,046 ERROR [STDERR] at $Proxy4.start(Unknown Source)
                11:16:26,047 ERROR [STDERR] at org.jboss.deployment.SARDeployer.start(SARDeployer.java:302)
                11:16:26,047 ERROR [STDERR] at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
                11:16:26,048 ERROR [STDERR] at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
                11:16:26,049 ERROR [STDERR] at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
                11:16:26,050 ERROR [STDERR] at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:766)
                11:16:26,051 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                11:16:26,052 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                11:16:26,052 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                11:16:26,053 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
                11:16:26,053 ERROR [STDERR] at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                11:16:26,062 ERROR [STDERR] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                11:16:26,062 ERROR [STDERR] at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
                11:16:26,063 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                11:16:26,064 ERROR [STDERR] at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
                11:16:26,066 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                11:16:26,067 ERROR [STDERR] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                11:16:26,068 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                11:16:26,069 ERROR [STDERR] at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
                11:16:26,070 ERROR [STDERR] at $Proxy5.deploy(Unknown Source)
                11:16:26,070 ERROR [STDERR] at org.jboss.system.server.ServerImpl.doStart(ServerImpl.java:482)
                11:16:26,071 ERROR [STDERR] at org.jboss.system.server.ServerImpl.start(ServerImpl.java:362)
                11:16:26,071 ERROR [STDERR] at org.jboss.Main.boot(Main.java:200)
                11:16:26,072 ERROR [STDERR] at org.jboss.Main$1.run(Main.java:508)
                11:16:26,073 ERROR [STDERR] at java.lang.Thread.run(Thread.java:595)
                11:16:26,075 ERROR [STDERR] Caused by: java.lang.NullPointerException
                11:16:26,075 ERROR [STDERR] at org.jboss.ejb3.service.ServiceContainer.registerManagementInterface(ServiceContainer.java:539)
                11:16:26,076 ERROR [STDERR] ... 144 more
                11:16:26,082 INFO [EJBContainer] STOPPED EJB: se.nordnet.service.test.soapmessage.ServiceReg ejbName: ServiceReg
                


                My code is pretty simple
                ServiceReg.java
                package se.nordnet.service.test.soapmessage;
                
                import org.jboss.annotation.ejb.Depends;
                import org.jboss.annotation.ejb.Management;
                import org.jboss.annotation.ejb.Service;
                
                @Service(objectName = "test:service=TEST")
                @Depends("jboss.ws:service=DeployerInterceptorEJB3")
                @Management(ServiceRegManagement.class)
                public class ServiceReg implements ServiceRegManagement {
                
                 private String simpleProperty = null;
                
                 public String getSimpleProperty() {
                 return simpleProperty;
                 }
                
                 public void setSimpleProperty(String simpleProperty) {
                 this.simpleProperty = simpleProperty;
                 }
                
                 // Lifecycle methods
                 public void create() throws Exception {
                 System.out
                 .println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> RegService - Creating");
                 }
                
                 public void start() throws Exception {
                 System.out
                 .println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> RegService - Starting");
                 }
                
                 public void stop() {
                 System.out
                 .println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> RegService - Stopping");
                 }
                
                 public void destroy() {
                 System.out
                 .println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> RegService - Destroying");
                 }
                
                }
                



                ServiceRegManagement.java
                package se.nordnet.service.test.soapmessage;
                
                public interface ServiceRegManagement {
                
                
                 public String getSimpleProperty();
                
                 public void setSimpleProperty(String simpleProperty);
                
                
                 // Lifecycle methods
                 void create() throws Exception;
                
                 void start() throws Exception;
                
                 void stop();
                
                 void destroy();
                
                }
                


                Does any of you know why I get this error or what I shall do to get rid of it.

                Thanks
                /Oskar