[jboss-cvs] JBoss Messaging SVN: r4160 - in trunk/docs/examples/messaging: src/org/jboss/messaging/example and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu May 8 04:54:46 EDT 2008
Author: timfox
Date: 2008-05-08 04:54:45 -0400 (Thu, 08 May 2008)
New Revision: 4160
Added:
trunk/docs/examples/messaging/src/org/jboss/messaging/example/SimpleExample.java
Removed:
trunk/docs/examples/messaging/src/org/jboss/messaging/example/EmbeddedExample.java
Modified:
trunk/docs/examples/messaging/build.xml
trunk/docs/examples/messaging/src/org/jboss/messaging/example/SSLClient.java
trunk/docs/examples/messaging/src/org/jboss/messaging/example/SimpleClient.java
Log:
Fixed examples
Modified: trunk/docs/examples/messaging/build.xml
===================================================================
--- trunk/docs/examples/messaging/build.xml 2008-05-08 08:48:10 UTC (rev 4159)
+++ trunk/docs/examples/messaging/build.xml 2008-05-08 08:54:45 UTC (rev 4160)
@@ -82,7 +82,7 @@
</target>
<target name="EmbeddedExample" depends="compile">
- <java classname="org.jboss.messaging.example.EmbeddedExample" fork="true">
+ <java classname="org.jboss.messaging.example.SimpleExample" fork="true">
<classpath refid="runtime.classpath"/>
</java>
</target>
Deleted: trunk/docs/examples/messaging/src/org/jboss/messaging/example/EmbeddedExample.java
===================================================================
--- trunk/docs/examples/messaging/src/org/jboss/messaging/example/EmbeddedExample.java 2008-05-08 08:48:10 UTC (rev 4159)
+++ trunk/docs/examples/messaging/src/org/jboss/messaging/example/EmbeddedExample.java 2008-05-08 08:54:45 UTC (rev 4160)
@@ -1,136 +0,0 @@
-/*
- * 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 java.util.HashSet;
-
-import org.jboss.messaging.core.client.ClientConnection;
-import org.jboss.messaging.core.client.ClientConnectionFactory;
-import org.jboss.messaging.core.client.ClientConsumer;
-import org.jboss.messaging.core.client.ClientProducer;
-import org.jboss.messaging.core.client.ClientSession;
-import org.jboss.messaging.core.client.ConnectionParams;
-import org.jboss.messaging.core.client.Location;
-import org.jboss.messaging.core.client.impl.ClientConnectionFactoryImpl;
-import org.jboss.messaging.core.client.impl.ConnectionParamsImpl;
-import org.jboss.messaging.core.client.impl.LocationImpl;
-import org.jboss.messaging.core.config.impl.ConfigurationImpl;
-import org.jboss.messaging.core.exception.MessagingException;
-import org.jboss.messaging.core.message.Message;
-import org.jboss.messaging.core.message.impl.MessageImpl;
-import org.jboss.messaging.core.remoting.TransportType;
-import org.jboss.messaging.core.security.CheckType;
-import org.jboss.messaging.core.security.JBMSecurityManager;
-import org.jboss.messaging.core.security.Role;
-import org.jboss.messaging.core.server.MessagingServer;
-import org.jboss.messaging.core.server.impl.MessagingServerImpl;
-import org.jboss.messaging.jms.client.JBossTextMessage;
-import org.jboss.messaging.util.SimpleString;
-
-/**
- * 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);
- configuration.setServerID(0);
- 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
-
- SimpleString atestq = new SimpleString("atestq");
-
- messagingServer.getPostOffice().addBinding(atestq, atestq, null, false, false);
-
- //then we create a client as normal
- Location location = new LocationImpl(0);
- ConnectionParams connectionParams = new ConnectionParamsImpl();
- ClientConnectionFactory connectionFactory = new ClientConnectionFactoryImpl(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/docs/examples/messaging/src/org/jboss/messaging/example/SSLClient.java
===================================================================
--- trunk/docs/examples/messaging/src/org/jboss/messaging/example/SSLClient.java 2008-05-08 08:48:10 UTC (rev 4159)
+++ trunk/docs/examples/messaging/src/org/jboss/messaging/example/SSLClient.java 2008-05-08 08:54:45 UTC (rev 4160)
@@ -71,12 +71,12 @@
ClientProducer clientProducer = clientSession.createProducer(queue);
Message message = new MessageImpl(JBossTextMessage.TYPE, false, 0,
System.currentTimeMillis(), (byte) 1);
- message.setPayload("Hello!".getBytes());
+ message.getBody().putString("Hello!");
clientProducer.send(message);
ClientConsumer clientConsumer = clientSession.createConsumer(queue, null, false, false, false);
clientConnection.start();
Message msg = clientConsumer.receive(5000);
- System.out.println("msg.getPayload() = " + new String(msg.getPayload()));
+ System.out.println("msg.getPayload() = " + msg.getBody().getString());
}
catch(Exception e)
{
Modified: trunk/docs/examples/messaging/src/org/jboss/messaging/example/SimpleClient.java
===================================================================
--- trunk/docs/examples/messaging/src/org/jboss/messaging/example/SimpleClient.java 2008-05-08 08:48:10 UTC (rev 4159)
+++ trunk/docs/examples/messaging/src/org/jboss/messaging/example/SimpleClient.java 2008-05-08 08:54:45 UTC (rev 4160)
@@ -59,12 +59,12 @@
ClientProducer clientProducer = clientSession.createProducer(queue);
Message message = new MessageImpl(JBossTextMessage.TYPE, false, 0,
System.currentTimeMillis(), (byte) 1);
- message.setPayload("Hello!".getBytes());
+ message.getBody().putString("Hello!");
clientProducer.send(message);
ClientConsumer clientConsumer = clientSession.createConsumer(queue, null, false, false, false);
clientConnection.start();
Message msg = clientConsumer.receive(5000);
- System.out.println("msg.getPayload() = " + new String(msg.getPayload()));
+ System.out.println("msg.getPayload() = " + msg.getBody().getString());
}
catch(Exception e)
{
Copied: trunk/docs/examples/messaging/src/org/jboss/messaging/example/SimpleExample.java (from rev 4158, trunk/docs/examples/messaging/src/org/jboss/messaging/example/EmbeddedExample.java)
===================================================================
--- trunk/docs/examples/messaging/src/org/jboss/messaging/example/SimpleExample.java (rev 0)
+++ trunk/docs/examples/messaging/src/org/jboss/messaging/example/SimpleExample.java 2008-05-08 08:54:45 UTC (rev 4160)
@@ -0,0 +1,136 @@
+/*
+ * 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 java.util.HashSet;
+
+import org.jboss.messaging.core.client.ClientConnection;
+import org.jboss.messaging.core.client.ClientConnectionFactory;
+import org.jboss.messaging.core.client.ClientConsumer;
+import org.jboss.messaging.core.client.ClientProducer;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.ConnectionParams;
+import org.jboss.messaging.core.client.Location;
+import org.jboss.messaging.core.client.impl.ClientConnectionFactoryImpl;
+import org.jboss.messaging.core.client.impl.ConnectionParamsImpl;
+import org.jboss.messaging.core.client.impl.LocationImpl;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.message.impl.MessageImpl;
+import org.jboss.messaging.core.remoting.TransportType;
+import org.jboss.messaging.core.security.CheckType;
+import org.jboss.messaging.core.security.JBMSecurityManager;
+import org.jboss.messaging.core.security.Role;
+import org.jboss.messaging.core.server.MessagingServer;
+import org.jboss.messaging.core.server.impl.MessagingServerImpl;
+import org.jboss.messaging.jms.client.JBossTextMessage;
+import org.jboss.messaging.util.SimpleString;
+
+/**
+ * A simple server is started with TCP transport, a message is sent and received.
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class SimpleExample
+{
+ 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.TCP);
+ configuration.setHost("localhost");
+ 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
+
+ SimpleString atestq = new SimpleString("atestq");
+
+ messagingServer.getPostOffice().addBinding(atestq, atestq, null, false, false);
+
+ //then we create a client as normal
+ Location location = new LocationImpl(TransportType.TCP, "localhost", 5400);
+ ConnectionParams connectionParams = new ConnectionParamsImpl();
+ ClientConnectionFactory connectionFactory = new ClientConnectionFactoryImpl(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.getBody().putString("Hello!");
+ clientProducer.send(message);
+ ClientConsumer clientConsumer = clientSession.createConsumer(atestq, null, false, false, false);
+ clientConnection.start();
+ Message msg = clientConsumer.receive(5000);
+ System.out.println("msg.getPayload() = " + msg.getBody().getString());
+ }
+ 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)
+ {
+ //
+ }
+ }
+ }
+ }
+}
More information about the jboss-cvs-commits
mailing list