1 /*------------------------------------------------------------------------------
2 Name: SimpleReader.java
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 Author: Wolfgang Kleinertz
6 ------------------------------------------------------------------------------*/
7 package javaclients.simplereader;
8
9 import org.xmlBlaster.client.I_Callback;
10 import org.xmlBlaster.client.I_XmlBlasterAccess;
11 import org.xmlBlaster.client.XmlBlasterAccess;
12 import org.xmlBlaster.client.key.UpdateKey;
13 import org.xmlBlaster.client.qos.UpdateQos;
14 import org.xmlBlaster.util.XmlBlasterException;
15 import org.xmlBlaster.util.Global;
16 import org.xmlBlaster.client.key.SubscribeKey;
17 import org.xmlBlaster.client.qos.SubscribeQos;
18 import org.xmlBlaster.client.qos.ConnectQos;
19
20
21
22 public class SimpleReader implements I_Callback {
23 private static final String ME = "SimpleReader";
24
25 private static final String USR_LOGIN = ME;
26 private static final String USR_PASSWD = "secret";
27
28 private I_XmlBlasterAccess xmlBlaster = null;
29 private Global glob = null;
30
31
32 public SimpleReader(I_XmlBlasterAccess _xmlBlaster, String _key) throws Exception{
33 this.xmlBlaster = _xmlBlaster;
34 glob = Global.instance();
35
36 // --- entweder ---
37 ConnectQos qos = new ConnectQos(glob, USR_LOGIN, USR_PASSWD);
38 xmlBlaster.connect(qos, this);
39
40 subscribe(_key);
41 }
42
43 public static void main(String[] args) {
44 try {
45 if (args.length!=2) {
46 printUsage();
47 System.exit(0);
48 }
49 if (!args[0].equals("-key")) {
50 printUsage();
51 System.exit(0);
52 }
53
54 I_XmlBlasterAccess xmlBlaster = new XmlBlasterAccess(args);
55 new SimpleReader(xmlBlaster, args[1]);
56
57 while (true) {
58 try {
59 Thread.sleep(10);
60 }
61 catch(Exception e) {
62 log_error( ME, e.toString(), "");
63 e.printStackTrace();
64 }
65 }
66 }
67 catch(Exception ex) {
68 log_error( ME, ex.toString(), "");
69 ex.printStackTrace();
70 }
71
72 }
73
74 private static void printUsage() {
75 System.out.println("java javaclients.SimpleReader -key <key> ...");
76 }
77
78 public String update(String loginName, UpdateKey updateKey, byte[] content, UpdateQos updateQos) throws XmlBlasterException
79 {
80 System.out.println("Key: "+updateKey.toXml()+" >>> Content: "+new String(content)+" >>> ---");
81 return ("Key: "+updateKey.toXml()+" >>> Content: "+new String(content)+" >>> ---");
82 }
83
84 private void subscribe(String _key) {
85 try {
86 SubscribeKey key = new SubscribeKey(glob, _key, "XPATH");
87 SubscribeQos qos = new SubscribeQos(glob);
88 xmlBlaster.subscribe(key.toXml(), qos.toXml());
89 }
90 catch( Exception ex ) {
91 System.err.println("error-error-error-error >>>"+ex.toString());
92 }
93 }
94
95 public static void log_error(String ME, String text1, String text2) {
96 System.err.println("ME:" + ME + "text:" + text1 + text2);
97 }
98
99
100 } // -- class
101
102 // --file
syntax highlighted by Code2HTML, v. 0.9.1