1 /*------------------------------------------------------------------------------
2 Name: ChessMover.java
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 Comment: The demo class which moves around the chess peaces
6 Version: $Id: ChessMover.java 13299 2005-03-24 10:58:29Z ruff $
7 ------------------------------------------------------------------------------*/
8 package javaclients.svg.rhino;
9
10 import org.xmlBlaster.util.XmlBlasterException;
11
12 import org.xmlBlaster.client.I_XmlBlasterAccess;
13 import org.xmlBlaster.util.Global;
14 import org.xmlBlaster.client.qos.ConnectQos;
15 import org.xmlBlaster.util.MsgUnit;
16 import java.util.Random;
17
18
19 /* This is a simple demo client which moves around the chess pieces used in
20 chessRhino.svg. It has been tested with batik 1.5 but it should even work
21 with Mozilla.
22 */
23 public class ChessMover
24 {
25 private static final String ME = "ChessMover";
26 protected I_XmlBlasterAccess connection = null;
27 private Random random = null;
28 private long sleepTime = 0L;
29
30 public ChessMover (String[] args) throws XmlBlasterException
31 {
32 Global glob = new Global(args);
33 sleepTime = Long.parseLong(args[1]);
34 random = new Random(100L);
35 this.connection = glob.getXmlBlasterAccess();
36 ConnectQos connectQos = new ConnectQos(glob, "chessMover", "secret");
37 this.connection.connect(connectQos, null);
38 }
39
40
41 public void publish () throws XmlBlasterException
42 {
43 int id = random.nextInt(32);
44 int x = random.nextInt(450);
45 int y = random.nextInt(450);
46
47 String key = "<?xml version='1.0'?><key oid='" + id + "'><chess>some chess name</chess></key>";
48 String qos = "<qos></qos>";
49 String transform = "translate(" + x + "," + y + ")";
50 String content = "<chess><id>" + id + "A</id><transform>" + transform + "</transform></chess>";
51 MsgUnit msg = new MsgUnit(key, content.getBytes(), qos);
52 this.connection.publish(msg);
53 try {
54 Thread.sleep(this.sleepTime);
55 }
56 catch (Exception ex) {}
57 }
58
59
60 public static void main (String[] args) {
61 try {
62
63 ChessMover mover = new ChessMover(args);
64 while (true) {
65 mover.publish();
66 }
67 }
68 catch (Exception ex) {
69 System.err.println(ex.toString());
70
71 System.err.println("usage: java javaclients.svg.rhino.ChessMover -interval updateInterval");
72 System.err.println("where updateInterval is the time in ms between each move");
73 System.exit(1);
74
75 }
76 }
77
78 }
syntax highlighted by Code2HTML, v. 0.9.1