1 package org.vamsas.client.simpleclient;
3 import java.beans.PropertyChangeEvent;
4 import java.beans.PropertyChangeSupport;
5 import java.util.Hashtable;
7 import org.apache.commons.logging.Log;
8 import org.apache.commons.logging.LogFactory;
9 import org.vamsas.client.Events;
12 * monitors watcher objects and generates events.
14 public class EventGeneratorThread extends Thread implements Runnable {
15 private static Log log = LogFactory.getLog(EventGeneratorThread.class);
16 private SimpleClient client;
17 private Hashtable handlers; // manager object
18 private VamsasSession session;
20 protected FileWatcher clientfile=null;
21 protected FileWatcher vamsasfile=null;
22 protected FileWatcher storeFile=null;
24 private boolean watch=false;
27 EventGeneratorThread(VamsasSession s, SimpleClient _client, Hashtable eventhandlers) {
28 if (eventhandlers==null || s==null || _client==null)
29 throw new Error("Null arguments to EventGeneratorThread constructor.");
30 handlers = eventhandlers;
33 setName(s.sessionDir.getName());
37 private void initWatchers() {
39 clientfile = session.getClientWatcher();
40 if (vamsasfile ==null)
41 vamsasfile = session.getDocWatcher();
42 if (storeFile == null)
43 storeFile = session.getStoreWatcher();
44 clientfile.setState();
45 vamsasfile.setState();
48 boolean ownsf = false;
50 * scans all watchers and fires changeEvents if necessary
51 * @return number of events generated.
53 private int checkforEvents() {
55 //TODO : leave slog.info messages for the events that occur.
57 // could make this general - but for now keep simple
58 if ((watchlock=storeFile.getChangedState())!=null) {
59 // TODO: define the storeFile semaphore mechanism : file exists - all clients inform their apps, and then the client that wrote the file should delete the file (it should hold the lock to it).
60 if (storeFile.exists) {
61 PropertyChangeSupport h = (PropertyChangeSupport) handlers.get(Events.DOCUMENT_FINALIZEAPPDATA);
63 log.debug("Triggering DOCUMENT_FINALIZEAPPDATA");
65 h.firePropertyChange(client.getSessionUrn(), null, client);
67 vamsasfile.setState();
71 if ((watchlock=clientfile.getChangedState())!=null) {
72 // see what happened to the clientfile - compare our internal version with the one in the file, or just send the updated list out...?
75 if ((watchlock=vamsasfile.getChangedState())!=null) {
76 // pass IClientDocument instance to app handler ?
81 private void initEvents() {
86 * probably don't need any of these below.
89 * @see java.lang.Thread#destroy()
91 public void destroy() {
95 * @see java.lang.Thread#interrupt()
97 public void interrupt() {
98 // TODO Auto-generated method stub
102 * @see java.lang.Thread#isInterrupted()
104 public boolean isInterrupted() {
105 // TODO Auto-generated method stub
106 return super.isInterrupted();
109 * @see java.lang.Thread#run()
112 // TODO Auto-generated method stub