1 // xmlBlaster/demo/javaclients/ClientPlugin.java
2 package javaclients;
3 import org.xmlBlaster.client.I_XmlBlasterAccess;
4 import org.xmlBlaster.client.XmlBlasterAccess;
5 import org.xmlBlaster.util.XmlBlasterException;
6 import org.xmlBlaster.util.MsgUnit;
7 import org.xmlBlaster.util.plugin.I_Plugin;
8 import org.xmlBlaster.util.plugin.PluginInfo;
9
10
11 /**
12 * This client is loaded by xmlBlaster as a plugin on startup, it then connects
13 * to xmlBlaster and gets synchronous a message and disconnects.
14 * <p />
15 * You need to add this plugin to xmlBlasterPlugins.xml, for example:
16 * <pre>
17 * <plugin id='ClientPlugin' className='javaclients.ClientPlugin'>
18 * <action do='LOAD' onStartupRunlevel='9'/>
19 * <action do='STOP' onShutdownRunlevel='6'/>
20 * </plugin>
21 * </pre>
22 * @see <a href="http://www.xmlBlaster.org/xmlBlaster/doc/requirements/engine.runlevel.html" target="others">run level requirement</a>
23 * @see <a href="http://www.xmlBlaster.org/xmlBlaster/doc/requirements/engine.runlevel.howto.html" target="others">run level howto requirement</a>
24 */
25 public class ClientPlugin implements I_Plugin
26 {
27 public void init(org.xmlBlaster.util.Global glob, PluginInfo pluginInfo)
28 throws XmlBlasterException {
29 doSomething();
30 }
31
32 public String getType() {
33 return "ClientPlugin";
34 }
35
36 public String getVersion() {
37 return "1.0";
38 }
39
40 public void shutdown() throws XmlBlasterException {
41 }
42
43 /**
44 * We login to xmlBlaster and check the free memory
45 */
46 private final void doSomething() {
47 try {
48 I_XmlBlasterAccess con = new XmlBlasterAccess(new String[0]);
49
50 con.connect(null, null); // Login to xmlBlaster
51
52 MsgUnit[] msgs = con.get("<key oid='__cmd:?freeMem'/>", null);
53
54 System.out.println("\n###ClientPlugin###: xmlBlaster has currently " +
55 new String(msgs[0].getContent()) + " bytes of free memory\n");
56
57 con.disconnect(null);
58 }
59 catch (Exception e) {
60 System.err.println("ClientPlugin: We have a problem: " + e.toString());
61 }
62 }
63 }
syntax highlighted by Code2HTML, v. 0.9.1