Re: [JBoss-user] (Code Example -- LONG) Timer MBan Problem

2001-06-12 Thread Burkhard Vogel

Hi,
so far so bad. What kind of interface do I have to implement?
Is there an example of EJBs using the timer-MBean service???
Help?
Burkhard
- Original Message -
From: Jim Brownfield [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, June 12, 2001 6:50 AM
Subject: RE: [JBoss-user] (Code Example -- LONG) Timer MBan Problem


 Here's an example that works for me.  YMMV.  I've tried to remove all
 application specific code, but still leave relavent timer MBean code.  I
 reset the timer on each timer call.  You can probably set the timer up to
 send periodically.  The timerInterval is in seconds in this example
(default
 10 seconds).  Blame formatting stuff on VisualAge :).

 Good luck!

 import java.util.*;
 import javax.naming.*;
 import javax.jms.*;
 import javax.management.*;
 import javax.management.timer.*;

 public class YourMBean extends org.jboss.util.ServiceMBeanSupport
implements
 YourMBeanInterface {
 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 {
 YourMBean.this.setTimer();
 /*
 Other Stuff Here
 */
 } catch (Exception e) {
 System.out.println(
 Exception in YourMBean inner class Listener:  +
 e.toString());
 }
 }
 }

 public String getName() {
 return YourNameHere;
 }

 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 [] { Your name here, One Time Timer, null, timerDate },
 new String [] { .getClass().getName(), .getClass().getName(),
 java.lang.Object, timerDate.getClass().getName() } );
 } catch (Exception e) {
 log.log( YourMBean.setTimer() 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 in YourMBean.setupTimer():  + e.toString());
 throw e;
 }
 setTimer();
 }

 public void start() throws java.lang.Exception {
 super.start();
 /*
 Some Stuff here
 */
 setupTimer();
 }
 }

  -Original Message-
  From: [EMAIL PROTECTED]
  [mailto:[EMAIL PROTECTED]]On Behalf Of Keerthi
  Panneer
  Sent: Monday, June 11, 2001 9:04 PM
  To: [EMAIL PROTECTED]
  Subject: Re: [JBoss-user] Timer MBan Problem
 
 
  Hi,
  I tried the example described at
  http://www.jboss.org/documentation/HTML/ch11s74.html
  but i could not get it work... please let me know if someone gives you a
  working source code
 
  thanks
  keerthi
 
 
  From: David Crecente [EMAIL PROTECTED]
  Reply-To: [EMAIL PROTECTED]
  To: Lista Jboss [EMAIL PROTECTED]
  Subject: [JBoss-user] Timer MBan Problem
  Date: Mon, 11 Jun 2001 18:40:37 +0200
  
  Hi all,
  Could someone send me a Timer MBean sample?
  
  Thank you in advance.
  
  ___
  JBoss-user mailing list
  [EMAIL PROTECTED]
  http://lists.sourceforge.net/lists/listinfo/jboss-user
 
 
_
  Get Your Private, Free E-mail from MSN Hotmail at
http://www.hotmail.com.
 
 
  ___
  JBoss-user mailing list
  [EMAIL PROTECTED]
  http://lists.sourceforge.net/lists/listinfo/jboss-user


 ___
 JBoss-user mailing list
 [EMAIL PROTECTED]
 http://lists.sourceforge.net/lists/listinfo/jboss-user


___
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user



RE: [JBoss-user] (Code Example -- LONG) Timer MBan Problem

2001-06-12 Thread David Crecente
 = subctx.createSubcontext(atom);
 }
 }

 return subctx;
 }

 private void rebind() throws NamingException
 {
 InitialContext rootCtx = new InitialContext();
 // Get the parent context into which we are to bind
 Name fullName = rootCtx.getNameParser().parse(jndiName);
 System.out.println(fullName=+fullName);
 Name parentName = fullName;
 if( fullName.size()  1 )
 parentName = fullName.getPrefix(fullName.size()-1);
 else
 parentName = new CompositeName();
 Context parentCtx = createContext(rootCtx, parentName);
 Name atomName = fullName.getSuffix(fullName.size()-1);
 String atom = atomName.get(0);
 NonSerializableFactory.rebind(parentCtx, atom, contextMap);
 }
 private void unbind(String jndiName)
 {
 try
 {
 Context rootCtx = (Context) new InitialContext();
 rootCtx.unbind(jndiName);
 NonSerializableFactory.unbind(jndiName);
 }
 catch(NamingException e)
 {
 e.printStackTrace();
 }
 }

 }



*   Listener class:*

package sonix;

