Return-Path: Delivered-To: apmail-jackrabbit-users-archive@locus.apache.org Received: (qmail 59190 invoked from network); 29 Nov 2007 21:38:12 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 29 Nov 2007 21:38:11 -0000 Received: (qmail 83440 invoked by uid 500); 29 Nov 2007 21:37:55 -0000 Delivered-To: apmail-jackrabbit-users-archive@jackrabbit.apache.org Received: (qmail 83410 invoked by uid 500); 29 Nov 2007 21:37:55 -0000 Mailing-List: contact users-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@jackrabbit.apache.org Delivered-To: mailing list users@jackrabbit.apache.org Received: (qmail 83371 invoked by uid 99); 29 Nov 2007 21:37:55 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 29 Nov 2007 13:37:55 -0800 X-ASF-Spam-Status: No, hits=4.0 required=10.0 tests=DNS_FROM_OPENWHOIS,FORGED_YAHOO_RCVD,SPF_HELO_PASS,SPF_PASS,WHOIS_MYPRIVREG X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of lists@nabble.com designates 216.139.236.158 as permitted sender) Received: from [216.139.236.158] (HELO kuber.nabble.com) (216.139.236.158) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 29 Nov 2007 21:37:57 +0000 Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1Ixr4i-0005q6-7r for users@jackrabbit.apache.org; Thu, 29 Nov 2007 13:37:36 -0800 Message-ID: <14035576.post@talk.nabble.com> Date: Thu, 29 Nov 2007 13:37:36 -0800 (PST) From: qcfireball To: users@jackrabbit.apache.org Subject: Re: RMI Observation In-Reply-To: <1196367896.6758.123.camel@bslm-046.corp.day.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: qcfireball@yahoo.com References: <14033021.post@talk.nabble.com> <1196367896.6758.123.camel@bslm-046.corp.day.com> X-Virus-Checked: Checked by ClamAV on apache.org Right now, I am just checking Observation out - to see how it works, how it responds to JCR changes. Here is my test class: public class WatchAll implements javax.jcr.observation.EventListener { /** * The version of this file, which is updated each time this class file * is modified. */ public static final String VERSION = "November 29, 2007, 12:36 PM"; /** Creates a new instance of WatchAll */ public WatchAll() {} public static void main(String[] sa) { log("Starting Listener..."); JcrHost host = new JcrHost(); host.setCredential("guest", "guest"); host.setHost("localhost"); host.setJackrabbitSpecific(true); host.setPort(1099); host.setRepositoryName("jackrabbit.repository"); host.setWorkspace("default"); Session s = null; try { s = host.createSession(); ClientObservationManager omgr = (ClientObservationManager) s.getWorkspace().getObservationManager(); String path0 = "/"; String path1 = "/content/Companies/TNC/en"; omgr.addEventListener(new WatchAll(), getAllTypes(), path0, true, null, null, true); synchronized(WatchAll.class) { WatchAll.class.wait(); } } catch (Exception ex) { Logger l = LoggerConfig.getLogger(WatchAll.class); l.log(Level.SEVERE, "ERROR:", ex); } finally { if (s!= null) s.logout(); } } private static int getAllTypes() { return Event.NODE_ADDED | Event.NODE_REMOVED | Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED | Event.PROPERTY_REMOVED; } public void onEvent(EventIterator eventIterator) { log("Processing Event"); for ( ; eventIterator.hasNext() ; ) { Event event = eventIterator.nextEvent(); switch (event.getType()) { case Event.NODE_ADDED : nodeAdded(event); break; case Event.NODE_REMOVED : nodeRemoved(event); break; case Event.PROPERTY_ADDED : propertyAdded(event); break; case Event.PROPERTY_CHANGED : propertyChanged(event); break; case Event.PROPERTY_REMOVED : propertyRemoved(event); break; default : break; } } } private void nodeAdded(Event event) { StringBuilder sb = new StringBuilder(256); sb.append("Node Added: "); showEvent(event, sb); } private void nodeRemoved(Event event) { StringBuilder sb = new StringBuilder(256); sb.append("Node Removed: "); showEvent(event, sb); } private void propertyAdded(Event event) { StringBuilder sb = new StringBuilder(256); sb.append("Property Added: "); showEvent(event, sb); } private void propertyChanged(Event event) { StringBuilder sb = new StringBuilder(256); sb.append("Property Changed: "); showEvent(event, sb); } private void propertyRemoved(Event event) { StringBuilder sb = new StringBuilder(256); sb.append("Property Removed: "); showEvent(event, sb); } private void showEvent(Event event, StringBuilder sb) { try { sb.append("Path = [").append(event.getPath()).append("] - "); sb.append("User = [").append(event.getUserID()).append("]\n"); log(sb); } catch (RepositoryException ex) { Logger l = LoggerConfig.getLogger(getClass()); l.log(Level.WARNING, "ERROR:", ex); } } private static void log(Object o) { if (o != null) { Logger l = LoggerConfig.getLogger(WatchAll.class); l.finest(o.toString()); } } } Felix Meschberger-2 wrote: > > Hi, > > Not sure, what you are trying to accomplish. From your description it > seems something like this: > > class MyThread extends Thread { > public void run() { > // register listener > } > } > > If this is so, it is expected behaviour :-) You register the listener > and then the events are dispatched to the onEvent method is called > asynchronously. What you would want to do is something like this: > > class MyListener implements EventListener { > void start() { > // register listener > } > void stop() { > // unregister listener > } > public void onEvent(EventIterator events) { > //... > } > } > > Regards > Felix > > Am Donnerstag, den 29.11.2007, 11:22 -0800 schrieb qcfireball: >> I noticed that when registering a new Observer via RMI, if I do not >> provide a >> "thread trick" the Thread immediately dies, and the Observer with it. >> >> Basically I am synchronizing on an arbitrary Object, then calling 'wait'. >> Not a very nice solution, but it works for now. Seems like a hack to me. >> >> I guess it makes sense that the Thread would immediately die without some >> kind of effert. I am wondering how other people are making sure that >> their >> Observer does not die? Are there ways that are preferred over others? >> >> Is this behavior going to be the same when registering an Observer within >> a >> web container, directly using the Jackrabbit API's? > > > -- View this message in context: http://www.nabble.com/RMI-Observation-tf4899371.html#a14035576 Sent from the Jackrabbit - Users mailing list archive at Nabble.com.