package org.vamsas.test.simpleclient; import java.io.File; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.vamsas.client.simpleclient.FileWatcher; import org.vamsas.client.simpleclient.Lock; import org.vamsas.client.simpleclient.SimpleDocument; import org.vamsas.client.simpleclient.VamsasArchiveReader; import org.vamsas.objects.core.VamsasDocument; /** * demo of archive watching process - should mimic the clientsfileTest watcher/monitor process. * @author jimp * */ public class ArchiveWatcher { private static Log log = LogFactory.getLog(ArchiveWatcher.class); public static void main(String[] args) { try { if (args!=null && args.length>0) { File archive = new File(args[0]); log.info("Watching file "+args[0]); /* if (!archive.exists()) archive.createNewFile(); */ // watch the new file... - taken straight from ClientsFileTest FileWatcher w = new FileWatcher(archive); while (true) { // get watcher's lock to ensure state change is fixed for retrieval Lock chlock = w.getChangedState(); if (chlock != null) if (archive.length()>0) { log.info("Noticed Testing update: "); VamsasArchiveReader vreader = new VamsasArchiveReader(archive); SimpleDocument sdoc = new SimpleDocument("testing vamsas watcher"); try { VamsasDocument d = sdoc.getVamsasDocument(vreader); if (d!=null) { ArchiveReports.reportDocument(d, vreader, false, System.out); } System.out.println("Update at "+System.currentTimeMillis()+"\n\n********************************************************\n"); } catch (Exception e) { log.error("Unmarshalling failed.",e); } vreader.close(); } } } } catch (Exception e) { log.error(e); } } }