10 Replies Latest reply on Dec 11, 2003 4:20 PM by sugramoin

    Problems in Using Local interface of entity bean in JMX

    sugramoin

      My MBean calls a entity bean and works with it in the same way as a session bean works with entity bean.

      I am using Local interfaces; i have packaged my MBeans in a seperate jar file and added that file to default/lib directory.

      I learned that MBeans are deployed first before even analysing the ear file, by jboss.

      problem:-
      I don't have my local interfaces of entity beans in my MBeans package; coz of which when deploying it getting an error saying class SOAndSO Local interface not found.

      Questions:-

      (1) Do i need to use Remote Interfaces.
      (2) Does'nt JMX MBeans works with local interfaces. (I know i am missing a lot here; it would be nice if you can explain me in details how this works or can give me a link which best addresses this issue)
      (3) or is there any other way of doin it

      TIA
      Moin

        • 1. Re: Problems in Using Local interface of entity bean in JMX

          You need to order your deployments so that the MBean instance is created after the local interfaces have been deployed to the server.

          A simple method of doing this is to uncomment the prefix deployment sorter in your conf/jboss-service.xml file and name your packages with a numeric prefix.

          For example:
          1.MyEJB.jar
          2.MyMBeans-service.xml

          -- Juha

          • 2. Re: Problems in Using Local interface of entity bean in JMX
            sugramoin

            I need more info on this where can i find it .
            TIA
            Moin

            • 3. Re: Problems in Using Local interface of entity bean in JMX

              PrefixDeployment sorter is in your jboss/server/<conf-name>/conf/jboss-service.xml file. It is already there as an uncommented section.

              Use search on your editor.

              -- Juha

              • 4. Re: Problems in Using Local interface of entity bean in JMX
                sugramoin

                Hey Juha Thanx for you help....

                Now i achieved Deployment sorting....
                I could see that working as i expected.

                But this din't slove my problem, it still complains about this env variable.

                14:56:36,296 INFO [TimeLineScheduler] starting Scheduler MBean
                14:56:36,296 INFO [TimeLineScheduler] Removing all aged time line schedules
                14:56:36,296 ERROR [STDERR] javax.naming.NameNotFoundException: env not bound
                14:56:36,296 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:495)
                14:56:36,296 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:503)
                14:56:36,312 ERROR [STDERR] at org.jnp.server.NamingServer.getObject(NamingServer.java:509)
                14:56:36,312 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:253)
                14:56:36,312 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:492)
                14:56:36,312 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:606)
                14:56:36,312 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:471)
                14:56:36,312 ERROR [STDERR] at javax.naming.InitialContext.lookup(InitialContext.java:347)
                


                Does'nt the env variable sets with EJB deploment..
                what i am i missing here please help me out.

                Moin.

                • 5. Re: Problems in Using Local interface of entity bean in JMX

                  It is a misconfiguration on looking up private environment entries. Depending what you're trying to do, in your code somewhere you have a lookup to "java:comp/env" namespace. You need to map this lookup to an actual bound object in the global or in-vm name space in the naming service. This is generally done in the components deployment descriptor which is attempting to do the lookup.

                  -- Juha

                  • 6. Re: Problems in Using Local interface of entity bean in JMX
                    sugramoin

                    I have all the descriptor files right. the same call to this Mbean when i do after the server starts its working fine.

                    Is there anything else which i may be doing wrong...?

                    Moin




                    • 7. Re: Problems in Using Local interface of entity bean in JMX

                      What are you trying to lookup and from which component?

                      -- Juha

                      • 8. Re: Problems in Using Local interface of entity bean in JMX
                        sugramoin

                        hey Juha thanx for all your help ...

                        Ok lemme present my scenario here...

                        I am using this MBean which is a Time Line Manager ( Kind of Scheduler) , this MBean deals wdirectly with one entity bean and athree session bean's.
                        Every thing is working fine when the server is already started all the calls to this Mbean are being executed the way i wanted.
                        But now a added a new feature in my application which deals with startup cleaning,, which is nothing but deleting few tuples from the database. I am using a entity bean to do that which is very common.

                        The components which ia looking up in the start() method of the mbean are an Entity Bean, and thats it. and am executing remove() method on the local interface of this entity bean.

                        well i am getting errors when i try to do a lookup it self of that entity bean.

                        this is the scene.

                        Please help me out here.
                        Moin

                        • 9.
                          sugramoin

                          This is my Mbean code, hope this will help figure out the problem.
                          I am getting an exception in getTimeLineHome() method when looking up an EJB.

                          waiting for help
                          Moin.

                          package com.k5networks.razorworks.module.razorwatch.central.management.scheduler;
                          
                          import com.k5networks.razorworks.module.razorwatch.central.management.scheduler.util.TimeLineMonitor;
                          import com.k5networks.razorworks.module.razorwatch.central.management.scheduler.util.ScheduleTask;
                          import com.k5networks.razorworks.module.razorwatch.central.management.scheduler.util.TaskPerformer;
                          import java.io.Serializable;
                          import java.util.Collection;
                          import java.util.Iterator;
                          import javax.naming.Context;
                          import javax.rmi.PortableRemoteObject;
                          import javax.naming.NamingException;
                          import javax.naming.InitialContext;
                          import javax.ejb.FinderException;
                          import javax.ejb.RemoveException;
                          import javax.ejb.CreateException;
                          import kommander.server.cs.entity.schedule.*;
                          import javax.management.MBeanServer;
                          import javax.management.ObjectName;
                          import kommander.vo.ScheduleVO;
                          import java.util.Vector;
                          import java.util.SortedSet;
                          import java.util.TreeSet;
                          import java.util.Calendar;
                          import java.util.Date;
                          import java.util.Hashtable;
                          /**
                           * Author: Naseeruddin.
                           *
                           * Copyright (c) 2003. Razor Eye. All Rights Reserved.
                           *
                           * This software is the confidential and proprietary information of Razor Eyes
                           * Technologies. You shall not disclose such Confidential Information and shall
                           * use it only in accordance with the terms of the source code license agreement
                           * you entered into with K5-Networks.
                           *
                           * TimeLineScheduler.java
                           * Nov 21, 2003
                           * com.k5networks.razorworks.module.razorwatch.central.management.scheduler
                           */
                          public class TimeLineScheduler extends org.jboss.system.ServiceMBeanSupport implements TimeLineSchedulerMBean, Serializable
                          {
                           // logger
                           final static org.jboss.logging.Logger logger = org.jboss.logging.Logger.getLogger(TimeLineScheduler.class.getName());
                           TimeLineMonitor monitor;
                           public TimeLineScheduler()
                           {
                           try
                           {
                           logger.info("Now binding the TimeLineScheduler ");
                           Context ctx = new javax.naming.InitialContext();
                           ctx.bind("TimeLineScheduler", this);
                           }
                           catch (Exception e)
                           {
                           logger.error("TimeLineScheduler-->> Something wrong in K5Store");
                           e.printStackTrace();
                           }
                           }
                           public ObjectName preRegister(MBeanServer server, ObjectName name) throws java.lang.Exception
                           {
                           logger.info("Adding Scheduler Mbean into JNDI service for lookups");
                           return new ObjectName(":service=TimeLineScheduler");
                           }
                           public void postRegister(java.lang.Boolean registrationDone)
                           {
                           }
                           public void preDeregister() throws java.lang.Exception
                           {
                           }
                           public void postDeregister()
                           {
                           }
                           public void start() throws Exception
                           {
                           logger.info("starting Scheduler MBean");
                           /*removeAllAged();
                           updateTimeLine();
                           interruptThread(generateCache());*/
                           }
                          
                          
                           public void stop()
                           {
                           logger.info("Stopping Scheduler MBean");
                           if (monitor != null)
                           {
                           monitor.tasks = new ScheduleTask[0];
                           monitor.destroy();
                           }
                           }
                           /**
                           * Given a Schedule's local interface it will generate all possible timmed trigers and adds them in TimeLineBean.
                           * @param shd_l
                           * @return
                           */
                           public boolean calculateNpopulateSchedule(Schedule_Local shd_l)
                           {
                           boolean job_done = false;
                           ScheduleVO vo = (ScheduleVO)shd_l.getProperties();
                           logger.info("Computing the time line instances for Schedule :- " + vo.getSchedule_key());
                           logger.info("The From time is :- " + new Date(vo.getFrom_date()));
                           logger.info("The To time is :- " + new Date(vo.getTo_date()));
                           logger.info("The Interval type is : - " + vo.getInterval_type());
                           logger.info("The Interval is :- " + vo.getInterval());
                           Calendar from_cal = Calendar.getInstance();
                           from_cal.setTimeInMillis(vo.getFrom_date());
                           Calendar to_cal = Calendar.getInstance();
                           to_cal.setTimeInMillis(vo.getTo_date());
                           Calendar current_cal = Calendar.getInstance();
                           current_cal.setTimeInMillis(from_cal.getTimeInMillis());
                           Calendar now_time = Calendar.getInstance();
                           Vector vec = new Vector();
                           if (vo.getInterval_type() == 2) // min
                           {
                           while (current_cal.before(to_cal))
                           {
                           now_time.setTimeInMillis(System.currentTimeMillis());
                           if (current_cal.after(now_time))
                           {
                           vec.addElement(new Long(current_cal.getTimeInMillis()));
                           }
                           current_cal.setTimeInMillis(current_cal.getTimeInMillis() + 60 * 1000 * vo.getInterval());
                           logger.info("adding By Minutes :- " + new Date(current_cal.getTimeInMillis()));
                           }
                           }
                           else
                           if (vo.getInterval_type() == 1) // hours
                           {
                           while (current_cal.before(to_cal))
                           {
                           now_time.setTimeInMillis(System.currentTimeMillis());
                           if (current_cal.after(now_time))
                           {
                           vec.addElement(new Long(current_cal.getTimeInMillis()));
                           }
                           current_cal.setTimeInMillis(current_cal.getTimeInMillis() + 60 * 60 * 1000 * vo.getInterval());
                           logger.info("adding By Hours :- " + new Date(current_cal.getTimeInMillis()));
                           }
                           }
                           logger.info("Total intervals computed = " + vec.size());
                           removeTimeLinesForSchedule(vo.getSchedule_key());
                           if (vo.isActive())
                           {
                           fillTimeLinesForSchedule(vo, vec);
                           }
                           return true;
                           }
                           /**
                           * Used for removing all TimeLines with schedule key key.
                           * @param key
                           * @return
                           */
                           public boolean removeTimeLinesForSchedules(Object[] keys)
                           {
                           logger.info("Removing a group of schedules from the TimeLineTable");
                           try
                           {
                           for (int i = 0; i < keys.length; i++)
                           {
                           removeTimeLinesForSchedule((String)keys);
                           }
                           return true;
                           }
                           catch (Exception e)
                           {
                           e.printStackTrace();
                           return false;
                           }
                           }
                           /**
                           * Used for removing all TimeLines with schedule key key.
                           * @param key
                           * @return
                           */
                           public boolean removeTimeLinesForSchedule(String key)
                           {
                           logger.info("Now removing updated schedule time line instances from TimeLine Bean for schedule key " + key);
                           try
                           {
                           // removing if there are any instances of schedule in time line.
                           Context ctx = new InitialContext();
                           TimeLine_LocalHome tl_lh = getTimeLineHome();
                           Collection col = tl_lh.findByScheduleKey(key);
                           Object[] col_array = col.toArray();
                           for (int index = 0; index < col_array.length; index++)
                           {
                           TimeLine_Local tl_l = (TimeLine_Local)col_array[index];
                           tl_l.remove();
                           }
                           return true;
                           }
                           catch (NamingException ne)
                           {
                           logger.debug(ne);
                           ne.printStackTrace();
                           return false;
                           }
                           catch (FinderException fe)
                           {
                           logger.debug(fe);
                           fe.printStackTrace();
                           return false;
                           }
                           catch (RemoveException re)
                           {
                           logger.debug(re);
                           re.printStackTrace();
                           return false;
                           }
                           }
                           /**
                           * TimeLine entities are added which were changed or newly added.
                           * @param vo
                           * @param die_times
                           * @return
                           */
                           public boolean fillTimeLinesForSchedule(ScheduleVO vo, Vector die_times)
                           {
                           logger.info("adding time line entries into TimeLine table with Schedule key = " + vo.getSchedule_key());
                           try
                           {
                           Context ctx = new InitialContext();
                           TimeLine_LocalHome tl_lh = getTimeLineHome();
                           for (final Iterator i = die_times.iterator(); i.hasNext();)
                           {
                           ScheduleTask st = new ScheduleTask(vo.getSchedule_key(), ((Long)i.next()).longValue(), "SCHEDULE");
                           tl_lh.create(st);
                           }
                           return true;
                           }
                           catch (NamingException ne)
                           {
                           logger.debug(ne);
                           ne.printStackTrace();
                           return false;
                           }
                           catch (CreateException ce)
                           {
                           logger.debug(ce);
                           ce.printStackTrace();
                           return false;
                           }
                           }
                          
                           /**
                           * Removes all the beans which have missed the schedule;
                           * reasons (a) Servers were down.
                           * (b) Servers were busy, processor allocation problems.
                           *
                           * @return
                           */
                           public boolean removeAllAged()
                           {
                           logger.info("Removing all aged time line schedules");
                           try
                           {
                           Context ctx = new InitialContext();
                           TimeLine_LocalHome tl_lh = getTimeLineHome();
                           Collection col = tl_lh.findAll();
                           Object[] col_array = col.toArray();
                           for (int index = 0; index < col_array.length; index++)
                           {
                           TimeLine_Local tl_l = (TimeLine_Local)col_array[index];
                           if (tl_l.getDie_time() < System.currentTimeMillis())
                           {
                           tl_l.remove();
                           }
                           }
                           return true;
                           }
                           catch (NamingException ne)
                           {
                           logger.debug(ne);
                           ne.printStackTrace();
                           return false;
                           }
                           catch (RemoveException re)
                           {
                           logger.debug(re);
                           re.printStackTrace();
                           return false;
                           }
                           catch (FinderException fe)
                           {
                           logger.debug(fe);
                           fe.printStackTrace();
                           return false;
                           }
                           }
                           /**
                           * called when ever there is a change in schedule.
                           * @return
                           */
                           public boolean updateTimeLine()
                           {
                           logger.info("Updating cache as there was a change made on schedule bean by Admin.");
                           boolean job_done = false;
                           try
                           {
                           Context ctx = new InitialContext();
                           Schedule_LocalHome shd_lh = (Schedule_LocalHome)ctx.lookup("java:comp/env/Schedule_Home");
                           //Schedule_LocalHome shd_lh = (Schedule_LocalHome)ctx.lookup("Schedule_Home");
                           Collection col = shd_lh.findAllChanged();
                           for (final Iterator i = col.iterator(); i.hasNext();)
                           {
                           Schedule_Local shd_l = (Schedule_Local)i.next();
                           calculateNpopulateSchedule(shd_l);
                           shd_l.setChanged(false);
                           }
                           return true;
                           }
                           catch (Exception e)
                           {
                           e.printStackTrace();
                           return false;
                           }
                           }
                           public ScheduleTask[] generateCache()
                           {
                           logger.info("Generating new cache.");
                           ScheduleTask[] sts = null;
                           try
                           {
                           Context ctx = new InitialContext();
                           TimeLine_LocalHome tl_lh = getTimeLineHome();
                           Collection col = tl_lh.findAll();
                           Vector vo_vec = new Vector();
                           for (final Iterator i = col.iterator(); i.hasNext();)
                           {
                           vo_vec.addElement(((TimeLine_Local)i.next()).properties());
                           }
                           SortedSet set = new TreeSet(vo_vec);
                           int cache_length = set.size();
                           if (cache_length > 100)
                           {
                           cache_length = 100;
                           }
                           sts = new ScheduleTask[cache_length];
                           int sts_index = 0;
                           for (final Iterator i = set.iterator(); i.hasNext();)
                           {
                           if (sts_index >= sts.length - 1)
                           break;
                           sts[sts_index] = (ScheduleTask)i.next();
                           logger.info("The value in the cache is :-" + sts[sts_index].getTask_key() + " The Die time is :- " + new Date(sts[sts_index].getDie_time()) + " At Index " + sts_index);
                           sts_index++;
                           }
                           return sts;
                           }
                           catch (NamingException ne)
                           {
                           logger.debug(ne);
                           ne.printStackTrace();
                           }
                           catch (FinderException fe)
                           {
                           logger.debug(fe);
                           fe.printStackTrace();
                           }
                           return null;
                           }
                           public void interruptThread(ScheduleTask[] sts)
                           {
                           if (sts == null)
                           {
                           logger.error("Could not interrupt the thread as the values passed after update are NULL");
                           return;
                           }
                           if (monitor == null || (!monitor.isAlive()))
                           {
                           logger.info("The Thread is not yet started; So Mbean is starting a new Thread with new Cache");
                           monitor = new TimeLineMonitor(sts);
                           monitor.start();
                           }
                           else
                           {
                           logger.info("The Thread is already alive; .`. Interrupting the Thread to work on new Cache.");
                           monitor.tasks = sts;
                           monitor.interrupt();
                           }
                           }
                           public TimeLine_LocalHome getTimeLineHome()
                           {
                           try
                           {
                           Context ctx = new InitialContext();
                           return (TimeLine_LocalHome)ctx.lookup("java:comp/env/TimeLine_Home");
                           //return (TimeLine_LocalHome)ctx.lookup("TimeLine_Home");
                           }
                           catch (Exception e)
                           {
                           e.printStackTrace();
                           }
                           return null;
                           }
                           }


                          • 10. NameNotFound env not bound
                            sugramoin

                            Exception NameNotFound XXXBean'sEjbName Not Bound is very common.......TRUE. (results if errors in ejbjar.xml file) but
                            Exception NameNotFound env NotBound is strange......at least to me

                            can any one tell me what are the possibilities of comming into a situation where your env variable is not bound.

                            if you want details can go back to previous postings its explained in detail.

                            Please respond........
                            Moin.