00001 package com.scalagent.joram.osgi.test;
00002
00003 import java.io.*;
00004
00005 import org.osgi.framework.*;
00006
00007 import javax.jms.*;
00008 import javax.naming.*;
00009
00010 import com.scalagent.joram.osgi.client.service.JoramClient;
00011
00012 public class Activator implements BundleActivator {
00013
00014 private static BundleContext bcontext;
00015
00016 public static BundleContext getBundleContext() {
00017 return bcontext;
00018 }
00019
00020 ServiceReference ref = null;
00021 JoramClient jclient = null;
00022
00028 public void start(BundleContext context) throws Exception {
00029 bcontext = context;
00030
00031 ref = context.getServiceReference(JoramClient.class.getName());
00032 jclient = (JoramClient) context.getService(ref);
00033
00034 Context ictx = jclient.getInitialContext();
00035 System.err.println("" + ictx.getClass());
00036
00037
00038 ClassLoader cl = getClass().getClassLoader();
00039
00040
00041 InputStream is = cl.getResourceAsStream("joramAdmin.xml");
00042 jclient.executeAdminXML(new InputStreamReader(is));
00043
00044 Reference refQ = (Reference) ictx.lookup("queue");
00045
00046 System.err.println("" + refQ.getClass());
00047 System.err.println("" + refQ.getFactoryClassName());
00048 System.err.println(refQ.toString());
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 ConnectionFactory cf = jclient.getTcpConnectionFactory("localhost", 16010);
00059 Connection cnx = cf.createConnection();
00060 Session sess = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
00061
00062 Queue queue = sess.createQueue((String) refQ.get("dest.name").getContent());
00063
00064 TextMessage msg = sess.createTextMessage();
00065 MessageProducer producer = sess.createProducer(queue);
00066 msg.setText("Hello world");
00067 producer.send(msg);
00068 sess.close();
00069 cnx.close();
00070 }
00071
00077 public void stop(BundleContext context) {
00078 context.ungetService(ref);
00079 }
00080 }