KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > scalagent > joram > osgi > test2 > Activator


1 package com.scalagent.joram.osgi.test2;
2
3 import java.io.*;
4 import java.util.Properties JavaDoc;
5
6 import org.osgi.framework.*;
7
8 import javax.jms.*;
9
10 import com.scalagent.joram.osgi.client.service.JoramClient;
11
12 public class Activator implements BundleActivator {
13
14   private static BundleContext bcontext;
15
16   public static BundleContext getBundleContext() {
17     return bcontext;
18   }
19
20   ServiceReference ref = null;
21   JoramClient jclient = null;
22
23   /**
24    * Implements BundleActivator.start().
25    *
26    * @param context the framework context for the bundle.
27    */

28   public void start(BundleContext context) throws Exception JavaDoc {
29     bcontext = context;
30
31     ref = context.getServiceReference(JoramClient.class.getName());
32     jclient = (JoramClient) context.getService(ref);
33
34     jclient.connect("localhost", 16010, "root", "root", 10);
35     ConnectionFactory cf = jclient.getTcpConnectionFactory("localhost", 16010);
36     jclient.createUser("anonymous", "anonymous");
37     Queue queue = jclient.createQueue("queue");
38     jclient.disconnect();
39
40     Connection cnx = cf.createConnection();
41     Session sess = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
42     TextMessage msg = sess.createTextMessage();
43     MessageProducer producer = sess.createProducer(queue);
44     msg.setText("Hello world");
45     producer.send(msg);
46     sess.close();
47     cnx.close();
48   }
49
50   /**
51    * Implements BundleActivator.stop().
52    *
53    * @param context the framework context for the bundle.
54    */

55   public void stop(BundleContext context) {
56     context.ungetService(ref);
57   }
58 }
59
Popular Tags