+ /* Iterator coms = commands.iterator();
+ int com=-1;
+ while ((coms!=null) && coms.hasNext()) {
+ com++;
+ if (args[argc].toLowerCase().equals((String) coms.next())) {
+ System.out.println("Doing "+args[argc]);
+ ClientHandle ch;
+ argc++;
+ switch (com) {
+ case 0:
+ // Add
+ ClientsFileTest.complainArgs(args.length, argc, "add", 2, "for the Client's 'Name' and 'Version'");
+ int pos = cfhand.addClient(ch=new ClientHandle(args[argc],args[argc+1]));
+ argc+=2;
+ if (pos!=0)
+ System.out.println("Client added at "+pos+" as urn:"+ch.getClientUrn());
+ else
+ System.out.println("Client was not added.");
+ break;
+ case 1:
+ // remove
+ ClientsFileTest.complainArgs(args.length, argc, "remove", 3, "for the Client's 'Name', Version and URN");
+ ch=new ClientHandle(args[argc], args[argc+1]);
+ ch.setClientUrn(args[argc+2]);
+ argc+=3;
+ cfhand.removeClient(ch, null);
+ System.out.println("Client removed (apparently)");
+ break;
+ case 2:
+ // list
+ ClientHandle[] chlist = cfhand.retrieveClientList();
+ if (chlist!=null) {
+ for (int chi=0,che=chlist.length; chi<che; chi++) {
+ System.out.println("Client "+chi+" ("+chlist[chi].getClientName()+" "+chlist[chi].getVersion()+" "+chlist[chi].getClientUrn()+")");
+ }
+ } else {
+ System.out.println("Client list is empty.");
+ }
+ break;
+ case 3:
+ // clear
+ cfhand = null;
+ cf.delete();
+ try {
+ cf.createNewFile();
+ cfhand = new ClientsFile(cf);
+ }
+ catch (Exception e) {
+ System.err.println("Failed on new empty clientfile creation!");
+ e.printStackTrace(System.err);
+ }
+ break;
+ case 4:
+ // watch
+ FileWatcher w=new FileWatcher(cf);
+ while (cf.exists()) {
+ // get watcher's lock to ensure state change is fixed for retrieval
+ Lock chlock=w.getChangedState();
+ if (chlock!=null) {
+ ClientHandle[] cl = cfhand.retrieveClientList(chlock);
+ System.out.println("-- Watching "+cf.getName());
+ //while (w.hasChanged())
+ // ;
+ if (cl!=null) {
+ for (int chi=0,che=cl.length; chi<che; chi++) {
+ System.out.println("Client "+chi+" ("+cl[chi].getClientName()+" "+cl[chi].getVersion()+" "+cl[chi].getClientUrn()+")");
+ }
+ } else {
+ System.out.println("Client list is empty.");
+ }
+ }
+
+ }
+ break;
+ case 5:
+ // monitor
+ ClientsFileTest.complainArgs(args.length, argc, "monitor", 2, "for the Client's 'Name' and 'Version'");
+ int clpos = cfhand.addClient(ch=new ClientHandle(args[argc],args[argc+1]));
+ argc+=2;
+ if (clpos!=0)
+ System.out.println("Monitor Client added at "+clpos+" as urn:"+ch.getClientUrn());
+ else {
+ System.err.println("Monitor Client was not added.");
+ break;
+ }
+ FileWatcher mon=new FileWatcher(cf);
+ while (cf.exists()) {
+ // get watcher's lock to ensure state change is fixed for retrieval
+ Lock chlock=mon.getChangedState();
+ if (chlock!=null) {
+ ClientHandle[] cl = cfhand.retrieveClientList(chlock);
+ System.out.println("-- Monitor "+cf.getName());
+ //while (w.hasChanged())
+ // ;
+ int newpos=-1;
+ if (cl!=null) {
+ for (int chi=0,che=cl.length; chi<che; chi++) {
+ if (ch.equals(cl[chi]))
+ newpos=chi+1;
+ }
+ }
+ if (newpos==-1) {
+ // add self again to cleared list.
+ newpos=cfhand.addClient(ch);
+ mon.setState();
+ if (newpos==0) {
+ System.err.println("Monitor client could not be re-added to list.");
+ break;
+ }
+ }
+ if (newpos!=clpos) {
+ System.out.println("Monitor client moved from "+clpos+" to "+newpos);
+ clpos=newpos;
+ }
+ }
+ }
+
+ }
+ coms = null;
+ }
+ } */
+