1 package org.vamsas.test.simpleclient;
5 import org.apache.commons.logging.Log;
6 import org.apache.commons.logging.LogFactory;
7 import org.vamsas.client.simpleclient.FileWatcher;
8 import org.vamsas.client.simpleclient.Lock;
9 import org.vamsas.client.simpleclient.SimpleDocument;
10 import org.vamsas.client.simpleclient.VamsasArchiveReader;
11 import org.vamsas.objects.core.VamsasDocument;
13 * demo of archive watching process - should mimic the clientsfileTest watcher/monitor process.
17 public class ArchiveWatcher {
18 private static Log log = LogFactory.getLog(ArchiveWatcher.class);
19 public static void main(String[] args) {
21 if (args!=null && args.length>0) {
23 File archive = new File(args[0]);
24 log.info("Watching file "+args[0]);
25 /* if (!archive.exists())
26 archive.createNewFile();
27 */ // watch the new file... - taken straight from ClientsFileTest
28 FileWatcher w = new FileWatcher(archive);
29 while (archive.exists()) {
31 // get watcher's lock to ensure state change is fixed for retrieval
32 Lock chlock = w.getChangedState();
34 if (archive.length()>0) {
35 log.info("Noticed Testing update: ");
36 VamsasArchiveReader vreader = new VamsasArchiveReader(archive);
37 SimpleDocument sdoc = new SimpleDocument("testing vamsas watcher");
39 VamsasDocument d = sdoc.getVamsasDocument(vreader);
41 ArchiveReports.reportDocument(d, vreader, false, System.out);
43 System.out.println("Update at "+System.currentTimeMillis()+"\n\n********************************************************\n");
44 } catch (Exception e) {
45 log.error("Unmarshalling failed.",e);
51 } catch (Exception e) {