-
1. Re: Calling EJB from timer MBean
schaefera Nov 26, 2001 8:09 PM (in response to jquest_j)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 Nov 27, 2001 11:55 AM (in response to jquest_j)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
schaefera Nov 27, 2001 10:27 PM (in response to jquest_j)What is the content of the method AInternet$Listener.handleNotification() ?
Andy -
4. Re: Calling EJB from timer MBean
jquest_j Nov 29, 2001 1:01 PM (in response to jquest_j)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
schaefera Nov 29, 2001 3:25 PM (in response to jquest_j)Can you give me the source code of your listener.
Andy -
6. Re: Calling EJB from timer MBean
jquest_j Dec 1, 2001 9:39 AM (in response to jquest_j)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
schaefera Dec 1, 2001 1:56 PM (in response to jquest_j)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 Dec 2, 2001 4:00 AM (in response to jquest_j)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.