summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-09-14 03:43:07 (EDT)
committerEike Stepper2007-09-14 03:43:07 (EDT)
commit0bac957dfb02b9c46de17effb80b49f82215493b (patch)
treef65426784d86bed85ea3f9ed8c473c76abf1334d
parent2be60a28c173f9f0815e9b4f6a110d0e2f575882 (diff)
downloadcdo-0bac957dfb02b9c46de17effb80b49f82215493b.zip
cdo-0bac957dfb02b9c46de17effb80b49f82215493b.tar.gz
cdo-0bac957dfb02b9c46de17effb80b49f82215493b.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.net4j.jms.tests/JMSSeparatedTest.launch17
-rw-r--r--plugins/org.eclipse.net4j.jms.tests/src/org/eclipse/net4j/jms/tests/JMSSeparatedTest.java150
2 files changed, 167 insertions, 0 deletions
diff --git a/plugins/org.eclipse.net4j.jms.tests/JMSSeparatedTest.launch b/plugins/org.eclipse.net4j.jms.tests/JMSSeparatedTest.launch
new file mode 100644
index 0000000..d233d63
--- /dev/null
+++ b/plugins/org.eclipse.net4j.jms.tests/JMSSeparatedTest.launch
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+<listEntry value="/org.eclipse.net4j.jms.tests/src/org/eclipse/net4j/jms/tests/JMSSeparatedTest.java"/>
+</listAttribute>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
+<listEntry value="1"/>
+</listAttribute>
+<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
+<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
+<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
+<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
+</listAttribute>
+<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.net4j.jms.tests.JMSSeparatedTest"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.net4j.jms.tests"/>
+<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Djava.naming.factory.initial=com.sun.jndi.rmi.registry.RegistryContextFactory&#13;&#10;-Djava.naming.provider.url=rmi://localhost:1199&#13;&#10;-Dnet4j.config=config"/>
+</launchConfiguration>
diff --git a/plugins/org.eclipse.net4j.jms.tests/src/org/eclipse/net4j/jms/tests/JMSSeparatedTest.java b/plugins/org.eclipse.net4j.jms.tests/src/org/eclipse/net4j/jms/tests/JMSSeparatedTest.java
new file mode 100644
index 0000000..54621b2
--- /dev/null
+++ b/plugins/org.eclipse.net4j.jms.tests/src/org/eclipse/net4j/jms/tests/JMSSeparatedTest.java
@@ -0,0 +1,150 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.jms.tests;
+
+import org.eclipse.net4j.IConnector;
+import org.eclipse.net4j.Net4jUtil;
+import org.eclipse.net4j.db.IDBAdapter;
+import org.eclipse.net4j.db.internal.derby.DerbyAdapter;
+import org.eclipse.net4j.internal.tcp.TCPAcceptorFactory;
+import org.eclipse.net4j.internal.tcp.TCPConnectorFactory;
+import org.eclipse.net4j.internal.util.container.ManagedContainer;
+import org.eclipse.net4j.internal.util.om.log.PrintLogHandler;
+import org.eclipse.net4j.internal.util.om.trace.PrintTraceHandler;
+import org.eclipse.net4j.jms.JMSInitialContext;
+import org.eclipse.net4j.jms.JMSUtil;
+import org.eclipse.net4j.jms.admin.IJMSAdmin;
+import org.eclipse.net4j.jms.admin.JMSAdminUtil;
+import org.eclipse.net4j.jms.internal.server.Server;
+import org.eclipse.net4j.jms.server.IStore;
+import org.eclipse.net4j.jms.server.JMSServerUtil;
+import org.eclipse.net4j.jms.server.jdbc.JDBCUtil;
+import org.eclipse.net4j.tcp.TCPUtil;
+import org.eclipse.net4j.util.container.IManagedContainer;
+import org.eclipse.net4j.util.om.OMPlatform;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.ObjectMessage;
+import javax.jms.Session;
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+public class JMSSeparatedTest
+{
+ public static void main(String[] args) throws Exception
+ {
+ try
+ {
+ Context context = init();
+ ConnectionFactory connectionFactory = (ConnectionFactory)context.lookup("net4j.jms.ConnectionFactory");
+ Destination destination = (Destination)context.lookup("StockTopic");
+
+ Connection connection = connectionFactory.createConnection();
+ Session session = connection.createSession(true, 0);
+
+ MessageProducer publisher = session.createProducer(destination);
+ MessageConsumer subscriber1 = session.createConsumer(destination);
+ MessageConsumer subscriber2 = session.createConsumer(destination);
+ subscriber1.setMessageListener(new MessageLogger("subscriber1"));
+ subscriber2.setMessageListener(new MessageLogger("subscriber2"));
+
+ connection.start();
+
+ publisher.send(session.createObjectMessage("Message 1"));
+ publisher.send(session.createObjectMessage("Message 2"));
+ publisher.send(session.createObjectMessage("Message 3"));
+ publisher.send(session.createObjectMessage("Message 4"));
+
+ session.commit();
+ }
+ finally
+ {
+ Thread.sleep(500);
+ Server.INSTANCE.deactivate();
+ }
+ }
+
+ private static Context init() throws Exception
+ {
+ OMPlatform.INSTANCE.addLogHandler(PrintLogHandler.CONSOLE);
+ OMPlatform.INSTANCE.addTraceHandler(PrintTraceHandler.CONSOLE);
+ OMPlatform.INSTANCE.setDebugging(true);
+
+ initServer();
+ return initClient();
+ }
+
+ private static void initServer() throws Exception
+ {
+ IDBAdapter.REGISTRY.put("derby", new DerbyAdapter());
+ IStore store = JDBCUtil.getStore();
+ Server.INSTANCE.setStore(store);
+ Server.INSTANCE.activate();
+
+ IManagedContainer serverContainer = new ManagedContainer();
+ Net4jUtil.prepareContainer(serverContainer);
+ TCPUtil.prepareContainer(serverContainer);
+ JMSServerUtil.prepareContainer(serverContainer);
+
+ TCPAcceptorFactory.get(serverContainer, null);
+ }
+
+ private static Context initClient() throws NamingException
+ {
+ IManagedContainer clientContainer = new ManagedContainer();
+ Net4jUtil.prepareContainer(clientContainer);
+ TCPUtil.prepareContainer(clientContainer);
+ JMSUtil.prepareContainer(clientContainer);
+ JMSAdminUtil.prepareContainer(clientContainer);
+
+ IConnector connector = TCPConnectorFactory.get(clientContainer, "localhost");
+
+ IJMSAdmin admin = JMSAdminUtil.createAdmin(connector);
+ admin.createQueue("StockQueue");
+ admin.createTopic("StockTopic");
+
+ return new JMSInitialContext(clientContainer);
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private static final class MessageLogger implements MessageListener
+ {
+ private String name;
+
+ public MessageLogger(String name)
+ {
+ this.name = name;
+ }
+
+ public void onMessage(Message message)
+ {
+ try
+ {
+ Object object = ((ObjectMessage)message).getObject();
+ System.out.println("\n------> MESSAGE for " + name + ": " + object + "\n");
+ message.acknowledge();
+ }
+ catch (JMSException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ }
+}