// -*- Java -*- // // This file is part of Siena, a wide-area event notification system. // See http://www.cs.colorado.edu/serl/dot/siena.html // // Author: Antonio Carzaniga // See the file AUTHORS for full details. // // Copyright (C) 1998-1999 University of Colorado // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, // USA, or send email to serl@cs.colorado.edu. // // // $Id: InterestedParty.java,v 1.2 2000/04/28 00:35:03 carzanig Exp $ // // // this is an example of an interested party, that is, a consumer of // notifications // import siena.*; public class InterestedParty implements Notifiable { public void notify(Event e) { System.out.println("I just got this event:"); System.out.println(e.toString()); }; public static void main(String[] args) { if(args.length != 1) { System.err.println("Usage: InterestedParty "); System.exit(1); } HierarchicalDispatcher siena; try { siena = new HierarchicalDispatcher(); siena.setMaster(args[0]); Filter f = new Filter(); f.addConstraint("name", "Antonio"); // name = "Antonio" f.addConstraint("age", AttributeConstraint.GT, 18); // age > 18 InterestedParty party = new InterestedParty(); System.out.println("subscribing for " + f.toString()); try { siena.subscribe(f, party); try { Thread.sleep(300000); // sleeps for five minutes } catch (java.lang.InterruptedException ex) { System.out.println("interrupted"); } System.out.println("unsubscribing"); siena.unsubscribe(f, party); } catch (SienaException ex) { System.err.println("Siena error:" + ex.toString()); } System.out.println("shutting down."); siena.shutdown(); System.exit(0); } catch (Exception ex) { ex.printStackTrace(); System.exit(1); } }; }