From: Gerald T. <gt...@e2...> - 2010-02-02 18:38:54
|
I've checked the online documentation and the Jira on these new objects and I'm a bit fuzzy on how they are used. I'm getting and exception using them and suspect I'm doing it wrong and the docs are a bit sparse. I *THINK* that the Humidor uses the SigarProxyCache underneath it and of course that uses the Sigar class inside it. I *THINK* that the SigarProxyCache just generates proxy objects for caching purposes and the Humidor goes one step further and produces SigarProxyCache object that are thread safe .... but I am not sure on this. I'm specifically interested on how to initialize these objects considering the possible interdependencies. Could someone explain this dynamic for me ... BTW I did appreciate the Humidor class name! -Gerald Talton E2open |
From: Gerald T. <gt...@e2...> - 2010-02-02 18:38:53
|
as a followup .. here is the exception: ======================================================= INFO | jvm 1 | 2010/02/01 14:00:02 | SEVERE: Job (DEFAULT.com.e2open.smi.explorers.vitria threw an exception. INFO | jvm 1 | 2010/02/01 14:00:02 | org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.ClassCastException: org.hyperic.sigar.Humidor$MyHandler] INFO | jvm 1 | 2010/02/01 14:00:02 | at org.quartz.core.JobRunShell.run(JobRunShell.java:206) INFO | jvm 1 | 2010/02/01 14:00:02 | at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520) INFO | jvm 1 | 2010/02/01 14:00:02 | * Nested Exception (Underlying Cause) --------------- INFO | jvm 1 | 2010/02/01 14:00:02 | java.lang.ClassCastException: org.hyperic.sigar.Humidor$MyHandler INFO | jvm 1 | 2010/02/01 14:00:02 | at org.hyperic.sigar.SigarProxyCache.getHandler(SigarProxyCache.java:86) INFO | jvm 1 | 2010/02/01 14:00:02 | at org.hyperic.sigar.SigarProxyCache.getSigar(SigarProxyCache.java:98) INFO | jvm 1 | 2010/02/01 14:00:02 | at org.hyperic.sigar.ptql.ProcessFinder.<init>(ProcessFinder.java:35) INFO | jvm 1 | 2010/02/01 14:00:02 | at org.hyperic.sigar.ptql.ProcessFinder.find(ProcessFinder.java:64) INFO | jvm 1 | 2010/02/01 14:00:02 | at com.e2open.smi.bundles.sigar.SigarService.processFinderFindPidsByString(SigarService.java:644) INFO | jvm 1 | 2010/02/01 14:00:02 | at com.e2open.smi.explorers.vitria.VitriaExplorer.isVitriaRunning(VitriaExplorer.java:39) INFO | jvm 1 | 2010/02/01 14:00:02 | at com.e2open.smi.explorers.vitria.VitriaExplorer.doExploration(VitriaExplorer.java:24) INFO | jvm 1 | 2010/02/01 14:00:02 | at com.e2open.smi.bundles.expmgr.Explorer.explore(Explorer.java:85) INFO | jvm 1 | 2010/02/01 14:00:02 | at com.e2open.smi.bundles.expmgr.ExplorerManager$ExplorerJob.execute(ExplorerManager.java:39) INFO | jvm 1 | 2010/02/01 14:00:02 | at org.quartz.core.JobRunShell.run(JobRunShell.java:195) INFO | jvm 1 | 2010/02/01 14:00:02 | at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520) ======================================================= and here is a code snippet where I initialize Sigar in my object ======================================================= private Humidor curHumidor; private SigarProxyCache curProxyCache; private Sigar curSigar; public void activate(ComponentContext compctx) throws Exception { System.out.println("activating SIGAR service"); if (logger != null) logger.info("activating SIGAR service"); this.compctx = compctx; curSigar = getInstance(); curProxyCache = new SigarProxyCache(curSigar, SigarProxyCache.EXPIRE_DEFAULT ); curHumidor = new Humidor(curSigar); ... public long[] processFinderFindPidsByString( String ptqlString ) throws SigarException { long[] pids; System.out.println("entering SigarService.processFinderFindPidsByString()"); pids = ProcessFinder.find(curHumidor.getSigar(), ptqlString); System.out.println("entering SigarService.processFinderFindPidsByString()"); return pids; } ======================================================= I suspect I'm doing something wrong in the initialization of these classes but have run out of ideas on what to do. Any help is appreciated. -Gerald Talton E2open |
From: Doug M. <do...@hy...> - 2010-02-02 22:50:57
|
Hi Gerald, Your synopsis on both classes is correct, there is a bit more detail on SigarProxyCache here: http://forums.hyperic.com/jiveforums/thread.jspa?threadID=628 Glad you appreciate the Humidor name! You would only need a Humidor to share a Sigar object between multiple threads. Sigar uses the reentrant versions of libc (or similar) functions underneath and any state is encapsulated with the underlying sigar_t object (no static variables). So, there is no synchronization required if each thread is using its own instance of a Sigar object. Looks like the ProcessFinder is hardwired to expect a SigarProxyCache impl: /** * @deprecated */ public ProcessFinder(SigarProxy proxy) { this(SigarProxyCache.getSigar(proxy)); } SigarProxy usage with ProcessFinder is also deprecated as of 1.5, when we ported the PTQL impl from Java to C. Even if ProcessFinder handled the Humidor case, the synchronization would be by-passed as would the caching of SigarProxyCache. So, if you're not making concurrent calls to ProcessFinder.find, the fix would be just to pass your Sigar curSigar object instead. Otherwise, you should synchronize the calls to ProcessFinder. And in any case we should add synchronization support to the ProcessFinder so you don't have to worry about it: http://jira.hyperic.com/browse/SIGAR-204 -Doug |
From: Gerald T. <gt...@e2...> - 2010-02-03 13:20:14
|
Thanks for the reply, I have this fixed now. I grabbed your source last night and rummaged through it and realized the Sigar dependence for ProcessFinder when I saw that line too. What I now do is give a separate Sigar object to each of the five OSGi bundles in my app and that seems to be working now. The reason for the interest in the Humidor class is I had a scheduler waking up multiple threads at the same time running in these 5 different bundles all hitting a single Sigar object in one bundle ... not good. Again, now each bundle owns it's own Sigar object so when the scheduler fires off all five threas at the same time ... each bundle has their own Sigar ... so not a problem. Also I am glad you are using the reentrant libc, I've been bitten not doing that in the past so that's reassuring. Thanks again for the quick reply. Gerald Talton E2open |