Hi all, finally i saved my trouble.
   I put my sonixMbean.jar (Listener.class, JNDIMapMBean.class,
JNDIMap.class) in lib/ext and now all is working fine.

   May be my code will be able useful to someone.

   Thanks all.

[-----------]


   My MBean is a mix with you prior code and JBoss documentacion example.

***********************
*   Inteface class:   *
***********************
package sonix;

// The JNDIMap MBean interface
 import javax.naming.NamingException;

 public interface JNDIMapMBean
 {
     public String getJndiName();
     public void setJndiName(String jndiName) throws NamingException;
     public void start() throws Exception;
     public void stop() throws Exception;
 }


*********************
*   MBean class:    *
*********************
package sonix;

// The JNDIMap MBean implementation
 import java.io.InputStream;
 import java.util.HashMap;
 import javax.naming.CompositeName;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.Name;
 import javax.naming.NamingException;
 import org.jboss.naming.NonSerializableFactory;
 import javax.management.*;
 import java.util.Set;
 import java.util.Date;
 import java.util.Properties;
 import sonix.session.*;
 import javax.rmi.PortableRemoteObject;


 public class JNDIMap  extends org.jboss.util.ServiceMBeanSupport implements
JNDIMapMBean
 {
     private String jndiName;
     private HashMap contextMap = new HashMap();
     private boolean started;

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



        public String getName() {return jndiName;}

        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 [] { jndiName, "10", null, timerDate, new
Long(javax.management.timer.Timer.ONE_SECOND*10)},
                        new String [] { "".getClass().getName(), 
"".getClass().getName(),
                                "java.lang.Object", timerDate.getClass().getName(),
Long.TYPE.getName()} );
          } catch (Exception e)
          {
                log.log( "JNDIMap.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 String getJndiName()
     {
        return jndiName;
     }
     public void setJndiName(String jndiName) throws NamingException
     {
         String oldName = this.jndiName;
         this.jndiName = jndiName;
         if( started )
         {
             unbind(oldName);
             try
             {
                 rebind();
             }
             catch(Exception e)
             {
                 NamingException ne = new NamingException("Failed to update
jndiName");
                 ne.setRootCause(e);
                 throw ne;
             }
         }
     }

     public void start() throws Exception



         started = true;
         rebind();

            setupTimer();
     }

     public void stop()
     {
         started = false;
         unbind(jndiName);
     }



     private static Context createContext(Context rootContext, Name name)
throws NamingException
     {
         Context subctx = rootContext;
         for(int n = 0; n < name.size(); n ++)
         {
             String atom = name.get(n);
             try
             {
                 Object obj = subctx.lookup(atom);
                 subctx = (Context) obj;
             }
             catch(NamingException e)
             {   // No binding exists, create a subcontext
                 subctx = 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: " +
> 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


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

Reply via email to