activator.java
来自「一个类似于openJMS分布在ObjectWeb之下的JMS消息中间件。」· Java 代码 · 共 59 行
JAVA
59 行
package com.scalagent.joram.osgi.test2;import java.io.*;import java.util.Properties;import org.osgi.framework.*;import javax.jms.*;import com.scalagent.joram.osgi.client.service.JoramClient;public class Activator implements BundleActivator { private static BundleContext bcontext; public static BundleContext getBundleContext() { return bcontext; } ServiceReference ref = null; JoramClient jclient = null; /** * Implements BundleActivator.start(). * * @param context the framework context for the bundle. */ public void start(BundleContext context) throws Exception { bcontext = context; ref = context.getServiceReference(JoramClient.class.getName()); jclient = (JoramClient) context.getService(ref); jclient.connect("localhost", 16010, "root", "root", 10); ConnectionFactory cf = jclient.getTcpConnectionFactory("localhost", 16010); jclient.createUser("anonymous", "anonymous"); Queue queue = jclient.createQueue("queue"); jclient.disconnect(); Connection cnx = cf.createConnection(); Session sess = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE); TextMessage msg = sess.createTextMessage(); MessageProducer producer = sess.createProducer(queue); msg.setText("Hello world"); producer.send(msg); sess.close(); cnx.close(); } /** * Implements BundleActivator.stop(). * * @param context the framework context for the bundle. */ public void stop(BundleContext context) { context.ungetService(ref); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?