Re: MBean InitialContext() Tomcat query- pls help
On Tue, Dec 27, 2011 at 4:06 PM, Pid * p...@pidster.com wrote: On 27 Dec 2011, at 01:33, S B sbl...@gmail.com wrote: On Mon, Dec 26, 2011 at 3:28 PM, Pid * p...@pidster.com wrote: On 26 Dec 2011, at 09:50, S B sbl...@gmail.com wrote: On Sat, Dec 24, 2011 at 6:29 PM, Pid p...@pidster.com wrote: On 23/12/2011 04:57, S B wrote: On Thu, Dec 22, 2011 at 8:49 PM, Pid p...@pidster.com wrote: On 22/12/2011 10:34, Konstantin Kolinko wrote: 2011/12/20 S B sbl...@gmail.com: Hi, I created and deployed an MBean in my tomcat. It uses datasource to connect to DB. My questions is: When I create InitialContext() inside MBean's constructor and pass the envContext to DBManager class to lookup datasource it works fine. However when I create InitialContext() in DBManager class, it fails. IIRC what InitialContext() sees as its environment highly depends on what classloader is active. That is TCCL = Thread.getContextClassLoader(). So while it is run from within web application your TCCL = your webapp's classloader. When it is invoked from jconsole it might be a separate Thread, not related to your web application. Like he ^^^ said. :) p -- [key:62590808] Hi Pid/Konstantin, yes you are right. I just verified it. When it is invoked from jconsole, the classloader is: sun.misc.Launcher$AppClassLoader@61e63e3d and when it is run within a web application the clasloader is WebAppClassloader. So, how can I force it to use webapp classloader during new InitialContext() while invoking from jconsole One possible way is to reuse the initialContext created during server startup. (pass it as param during invocation from jconsole). Is there a smarter way ?? I am a bit concerned about how you are registering the bean inside the bean's own constructor. I am not clear on how you are subsequently unregistering that bean, before the reloading operation - and I am not at all clear what the purpose of reloading is anyway. Is there a reason that the MBean itself needs to be recreated? Bear in mind that you are attempting to re-initialise the MBean, while you are still using it. This does not seem like a good idea to me. I would suggest that you either have a separate Manager MBean that does the reloading, or just have the reload method call the actual code on the DB, without re-initialising the bean. p -- [key:62590808] Hi, un-registering of mbean doesn't happen until servlet's destroy method is called. Actually, registration of bean happen only once, ie during server startup. This time mbean's constructor is called and it is registered with MBean server. (I was wrong earlier when I said, constructor is called on each invocation of reload() method from jconsole. sorry about that. i was lill confused.) MBean is never re-created. It is created only once and registered only once. actual flow is: click reload() on jconsole gui. *it causes constructor of MBeanImpl to run. (verified from logs.)* -- *Wrong. pls disregard this statement.* calls reload() defined in MBeanImpl. calls DBManager.reload() inside DBManager.reload() it fails at InitialContext initContext = new InitialContext(); the exception is - javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory] OK, but what is the purpose of DBManager.reload()? p - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org Hi Pid, Marry Christmas !!! Purpose of DBManager.reload() is to load some application specific data from DB. Pls don't consider reload() as reload of MBean. reload() can better be renamed as loadData(). when I invoke reload() from jconsole my application is suppose to make a db connection and load app specific data from database. OK, so why not retain a reference to the DataSource that you're getting the connection from? p - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org yes. thats one possible workaround. I followed similar approach and retailed reference of Context (which i used to get datasource during invocation from jconsole). This approach works. And as Konstantin earlier said it is because of different class loaders that I can't do new InitialContext() during invocation from jconsole. *My question is: how can I force it to use webapp classloader during new InitialContext() while invoking from jconsole.* is there a way to do something like
Re: MBean InitialContext() Tomcat query- pls help
On 27 Dec 2011, at 11:16, S B sbl...@gmail.com wrote: On Tue, Dec 27, 2011 at 4:06 PM, Pid * p...@pidster.com wrote: On 27 Dec 2011, at 01:33, S B sbl...@gmail.com wrote: On Mon, Dec 26, 2011 at 3:28 PM, Pid * p...@pidster.com wrote: On 26 Dec 2011, at 09:50, S B sbl...@gmail.com wrote: On Sat, Dec 24, 2011 at 6:29 PM, Pid p...@pidster.com wrote: On 23/12/2011 04:57, S B wrote: On Thu, Dec 22, 2011 at 8:49 PM, Pid p...@pidster.com wrote: On 22/12/2011 10:34, Konstantin Kolinko wrote: 2011/12/20 S B sbl...@gmail.com: Hi, I created and deployed an MBean in my tomcat. It uses datasource to connect to DB. My questions is: When I create InitialContext() inside MBean's constructor and pass the envContext to DBManager class to lookup datasource it works fine. However when I create InitialContext() in DBManager class, it fails. IIRC what InitialContext() sees as its environment highly depends on what classloader is active. That is TCCL = Thread.getContextClassLoader(). So while it is run from within web application your TCCL = your webapp's classloader. When it is invoked from jconsole it might be a separate Thread, not related to your web application. Like he ^^^ said. :) p -- [key:62590808] Hi Pid/Konstantin, yes you are right. I just verified it. When it is invoked from jconsole, the classloader is: sun.misc.Launcher$AppClassLoader@61e63e3d and when it is run within a web application the clasloader is WebAppClassloader. So, how can I force it to use webapp classloader during new InitialContext() while invoking from jconsole One possible way is to reuse the initialContext created during server startup. (pass it as param during invocation from jconsole). Is there a smarter way ?? I am a bit concerned about how you are registering the bean inside the bean's own constructor. I am not clear on how you are subsequently unregistering that bean, before the reloading operation - and I am not at all clear what the purpose of reloading is anyway. Is there a reason that the MBean itself needs to be recreated? Bear in mind that you are attempting to re-initialise the MBean, while you are still using it. This does not seem like a good idea to me. I would suggest that you either have a separate Manager MBean that does the reloading, or just have the reload method call the actual code on the DB, without re-initialising the bean. p -- [key:62590808] Hi, un-registering of mbean doesn't happen until servlet's destroy method is called. Actually, registration of bean happen only once, ie during server startup. This time mbean's constructor is called and it is registered with MBean server. (I was wrong earlier when I said, constructor is called on each invocation of reload() method from jconsole. sorry about that. i was lill confused.) MBean is never re-created. It is created only once and registered only once. actual flow is: click reload() on jconsole gui. *it causes constructor of MBeanImpl to run. (verified from logs.)* -- *Wrong. pls disregard this statement.* calls reload() defined in MBeanImpl. calls DBManager.reload() inside DBManager.reload() it fails at InitialContext initContext = new InitialContext(); the exception is - javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory] OK, but what is the purpose of DBManager.reload()? p - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org Hi Pid, Marry Christmas !!! Purpose of DBManager.reload() is to load some application specific data from DB. Pls don't consider reload() as reload of MBean. reload() can better be renamed as loadData(). when I invoke reload() from jconsole my application is suppose to make a db connection and load app specific data from database. OK, so why not retain a reference to the DataSource that you're getting the connection from? p - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org yes. thats one possible workaround. I followed similar approach and retailed reference of Context (which i used to get datasource during invocation from jconsole). This approach works. And as Konstantin earlier said it is because of different class loaders that I can't do new InitialContext() during invocation from jconsole. *My question is: how can I force it to use webapp classloader during new InitialContext() while invoking from jconsole.* is there a way to do something like InitialContext.useClassLoader(webaappClassLoader) ? During server startup InitialContext() used
Re: MBean InitialContext() Tomcat query- pls help
On Tue, Dec 27, 2011 at 6:55 PM, Konstantin Kolinko knst.koli...@gmail.comwrote: 2011/12/27 S B sbl...@gmail.com: On Tue, Dec 27, 2011 at 4:53 PM, Pid * p...@pidster.com wrote: On 27 Dec 2011, at 11:16, S B sbl...@gmail.com wrote: On Tue, Dec 27, 2011 at 4:06 PM, Pid * p...@pidster.com wrote: On 27 Dec 2011, at 01:33, S B sbl...@gmail.com wrote: On Mon, Dec 26, 2011 at 3:28 PM, Pid * p...@pidster.com wrote: On 26 Dec 2011, at 09:50, S B sbl...@gmail.com wrote: On Sat, Dec 24, 2011 at 6:29 PM, Pid p...@pidster.com wrote: On 23/12/2011 04:57, S B wrote: On Thu, Dec 22, 2011 at 8:49 PM, Pid p...@pidster.com wrote: On 22/12/2011 10:34, Konstantin Kolinko wrote: 2011/12/20 S B sbl...@gmail.com: Hi, I created and deployed an MBean in my tomcat. It uses datasource to connect to DB. My questions is: When I create InitialContext() inside MBean's constructor and pass the envContext to DBManager class to lookup datasource it works fine. However when I create InitialContext() in DBManager class, it fails. IIRC what InitialContext() sees as its environment highly depends on what classloader is active. That is TCCL = Thread.getContextClassLoader(). So while it is run from within web application your TCCL = your webapp's classloader. When it is invoked from jconsole it might be a separate Thread, not related to your web application. Like he ^^^ said. :) p -- [key:62590808] Hi Pid/Konstantin, yes you are right. I just verified it. When it is invoked from jconsole, the classloader is: sun.misc.Launcher$AppClassLoader@61e63e3d and when it is run within a web application the clasloader is WebAppClassloader. So, how can I force it to use webapp classloader during new InitialContext() while invoking from jconsole One possible way is to reuse the initialContext created during server startup. (pass it as param during invocation from jconsole). Is there a smarter way ?? I am a bit concerned about how you are registering the bean inside the bean's own constructor. I am not clear on how you are subsequently unregistering that bean, before the reloading operation - and I am not at all clear what the purpose of reloading is anyway. Is there a reason that the MBean itself needs to be recreated? Bear in mind that you are attempting to re-initialise the MBean, while you are still using it. This does not seem like a good idea to me. I would suggest that you either have a separate Manager MBean that does the reloading, or just have the reload method call the actual code on the DB, without re-initialising the bean. p -- [key:62590808] Hi, un-registering of mbean doesn't happen until servlet's destroy method is called. Actually, registration of bean happen only once, ie during server startup. This time mbean's constructor is called and it is registered with MBean server. (I was wrong earlier when I said, constructor is called on each invocation of reload() method from jconsole. sorry about that. i was lill confused.) MBean is never re-created. It is created only once and registered only once. actual flow is: click reload() on jconsole gui. *it causes constructor of MBeanImpl to run. (verified from logs.)* -- *Wrong. pls disregard this statement.* calls reload() defined in MBeanImpl. calls DBManager.reload() inside DBManager.reload() it fails at InitialContext initContext = new InitialContext(); the exception is - javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory] OK, but what is the purpose of DBManager.reload()? p - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org Hi Pid, Marry Christmas !!! Purpose of DBManager.reload() is to load some application specific data from DB. Pls don't consider reload() as reload of MBean. reload() can better be renamed as loadData(). when I invoke reload() from jconsole my application is suppose to make a db connection and load app specific data from database. OK, so why not retain a reference to the DataSource that you're getting the connection from? p - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org yes. thats one possible workaround. I followed similar
Re: MBean InitialContext() Tomcat query- pls help
On 27 Dec 2011, at 01:33, S B sbl...@gmail.com wrote: On Mon, Dec 26, 2011 at 3:28 PM, Pid * p...@pidster.com wrote: On 26 Dec 2011, at 09:50, S B sbl...@gmail.com wrote: On Sat, Dec 24, 2011 at 6:29 PM, Pid p...@pidster.com wrote: On 23/12/2011 04:57, S B wrote: On Thu, Dec 22, 2011 at 8:49 PM, Pid p...@pidster.com wrote: On 22/12/2011 10:34, Konstantin Kolinko wrote: 2011/12/20 S B sbl...@gmail.com: Hi, I created and deployed an MBean in my tomcat. It uses datasource to connect to DB. My questions is: When I create InitialContext() inside MBean's constructor and pass the envContext to DBManager class to lookup datasource it works fine. However when I create InitialContext() in DBManager class, it fails. IIRC what InitialContext() sees as its environment highly depends on what classloader is active. That is TCCL = Thread.getContextClassLoader(). So while it is run from within web application your TCCL = your webapp's classloader. When it is invoked from jconsole it might be a separate Thread, not related to your web application. Like he ^^^ said. :) p -- [key:62590808] Hi Pid/Konstantin, yes you are right. I just verified it. When it is invoked from jconsole, the classloader is: sun.misc.Launcher$AppClassLoader@61e63e3d and when it is run within a web application the clasloader is WebAppClassloader. So, how can I force it to use webapp classloader during new InitialContext() while invoking from jconsole One possible way is to reuse the initialContext created during server startup. (pass it as param during invocation from jconsole). Is there a smarter way ?? I am a bit concerned about how you are registering the bean inside the bean's own constructor. I am not clear on how you are subsequently unregistering that bean, before the reloading operation - and I am not at all clear what the purpose of reloading is anyway. Is there a reason that the MBean itself needs to be recreated? Bear in mind that you are attempting to re-initialise the MBean, while you are still using it. This does not seem like a good idea to me. I would suggest that you either have a separate Manager MBean that does the reloading, or just have the reload method call the actual code on the DB, without re-initialising the bean. p -- [key:62590808] Hi, un-registering of mbean doesn't happen until servlet's destroy method is called. Actually, registration of bean happen only once, ie during server startup. This time mbean's constructor is called and it is registered with MBean server. (I was wrong earlier when I said, constructor is called on each invocation of reload() method from jconsole. sorry about that. i was lill confused.) MBean is never re-created. It is created only once and registered only once. actual flow is: click reload() on jconsole gui. *it causes constructor of MBeanImpl to run. (verified from logs.)* -- *Wrong. pls disregard this statement.* calls reload() defined in MBeanImpl. calls DBManager.reload() inside DBManager.reload() it fails at InitialContext initContext = new InitialContext(); the exception is - javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory] OK, but what is the purpose of DBManager.reload()? p - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org Hi Pid, Marry Christmas !!! Purpose of DBManager.reload() is to load some application specific data from DB. Pls don't consider reload() as reload of MBean. reload() can better be renamed as loadData(). when I invoke reload() from jconsole my application is suppose to make a db connection and load app specific data from database. OK, so why not retain a reference to the DataSource that you're getting the connection from? p - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: MBean InitialContext() Tomcat query- pls help
2011/12/27 S B sbl...@gmail.com: On Tue, Dec 27, 2011 at 4:53 PM, Pid * p...@pidster.com wrote: On 27 Dec 2011, at 11:16, S B sbl...@gmail.com wrote: On Tue, Dec 27, 2011 at 4:06 PM, Pid * p...@pidster.com wrote: On 27 Dec 2011, at 01:33, S B sbl...@gmail.com wrote: On Mon, Dec 26, 2011 at 3:28 PM, Pid * p...@pidster.com wrote: On 26 Dec 2011, at 09:50, S B sbl...@gmail.com wrote: On Sat, Dec 24, 2011 at 6:29 PM, Pid p...@pidster.com wrote: On 23/12/2011 04:57, S B wrote: On Thu, Dec 22, 2011 at 8:49 PM, Pid p...@pidster.com wrote: On 22/12/2011 10:34, Konstantin Kolinko wrote: 2011/12/20 S B sbl...@gmail.com: Hi, I created and deployed an MBean in my tomcat. It uses datasource to connect to DB. My questions is: When I create InitialContext() inside MBean's constructor and pass the envContext to DBManager class to lookup datasource it works fine. However when I create InitialContext() in DBManager class, it fails. IIRC what InitialContext() sees as its environment highly depends on what classloader is active. That is TCCL = Thread.getContextClassLoader(). So while it is run from within web application your TCCL = your webapp's classloader. When it is invoked from jconsole it might be a separate Thread, not related to your web application. Like he ^^^ said. :) p -- [key:62590808] Hi Pid/Konstantin, yes you are right. I just verified it. When it is invoked from jconsole, the classloader is: sun.misc.Launcher$AppClassLoader@61e63e3d and when it is run within a web application the clasloader is WebAppClassloader. So, how can I force it to use webapp classloader during new InitialContext() while invoking from jconsole One possible way is to reuse the initialContext created during server startup. (pass it as param during invocation from jconsole). Is there a smarter way ?? I am a bit concerned about how you are registering the bean inside the bean's own constructor. I am not clear on how you are subsequently unregistering that bean, before the reloading operation - and I am not at all clear what the purpose of reloading is anyway. Is there a reason that the MBean itself needs to be recreated? Bear in mind that you are attempting to re-initialise the MBean, while you are still using it. This does not seem like a good idea to me. I would suggest that you either have a separate Manager MBean that does the reloading, or just have the reload method call the actual code on the DB, without re-initialising the bean. p -- [key:62590808] Hi, un-registering of mbean doesn't happen until servlet's destroy method is called. Actually, registration of bean happen only once, ie during server startup. This time mbean's constructor is called and it is registered with MBean server. (I was wrong earlier when I said, constructor is called on each invocation of reload() method from jconsole. sorry about that. i was lill confused.) MBean is never re-created. It is created only once and registered only once. actual flow is: click reload() on jconsole gui. *it causes constructor of MBeanImpl to run. (verified from logs.)* -- *Wrong. pls disregard this statement.* calls reload() defined in MBeanImpl. calls DBManager.reload() inside DBManager.reload() it fails at InitialContext initContext = new InitialContext(); the exception is - javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory] OK, but what is the purpose of DBManager.reload()? p - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org Hi Pid, Marry Christmas !!! Purpose of DBManager.reload() is to load some application specific data from DB. Pls don't consider reload() as reload of MBean. reload() can better be renamed as loadData(). when I invoke reload() from jconsole my application is suppose to make a db connection and load app specific data from database. OK, so why not retain a reference to the DataSource that you're getting the connection from? p - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org yes. thats one possible workaround. I followed similar approach and retailed reference of Context (which i used to get datasource during invocation from jconsole). This approach works. And as Konstantin earlier said it is because of different class loaders that I can't do new InitialContext() during invocation from
Re: MBean InitialContext() Tomcat query- pls help
On Tue, Dec 27, 2011 at 4:53 PM, Pid * p...@pidster.com wrote: On 27 Dec 2011, at 11:16, S B sbl...@gmail.com wrote: On Tue, Dec 27, 2011 at 4:06 PM, Pid * p...@pidster.com wrote: On 27 Dec 2011, at 01:33, S B sbl...@gmail.com wrote: On Mon, Dec 26, 2011 at 3:28 PM, Pid * p...@pidster.com wrote: On 26 Dec 2011, at 09:50, S B sbl...@gmail.com wrote: On Sat, Dec 24, 2011 at 6:29 PM, Pid p...@pidster.com wrote: On 23/12/2011 04:57, S B wrote: On Thu, Dec 22, 2011 at 8:49 PM, Pid p...@pidster.com wrote: On 22/12/2011 10:34, Konstantin Kolinko wrote: 2011/12/20 S B sbl...@gmail.com: Hi, I created and deployed an MBean in my tomcat. It uses datasource to connect to DB. My questions is: When I create InitialContext() inside MBean's constructor and pass the envContext to DBManager class to lookup datasource it works fine. However when I create InitialContext() in DBManager class, it fails. IIRC what InitialContext() sees as its environment highly depends on what classloader is active. That is TCCL = Thread.getContextClassLoader(). So while it is run from within web application your TCCL = your webapp's classloader. When it is invoked from jconsole it might be a separate Thread, not related to your web application. Like he ^^^ said. :) p -- [key:62590808] Hi Pid/Konstantin, yes you are right. I just verified it. When it is invoked from jconsole, the classloader is: sun.misc.Launcher$AppClassLoader@61e63e3d and when it is run within a web application the clasloader is WebAppClassloader. So, how can I force it to use webapp classloader during new InitialContext() while invoking from jconsole One possible way is to reuse the initialContext created during server startup. (pass it as param during invocation from jconsole). Is there a smarter way ?? I am a bit concerned about how you are registering the bean inside the bean's own constructor. I am not clear on how you are subsequently unregistering that bean, before the reloading operation - and I am not at all clear what the purpose of reloading is anyway. Is there a reason that the MBean itself needs to be recreated? Bear in mind that you are attempting to re-initialise the MBean, while you are still using it. This does not seem like a good idea to me. I would suggest that you either have a separate Manager MBean that does the reloading, or just have the reload method call the actual code on the DB, without re-initialising the bean. p -- [key:62590808] Hi, un-registering of mbean doesn't happen until servlet's destroy method is called. Actually, registration of bean happen only once, ie during server startup. This time mbean's constructor is called and it is registered with MBean server. (I was wrong earlier when I said, constructor is called on each invocation of reload() method from jconsole. sorry about that. i was lill confused.) MBean is never re-created. It is created only once and registered only once. actual flow is: click reload() on jconsole gui. *it causes constructor of MBeanImpl to run. (verified from logs.)* -- *Wrong. pls disregard this statement.* calls reload() defined in MBeanImpl. calls DBManager.reload() inside DBManager.reload() it fails at InitialContext initContext = new InitialContext(); the exception is - javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory] OK, but what is the purpose of DBManager.reload()? p - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org Hi Pid, Marry Christmas !!! Purpose of DBManager.reload() is to load some application specific data from DB. Pls don't consider reload() as reload of MBean. reload() can better be renamed as loadData(). when I invoke reload() from jconsole my application is suppose to make a db connection and load app specific data from database. OK, so why not retain a reference to the DataSource that you're getting the connection from? p - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org yes. thats one possible workaround. I followed similar approach and retailed reference of Context (which i used to get datasource during invocation from jconsole). This approach works. And as Konstantin earlier said it is because of different class loaders that I can't do new InitialContext() during invocation from jconsole. *My question is: how
Re: MBean InitialContext() Tomcat query- pls help
On Sat, Dec 24, 2011 at 6:29 PM, Pid p...@pidster.com wrote: On 23/12/2011 04:57, S B wrote: On Thu, Dec 22, 2011 at 8:49 PM, Pid p...@pidster.com wrote: On 22/12/2011 10:34, Konstantin Kolinko wrote: 2011/12/20 S B sbl...@gmail.com: Hi, I created and deployed an MBean in my tomcat. It uses datasource to connect to DB. My questions is: When I create InitialContext() inside MBean's constructor and pass the envContext to DBManager class to lookup datasource it works fine. However when I create InitialContext() in DBManager class, it fails. IIRC what InitialContext() sees as its environment highly depends on what classloader is active. That is TCCL = Thread.getContextClassLoader(). So while it is run from within web application your TCCL = your webapp's classloader. When it is invoked from jconsole it might be a separate Thread, not related to your web application. Like he ^^^ said. :) p -- [key:62590808] Hi Pid/Konstantin, yes you are right. I just verified it. When it is invoked from jconsole, the classloader is: sun.misc.Launcher$AppClassLoader@61e63e3d and when it is run within a web application the clasloader is WebAppClassloader. So, how can I force it to use webapp classloader during new InitialContext() while invoking from jconsole One possible way is to reuse the initialContext created during server startup. (pass it as param during invocation from jconsole). Is there a smarter way ?? I am a bit concerned about how you are registering the bean inside the bean's own constructor. I am not clear on how you are subsequently unregistering that bean, before the reloading operation - and I am not at all clear what the purpose of reloading is anyway. Is there a reason that the MBean itself needs to be recreated? Bear in mind that you are attempting to re-initialise the MBean, while you are still using it. This does not seem like a good idea to me. I would suggest that you either have a separate Manager MBean that does the reloading, or just have the reload method call the actual code on the DB, without re-initialising the bean. p -- [key:62590808] Hi, un-registering of mbean doesn't happen until servlet's destroy method is called. Actually, registration of bean happen only once, ie during server startup. This time mbean's constructor is called and it is registered with MBean server. (I was wrong earlier when I said, constructor is called on each invocation of reload() method from jconsole. sorry about that. i was lill confused.) MBean is never re-created. It is created only once and registered only once. actual flow is: click reload() on jconsole gui. *it causes constructor of MBeanImpl to run. (verified from logs.)* -- *Wrong. pls disregard this statement.* calls reload() defined in MBeanImpl. calls DBManager.reload() inside DBManager.reload() it fails at InitialContext initContext = new InitialContext(); the exception is - javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory]
Re: MBean InitialContext() Tomcat query- pls help
On 26 Dec 2011, at 09:50, S B sbl...@gmail.com wrote: On Sat, Dec 24, 2011 at 6:29 PM, Pid p...@pidster.com wrote: On 23/12/2011 04:57, S B wrote: On Thu, Dec 22, 2011 at 8:49 PM, Pid p...@pidster.com wrote: On 22/12/2011 10:34, Konstantin Kolinko wrote: 2011/12/20 S B sbl...@gmail.com: Hi, I created and deployed an MBean in my tomcat. It uses datasource to connect to DB. My questions is: When I create InitialContext() inside MBean's constructor and pass the envContext to DBManager class to lookup datasource it works fine. However when I create InitialContext() in DBManager class, it fails. IIRC what InitialContext() sees as its environment highly depends on what classloader is active. That is TCCL = Thread.getContextClassLoader(). So while it is run from within web application your TCCL = your webapp's classloader. When it is invoked from jconsole it might be a separate Thread, not related to your web application. Like he ^^^ said. :) p -- [key:62590808] Hi Pid/Konstantin, yes you are right. I just verified it. When it is invoked from jconsole, the classloader is: sun.misc.Launcher$AppClassLoader@61e63e3d and when it is run within a web application the clasloader is WebAppClassloader. So, how can I force it to use webapp classloader during new InitialContext() while invoking from jconsole One possible way is to reuse the initialContext created during server startup. (pass it as param during invocation from jconsole). Is there a smarter way ?? I am a bit concerned about how you are registering the bean inside the bean's own constructor. I am not clear on how you are subsequently unregistering that bean, before the reloading operation - and I am not at all clear what the purpose of reloading is anyway. Is there a reason that the MBean itself needs to be recreated? Bear in mind that you are attempting to re-initialise the MBean, while you are still using it. This does not seem like a good idea to me. I would suggest that you either have a separate Manager MBean that does the reloading, or just have the reload method call the actual code on the DB, without re-initialising the bean. p -- [key:62590808] Hi, un-registering of mbean doesn't happen until servlet's destroy method is called. Actually, registration of bean happen only once, ie during server startup. This time mbean's constructor is called and it is registered with MBean server. (I was wrong earlier when I said, constructor is called on each invocation of reload() method from jconsole. sorry about that. i was lill confused.) MBean is never re-created. It is created only once and registered only once. actual flow is: click reload() on jconsole gui. *it causes constructor of MBeanImpl to run. (verified from logs.)* -- *Wrong. pls disregard this statement.* calls reload() defined in MBeanImpl. calls DBManager.reload() inside DBManager.reload() it fails at InitialContext initContext = new InitialContext(); the exception is - javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory] OK, but what is the purpose of DBManager.reload()? p - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: MBean InitialContext() Tomcat query- pls help
On Mon, Dec 26, 2011 at 3:28 PM, Pid * p...@pidster.com wrote: On 26 Dec 2011, at 09:50, S B sbl...@gmail.com wrote: On Sat, Dec 24, 2011 at 6:29 PM, Pid p...@pidster.com wrote: On 23/12/2011 04:57, S B wrote: On Thu, Dec 22, 2011 at 8:49 PM, Pid p...@pidster.com wrote: On 22/12/2011 10:34, Konstantin Kolinko wrote: 2011/12/20 S B sbl...@gmail.com: Hi, I created and deployed an MBean in my tomcat. It uses datasource to connect to DB. My questions is: When I create InitialContext() inside MBean's constructor and pass the envContext to DBManager class to lookup datasource it works fine. However when I create InitialContext() in DBManager class, it fails. IIRC what InitialContext() sees as its environment highly depends on what classloader is active. That is TCCL = Thread.getContextClassLoader(). So while it is run from within web application your TCCL = your webapp's classloader. When it is invoked from jconsole it might be a separate Thread, not related to your web application. Like he ^^^ said. :) p -- [key:62590808] Hi Pid/Konstantin, yes you are right. I just verified it. When it is invoked from jconsole, the classloader is: sun.misc.Launcher$AppClassLoader@61e63e3d and when it is run within a web application the clasloader is WebAppClassloader. So, how can I force it to use webapp classloader during new InitialContext() while invoking from jconsole One possible way is to reuse the initialContext created during server startup. (pass it as param during invocation from jconsole). Is there a smarter way ?? I am a bit concerned about how you are registering the bean inside the bean's own constructor. I am not clear on how you are subsequently unregistering that bean, before the reloading operation - and I am not at all clear what the purpose of reloading is anyway. Is there a reason that the MBean itself needs to be recreated? Bear in mind that you are attempting to re-initialise the MBean, while you are still using it. This does not seem like a good idea to me. I would suggest that you either have a separate Manager MBean that does the reloading, or just have the reload method call the actual code on the DB, without re-initialising the bean. p -- [key:62590808] Hi, un-registering of mbean doesn't happen until servlet's destroy method is called. Actually, registration of bean happen only once, ie during server startup. This time mbean's constructor is called and it is registered with MBean server. (I was wrong earlier when I said, constructor is called on each invocation of reload() method from jconsole. sorry about that. i was lill confused.) MBean is never re-created. It is created only once and registered only once. actual flow is: click reload() on jconsole gui. *it causes constructor of MBeanImpl to run. (verified from logs.)* -- *Wrong. pls disregard this statement.* calls reload() defined in MBeanImpl. calls DBManager.reload() inside DBManager.reload() it fails at InitialContext initContext = new InitialContext(); the exception is - javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory] OK, but what is the purpose of DBManager.reload()? p - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org Hi Pid, Marry Christmas !!! Purpose of DBManager.reload() is to load some application specific data from DB. Pls don't consider reload() as reload of MBean. reload() can better be renamed as loadData(). when I invoke reload() from jconsole my application is suppose to make a db connection and load app specific data from database.
Re: MBean InitialContext() Tomcat query- pls help
On 23/12/2011 04:57, S B wrote: On Thu, Dec 22, 2011 at 8:49 PM, Pid p...@pidster.com wrote: On 22/12/2011 10:34, Konstantin Kolinko wrote: 2011/12/20 S B sbl...@gmail.com: Hi, I created and deployed an MBean in my tomcat. It uses datasource to connect to DB. My questions is: When I create InitialContext() inside MBean's constructor and pass the envContext to DBManager class to lookup datasource it works fine. However when I create InitialContext() in DBManager class, it fails. IIRC what InitialContext() sees as its environment highly depends on what classloader is active. That is TCCL = Thread.getContextClassLoader(). So while it is run from within web application your TCCL = your webapp's classloader. When it is invoked from jconsole it might be a separate Thread, not related to your web application. Like he ^^^ said. :) p -- [key:62590808] Hi Pid/Konstantin, yes you are right. I just verified it. When it is invoked from jconsole, the classloader is: sun.misc.Launcher$AppClassLoader@61e63e3d and when it is run within a web application the clasloader is WebAppClassloader. So, how can I force it to use webapp classloader during new InitialContext() while invoking from jconsole One possible way is to reuse the initialContext created during server startup. (pass it as param during invocation from jconsole). Is there a smarter way ?? I am a bit concerned about how you are registering the bean inside the bean's own constructor. I am not clear on how you are subsequently unregistering that bean, before the reloading operation - and I am not at all clear what the purpose of reloading is anyway. Is there a reason that the MBean itself needs to be recreated? Bear in mind that you are attempting to re-initialise the MBean, while you are still using it. This does not seem like a good idea to me. I would suggest that you either have a separate Manager MBean that does the reloading, or just have the reload method call the actual code on the DB, without re-initialising the bean. p -- [key:62590808] signature.asc Description: OpenPGP digital signature
Re: MBean InitialContext() Tomcat query- pls help
2011/12/20 S B sbl...@gmail.com: Hi, I created and deployed an MBean in my tomcat. It uses datasource to connect to DB. My questions is: When I create InitialContext() inside MBean's constructor and pass the envContext to DBManager class to lookup datasource it works fine. However when I create InitialContext() in DBManager class, it fails. IIRC what InitialContext() sees as its environment highly depends on what classloader is active. That is TCCL = Thread.getContextClassLoader(). So while it is run from within web application your TCCL = your webapp's classloader. When it is invoked from jconsole it might be a separate Thread, not related to your web application. Best regards, Konstantin Kolinko - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: MBean InitialContext() Tomcat query- pls help
On 22/12/2011 10:34, Konstantin Kolinko wrote: 2011/12/20 S B sbl...@gmail.com: Hi, I created and deployed an MBean in my tomcat. It uses datasource to connect to DB. My questions is: When I create InitialContext() inside MBean's constructor and pass the envContext to DBManager class to lookup datasource it works fine. However when I create InitialContext() in DBManager class, it fails. IIRC what InitialContext() sees as its environment highly depends on what classloader is active. That is TCCL = Thread.getContextClassLoader(). So while it is run from within web application your TCCL = your webapp's classloader. When it is invoked from jconsole it might be a separate Thread, not related to your web application. Like he ^^^ said. :) p -- [key:62590808] signature.asc Description: OpenPGP digital signature
Re: MBean InitialContext() Tomcat query- pls help
On Thu, Dec 22, 2011 at 8:49 PM, Pid p...@pidster.com wrote: On 22/12/2011 10:34, Konstantin Kolinko wrote: 2011/12/20 S B sbl...@gmail.com: Hi, I created and deployed an MBean in my tomcat. It uses datasource to connect to DB. My questions is: When I create InitialContext() inside MBean's constructor and pass the envContext to DBManager class to lookup datasource it works fine. However when I create InitialContext() in DBManager class, it fails. IIRC what InitialContext() sees as its environment highly depends on what classloader is active. That is TCCL = Thread.getContextClassLoader(). So while it is run from within web application your TCCL = your webapp's classloader. When it is invoked from jconsole it might be a separate Thread, not related to your web application. Like he ^^^ said. :) p -- [key:62590808] Hi Pid/Konstantin, yes you are right. I just verified it. When it is invoked from jconsole, the classloader is: sun.misc.Launcher$AppClassLoader@61e63e3d and when it is run within a web application the clasloader is WebAppClassloader. So, how can I force it to use webapp classloader during new InitialContext() while invoking from jconsole One possible way is to reuse the initialContext created during server startup. (pass it as param during invocation from jconsole). Is there a smarter way ?? Thanks,
Re: MBean InitialContext() Tomcat query- pls help
On Wed, Dec 21, 2011 at 12:09 AM, Pid * p...@pidster.com wrote: On 20 Dec 2011, at 15:47, S B sbl...@gmail.com wrote: On Tue, Dec 20, 2011 at 7:00 PM, Pid p...@pidster.com wrote: On 20/12/2011 11:57, S B wrote: MBeanImpl code is packaged as a war and deployed in tomcat along with it's mbeans-descriptor.xml I am not using ServletContextListener in my code. (mbean registration is done inside constructor). Right, but what is calling the constructor? constructor is run during server startup hook. MBean is registered during that time . This is like pulling teeth. What exactly is the server startup hook? Mbean is registered using below code (in constructor): MBeanServer server = getServer(); server.registerMBean(*this*, new ObjectName(StoreServerSyncAndReloadConstants.MBEAN_NAME) When we invoke reload() from jconsole, it causes class to load and call How can it do that if it needs to be loaded already for the MBean to work? How are you unloading it? it's public constructor and create instance before calling reload() on that instance. Right. I can't make any sense out of the above. During reload() constructor is called again and registration code runs again. So you re-register the Mbean that you're using to load the same MBean? p Sorry about the confusion. I'll try to put in a more clear way. Here is the complete flow from beginning. There is a *ConfiguratorLoadingServlet* which loads and initializes on tomcat startup. *load-on-startup* in *web.xml* causes that to happen. In *init()* method of *ConfiguratorLoadingServlet* it does new *MBeanImpl() *which causes mbean registration code inside its constructor to run. After that in same *init() *method it calls *DBManager.reload()* which causes config properties to load from db during startup. DBManager.reload() code is like this: { InitialContext initContext = new InitialContext(); Context context = (Context) initContext.lookup(java:comp/env); BasicDataSource ds = (BasicDataSource) context.lookup(jdbc/ + dataSourceName); // use ds to connect to db and get records. } MBeanImpl constructor code is like this: public MBeanImpl() { try { MBeanServer server = getServer(); server.registerMBean(this, new ObjectName(StoreServerSyncAndReloadConstants.MBEAN_NAME)); } catch (Exception e) { logger.error(Error in Rgistering the Configurator MBean,e); logger.warn(Configurator is NOT Available through JMX); } } in destroy() method of *ConfiguratorLoadingServlet* it does the unregisterMBean. *Above flow works fine during tomcat startup. records are loaded successfully. * *Problem shows up when I invoke reload() from jconsole gui.* Here is the flow that fails. click reload() on jconsole gui. it causes constructor of MBeanImpl to run. (verified from logs.) calls reload() defined in MBeanImpl. calls DBManager.reload() inside DBManager.reload() it fails at InitialContext initContext = new InitialContext(); the exception is - javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory] *Workaround : * I modified MBeanImpl() constructor like this: private Context envContext = null; public MBeanImpl() { InitialContext initialContext; try { initialContext = new InitialContext(); envContext = (Context) initialContext.lookup(java:/comp/env); } catch (NamingException e1) { e1.printStackTrace(); } try { MBeanServer server = getServer(); server.registerMBean(this, new ObjectName(StoreServerSyncAndReloadConstants.MBEAN_NAME)); } catch (Exception e) { logger.error(Error in Rgistering the Configurator MBean,e); logger.warn(Configurator is NOT Available through JMX); } } Passed envContext as a parameter to DBManager(envContext) Modified DBManager code looks like this : DBManager.reload(Context envContext) { BasicDataSource ds = (BasicDataSource) envContext.lookup(jdbc/ + dataSourceName); // use ds to connect to db and get records. } Now if I invoke reload() from jconsole it works fine. The flow goes as follows: click reload() on jconsole gui causes constructor of MBeanImpl to run where it does new InitialContext() invokes reload() where it passes envContext object as parameter to DBManager.reload(envContext) DBManager uses passed in object to lookup datasource flow completes with success. *My question is : when I invoked reload() from jconsole , why it failed when it tried to create new InitialContext() in DBManager. But when same reload() is invoked during tomcat startup it succeeds. Another question: Is there a better workaround to this problem?* (I am using
MBean InitialContext() Tomcat query- pls help
Hi, I created and deployed an MBean in my tomcat. It uses datasource to connect to DB. My questions is: When I create InitialContext() inside MBean's constructor and pass the envContext to DBManager class to lookup datasource it works fine. However when I create InitialContext() in DBManager class, it fails. Is it necessary to create InitialContext() during loading of MBean (either in ContextListener class or inside MBean constructor). When I did new InitialContext() in my DBManager class which is called from hello method of MBean it failed with below exception: avax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory] I invoked hello method of MBean from JConsole. Please let me know is it Tomcat specific? or same behavior is seen across all app servers. Also, What difference does it make if I create InitialContext inside MBean's constructor or in some other class at a later point of time. Thanks Ravi
Re: MBean InitialContext() Tomcat query- pls help
On 20 Dec 2011, at 11:02, S B sbl...@gmail.com wrote: Hi, I created and deployed an MBean in my tomcat. It uses datasource to connect to DB. Which version of Java? Tomcat? My questions is: When I create InitialContext() inside MBean's constructor and pass the envContext to DBManager class to lookup datasource it works fine. However when I create InitialContext() in DBManager class, it fails. Is it necessary to create InitialContext() during loading of MBean (either in ContextListener class or inside MBean constructor). It depends on where you run the code. You haven't told us this. Can you post a code example. p When I did new InitialContext() in my DBManager class which is called from hello method of MBean it failed with below exception: avax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory] I invoked hello method of MBean from JConsole. Please let me know is it Tomcat specific? or same behavior is seen across all app servers. Also, What difference does it make if I create InitialContext inside MBean's constructor or in some other class at a later point of time. Thanks Ravi - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: MBean InitialContext() Tomcat query- pls help
Hi, I am using : Server version: Apache Tomcat/6.0.32 OS Name:Mac OS X OS Version: 10.6.8 Architecture: x86_64 JVM Version:1.6.0_29-b11-402-10M3527 Thanks, Ravi On Tue, Dec 20, 2011 at 4:52 PM, Pid * p...@pidster.com wrote: On 20 Dec 2011, at 11:02, S B sbl...@gmail.com wrote: Hi, I created and deployed an MBean in my tomcat. It uses datasource to connect to DB. Which version of Java? Tomcat? My questions is: When I create InitialContext() inside MBean's constructor and pass the envContext to DBManager class to lookup datasource it works fine. However when I create InitialContext() in DBManager class, it fails. Is it necessary to create InitialContext() during loading of MBean (either in ContextListener class or inside MBean constructor). It depends on where you run the code. You haven't told us this. Can you post a code example. p When I did new InitialContext() in my DBManager class which is called from hello method of MBean it failed with below exception: avax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory] I invoked hello method of MBean from JConsole. Please let me know is it Tomcat specific? or same behavior is seen across all app servers. Also, What difference does it make if I create InitialContext inside MBean's constructor or in some other class at a later point of time. Thanks Ravi - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: MBean InitialContext() Tomcat query- pls help
Code Sample that fails with exception(I am invoking reload() from jconsole ): class MBeanImpl implements MBeanInterface{ public MBeanImpl{ // code to register this bean. } @Override public void reload() { DBManager.loadFromDB(); } } class DBManager{ public static void loadFromDB(){ InitialContext initContext = new InitialContext(); // here it fails with exception avax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root // exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory] Context context = (Context) initContext.lookup(java:comp/env); logger.info(context found + context); BasicDataSource ds = (BasicDataSource) context.lookup(jdbc/ + dataSourceName); ... ... } } - Code Sample that works: class MBeanImpl implements MBeanInterface{ private Context envContext = null; public MBeanImpl{ InitialContext initialContext = new InitialContext(); envContext = (Context) initialContext.lookup(java:/comp/env); // code to register this bean. } @Override public void reload() { DBManager.loadFromDB(envContext); // passed context object obtained in constructor } } class DBManager{ public static void loadFromDB(Context context){ BasicDataSource ds = (BasicDataSource) context.lookup(jdbc/ + dataSourceName); // works fine as I am not creating new InitialContext here. ... ... } } On Tue, Dec 20, 2011 at 4:59 PM, S B sbl...@gmail.com wrote: Hi, I am using : Server version: Apache Tomcat/6.0.32 OS Name:Mac OS X OS Version: 10.6.8 Architecture: x86_64 JVM Version:1.6.0_29-b11-402-10M3527 Thanks, Ravi On Tue, Dec 20, 2011 at 4:52 PM, Pid * p...@pidster.com wrote: On 20 Dec 2011, at 11:02, S B sbl...@gmail.com wrote: Hi, I created and deployed an MBean in my tomcat. It uses datasource to connect to DB. Which version of Java? Tomcat? My questions is: When I create InitialContext() inside MBean's constructor and pass the envContext to DBManager class to lookup datasource it works fine. However when I create InitialContext() in DBManager class, it fails. Is it necessary to create InitialContext() during loading of MBean (either in ContextListener class or inside MBean constructor). It depends on where you run the code. You haven't told us this. Can you post a code example. p When I did new InitialContext() in my DBManager class which is called from hello method of MBean it failed with below exception: avax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory] I invoked hello method of MBean from JConsole. Please let me know is it Tomcat specific? or same behavior is seen across all app servers. Also, What difference does it make if I create InitialContext inside MBean's constructor or in some other class at a later point of time. Thanks Ravi - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: MBean InitialContext() Tomcat query- pls help
On 20/12/2011 11:29, S B wrote: Hi, I am using : Server version: Apache Tomcat/6.0.32 OS Name:Mac OS X OS Version: 10.6.8 Architecture: x86_64 JVM Version:1.6.0_29-b11-402-10M3527 Thanks, Ravi Please post replies below the question, so the conversation order is easily readable. Please answer the other question below. On Tue, Dec 20, 2011 at 4:52 PM, Pid * p...@pidster.com wrote: On 20 Dec 2011, at 11:02, S B sbl...@gmail.com wrote: Hi, I created and deployed an MBean in my tomcat. It uses datasource to connect to DB. Which version of Java? Tomcat? My questions is: When I create InitialContext() inside MBean's constructor and pass the envContext to DBManager class to lookup datasource it works fine. However when I create InitialContext() in DBManager class, it fails. Is it necessary to create InitialContext() during loading of MBean (either in ContextListener class or inside MBean constructor). It depends on where you run the code. You haven't told us this. Can you post a code example. As above, where are you putting your code? p When I did new InitialContext() in my DBManager class which is called from hello method of MBean it failed with below exception: avax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory] I invoked hello method of MBean from JConsole. Please let me know is it Tomcat specific? or same behavior is seen across all app servers. Also, What difference does it make if I create InitialContext inside MBean's constructor or in some other class at a later point of time. Thanks Ravi - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org -- [key:62590808] signature.asc Description: OpenPGP digital signature
Re: MBean InitialContext() Tomcat query- pls help
On 20/12/2011 11:46, S B wrote: Code Sample that fails with exception(I am invoking reload() from jconsole ): class MBeanImpl implements MBeanInterface{ public MBeanImpl{ // code to register this bean. } @Override public void reload() { DBManager.loadFromDB(); } } class DBManager{ public static void loadFromDB(){ InitialContext initContext = new InitialContext(); // here it fails with exception avax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root // exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory] Context context = (Context) initContext.lookup(java:comp/env); logger.info(context found + context); BasicDataSource ds = (BasicDataSource) context.lookup(jdbc/ + dataSourceName); ... ... } } - Code Sample that works: class MBeanImpl implements MBeanInterface{ private Context envContext = null; public MBeanImpl{ InitialContext initialContext = new InitialContext(); envContext = (Context) initialContext.lookup(java:/comp/env); // code to register this bean. } @Override public void reload() { DBManager.loadFromDB(envContext); // passed context object obtained in constructor } } class DBManager{ public static void loadFromDB(Context context){ BasicDataSource ds = (BasicDataSource) context.lookup(jdbc/ + dataSourceName); // works fine as I am not creating new InitialContext here. ... ... } } Where does the MBeanImpl code run? In a ServletContextListener, or somewhere else? p On Tue, Dec 20, 2011 at 4:59 PM, S B sbl...@gmail.com wrote: Hi, I am using : Server version: Apache Tomcat/6.0.32 OS Name:Mac OS X OS Version: 10.6.8 Architecture: x86_64 JVM Version:1.6.0_29-b11-402-10M3527 Thanks, Ravi On Tue, Dec 20, 2011 at 4:52 PM, Pid * p...@pidster.com wrote: On 20 Dec 2011, at 11:02, S B sbl...@gmail.com wrote: Hi, I created and deployed an MBean in my tomcat. It uses datasource to connect to DB. Which version of Java? Tomcat? My questions is: When I create InitialContext() inside MBean's constructor and pass the envContext to DBManager class to lookup datasource it works fine. However when I create InitialContext() in DBManager class, it fails. Is it necessary to create InitialContext() during loading of MBean (either in ContextListener class or inside MBean constructor). It depends on where you run the code. You haven't told us this. Can you post a code example. p When I did new InitialContext() in my DBManager class which is called from hello method of MBean it failed with below exception: avax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory] I invoked hello method of MBean from JConsole. Please let me know is it Tomcat specific? or same behavior is seen across all app servers. Also, What difference does it make if I create InitialContext inside MBean's constructor or in some other class at a later point of time. Thanks Ravi - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org -- [key:62590808] signature.asc Description: OpenPGP digital signature
Re: MBean InitialContext() Tomcat query- pls help
MBeanImpl code is packaged as a war and deployed in tomcat along with it's mbeans-descriptor.xml I am not using ServletContextListener in my code. (mbean registration is done inside constructor). (I am using gmail and hitting reply button on your messages. Please let me know if my messages are not being put in order as mailing list expects.) On Tue, Dec 20, 2011 at 5:18 PM, Pid p...@pidster.com wrote: On 20/12/2011 11:46, S B wrote: Code Sample that fails with exception(I am invoking reload() from jconsole ): class MBeanImpl implements MBeanInterface{ public MBeanImpl{ // code to register this bean. } @Override public void reload() { DBManager.loadFromDB(); } } class DBManager{ public static void loadFromDB(){ InitialContext initContext = new InitialContext(); // here it fails with exception avax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root // exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory] Context context = (Context) initContext.lookup(java:comp/env); logger.info(context found + context); BasicDataSource ds = (BasicDataSource) context.lookup(jdbc/ + dataSourceName); ... ... } } - Code Sample that works: class MBeanImpl implements MBeanInterface{ private Context envContext = null; public MBeanImpl{ InitialContext initialContext = new InitialContext(); envContext = (Context) initialContext.lookup(java:/comp/env); // code to register this bean. } @Override public void reload() { DBManager.loadFromDB(envContext); // passed context object obtained in constructor } } class DBManager{ public static void loadFromDB(Context context){ BasicDataSource ds = (BasicDataSource) context.lookup(jdbc/ + dataSourceName); // works fine as I am not creating new InitialContext here. ... ... } } Where does the MBeanImpl code run? In a ServletContextListener, or somewhere else? p On Tue, Dec 20, 2011 at 4:59 PM, S B sbl...@gmail.com wrote: Hi, I am using : Server version: Apache Tomcat/6.0.32 OS Name:Mac OS X OS Version: 10.6.8 Architecture: x86_64 JVM Version:1.6.0_29-b11-402-10M3527 Thanks, Ravi On Tue, Dec 20, 2011 at 4:52 PM, Pid * p...@pidster.com wrote: On 20 Dec 2011, at 11:02, S B sbl...@gmail.com wrote: Hi, I created and deployed an MBean in my tomcat. It uses datasource to connect to DB. Which version of Java? Tomcat? My questions is: When I create InitialContext() inside MBean's constructor and pass the envContext to DBManager class to lookup datasource it works fine. However when I create InitialContext() in DBManager class, it fails. Is it necessary to create InitialContext() during loading of MBean (either in ContextListener class or inside MBean constructor). It depends on where you run the code. You haven't told us this. Can you post a code example. p When I did new InitialContext() in my DBManager class which is called from hello method of MBean it failed with below exception: avax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory] I invoked hello method of MBean from JConsole. Please let me know is it Tomcat specific? or same behavior is seen across all app servers. Also, What difference does it make if I create InitialContext inside MBean's constructor or in some other class at a later point of time. Thanks Ravi - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org -- [key:62590808]
Re: MBean InitialContext() Tomcat query- pls help
On 20/12/2011 11:57, S B wrote: MBeanImpl code is packaged as a war and deployed in tomcat along with it's mbeans-descriptor.xml I am not using ServletContextListener in my code. (mbean registration is done inside constructor). Right, but what is calling the constructor? (I am using gmail and hitting reply button on your messages. Please let me know if my messages are not being put in order as mailing list expects.) That shouldn't prevent you from scrolling down and entering your replies at the appropriate points in the text. Just like I am. p On Tue, Dec 20, 2011 at 5:18 PM, Pid p...@pidster.com wrote: On 20/12/2011 11:46, S B wrote: Code Sample that fails with exception(I am invoking reload() from jconsole ): class MBeanImpl implements MBeanInterface{ public MBeanImpl{ // code to register this bean. } @Override public void reload() { DBManager.loadFromDB(); } } class DBManager{ public static void loadFromDB(){ InitialContext initContext = new InitialContext(); // here it fails with exception avax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root // exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory] Context context = (Context) initContext.lookup(java:comp/env); logger.info(context found + context); BasicDataSource ds = (BasicDataSource) context.lookup(jdbc/ + dataSourceName); ... ... } } - Code Sample that works: class MBeanImpl implements MBeanInterface{ private Context envContext = null; public MBeanImpl{ InitialContext initialContext = new InitialContext(); envContext = (Context) initialContext.lookup(java:/comp/env); // code to register this bean. } @Override public void reload() { DBManager.loadFromDB(envContext); // passed context object obtained in constructor } } class DBManager{ public static void loadFromDB(Context context){ BasicDataSource ds = (BasicDataSource) context.lookup(jdbc/ + dataSourceName); // works fine as I am not creating new InitialContext here. ... ... } } Where does the MBeanImpl code run? In a ServletContextListener, or somewhere else? p On Tue, Dec 20, 2011 at 4:59 PM, S B sbl...@gmail.com wrote: Hi, I am using : Server version: Apache Tomcat/6.0.32 OS Name:Mac OS X OS Version: 10.6.8 Architecture: x86_64 JVM Version:1.6.0_29-b11-402-10M3527 Thanks, Ravi On Tue, Dec 20, 2011 at 4:52 PM, Pid * p...@pidster.com wrote: On 20 Dec 2011, at 11:02, S B sbl...@gmail.com wrote: Hi, I created and deployed an MBean in my tomcat. It uses datasource to connect to DB. Which version of Java? Tomcat? My questions is: When I create InitialContext() inside MBean's constructor and pass the envContext to DBManager class to lookup datasource it works fine. However when I create InitialContext() in DBManager class, it fails. Is it necessary to create InitialContext() during loading of MBean (either in ContextListener class or inside MBean constructor). It depends on where you run the code. You haven't told us this. Can you post a code example. p When I did new InitialContext() in my DBManager class which is called from hello method of MBean it failed with below exception: avax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory] I invoked hello method of MBean from JConsole. Please let me know is it Tomcat specific? or same behavior is seen across all app servers. Also, What difference does it make if I create InitialContext inside MBean's constructor or in some other class at a later point of time. Thanks Ravi - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org -- [key:62590808] -- [key:62590808] signature.asc Description: OpenPGP digital signature
Re: MBean InitialContext() Tomcat query- pls help
On Tue, Dec 20, 2011 at 7:00 PM, Pid p...@pidster.com wrote: On 20/12/2011 11:57, S B wrote: MBeanImpl code is packaged as a war and deployed in tomcat along with it's mbeans-descriptor.xml I am not using ServletContextListener in my code. (mbean registration is done inside constructor). Right, but what is calling the constructor? constructor is run during server startup hook. MBean is registered during that time . MBean is registered using below code (in constructor): MBeanServer server = getServer(); server.registerMBean(*this*, new ObjectName(StoreServerSyncAndReloadConstants.MBEAN_NAME) When we invoke reload() from jconsole, it causes class to load and call it's public constructor and create instance before calling reload() on that instance. During reload() constructor is called again and registration code runs again. (I am using gmail and hitting reply button on your messages. Please let me know if my messages are not being put in order as mailing list expects.) That shouldn't prevent you from scrolling down and entering your replies at the appropriate points in the text. Just like I am. p On Tue, Dec 20, 2011 at 5:18 PM, Pid p...@pidster.com wrote: On 20/12/2011 11:46, S B wrote: Code Sample that fails with exception(I am invoking reload() from jconsole ): class MBeanImpl implements MBeanInterface{ public MBeanImpl{ // code to register this bean. } @Override public void reload() { DBManager.loadFromDB(); } } class DBManager{ public static void loadFromDB(){ InitialContext initContext = new InitialContext(); // here it fails with exception avax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root // exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory] Context context = (Context) initContext.lookup(java:comp/env); logger.info(context found + context); BasicDataSource ds = (BasicDataSource) context.lookup(jdbc/ + dataSourceName); ... ... } } - Code Sample that works: class MBeanImpl implements MBeanInterface{ private Context envContext = null; public MBeanImpl{ InitialContext initialContext = new InitialContext(); envContext = (Context) initialContext.lookup(java:/comp/env); // code to register this bean. } @Override public void reload() { DBManager.loadFromDB(envContext); // passed context object obtained in constructor } } class DBManager{ public static void loadFromDB(Context context){ BasicDataSource ds = (BasicDataSource) context.lookup(jdbc/ + dataSourceName); // works fine as I am not creating new InitialContext here. ... ... } } Where does the MBeanImpl code run? In a ServletContextListener, or somewhere else? p On Tue, Dec 20, 2011 at 4:59 PM, S B sbl...@gmail.com wrote: Hi, I am using : Server version: Apache Tomcat/6.0.32 OS Name:Mac OS X OS Version: 10.6.8 Architecture: x86_64 JVM Version:1.6.0_29-b11-402-10M3527 Thanks, Ravi On Tue, Dec 20, 2011 at 4:52 PM, Pid * p...@pidster.com wrote: On 20 Dec 2011, at 11:02, S B sbl...@gmail.com wrote: Hi, I created and deployed an MBean in my tomcat. It uses datasource to connect to DB. Which version of Java? Tomcat? My questions is: When I create InitialContext() inside MBean's constructor and pass the envContext to DBManager class to lookup datasource it works fine. However when I create InitialContext() in DBManager class, it fails. Is it necessary to create InitialContext() during loading of MBean (either in ContextListener class or inside MBean constructor). It depends on where you run the code. You haven't told us this. Can you post a code example. p When I did new InitialContext() in my DBManager class which is called from hello method of MBean it failed with below exception: avax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory] I invoked hello method of MBean from JConsole. Please let me know is it Tomcat specific? or same behavior is seen across all app servers. Also, What difference does it make if I create InitialContext inside MBean's constructor or in some other class at
Re: MBean InitialContext() Tomcat query- pls help
On 20 Dec 2011, at 15:47, S B sbl...@gmail.com wrote: On Tue, Dec 20, 2011 at 7:00 PM, Pid p...@pidster.com wrote: On 20/12/2011 11:57, S B wrote: MBeanImpl code is packaged as a war and deployed in tomcat along with it's mbeans-descriptor.xml I am not using ServletContextListener in my code. (mbean registration is done inside constructor). Right, but what is calling the constructor? constructor is run during server startup hook. MBean is registered during that time . This is like pulling teeth. What exactly is the server startup hook? Mbean is registered using below code (in constructor): MBeanServer server = getServer(); server.registerMBean(*this*, new ObjectName(StoreServerSyncAndReloadConstants.MBEAN_NAME) When we invoke reload() from jconsole, it causes class to load and call How can it do that if it needs to be loaded already for the MBean to work? How are you unloading it? it's public constructor and create instance before calling reload() on that instance. Right. I can't make any sense out of the above. During reload() constructor is called again and registration code runs again. So you re-register the Mbean that you're using to load the same MBean? p (I am using gmail and hitting reply button on your messages. Please let me know if my messages are not being put in order as mailing list expects.) That shouldn't prevent you from scrolling down and entering your replies at the appropriate points in the text. Just like I am. p On Tue, Dec 20, 2011 at 5:18 PM, Pid p...@pidster.com wrote: On 20/12/2011 11:46, S B wrote: Code Sample that fails with exception(I am invoking reload() from jconsole ): class MBeanImpl implements MBeanInterface{ public MBeanImpl{ // code to register this bean. } @Override public void reload() { DBManager.loadFromDB(); } } class DBManager{ public static void loadFromDB(){ InitialContext initContext = new InitialContext(); // here it fails with exception avax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root // exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory] Context context = (Context) initContext.lookup(java:comp/env); logger.info(context found + context); BasicDataSource ds = (BasicDataSource) context.lookup(jdbc/ + dataSourceName); ... ... } } - Code Sample that works: class MBeanImpl implements MBeanInterface{ private Context envContext = null; public MBeanImpl{ InitialContext initialContext = new InitialContext(); envContext = (Context) initialContext.lookup(java:/comp/env); // code to register this bean. } @Override public void reload() { DBManager.loadFromDB(envContext); // passed context object obtained in constructor } } class DBManager{ public static void loadFromDB(Context context){ BasicDataSource ds = (BasicDataSource) context.lookup(jdbc/ + dataSourceName); // works fine as I am not creating new InitialContext here. ... ... } } Where does the MBeanImpl code run? In a ServletContextListener, or somewhere else? p On Tue, Dec 20, 2011 at 4:59 PM, S B sbl...@gmail.com wrote: Hi, I am using : Server version: Apache Tomcat/6.0.32 OS Name:Mac OS X OS Version: 10.6.8 Architecture: x86_64 JVM Version:1.6.0_29-b11-402-10M3527 Thanks, Ravi On Tue, Dec 20, 2011 at 4:52 PM, Pid * p...@pidster.com wrote: On 20 Dec 2011, at 11:02, S B sbl...@gmail.com wrote: Hi, I created and deployed an MBean in my tomcat. It uses datasource to connect to DB. Which version of Java? Tomcat? My questions is: When I create InitialContext() inside MBean's constructor and pass the envContext to DBManager class to lookup datasource it works fine. However when I create InitialContext() in DBManager class, it fails. Is it necessary to create InitialContext() during loading of MBean (either in ContextListener class or inside MBean constructor). It depends on where you run the code. You haven't told us this. Can you post a code example. p When I did new InitialContext() in my DBManager class which is called from hello method of MBean it failed with below exception: avax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory] I invoked hello method of MBean from JConsole. Please let me know is it