12 Replies Latest reply on Oct 27, 2009 4:50 AM by fuchs

    Client calls Timer only once

    fuchs

      Hello.
      I am using JBoss 5.0.1.GA.
      I need to build a TimerService with EJB3.
      Therefor, I am using the Tutorial, which can be found under the documentation of EJB3.
      After some changes the Timer-Tutorial is running.

      Now, the Server-Methode should be called every fifth sec.
      In my Application it is only once called.

      Here my code for the Client:

      package ejb.timer.createbill;
      
      import java.util.Properties;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      import javax.rmi.PortableRemoteObject;
      
      
      public class Client
      {
       public static void main(String[] args) throws Exception
       {
       System.out.println("HELLO FROM CLIENT !");
      
       try {
       Properties p = new Properties();
       p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
       p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
       p.put(Context.PROVIDER_URL, "jnp://localhost:1099");
       Context ctx = new InitialContext(p);
      
       Object ref = ctx.lookup("TimerBean/remote");
       ExampleTimer cbr =(ExampleTimer) PortableRemoteObject.narrow(ref, ExampleTimer.class);
       cbr.scheduleTimer(1000);
      
       } catch (NamingException e){
       e.printStackTrace();
       }
       }
      }
      


      I also add the following Argument to the Client Application:
      Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory

      Can someone help me?
      Thx!

        • 1. Re: Client calls Timer only once
          jaikiran

           

          "Fuchs" wrote:

          After some changes the Timer-Tutorial is running.

          What changes did you do? The tutorials should not require any changes (maybe just the JBOSS_HOME stuff) to run correctly. So let us know of the changes you did, so that we can fix them (if they are some bugs) accordingly.

          "Fuchs" wrote:

          Now, the Server-Methode should be called every fifth sec.
          In my Application it is only once called.

          Can you post the logs on the console from both the client and server side? Please do *not* post the server.log. Just the console log should be fine.

          "Fuchs" wrote:

          I also add the following Argument to the Client Application:
          Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory

          That shouldn't be added. Any specific reason you are adding that?

          • 2. Re: Client calls Timer only once
            fuchs

            Excuse that I have not explained my post enough.
            Now, I want to make up this.

            build.xml:
            The build.xml script generates an *.ejbjar file which is not deployed by my jboss 5.0.1.GA default server. So I changed the build-script to make a *.jar file.
            I also changed the directories, where EJB is found, from "/server/default/deploy/ejb3.deployer" to "/server/default/deployers/ejb3.deployer".
            The path to "jboss-aop-jdk50.deployer", I changed to "/server/default/deployers/jboss-aop-jboss5.deployer".
            That was all what I changed on the server-side.

            Client.java:
            The client.java in the tutorial looks like this:

            InitialContext ctx = new InitialContext();
            ExampleTimer timer = (ExampleTimer) ctx.lookup(ExampleTimer.class.getName());
            timer.scheduleTimer(5000);
            


            It use a "jndi.properties" which looks like this:
            java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
            java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
            java.naming.provider.url=localhost


            With this Configuration, I get the following exception:
            com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl <init>
             WARNUNG: "IOP00410201: (COMM_FAILURE) Connection failure: socketType: IIOP_CLEAR_TEXT; hostname: xxx.xx.xx.xxx; port: 900"
             org.omg.CORBA.COMM_FAILURE: vmcid: SUN minor code: 201 completed: No
             ...
             Caused by: java.net.ConnectException: Connection refused: connect


            900 is the wrong port, so I implemented the following in the client.java:
            try {
             Properties p = new Properties();
             p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
             p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
             p.put(Context.PROVIDER_URL, "jnp://localhost:1099");
             Context ctx = new InitialContext(p);
             Object ref = ctx.lookup("TimerBean/remote");
             ExampleTimer cbr =(ExampleTimer) PortableRemoteObject.narrow(ref, ExampleTimer.class);
             cbr.scheduleTimer(5000);
            
             } catch (NamingException e){
             e.printStackTrace();
            }


            The next exception was:
            javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
             ...
             Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory


            After I added the jbossall-client.jar it deployed.

            I could not reproduce why I added these arguments (-Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory), so I removed them.

            Client-Console:
            HELLO FROM CLIENT !
            log4j:WARN No appenders could be found for logger (org.jnp.interfaces.TimedSocketFactory).
            log4j:WARN Please initialize the log4j system properly.



            Server-Console:
            Jboss start
            ...
            10:58:20,775 INFO [JndiSessionRegistrarBase] Binding the following Entries in G
            lobal JNDI:
            
             SecureDeploymentManager/remote - EJB3.x Default Remote Business Interfac
            e
             SecureDeploymentManager/remote-org.jboss.deployers.spi.management.deploy
            .DeploymentManager - EJB3.x Remote Business Interface
            
            10:58:20,934 INFO [SessionSpecContainer] Starting jboss.j2ee:jar=profileservice
            -secured.jar,name=SecureManagementView,service=EJB3
            10:58:20,934 INFO [EJBContainer] STARTED EJB: org.jboss.profileservice.ejb.Secu
            reManagementView ejbName: SecureManagementView
            10:58:20,966 INFO [JndiSessionRegistrarBase] Binding the following Entries in G
            lobal JNDI:
            
             SecureManagementView/remote - EJB3.x Default Remote Business Interface
             SecureManagementView/remote-org.jboss.deployers.spi.management.Managemen
            tView - EJB3.x Remote Business Interface
            
            10:58:21,156 INFO [SessionSpecContainer] Starting jboss.j2ee:jar=profileservice
            -secured.jar,name=SecureProfileService,service=EJB3
            10:58:21,156 INFO [EJBContainer] STARTED EJB: org.jboss.profileservice.ejb.Secu
            reProfileServiceBean ejbName: SecureProfileService
            10:58:21,204 INFO [JndiSessionRegistrarBase] Binding the following Entries in G
            lobal JNDI:
            
             SecureProfileService/remote - EJB3.x Default Remote Business Interface
             SecureProfileService/remote-org.jboss.profileservice.spi.ProfileService
            - EJB3.x Remote Business Interface
            
            10:58:21,744 INFO [TomcatDeployment] deploy, ctxPath=/admin-console
            10:58:22,649 INFO [config] Initializing Mojarra (1.2_12-b01-FCS) for context '/
            admin-console'
            10:58:29,398 INFO [TomcatDeployment] deploy, ctxPath=/
            10:58:29,763 INFO [TomcatDeployment] deploy, ctxPath=/jmx-console
            10:58:30,001 INFO [Http11Protocol] Starting Coyote HTTP/1.1 on http-127.0.0.1-8
            080
            10:58:30,112 INFO [AjpProtocol] Starting Coyote AJP/1.3 on ajp-127.0.0.1-8009
            10:58:30,128 INFO [ServerImpl] JBoss (Microcontainer) [5.1.0.GA (build: SVNTag=
            JBoss_5_1_0_GA date=200905221053)] Started in 1m:55s:949ms
            
            
            After deploy:
            11:01:13,169 INFO [Ejb3DependenciesDeployer] Encountered deployment AbstractVFS
            DeploymentContext@16634496{vfszip:/D:/server/exp-server/jboss-5.1.0.GA/server/de
            fault/deploy/tutorial.jar/}
            11:01:13,201 INFO [Ejb3DependenciesDeployer] Encountered deployment AbstractVFS
            DeploymentContext@16634496{vfszip:/D:/server/exp-server/jboss-5.1.0.GA/server/de
            fault/deploy/tutorial.jar/}
            11:01:13,421 INFO [JBossASKernel] Created KernelDeployment for: tutorial.jar
            11:01:13,421 INFO [JBossASKernel] installing bean: jboss.j2ee:jar=tutorial.jar,
            name=TimerBean,service=EJB3
            11:01:13,421 INFO [JBossASKernel] with dependencies:
            11:01:13,421 INFO [JBossASKernel] and demands:
            11:01:13,421 INFO [JBossASKernel] jboss.ejb:service=EJBTimerService
            11:01:13,421 INFO [JBossASKernel] and supplies:
            11:01:13,421 INFO [JBossASKernel] jndi:TimerBean/remote
            11:01:13,421 INFO [JBossASKernel] jndi:TimerBean/remote-ejb.timer.createbi
            ll.ExampleTimer
            11:01:13,421 INFO [JBossASKernel] Class:ejb.timer.createbill.ExampleTimer
            11:01:13,421 INFO [JBossASKernel] Added bean(jboss.j2ee:jar=tutorial.jar,name=T
            imerBean,service=EJB3) to KernelDeployment of: tutorial.jar
            11:01:13,421 INFO [EJB3EndpointDeployer] Deploy AbstractBeanMetaData@150f2ec{na
            me=jboss.j2ee:jar=tutorial.jar,name=TimerBean,service=EJB3_endpoint bean=org.jbo
            ss.ejb3.endpoint.deployers.impl.EndpointImpl properties=[container] constructor=
            null autowireCandidate=true}
            11:01:13,499 INFO [SessionSpecContainer] Starting jboss.j2ee:jar=tutorial.jar,n
            ame=TimerBean,service=EJB3
            11:01:13,499 INFO [EJBContainer] STARTED EJB: ejb.timer.createbill.TimerBean ej
            bName: TimerBean
            11:01:13,515 INFO [JndiSessionRegistrarBase] Binding the following Entries in G
            lobal JNDI:
            
             TimerBean/remote - EJB3.x Default Remote Business Interface
             TimerBean/remote-ejb.timer.createbill.ExampleTimer - EJB3.x Remote Busin
            ess Interface
            
            After start
            11:13:50,323 WARN [InterceptorsFactory] EJBTHREE-1246: Do not use InterceptorsF
            actory with a ManagedObjectAdvisor, InterceptorRegistry should be used via the b
            ean container
            11:13:50,323 WARN [InterceptorsFactory] EJBTHREE-1246: Do not use InterceptorsF
            actory with a ManagedObjectAdvisor, InterceptorRegistry should be used via the b
            ean container
            11:13:55,497 INFO [STDOUT] ---------------------
            11:13:55,497 INFO [STDOUT] * Received Timer event: Hello World
            11:13:55,497 INFO [STDOUT] ---------------------


            But the receiving of the timer event appears only once.

            • 3. Re: Client calls Timer only once
              jaikiran

               

              "Fuchs" wrote:


              build.xml:
              The build.xml script generates an *.ejbjar file which is not deployed by my jboss 5.0.1.GA default server. So I changed the build-script to make a *.jar file.
              I also changed the directories, where EJB is found, from "/server/default/deploy/ejb3.deployer" to "/server/default/deployers/ejb3.deployer".
              The path to "jboss-aop-jdk50.deployer", I changed to "/server/default/deployers/jboss-aop-jboss5.deployer".
              That was all what I changed on the server-side.



              Could you point us to the URL of the tutorial you are referring to? I have a feeling that you are running the 4.x tutorials against AS-5.x. The build.xml for the latest tutorials targeted against AS-5.x, which are available here http://www.jboss.org/ejb3/docs/, has no references to any of the files you mentioned.

              • 4. Re: Client calls Timer only once
                jaikiran

                 

                11:01:13,499 INFO [EJBContainer] STARTED EJB: ejb.timer.createbill.TimerBean ejbName: TimerBean


                You definitely are running AS-4.x tutorials against AS-5 :) The new EJB3 tutorials for AS-5 are available at the link that i posted in my previous reply.


                • 5. Re: Client calls Timer only once
                  fuchs

                  Thanks! thats correct, I used the old example.
                  This explains why I had to change so much things. :-).

                  But now, if I use the timer-example for jboss 5, the result is the same:

                  16:52:33,365 INFO [Ejb3DependenciesDeployer] Encountered deployment AbstractVFS
                  DeploymentContext@5005412{vfszip:/D:/server/exp-server/jboss-5.1.0.GA/server/def
                  ault/deploy/jboss-ejb3-tutorial-timer.jar/}
                  16:52:33,381 INFO [Ejb3DependenciesDeployer] Encountered deployment AbstractVFS
                  DeploymentContext@5005412{vfszip:/D:/server/exp-server/jboss-5.1.0.GA/server/def
                  ault/deploy/jboss-ejb3-tutorial-timer.jar/}
                  16:52:33,725 INFO [JBossASKernel] Created KernelDeployment for: jboss-ejb3-tuto
                  rial-timer.jar
                  16:52:33,725 INFO [JBossASKernel] installing bean: jboss.j2ee:jar=jboss-ejb3-tu
                  torial-timer.jar,name=ExampleTimerBean,service=EJB3
                  16:52:33,725 INFO [JBossASKernel] with dependencies:
                  16:52:33,725 INFO [JBossASKernel] and demands:
                  16:52:33,725 INFO [JBossASKernel] jboss.ejb:service=EJBTimerService
                  16:52:33,725 INFO [JBossASKernel] and supplies:
                  16:52:33,725 INFO [JBossASKernel] Class:jboss5ejb3.timer.bean.ExampleTimer
                  
                  16:52:33,725 INFO [JBossASKernel] jndi:ExampleTimerBean/remote-jboss5ejb3.
                  timer.bean.ExampleTimer
                  16:52:33,725 INFO [JBossASKernel] jndi:ExampleTimerBean/remote
                  16:52:33,725 INFO [JBossASKernel] Added bean(jboss.j2ee:jar=jboss-ejb3-tutorial
                  -timer.jar,name=ExampleTimerBean,service=EJB3) to KernelDeployment of: jboss-ejb
                  3-tutorial-timer.jar
                  16:52:33,725 INFO [EJB3EndpointDeployer] Deploy AbstractBeanMetaData@1d3da65{na
                  me=jboss.j2ee:jar=jboss-ejb3-tutorial-timer.jar,name=ExampleTimerBean,service=EJ
                  B3_endpoint bean=org.jboss.ejb3.endpoint.deployers.impl.EndpointImpl properties=
                  [container] constructor=null autowireCandidate=true}
                  16:52:33,787 INFO [SessionSpecContainer] Starting jboss.j2ee:jar=jboss-ejb3-tut
                  orial-timer.jar,name=ExampleTimerBean,service=EJB3
                  16:52:33,803 INFO [EJBContainer] STARTED EJB: jboss5ejb3.timer.bean.ExampleTime
                  rBean ejbName: ExampleTimerBean
                  16:52:33,803 INFO [JndiSessionRegistrarBase] Binding the following Entries in G
                  lobal JNDI:
                  
                   ExampleTimerBean/remote - EJB3.x Default Remote Business Interface
                   ExampleTimerBean/remote-jboss5ejb3.timer.bean.ExampleTimer - EJB3.x Remo
                  te Business Interface
                  
                  16:52:40,068 WARN [InterceptorsFactory] EJBTHREE-1246: Do not use InterceptorsF
                  actory with a ManagedObjectAdvisor, InterceptorRegistry should be used via the b
                  ean container
                  16:52:40,068 WARN [InterceptorsFactory] EJBTHREE-1246: Do not use InterceptorsF
                  actory with a ManagedObjectAdvisor, InterceptorRegistry should be used via the b
                  ean container
                  16:52:40,381 INFO [STDOUT] ---------------------
                  16:52:40,381 INFO [STDOUT] Created a timer event to be triggered after 5000 mil
                  li seconds
                  16:52:40,381 INFO [STDOUT] ---------------------
                  16:52:45,115 INFO [STDOUT] ---------------------
                  16:52:45,115 INFO [STDOUT] * Received Timer event: Hello World
                  16:52:45,115 INFO [STDOUT] ---------------------
                  


                  Do I have to add additional things to the Jboss, like special libraries ?



                  • 6. Re: Client calls Timer only once
                    jaikiran

                    Now that we know you are looking at the correct examples, let's look into the details :)

                    "Fuchs" wrote:

                    Now, the Server-Methode should be called every fifth sec.
                    In my Application it is only once called.


                    If you look at the bean implementation http://anonsvn.jboss.org/repos/jbossas/projects/ejb3/trunk/docs/tutorial/timer/src/org/jboss/tutorial/timer/bean/ExampleTimerBean.java, we are calling the createTimer with 2 arguments:

                    ctx.getTimerService().createTimer(new Date(new Date().getTime() + milliseconds), "Hello World");
                    


                    This will create a timer which is scheduled to be triggered at the specified time, only once. If you want it to repeat every x milli seconds, then you will have to use the overloaded method which accepts 3 arguments http://java.sun.com/javaee/5/docs/api/javax/ejb/TimerService.html#createTimer(java.util.Date,%20long,%20java.io.Serializable)

                    • 7. Re: Client calls Timer only once
                      fuchs

                      Thank you jaikiran!

                      • 8. Re: Client calls Timer only once
                        fuchs

                        after i deploying my application i get this error from the java console:

                        [java] Exception in thread "main" javax.naming.NameNotFoundException: CustomerArchivTimerBean not bound
                         [java] at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
                         [java] at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
                         [java] at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
                         [java] at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
                         [java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                         [java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                         [java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                         [java] at java.lang.reflect.Method.invoke(Method.java:597)
                         [java] at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305)
                         [java] at sun.rmi.transport.Transport$1.run(Transport.java:159)
                         [java] at java.security.AccessController.doPrivileged(Native Method)
                         [java] at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
                         [java] at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
                         [java] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
                         [java] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
                         [java] at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
                         [java] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
                         [java] at java.lang.Thread.run(Thread.java:619)
                         [java] at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255)
                         [java] at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)
                         [java] at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:142)
                         [java] at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
                         [java] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:667)
                         [java] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
                         [java] at javax.naming.InitialContext.lookup(InitialContext.java:392)
                         [java] at ejb3.timer.client.CustomerArchivClient.testClusterScheduleIntervalTimer(CustomerArchivClient.java:22)
                         [java] at ejb3.timer.client.CustomerArchivClient.main(CustomerArchivClient.java:15)
                         [java] Java Result: 1


                        The JBoss console says:
                        ObjectName: jboss.j2ee:jar=customerTimer.ejb3,name=CustomerArchivTimerBean,service=EJB3
                         State: FAILED
                         Reason: java.lang.IllegalArgumentException: ejb3.timer.bean.CustomerArchivTimerBean is not an interface


                        in the jboss web-console the ejb3-service CustomerArchivTimerBean is registered. i am confused why the Bean isnt found.

                        is there anyone who has an idea what i am doing wrong this time, or what the exception mean?

                        • 9. Re: Client calls Timer only once
                          jaikiran

                          Your bean is not deployed because of this error:

                          Reason: java.lang.IllegalArgumentException: ejb3.timer.bean.CustomerArchivTimerBean is not an interface


                          What does your bean class and its interfaces look like, including the annotations?

                          • 10. Re: Client calls Timer only once
                            fuchs

                            The Bean class:

                            @Stateless
                            @Remote (CustomerArchivTimerBean.class)
                            public class CustomerArchivTimerBean implements CustomerArchivTimerProxy
                            {
                             private @Resource SessionContext ctx;
                            
                             public void scheduleTimer(Date expiration, Serializable info)
                             {
                             System.out.println("Create single action timer [info=" + info + "]");
                             ctx.getTimerService().createTimer(expiration, info);
                             }
                            
                             public void scheduleTimer(long initialDuration, long intervalDuration, Serializable info)
                             {
                             System.out.println("Create initial+interval timer [info=" + info + "]");
                             ctx.getTimerService().createTimer(initialDuration, intervalDuration, info);
                             }
                            
                             public void cancelTimer(Serializable info)
                             {
                             System.out.println("Cancel timer [info=" + info + "]");
                             Collection<Timer> timers = ctx.getTimerService().getTimers();
                             for (Timer timer : timers)
                             {
                             if (timer.getInfo().equals(info))
                             {
                             System.out.println("Timer[info=" + info + "] found, cancelling...");
                             timer.cancel();
                             System.out.println("Timer[info=" + info + "] cancelled");
                             }
                             }
                            
                             }
                            
                             @Timeout
                             public void timeoutHandler(Timer timer) throws Exception
                             {
                             System.out.println("Received timer event: " + timer.getInfo());
                             Date date = new Date(System.currentTimeMillis());
                             System.out.println("Current time is: " + date + ", origin: timeoutHandler");
                             cancelTimer("CustomerArchivTimer");
                             }
                            
                            }
                            


                            The interface of the Bean:
                            public interface CustomerArchivTimerProxy
                            {
                            
                             public void scheduleTimer(Date expiration, Serializable info);
                            
                             public void scheduleTimer(long initialDuration, long intervalDuration, Serializable info);
                            
                             public void cancelTimer(Serializable info);
                            
                             public void timeoutHandler(Timer timer) throws Exception;
                            
                            }
                            


                            The client methods are:
                             public static void main(String[] args) throws Exception
                             {
                            
                             testClusterScheduleIntervalTimer();
                             System.out.println("Timer scheduled to trigger after 10 seconds");
                             }
                            
                             public static void testClusterScheduleIntervalTimer() throws Exception
                             {
                             InitialContext ctx = new InitialContext();
                             CustomerArchivTimerProxy timer = (CustomerArchivTimerProxy) ctx.lookup("CustomerArchivTimerBean/remote");
                             timer.scheduleTimer(10000, 5000, "CustomerArchivTimer");
                             }
                            


                            The jndi properties:
                            java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
                            java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
                            java.naming.provider.url=localhost
                            



                            • 11. Re: Client calls Timer only once
                              wolfgangknauf

                              Hi,

                              @Remote (CustomerArchivTimerBean.class)
                              should be
                              @Remote (CustomerArchivTimerProxy.class)


                              But you could place the annotation also on the remote interface itself, without any attributes:
                              @Remote
                              public interface CustomerArchivTimerProxy
                              {
                              


                              Best regards

                              Wolfgang

                              • 12. Re: Client calls Timer only once
                                fuchs

                                An easy one, thanks. The problem ist solved!