[jboss-cvs] JBoss Messaging SVN: r6493 - in trunk: examples/jms and 9 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Apr 20 08:50:08 EDT 2009
Author: timfox
Date: 2009-04-20 08:50:07 -0400 (Mon, 20 Apr 2009)
New Revision: 6493
Added:
trunk/examples/jms/instantiate-connection-factory/
trunk/examples/jms/instantiate-connection-factory/build.xml
trunk/examples/jms/instantiate-connection-factory/readme.html
trunk/examples/jms/instantiate-connection-factory/server0/
trunk/examples/jms/instantiate-connection-factory/server0/client-jndi.properties
trunk/examples/jms/instantiate-connection-factory/server0/jbm-configuration.xml
trunk/examples/jms/instantiate-connection-factory/server0/jbm-jms.xml
trunk/examples/jms/instantiate-connection-factory/server0/jbm-queues.xml
trunk/examples/jms/instantiate-connection-factory/server0/jbm-standalone-beans.xml
trunk/examples/jms/instantiate-connection-factory/server0/jbm-users.xml
trunk/examples/jms/instantiate-connection-factory/src/
trunk/examples/jms/instantiate-connection-factory/src/org/
trunk/examples/jms/instantiate-connection-factory/src/org/jboss/
trunk/examples/jms/instantiate-connection-factory/src/org/jboss/jms/
trunk/examples/jms/instantiate-connection-factory/src/org/jboss/jms/example/
trunk/examples/jms/instantiate-connection-factory/src/org/jboss/jms/example/InstantiateConnectionFactoryExample.java
Modified:
trunk/.classpath
trunk/src/main/org/jboss/messaging/core/client/impl/ConnectionManagerImpl.java
trunk/src/main/org/jboss/messaging/core/config/TransportConfiguration.java
Log:
added cf direct instantiating example
Modified: trunk/.classpath
===================================================================
--- trunk/.classpath 2009-04-20 12:14:15 UTC (rev 6492)
+++ trunk/.classpath 2009-04-20 12:50:07 UTC (rev 6493)
@@ -14,6 +14,7 @@
<classpathentry kind="src" path="src/schemas"/>
<classpathentry kind="src" path="tests/joram-tests/src"/>
<classpathentry kind="src" path="tests/joram-tests/config"/>
+ <classpathentry kind="src" path="examples/jms/instantiate-connection-factory/src"/>
<classpathentry kind="src" path="examples/jms/pre-acknowledge/src"/>
<classpathentry kind="src" path="examples/jms/static-selector/src"/>
<classpathentry kind="src" path="examples/jms/topic-hierarchies/src"/>
Property changes on: trunk/examples/jms/instantiate-connection-factory
___________________________________________________________________
Name: svn:ignore
+ build
logs
Added: trunk/examples/jms/instantiate-connection-factory/build.xml
===================================================================
--- trunk/examples/jms/instantiate-connection-factory/build.xml (rev 0)
+++ trunk/examples/jms/instantiate-connection-factory/build.xml 2009-04-20 12:50:07 UTC (rev 6493)
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE project [
+ <!ENTITY libraries SYSTEM "../../../thirdparty/libraries.ent">
+ ]>
+
+<!-- =========================================================================================== -->
+<!-- -->
+<!-- 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. -->
+<!-- -->
+<!-- =========================================================================================== -->
+
+
+<project default="run" name="JBoss Messaging Instantiate ConnectionFactory Example">
+
+ <import file="../common/build.xml"/>
+
+ <target name="run">
+ <antcall target="runExample">
+ <param name="example.classname" value="org.jboss.jms.example.InstantiateConnectionFactoryExample"/>
+ </antcall>
+ </target>
+
+ <target name="runRemote">
+ <antcall target="runExample">
+ <param name="example.classname" value="org.jboss.jms.example.InstantiateConnectionFactoryExample"/>
+ <param name="jbm.example.runServer" value="false"/>
+ </antcall>
+ </target>
+
+</project>
\ No newline at end of file
Added: trunk/examples/jms/instantiate-connection-factory/readme.html
===================================================================
--- trunk/examples/jms/instantiate-connection-factory/readme.html (rev 0)
+++ trunk/examples/jms/instantiate-connection-factory/readme.html 2009-04-20 12:50:07 UTC (rev 6493)
@@ -0,0 +1,117 @@
+<html>
+ <head>
+ <title>JBoss Messaging JMS Instantiate Connection Factory Example</title>
+ <link rel="stylesheet" type="text/css" href="../common/common.css">
+ </head>
+ <body>
+ <h1>JBoss Messaging JMS Instantiate Connection Factory Example</h1>
+ <br>
+
+ <p>Usually, JMS Objects such as ConnectionFactory, Queue and Topic instances are looked up from JNDI
+ before being used by the client code. This objects are called "administered objects" in JMS specification
+ terminology.</p>
+ <p>However, in some cases a JNDI server may not be available or desired. To come to the rescue JBoss Messaging
+ also supports the direct instantiation of these administered objects on the client side.</p>
+ <p>This allows the full set of JMS functionality to be available without requiring a JNDI server!</p>
+ <p>This example is very simple and based on the simple Queue example, however in this example we
+ instantiate the JMS Queue and ConnectionFactory objects directly.</p>
+ <p>A wide variety of constructors are available for instantiating ConnectionFactory objects. In this example
+ we use a simple constructor which just takes the server connection details so it knows where to make the
+ connection to.</p>
+ <p>Other constructors are avilable so all the connection factory parameters can be specified
+ including specifying UDP discovery so the client does not need hard-wired knowledge of where the servers
+ are that it wishes to connect to, or for specifying live-backup pairs of servers for failover.</p>
+ <p>For more information on instantiating ConnectionFactories directly please consult the user manual and
+ javadoc.</p>
+
+ <h2>Example step-by-step</h2>
+ <p><i>To run the example, simply type <code>ant</code> from this directory</i></p>
+ <br>
+ <ol>
+ <li>Instead of looking it up from JNDI we directly instantiate the JMS Queue object. We
+ pass in the name of the JMS Queue in the constructor. The actual JMS Queue must already be deployed on
+ the server.</li>
+ <pre>
+ <code>
+ Queue queue = new JBossQueue("exampleQueue");</code>
+ </pre>
+
+ <li>Instantiate the TransportConfiguration object. The TransportConfiguration instance encapsulates
+ the connection details of the server we're connecting to. In this case we're using Netty as a transport, and
+ we're specifying to connect on port 5446.</li>
+ <pre>
+ <code>
+ Map<String, Object> connectionParams = new HashMap<String, Object>();
+
+ connectionParams.put(PORT_PROP_NAME, 5446);
+
+ TransportConfiguration transportConfiguration = new TransportConfiguration(NettyConnectorFactory.class.getName(),
+ connectionParams);
+
+ </code>
+ </pre>
+
+ <li>Directly instantiate the JMS ConnectionFactory object using that TransportConfiguration.</li>
+ <pre>
+ <code>
+ ConnectionFactory cf = new JBossConnectionFactory(transportConfiguration);
+ </code>
+ </pre>
+
+ <li>We create a JMS connection</li>
+ <pre>
+ <code>connection = cf.createConnection();</code>
+ </pre>
+
+ <li>We create a JMS session. The session is created as non transacted and will auto acknowledge messages.</li>
+ <pre>
+ <code>Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);</code>
+ </pre>
+
+ <li>We create a JMS message producer on the session. This will be used to send the messages.</li>
+ <pre>
+ <code>MessageProducer messageProducer = session.createProducer(topic);</code>
+ </pre>
+
+ <li>We create a JMS text message that we are going to send.</li>
+ <pre>
+ <code>TextMessage message = session.createTextMessage("This is a text message");</code>
+ </pre>
+
+ <li>We send message to the queue</li>
+ <pre>
+ <code>messageProducer.send(message);</code>
+ </pre>
+
+ <li>We create a JMS Message Consumer to receive the message.</li>
+ <pre>
+ <code>MessageConsumer messageConsumer = session.createConsumer(queue);</code>
+ </pre>
+
+ <li>We start the connection. In order for delivery to occur on any consumers or subscribers on a connection, the connection must be started</li>
+ <pre>
+ <code>connection.start();</code>
+ </pre>
+
+ <li>The message arrives at the consumer. In this case we use a timeout of 5000 milliseconds but we could use a blocking 'receive()'</li>
+ <pre>
+ <code>TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);</code>
+ </pre>
+
+ <li>And finally, <b>always</b> remember to close your resources after use, in a <code>finally</code> block.</li>
+
+ <pre>
+ <code>finally
+ {
+ if (connection != null)
+ {
+ connection.close();
+ }
+ }</code>
+ </pre>
+
+
+
+ </ol>
+ </body>
+</html>
\ No newline at end of file
Property changes on: trunk/examples/jms/instantiate-connection-factory/server0
___________________________________________________________________
Name: svn:ignore
+ data
logs
Added: trunk/examples/jms/instantiate-connection-factory/server0/client-jndi.properties
===================================================================
--- trunk/examples/jms/instantiate-connection-factory/server0/client-jndi.properties (rev 0)
+++ trunk/examples/jms/instantiate-connection-factory/server0/client-jndi.properties 2009-04-20 12:50:07 UTC (rev 6493)
@@ -0,0 +1,3 @@
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.provider.url=jnp://localhost:1099
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
Added: trunk/examples/jms/instantiate-connection-factory/server0/jbm-configuration.xml
===================================================================
--- trunk/examples/jms/instantiate-connection-factory/server0/jbm-configuration.xml (rev 0)
+++ trunk/examples/jms/instantiate-connection-factory/server0/jbm-configuration.xml 2009-04-20 12:50:07 UTC (rev 6493)
@@ -0,0 +1,29 @@
+<deployment xmlns="urn:jboss:messaging"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-configuration.xsd">
+ <configuration>
+
+ <!-- Connectors -->
+
+ <connectors>
+ <connector name="netty-connector">
+ <factory-class>org.jboss.messaging.integration.transports.netty.NettyConnectorFactory</factory-class>
+ <param key="jbm.remoting.netty.port" value="5446" type="Integer"/>
+ </connector>
+ </connectors>
+
+ <!-- Acceptors -->
+ <acceptors>
+ <acceptor name="netty-acceptor">
+ <factory-class>org.jboss.messaging.integration.transports.netty.NettyAcceptorFactory</factory-class>
+ <param key="jbm.remoting.netty.port" value="5446" type="Integer"/>
+ </acceptor>
+ </acceptors>
+
+ <!-- Other config -->
+
+ <journal-min-files>2</journal-min-files>
+
+ </configuration>
+
+</deployment>
Added: trunk/examples/jms/instantiate-connection-factory/server0/jbm-jms.xml
===================================================================
--- trunk/examples/jms/instantiate-connection-factory/server0/jbm-jms.xml (rev 0)
+++ trunk/examples/jms/instantiate-connection-factory/server0/jbm-jms.xml 2009-04-20 12:50:07 UTC (rev 6493)
@@ -0,0 +1,10 @@
+<deployment xmlns="urn:jboss:messaging"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-jms.xsd ">
+
+ <!--the queue used by the example-->
+ <queue name="exampleQueue">
+ <entry name="/queue/exampleQueue"/>
+ </queue>
+
+</deployment>
Added: trunk/examples/jms/instantiate-connection-factory/server0/jbm-queues.xml
===================================================================
--- trunk/examples/jms/instantiate-connection-factory/server0/jbm-queues.xml (rev 0)
+++ trunk/examples/jms/instantiate-connection-factory/server0/jbm-queues.xml 2009-04-20 12:50:07 UTC (rev 6493)
@@ -0,0 +1,15 @@
+<settings xmlns="urn:jboss:messaging"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-queues.xsd ">
+
+ <!--security for example queue-->
+ <security match="jms.queue.exampleQueue">
+ <permission type="createDurableQueue" roles="guest"/>
+ <permission type="deleteDurableQueue" roles="guest"/>
+ <permission type="createTempQueue" roles="guest"/>
+ <permission type="deleteTempQueue" roles="guest"/>
+ <permission type="consume" roles="guest"/>
+ <permission type="send" roles="guest"/>
+ </security>
+
+</settings>
Added: trunk/examples/jms/instantiate-connection-factory/server0/jbm-standalone-beans.xml
===================================================================
--- trunk/examples/jms/instantiate-connection-factory/server0/jbm-standalone-beans.xml (rev 0)
+++ trunk/examples/jms/instantiate-connection-factory/server0/jbm-standalone-beans.xml 2009-04-20 12:50:07 UTC (rev 6493)
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="Naming" class="org.jnp.server.NamingBeanImpl"/>
+
+ <!-- JNDI server. Disable this if you don't want JNDI -->
+ <bean name="JNDIServer" class="org.jnp.server.Main">
+ <property name="namingInfo">
+ <inject bean="Naming"/>
+ </property>
+ <property name="port">1099</property>
+ <property name="bindAddress">localhost</property>
+ <property name="rmiPort">1098</property>
+ <property name="rmiBindAddress">localhost</property>
+ </bean>
+
+ <!-- MBean server -->
+ <bean name="MBeanServer" class="javax.management.MBeanServer">
+ <constructor factoryClass="java.lang.management.ManagementFactory"
+ factoryMethod="getPlatformMBeanServer"/>
+ </bean>
+
+ <!-- The core configuration -->
+ <bean name="Configuration" class="org.jboss.messaging.core.config.impl.FileConfiguration"/>
+
+ <!-- The security manager -->
+ <bean name="JBMSecurityManager" class="org.jboss.messaging.core.security.impl.JBMSecurityManagerImpl">
+ <start ignored="true"/>
+ <stop ignored="true"/>
+ </bean>
+
+ <!-- The core server -->
+ <bean name="MessagingServer" class="org.jboss.messaging.core.server.impl.MessagingServerImpl">
+ <constructor>
+ <parameter>
+ <inject bean="Configuration"/>
+ </parameter>
+ <parameter>
+ <inject bean="MBeanServer"/>
+ </parameter>
+ <parameter>
+ <inject bean="JBMSecurityManager"/>
+ </parameter>
+ </constructor>
+ </bean>
+
+ <!-- The JMS server -->
+ <bean name="JMSServerManager" class="org.jboss.messaging.jms.server.impl.JMSServerManagerImpl">
+ <constructor>
+ <parameter>
+ <inject bean="MessagingServer"/>
+ </parameter>
+ </constructor>
+ </bean>
+
+</deployment>
Added: trunk/examples/jms/instantiate-connection-factory/server0/jbm-users.xml
===================================================================
--- trunk/examples/jms/instantiate-connection-factory/server0/jbm-users.xml (rev 0)
+++ trunk/examples/jms/instantiate-connection-factory/server0/jbm-users.xml 2009-04-20 12:50:07 UTC (rev 6493)
@@ -0,0 +1,7 @@
+<deployment xmlns="urn:jboss:messaging" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-users.xsd ">
+ <!-- the default user. this is used where username is null-->
+ <defaultuser name="guest" password="guest">
+ <role name="guest"/>
+ </defaultuser>
+</deployment>
\ No newline at end of file
Added: trunk/examples/jms/instantiate-connection-factory/src/org/jboss/jms/example/InstantiateConnectionFactoryExample.java
===================================================================
--- trunk/examples/jms/instantiate-connection-factory/src/org/jboss/jms/example/InstantiateConnectionFactoryExample.java (rev 0)
+++ trunk/examples/jms/instantiate-connection-factory/src/org/jboss/jms/example/InstantiateConnectionFactoryExample.java 2009-04-20 12:50:07 UTC (rev 6493)
@@ -0,0 +1,119 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * 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.jms.example;
+
+import static org.jboss.messaging.integration.transports.netty.TransportConstants.PORT_PROP_NAME;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.integration.transports.netty.NettyConnectorFactory;
+import org.jboss.messaging.jms.JBossQueue;
+import org.jboss.messaging.jms.client.JBossConnectionFactory;
+
+/**
+ *
+ * This example demonstrates how a JMS client can directly instantiate it's JMS Objects like
+ * Queue, ConnectionFactory, etc. without having to use JNDI at all.
+ *
+ * For more information please see the readme.html file.
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class InstantiateConnectionFactoryExample extends JMSExample
+{
+ public static void main(String[] args)
+ {
+ new InstantiateConnectionFactoryExample().run(args);
+ }
+
+ public boolean runExample() throws Exception
+ {
+ Connection connection = null;
+ try
+ {
+ // Step 1. Directly instantiate the JMS Queue object.
+ Queue queue = new JBossQueue("exampleQueue");
+
+ // Step 2. Instantiate the TransportConfiguration object which contains the knowledge of what transport to use,
+ // The server port etc.
+
+ Map<String, Object> connectionParams = new HashMap<String, Object>();
+
+ connectionParams.put(PORT_PROP_NAME, 5446);
+
+ TransportConfiguration transportConfiguration = new TransportConfiguration(NettyConnectorFactory.class.getName(),
+ connectionParams);
+
+ // Step 3 Directly instantiate the JMS ConnectionFactory object using that TransportConfiguration
+ ConnectionFactory cf = new JBossConnectionFactory(transportConfiguration);
+
+ // Step 4.Create a JMS Connection
+ connection = cf.createConnection();
+
+ // Step 5. Create a JMS Session
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ // Step 6. Create a JMS Message Producer
+ MessageProducer producer = session.createProducer(queue);
+
+ // Step 7. Create a Text Message
+ TextMessage message = session.createTextMessage("This is a text message");
+
+ System.out.println("Sent message: " + message.getText());
+
+ // Step 8. Send the Message
+ producer.send(message);
+
+ // Step 9. Create a JMS Message Consumer
+ MessageConsumer messageConsumer = session.createConsumer(queue);
+
+ // Step 10. Start the Connection
+ connection.start();
+
+ // Step 11. Receive the message
+ TextMessage messageReceived = (TextMessage)messageConsumer.receive(5000);
+
+ System.out.println("Received message: " + messageReceived.getText());
+
+ return true;
+ }
+ finally
+ {
+ if (connection != null)
+ {
+ connection.close();
+ }
+ }
+ }
+
+}
Modified: trunk/src/main/org/jboss/messaging/core/client/impl/ConnectionManagerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ConnectionManagerImpl.java 2009-04-20 12:14:15 UTC (rev 6492)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ConnectionManagerImpl.java 2009-04-20 12:50:07 UTC (rev 6493)
@@ -278,7 +278,7 @@
{
// This can happen if the connection manager gets closed - e.g. the server gets shut down
- throw new MessagingException(MessagingException.NOT_CONNECTED, "Unable to connect to server");
+ throw new MessagingException(MessagingException.NOT_CONNECTED, "Unable to connect to server using configuration " + connectorConfig);
}
channel1 = connection.getChannel(1, -1, false);
Modified: trunk/src/main/org/jboss/messaging/core/config/TransportConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/config/TransportConfiguration.java 2009-04-20 12:14:15 UTC (rev 6492)
+++ trunk/src/main/org/jboss/messaging/core/config/TransportConfiguration.java 2009-04-20 12:50:07 UTC (rev 6493)
@@ -52,112 +52,6 @@
private static final byte TYPE_STRING = 3;
- public void encode(final MessagingBuffer buffer)
- {
- buffer.writeString(name);
- buffer.writeString(factoryClassName);
-
- buffer.writeInt(params == null ? 0 : params.size());
-
- if (params != null)
- {
- for (Map.Entry<String, Object> entry : params.entrySet())
- {
- buffer.writeString(entry.getKey());
-
- Object val = entry.getValue();
-
- if (val instanceof Boolean)
- {
- buffer.writeByte(TYPE_BOOLEAN);
- buffer.writeBoolean((Boolean)val);
- }
- else if (val instanceof Integer)
- {
- buffer.writeByte(TYPE_INT);
- buffer.writeInt((Integer)val);
- }
- else if (val instanceof Long)
- {
- buffer.writeByte(TYPE_LONG);
- buffer.writeLong((Long)val);
- }
- else if (val instanceof String)
- {
- buffer.writeByte(TYPE_STRING);
- buffer.writeString((String)val);
- }
- else
- {
- throw new IllegalArgumentException("Invalid type " + val);
- }
- }
- }
- }
-
- public void decode(final MessagingBuffer buffer)
- {
- name = buffer.readString();
- factoryClassName = buffer.readString();
-
- int num = buffer.readInt();
-
- if (params == null)
- {
- if (num > 0)
- {
- params = new HashMap<String, Object>();
- }
- }
- else
- {
- params.clear();
- }
-
- for (int i = 0; i < num; i++)
- {
- String key = buffer.readString();
-
- byte type = buffer.readByte();
-
- Object val;
-
- switch (type)
- {
- case TYPE_BOOLEAN:
- {
- val = buffer.readBoolean();
-
- break;
- }
- case TYPE_INT:
- {
- val = buffer.readInt();
-
- break;
- }
- case TYPE_LONG:
- {
- val = buffer.readLong();
-
- break;
- }
- case TYPE_STRING:
- {
- val = buffer.readString();
-
- break;
- }
- default:
- {
- throw new IllegalArgumentException("Invalid type " + type);
- }
- }
-
- params.put(key, val);
- }
- }
-
public static String[] splitHosts(final String commaSeparatedHosts)
{
if (commaSeparatedHosts == null)
@@ -296,6 +190,112 @@
return str.toString();
}
+ public void encode(final MessagingBuffer buffer)
+ {
+ buffer.writeString(name);
+ buffer.writeString(factoryClassName);
+
+ buffer.writeInt(params == null ? 0 : params.size());
+
+ if (params != null)
+ {
+ for (Map.Entry<String, Object> entry : params.entrySet())
+ {
+ buffer.writeString(entry.getKey());
+
+ Object val = entry.getValue();
+
+ if (val instanceof Boolean)
+ {
+ buffer.writeByte(TYPE_BOOLEAN);
+ buffer.writeBoolean((Boolean)val);
+ }
+ else if (val instanceof Integer)
+ {
+ buffer.writeByte(TYPE_INT);
+ buffer.writeInt((Integer)val);
+ }
+ else if (val instanceof Long)
+ {
+ buffer.writeByte(TYPE_LONG);
+ buffer.writeLong((Long)val);
+ }
+ else if (val instanceof String)
+ {
+ buffer.writeByte(TYPE_STRING);
+ buffer.writeString((String)val);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Invalid type " + val);
+ }
+ }
+ }
+ }
+
+ public void decode(final MessagingBuffer buffer)
+ {
+ name = buffer.readString();
+ factoryClassName = buffer.readString();
+
+ int num = buffer.readInt();
+
+ if (params == null)
+ {
+ if (num > 0)
+ {
+ params = new HashMap<String, Object>();
+ }
+ }
+ else
+ {
+ params.clear();
+ }
+
+ for (int i = 0; i < num; i++)
+ {
+ String key = buffer.readString();
+
+ byte type = buffer.readByte();
+
+ Object val;
+
+ switch (type)
+ {
+ case TYPE_BOOLEAN:
+ {
+ val = buffer.readBoolean();
+
+ break;
+ }
+ case TYPE_INT:
+ {
+ val = buffer.readInt();
+
+ break;
+ }
+ case TYPE_LONG:
+ {
+ val = buffer.readLong();
+
+ break;
+ }
+ case TYPE_STRING:
+ {
+ val = buffer.readString();
+
+ break;
+ }
+ default:
+ {
+ throw new IllegalArgumentException("Invalid type " + type);
+ }
+ }
+
+ params.put(key, val);
+ }
+ }
+
private String replaceWildcardChars(final String str)
{
return str.replace('.', '-');
More information about the jboss-cvs-commits
mailing list