1 // xmlBlaster/demo/javaclients/HelloWorldNative.java
2 package javaclients;
3 import org.xmlBlaster.client.qos.ConnectQos;
4 import org.xmlBlaster.client.I_XmlBlasterAccess;
5 import org.xmlBlaster.client.XmlBlasterAccess;
6 import org.xmlBlaster.util.Global;
7 import org.xmlBlaster.util.XmlBlasterException;
8 import org.xmlBlaster.util.plugin.I_Plugin;
9 import org.xmlBlaster.util.plugin.PluginInfo;
10
11
12 /**
13 * This native client plugin is loaded by xmlBlaster on startup,
14 * it then connects to xmlBlaster.
15 * <p />
16 * You need to add this plugin to xmlBlasterPlugins.xml, for example:
17 * <pre>
18 * <plugin id='HelloWorldNative' className='javaclients.HelloWorldNative'>
19 * <action do='LOAD' onStartupRunlevel='3' sequence='0' onFail='resource.configuration.pluginFailed'/>
20 * <action do='STOP' onShutdownRunlevel='6' sequence='4'/>
21 * </plugin>
22 * </pre>
23 * As a protocol driver to talk to xmlBlaster it has configured "LOCAL", this
24 * plugin works only if client and server is in the same virtual machine (JVM).
25 * Other protocols like CORBA or SOCKET would work as well but carry the overhead
26 * of sending the message over TCP/IP.
27 * @see <a href="http://www.xmlBlaster.org/xmlBlaster/doc/requirements/protocol.local.html" target="others">native protocol requirement</a>
28 * @see <a href="http://www.xmlBlaster.org/xmlBlaster/doc/requirements/engine.runlevel.html" target="others">run level requirement</a>
29 */
30 public class HelloWorldNative implements I_Plugin
31 {
32 private Global glob;
33
34 private final void doLogin() {
35 try {
36 System.err.println("HelloWorldNative: Connecting with protocol 'LOCAL' to xmlBlaster\n");
37 I_XmlBlasterAccess con = new XmlBlasterAccess(glob);
38
39 ConnectQos qos = new ConnectQos(this.glob); /* Client side object */
40 qos.setPtpAllowed(false);
41 qos.setUserId("A-NATIVE-CLIENT-PLUGIN");
42 qos.getSessionQos().setSessionTimeout(0L);
43 con.connect(qos, null); // Login to xmlBlaster as "A-NATIVE-CLIENT-PLUGIN"
44 //Here we could publish or subscribe etc., see HelloWorld3.java how to do it
45 //con.disconnect(null);
46 }
47 catch (Exception e) {
48 System.err.println("HelloWorldNative: We have a problem: " + e.toString());
49 }
50 }
51
52 public void init(org.xmlBlaster.util.Global glob, PluginInfo pluginInfo) throws XmlBlasterException {
53 this.glob = glob.getClone(glob.getNativeConnectArgs()); // Sets "-protocol LOCAL" etc.
54 this.glob.addObjectEntry("ServerNodeScope", glob.getObjectEntry("ServerNodeScope"));
55 System.out.println("\nHelloWorldNative: init(): The plugin is loaded");
56 doLogin();
57 }
58
59 public String getType() {
60 return "HelloWorldNative";
61 }
62
63 public String getVersion() {
64 return "1.0";
65 }
66
67 public void shutdown() throws XmlBlasterException {
68 System.err.println("\nHelloWorldNative: shutdown()\n");
69 }
70
71 /** To start as a plugin */
72 public HelloWorldNative() {}
73
74 /** To start as a separate client: java javaclients.HelloWorldNative */
75 public HelloWorldNative(String args[]) {
76 this.glob = new Global(args);
77 doLogin();
78 }
79
80 public static void main(String args[]) {
81 new HelloWorldNative(args);
82 }
83 }
syntax highlighted by Code2HTML, v. 0.9.1