01: /*
02:
03: * <copyright>
04: *
05: * Copyright 2002-2007 BBNT Solutions, LLC
06: * under sponsorship of the Defense Advanced Research Projects
07: * Agency (DARPA).
08: *
09: * You can redistribute this software and/or modify it under the
10: * terms of the Cougaar Open Source License as published on the
11: * Cougaar Open Source Website (www.cougaar.org).
12: *
13: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
15: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
16: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
17: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24: *
25: * </copyright>
26:
27: */
28:
29: package org.cougaar.qos.qrs;
30:
31: /**
32: * Used only for internal testing of DataFeeds.
33: */
34: public class FeedTester implements DataFeedListener {
35: private static DataValue value;
36:
37: public static void main(String[] args) {
38: String propertiesFile = null;
39: String feedname = null;
40: String key = null;
41: FeedTester fer = new FeedTester();
42:
43: for (int i = 0; i < args.length; i++) {
44: if (args.length < 6) {
45: System.exit(0);
46: }
47: String arg = args[i];
48: if (arg.equals("-conf")) {
49: propertiesFile = args[++i];
50: } else if (arg.equals("-feed")) {
51: feedname = args[++i];
52: } else if (arg.equals("-key")) {
53: key = args[++i];
54: } else {
55: System.err.println("Skipping unknown option " + arg);
56: }
57: }
58:
59: try {
60: RSS rss = RSS.makeInstance(propertiesFile);
61: DataFeed feed = rss.getFeed(feedname);
62:
63: feed.addListenerForKey(fer, key);
64: while (true) {
65: value = feed.lookup(key);
66: System.out.println("lookup value" + value);
67: try {
68: Thread.sleep(1200);
69: } catch (InterruptedException ex) {
70: }
71: }
72: } catch (Exception ex) {
73: ex.printStackTrace();
74: }
75:
76: }
77:
78: public void newData(DataFeed store, String key, DataValue data) {
79: System.out.println("Subscribing to " + store
80: + " value obtained" + data);
81: if (!value.equals(data)) {
82: System.out
83: .println("subscription and look up values are different");
84: }
85:
86: }
87:
88: }
|