[jboss-cvs] JBoss Messaging SVN: r4105 - in trunk: docs/examples and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Apr 23 10:31:11 EDT 2008
Author: ataylor
Date: 2008-04-23 10:31:11 -0400 (Wed, 23 Apr 2008)
New Revision: 4105
Added:
trunk/docs/examples/messaging/src/org/jboss/messaging/example/EmbeddedExample.java
Modified:
trunk/build-messaging.xml
trunk/docs/examples/build.properties
trunk/docs/examples/messaging/build.xml
trunk/src/main/org/jboss/messaging/core/server/MessagingServer.java
Log:
added embedded example and added setter to MessagingServer intf
Modified: trunk/build-messaging.xml
===================================================================
--- trunk/build-messaging.xml 2008-04-23 13:48:52 UTC (rev 4104)
+++ trunk/build-messaging.xml 2008-04-23 14:31:11 UTC (rev 4105)
@@ -500,7 +500,7 @@
<exclude name="build.properties"/>
</fileset>
</copy>
- <echo message="lib.dir=../../../lib${line.separator}client.jar=../../../lib/jboss-messaging-client.jar${line.separator}config.dir=../../../config"
+ <echo message="lib.dir=../../../lib${line.separator}client.jar=../../../lib/jboss-messaging-client.jar${line.separator}config.dir=../../../config${line.separator}server.jar=../../../lib/jboss-messaging.jar"
file="${build.distro.examples.dir}/build.properties"/>
<echo message="java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory${line.separator}java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces"
file="${build.distro.config.dir}/jndi.properties"/>
Modified: trunk/docs/examples/build.properties
===================================================================
--- trunk/docs/examples/build.properties 2008-04-23 13:48:52 UTC (rev 4104)
+++ trunk/docs/examples/build.properties 2008-04-23 14:31:11 UTC (rev 4105)
@@ -1,3 +1,4 @@
lib.dir=../../../thirdparty
client.jar=../../../build/jars/jboss-messaging-client.jar
+server.jar=../../../build/jars/jboss-messaging.jar
config.dir=../../../tests/etc/
Modified: trunk/docs/examples/messaging/build.xml
===================================================================
--- trunk/docs/examples/messaging/build.xml 2008-04-23 13:48:52 UTC (rev 4104)
+++ trunk/docs/examples/messaging/build.xml 2008-04-23 14:31:11 UTC (rev 4105)
@@ -44,6 +44,7 @@
<include name="**/*.jar"/>
</fileset>
<pathelement location="${client.jar}"/>
+ <pathelement location="${server.jar}"/>
</path>
<path id="runtime.classpath">
@@ -80,4 +81,10 @@
</java>
</target>
+ <target name="EmbeddedExample" depends="compile">
+ <java classname="org.jboss.messaging.example.EmbeddedExample" fork="true">
+ <classpath refid="runtime.classpath"/>
+ </java>
+ </target>
+
</project>
\ No newline at end of file
Added: trunk/docs/examples/messaging/src/org/jboss/messaging/example/EmbeddedExample.java
===================================================================
--- trunk/docs/examples/messaging/src/org/jboss/messaging/example/EmbeddedExample.java (rev 0)
+++ trunk/docs/examples/messaging/src/org/jboss/messaging/example/EmbeddedExample.java 2008-04-23 14:31:11 UTC (rev 4105)
@@ -0,0 +1,126 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.example;
+
+import org.jboss.messaging.core.server.MessagingServer;
+import org.jboss.messaging.core.server.impl.MessagingServerImpl;
+import org.jboss.messaging.core.config.Configuration;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.remoting.TransportType;
+import org.jboss.messaging.core.client.*;
+import org.jboss.messaging.core.client.impl.LocationImpl;
+import org.jboss.messaging.core.client.impl.ConnectionParamsImpl;
+import org.jboss.messaging.core.client.impl.ClientConnectionFactoryImpl;
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.message.impl.MessageImpl;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.security.Role;
+import org.jboss.messaging.core.security.JBMSecurityManager;
+import org.jboss.messaging.core.security.CheckType;
+import org.jboss.messaging.jms.client.JBossTextMessage;
+
+import java.util.HashSet;
+
+/**
+ * A simple embedded server is started with an INVM transport, a message is sentr and received.
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class EmbeddedExample
+{
+ public static void main(String[] args) throws Exception
+ {
+ MessagingServer messagingServer = null;
+ ClientConnection clientConnection = null;
+
+ try
+ {
+ //create a new server with an invm transport, we could use TCP if needed
+ ConfigurationImpl configuration = new ConfigurationImpl();
+ configuration.setTransport(TransportType.INVM);
+ messagingServer = new MessagingServerImpl(configuration);
+ //lets use our own security manager, we could use the default if needed but we would need to make sure that
+ // jbm-security.xml and queues.xml are in the classpath
+ messagingServer.setSecurityManager(new JBMSecurityManager()
+ {
+ public boolean validateUser(String user, String password)
+ {
+ return true;
+ }
+
+ public boolean validateUserAndRole(String user, String password, HashSet<Role> roles, CheckType checkType)
+ {
+ return true;
+ }
+ });
+ //start the server
+ messagingServer.start();
+ //add a new binding
+ messagingServer.getPostOffice().addBinding("atestq", "atestq", null, false, false);
+
+ //then we create a client as normal
+ Location location = new LocationImpl(TransportType.INVM);
+ ConnectionParams connectionParams = new ConnectionParamsImpl();
+ ClientConnectionFactory connectionFactory = new ClientConnectionFactoryImpl(0, location, connectionParams);
+
+ clientConnection = connectionFactory.createConnection();
+ ClientSession clientSession = clientConnection.createClientSession(false, true, true, 100, true, false);
+ ClientProducer clientProducer = clientSession.createProducer("atestq");
+ Message message = new MessageImpl(JBossTextMessage.TYPE, false, 0,
+ System.currentTimeMillis(), (byte) 1);
+ message.setPayload("Hello!".getBytes());
+ clientProducer.send(message);
+ ClientConsumer clientConsumer = clientSession.createConsumer("atestq", null, false, false, false);
+ clientConnection.start();
+ Message msg = clientConsumer.receive(5000);
+ System.out.println("msg.getPayload() = " + new String(msg.getPayload()));
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ if (clientConnection != null)
+ {
+ try
+ {
+ clientConnection.close();
+ }
+ catch (MessagingException e1)
+ {
+ //
+ }
+ }
+ if (messagingServer != null && messagingServer.isStarted())
+ {
+ try
+ {
+ messagingServer.stop();
+ }
+ catch (Exception e1)
+ {
+ //
+ }
+ }
+ }
+ }
+}
Modified: trunk/src/main/org/jboss/messaging/core/server/MessagingServer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/MessagingServer.java 2008-04-23 13:48:52 UTC (rev 4104)
+++ trunk/src/main/org/jboss/messaging/core/server/MessagingServer.java 2008-04-23 14:31:11 UTC (rev 4105)
@@ -81,6 +81,8 @@
SecurityStore getSecurityStore();
+ void setSecurityManager(JBMSecurityManager securityManager);
+
public JBMSecurityManager getSecurityManager();
HierarchicalRepository<QueueSettings> getQueueSettingsRepository();
More information about the jboss-cvs-commits
mailing list