import javax.management.*;
import javax.naming.*;
import sonix.session.*;
import javax.rmi.PortableRemoteObject;
import java.util.Properties;

  public class Listener implements NotificationListener
  {
public void handleNotification(Notification pNotification, Object
pHandback)
{
  // Here to whatever you want or call a method
  // in the outer class
  System.out.println( You got a Notification:  + pNotification );

  Properties 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.provider.url,  192.168.27.148:1099);
  env.setProperty(java.naming.factory.url.pkgs,  org.jboss.naming);


  try
  {
System.out.println(Getting context);
InitialContext jndiContext = new InitialContext(env);
System.out.println(Bind on. + jndiContext);
Object ref  = jndiContext.lookup(sonix/session/ProcessNewAlarmS);
System.out.println(Getting home);
ProcessNewAlarmSHome alarmahome =
(ProcessNewAlarmSHome)PortableRemoteObject.narrow (ref,
ProcessNewAlarmSHome.class);
System.out.println(Getting interface remote.);
ProcessNewAlarmS alarma = alarmahome.create();
System.out.println(sending alarms);
alarma.notifyAlarms();
  }
  catch(javax.naming.NamingException e)
  {
 System.out.println(Error:  + e.getMessage());
  }
  catch(javax.ejb.CreateException e)
  {
 System.out.println(Error:  + e.getMessage());
  }
  catch(java.rmi.RemoteException e)
  {
 System.out.println(Error:  + e.getMessage());
  }
  catch(Exception e)
  {
 System.out.println(Error:  + e.getMessage());
  }

}
  }






[---The en sample-]
-Mensaje original-
De: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]En nombre de Burkhard
Vogel
Enviado el: martes 12 de junio de 2001 12:04
Para: [EMAIL PROTECTED]
Asunto: Re: [JBoss-user] (Code Example -- LONG) Timer MBan Problem


Hi,
so far so bad. What kind of interface do I have to implement?
Is there an example of EJBs using the timer-MBean service???
Help?
Burkhard
- Original Message -
From: Jim Brownfield [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, June 12, 2001 6:50 AM
Subject: RE: [JBoss-user] (Code Example -- LONG) Timer MBan Problem


 Here's an example that works for me.  YMMV.  I've tried to remove all
 application specific code, but still leave relavent timer MBean code.  I
 reset the timer on each timer call.  You can probably set the timer up to
 send periodically.  The timerInterval is in seconds in this example
(default
 10 seconds).  Blame formatting stuff on VisualAge :).

 Good luck!

 import java.util.*;
 import javax.naming.*;
 import javax.jms.*;
 import javax.management.*;
 import javax.management.timer.*;

 public class YourMBean extends org.jboss.util.ServiceMBeanSupport
implements
 YourMBeanInterface {
 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 {
 YourMBean.this.setTimer();
 /*
 Other Stuff Here
 */
 } catch (Exception e) {
 System.out.println(
 Exception in YourMBean inner class Listener

RE: [JBoss-user] (Code Example -- LONG) Timer MBan Problem

2001-06-11 Thread Jim Brownfield

Here's an example that works for me.  YMMV.  I've tried to remove all
application specific code, but still leave relavent timer MBean code.  I
reset the timer on each timer call.  You can probably set the timer up to
send periodically.  The timerInterval is in seconds in this example (default
10 seconds).  Blame formatting stuff on VisualAge :).

Good luck!

import java.util.*;
import javax.naming.*;
import javax.jms.*;
import javax.management.*;
import javax.management.timer.*;

public class YourMBean extends org.jboss.util.ServiceMBeanSupport implements
YourMBeanInterface {
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 {
YourMBean.this.setTimer();
/*
Other Stuff Here
*/
} catch (Exception e) {
System.out.println(
Exception in YourMBean inner class Listener:  +
e.toString());
}
}
}

public String getName() {
return YourNameHere;
}

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 [] { Your name here, One Time Timer, null, 
timerDate },
new String [] { .getClass().getName(), 
.getClass().getName(),
java.lang.Object, timerDate.getClass().getName() } );
} catch (Exception e) {
log.log( YourMBean.setTimer() 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 in YourMBean.setupTimer():  + e.toString());
throw e;
}
setTimer();
}

public void start() throws java.lang.Exception {
super.start();
/*
Some Stuff here
*/
setupTimer();
}
}

 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED]]On Behalf Of Keerthi
 Panneer
 Sent: Monday, June 11, 2001 9:04 PM
 To: [EMAIL PROTECTED]
 Subject: Re: [JBoss-user] Timer MBan Problem


 Hi,
 I tried the example described at
 http://www.jboss.org/documentation/HTML/ch11s74.html
 but i could not get it work... please let me know if someone gives you a
 working source code

 thanks
 keerthi


 From: David Crecente [EMAIL PROTECTED]
 Reply-To: [EMAIL PROTECTED]
 To: Lista Jboss [EMAIL PROTECTED]
 Subject: [JBoss-user] Timer MBan Problem
 Date: Mon, 11 Jun 2001 18:40:37 +0200
 
 Hi all,
 Could someone send me a Timer MBean sample?
 
 Thank you in advance.
 
 ___
 JBoss-user mailing list
 [EMAIL PROTECTED]
 http://lists.sourceforge.net/lists/listinfo/jboss-user

 _
 Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.


 ___
 JBoss-user mailing list
 [EMAIL PROTECTED]
 http://lists.sourceforge.net/lists/listinfo/jboss-user


___
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user