8 Replies Latest reply on Dec 2, 2001 4:00 AM by jquest_j

    Calling EJB from timer MBean

    jquest_j Newbie

      Hi all,

      We send it for second time.

      How can we call EJB from timer MBean.
      The MBean is working well, but by calling a EJB - stateless session bean
      we get Exception.

      We reader the docs ( JB 2.4.3) and can not find this problem.
      Any working examples?

      Many thanks in advance.

        • 1. Re: Calling EJB from timer MBean
          Andreas Schaefer Apprentice

          I would help if you would provide us with the exception (Stack Trace).

          You can have several problems but I would guess that you either forgot to make the Home/Remote Interface available to you client (like for a web-client) or that you have a problem to look them up.

          Andy

          • 2. Re: Calling EJB from timer MBean
            jquest_j Newbie

            Hi Andy,

            The exception is:

            [Default] java.lang.NoSuchMethodError
            [Default] at mypackage.services.AInternet$Listener.handleNotification(AInternet.java:71)
            [Default]
            [Default] at com.sun.management.jmx.MBeanServerNotificationListener.handleNotification(MBeanServerNotificationListener.java:48)
            [Default]
            [Default] at javax.management.NotificationBroadcasterSupport.sendNotification(NotificationBroadcasterSupport.java:142)
            [Default]
            [Default] at javax.management.timer.Timer.sendNotification(Timer.java:1119)


            I can find the interface.
            The exception occur by EJB method calling.

            Many thanks in advance.

            • 3. Re: Calling EJB from timer MBean
              Andreas Schaefer Apprentice

              What is the content of the method AInternet$Listener.handleNotification() ?

              Andy

              • 4. Re: Calling EJB from timer MBean
                jquest_j Newbie

                Hi ,

                I am not sure, but in my config (jboss.jcml) file I have:




                Listener.handleNotification() is intern in AInternet
                defined.

                Many thanks.

                • 5. Re: Calling EJB from timer MBean
                  Andreas Schaefer Apprentice

                  Can you give me the source code of your listener.

                  Andy

                  • 6. Re: Calling EJB from timer MBean
                    jquest_j Newbie

                    Hi Andy,

                    Yes I can.


                    package mypackage.services;

                    import java.util.*;
                    import javax.naming.*;
                    import javax.jms.*;
                    import javax.management.*;
                    import javax.management.timer.*;
                    import myejb.*;
                    import javax.rmi.PortableRemoteObject;

                    /**
                    *
                    *
                    *
                    */
                    public class AInternet extends org.jboss.util.ServiceMBeanSupport implements AInternetMBean{

                    protected MyEJBHome LogHome = null;
                    protected MyEJB LogF = null;
                    protected Properties env;
                    protected Object ref = null;
                    protected InitialContext jndiContext = null;

                    protected boolean isUsed = false;

                    protected javax.management.MBeanServer mbeanServer = null;
                    protected javax.management.ObjectInstance timerRef = null;
                    protected long timeInterval = 10 * javax.management.timer.Timer.ONE_SECOND;

                    public class Listener implements NotificationListener {
                    public void handleNotification(Notification pNotification, Object pHandback) {
                    try {
                    AInternet.this.setTimer();

                    AInternet.this.callF();
                    // Other Stuff Here
                    } catch (Exception e) {
                    System.out.println( "Exception : " + e.toString());
                    }
                    }
                    }

                    public String getName() {
                    return "MyServ";
                    }

                    public long getTimeInterval() {
                    return timeInterval;
                    }

                    public javax.management.ObjectName preRegister(javax.management.MBeanServer param1, javax.management.ObjectName param2) throws java.lang.Exception {
                    mbeanServer = param1;
                    return super.preRegister( param1, param2 );
                    }

                    public void setTimeInterval(long newTimeInterval) {
                    timeInterval = newTimeInterval * javax.management.timer.Timer.ONE_SECOND;
                    }

                    public void setTimer() throws java.lang.Exception {
                    try {
                    Date timerDate = new Date( new Date().getTime() + getTimeInterval() );
                    Integer theTimer = (Integer) mbeanServer.invoke( timerRef.getObjectName(), "addNotification", new Object [] { "MyServ", "One Time Timer", null, timerDate }, new String [] { "".getClass().getName(), "".getClass().getName(), "java.lang.Object", timerDate.getClass().getName() } );
                    } catch (Exception e) {
                    log.log( "Exception: " + e.getMessage() ); throw e;
                    }
                    }

                    public void setupTimer() throws Exception {
                    try {
                    Set beanList = mbeanServer.queryMBeans( new ObjectName("DefaultDomain", "service", "timer"), null);
                    if (!beanList.isEmpty()) {
                    timerRef = (ObjectInstance) beanList.iterator().next();
                    }

                    mbeanServer.addNotificationListener( timerRef.getObjectName(), new Listener(), null, null );
                    } catch (Exception e) {
                    log.log("Exception: " + e.toString());
                    throw e;
                    }

                    setTimer();
                    }


                    /** Creates new AInternetM */
                    public AInternet() {
                    }

                    public void setMBName(String mbName) throws NamingException {

                    }

                    public void start() throws java.lang.Exception {
                    super.start();
                    setupTimer();
                    }

                    public void stop(){
                    super.stop();
                    }

                    public void callF(){
                    try{


                    env = new Properties();

                    env.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
                    env.setProperty("java.naming.provider.url", "localhost:1099");
                    env.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");

                    jndiContext = new InitialContext(env);

                    ref = jndiContext.lookup("MyEJBJNDI");

                    System.out.println( "S5");

                    LogHome = (MyEJBHome) PortableRemoteObject.narrow(ref,MyEJBHome.class);

                    LogF = LogHome.create();


                    System.out.println( "S7 :" + LogF);


                    LogF.MyCall();

                    System.out.println( "CALL OK");

                    } catch ( Exception e1){
                    System.out.println( " Exception is: " + e1.toString());
                    return;
                    }
                    }
                    }


                    In callF() I can see the message S7, but can not start the EJB method. I can not see the message for "CALL OK".

                    If I comment LogF.MyCall(); I see the message "CALL OK".

                    Where is the problem?

                    Many thanks in advance.



                    • 7. Re: Calling EJB from timer MBean
                      Andreas Schaefer Apprentice

                      In the catch() block just below the call "LogF.MyCall()" please add a "e1.printStackTrace()" and post this stack trace here.

                      Thanx - Andy

                      • 8. Re: Calling EJB from timer MBean
                        jquest_j Newbie

                        Hi Andy,

                        I try to print the stack.

                        I do not understand what is happen, but the call is working now.

                        I will test it in more complex example.
                        For the moment it is working.

                        Many thanks for you help.