[jboss-svn-commits] JBL Code SVN: r5360 - in labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks: . src/org/jboss/soa/esb/samples/loanbroker/banks
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Jul 31 10:41:13 EDT 2006
Author: kurt.stam at jboss.com
Date: 2006-07-31 10:41:11 -0400 (Mon, 31 Jul 2006)
New Revision: 5360
Modified:
labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/bank.properties
labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/build.xml
labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/src/org/jboss/soa/esb/samples/loanbroker/banks/ManagerJMS.java
Log:
adding some more javadoc
Modified: labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/bank.properties
===================================================================
--- labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/bank.properties 2006-07-31 14:00:26 UTC (rev 5359)
+++ labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/bank.properties 2006-07-31 14:41:11 UTC (rev 5360)
@@ -1 +1,5 @@
-monitored.directory=C:/Temp
+file.monitored.directory=C:/Temp
+
+jms.provider.url=localhost
+jms.queue.in=queue/B
+jms.queue.out=queue/A
Modified: labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/build.xml
===================================================================
--- labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/build.xml 2006-07-31 14:00:26 UTC (rev 5359)
+++ labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/build.xml 2006-07-31 14:41:11 UTC (rev 5360)
@@ -73,25 +73,20 @@
basedir="${org.jboss.esb.samples.loanbroker.banks.classes.dir}"
includes="**/*.class"
/>
- <jar jarfile="${org.jboss.esb.samples.loanbroker.banks.dest}/dist/lib/pollmgt.sar">
- <fileset dir="${org.jboss.esb.samples.loanbroker.banks.lib.ext.dir}" includes="pollmgt.jar,org.sadun.util.jar"/>
- <metainf dir="${basedir}/config/pollmgt/META-INF"/>
- </jar>
</target>
<target name="runJMSBank" depends="org.jboss.esb.samples.loanbroker.banks.jar">
<echo>Running JMS Based Bank</echo>
<echo>Note that your app-server on host: localhost needs to be up and running!</echo>
- <java fork="yes" classname="org.jboss.soa.esb.samples.loanbroker.banks.ManagerJMS" failonerror="true">
- <sysproperty key="java.naming.factory.initial" value="org.jnp.interfaces.NamingContextFactory"/>
- <sysproperty key="java.naming.provider.url" value="localhost:1099"/>
+ <java fork="yes" classname="org.jboss.soa.esb.samples.loanbroker.banks.ManagerJMS" failonerror="true"
+ args="${jms.provider.url},${jms.queue.in},${jms.queue.out}">
<classpath refid="org.jboss.esb.samples.loanbroker.banks.testclasspath"/>
</java>
</target>
<target name="runFileBank" depends="org.jboss.esb.samples.loanbroker.banks.jar">
<echo>Running File Based Bank</echo>
- <java fork="yes" classname="org.jboss.soa.esb.samples.loanbroker.banks.ManagerFlatFile" failonerror="true" args="${monitored.directory}">
+ <java fork="yes" classname="org.jboss.soa.esb.samples.loanbroker.banks.ManagerFlatFile" failonerror="true" args="${file.monitored.directory}">
<classpath refid="org.jboss.esb.samples.loanbroker.banks.testclasspath"/>
</java>
</target>
Modified: labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/src/org/jboss/soa/esb/samples/loanbroker/banks/ManagerJMS.java
===================================================================
--- labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/src/org/jboss/soa/esb/samples/loanbroker/banks/ManagerJMS.java 2006-07-31 14:00:26 UTC (rev 5359)
+++ labs/jbossesb/trunk/product/docs/samples/trailblazer/bankloanbrokerdemo/banks/src/org/jboss/soa/esb/samples/loanbroker/banks/ManagerJMS.java 2006-07-31 14:41:11 UTC (rev 5360)
@@ -1,24 +1,24 @@
/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, 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.
-*/
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.soa.esb.samples.loanbroker.banks;
import java.math.BigDecimal;
@@ -38,82 +38,141 @@
import javax.naming.InitialContext;
import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
import org.apache.log4j.xml.DOMConfigurator;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
-public class ManagerJMS implements javax.jms.MessageListener
-{
- private static Logger log = Logger.getLogger(ManagerJMS.class);
- private static final String BANK_NAME = "JMSBasedBank";
+/**
+ * The JMS Manager listens to an incoming queue (by default queue/A on localhost). It consumes the
+ * message assuming it is a TextMessage, and that the text is an XML structure that can be marshalled
+ * into a BankQuoteRequest. The request will be processed and a BankQuote Reply will be serialized to XML
+ * and send to the outgoing queue (by default this is queue/B on localhost).
+ *
+ * @author kstam
+ *
+ */
+public class ManagerJMS implements javax.jms.MessageListener {
+ private static Logger logger = Logger.getLogger(ManagerJMS.class);
+ /** Name of the Bank */
+ private static final String BANK_NAME = "JMSBasedBank";
+ /** Rate premium the bank charges */
private static final BigDecimal RATE_PREMIUM = BigDecimal.valueOf(0.50);
- private static final int MAXLOANTERM = 120;
+ /** Maximum duration of the loan the bank will accept [months] */
+ private static final int MAXLOANTERM = 120;
+ /** Default incoming queue */
+ private static String QUEUE_IN = "queue/A";
+ /** Default outgoing queue */
+ private static String QUEUE_OUT = "queue/B";
+ /** Default jms provider url */
+ private static String PROVIDER_URL = "localhost";
+ /** Context used to lookup the Queues */
private static InitialContext ctx;
+ /** Properties used when constructing the InitialContext */
private static Properties properties = new Properties();
+ /** Queue connection for incoming queue */
QueueConnection inQueueConnection;
-
- public void listen()
- {
- try {
- properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
- properties.put(Context.URL_PKG_PREFIXES, "org.jnp.interfaces");
- properties.put(Context.PROVIDER_URL, "localhost");
- ctx = new InitialContext(properties);
- log.info("Looking up queue");
- Queue inQueue = (Queue) ctx.lookup("queue/A");
- log.info("Looking up connection factory");
- QueueConnectionFactory qcf = (QueueConnectionFactory) ctx.lookup("UIL2ConnectionFactory");
- log.info("Creating connection");
- inQueueConnection = qcf.createQueueConnection();
- log.info("Creating session");
- QueueSession qs = inQueueConnection .createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
- QueueReceiver qr = qs.createReceiver(inQueue);
- qr.setMessageListener(this);
- inQueueConnection .start();
- } catch (Exception e) {
- log.error(e.getMessage(),e);
- }
+
+ /**
+ * Sets up the queue listener. By default is listenes to queue/A on localhost.
+ */
+ public void listen() {
+ try {
+ properties.put(Context.INITIAL_CONTEXT_FACTORY,
+ "org.jnp.interfaces.NamingContextFactory");
+ properties.put(Context.URL_PKG_PREFIXES, "org.jnp.interfaces");
+ properties.put(Context.PROVIDER_URL, PROVIDER_URL);
+ ctx = new InitialContext(properties);
+ logger.info("Looking up queue");
+ Queue inQueue = (Queue) ctx.lookup(QUEUE_IN);
+ logger.info("Looking up connection factory");
+ QueueConnectionFactory qcf = (QueueConnectionFactory) ctx
+ .lookup("UIL2ConnectionFactory");
+ logger.info("Creating connection");
+ inQueueConnection = qcf.createQueueConnection();
+ logger.info("Creating session");
+ QueueSession qs = inQueueConnection.createQueueSession(false,
+ Session.DUPS_OK_ACKNOWLEDGE);
+ QueueReceiver qr = qs.createReceiver(inQueue);
+ qr.setMessageListener(this);
+ inQueueConnection.start();
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ }
}
-
+ /**
+ * Sets up the queue listener. By default is listenes to queue/A on localhost. It consumes the
+ * message assuming it is a TextMessage, and that the text is an XML structure that can be marshalled
+ * into a BankQuoteRequest. The request will be processed and a BankQuote Reply will be serialized to XML
+ * and send to the outgoing queue (by default this is queue/B on localhost). If the processing results
+ * in an error a BankQuoteReply with ErrorCode other then 0 is send to the outgoing queue.
+ *
+ * @see javax.jms.MessageListener#onMessage(javax.jms.Message)
+ */
public void onMessage(Message message) {
QueueConnection outQueueConnection;
- log.info("Got message: " + message);
- try {
- TextMessage textMessage = (TextMessage) message;
- String xml=textMessage.getText();
- XStream xstream = new XStream(new DomDriver());
- BankQuoteRequest bankQuoteRequest = (BankQuoteRequest) xstream.fromXML(xml);
- Bank bank = new Bank(BANK_NAME, RATE_PREMIUM, MAXLOANTERM);
- BankQuoteReply bankQuoteReply = bank.processMessage(bankQuoteRequest);
- String bankQuoteReplyXML = xstream.toXML(bankQuoteReply);
- Queue outQueue = (Queue) ctx.lookup("queue/B");
- log.info("Looking up connection factory");
- QueueConnectionFactory qcf = (QueueConnectionFactory) ctx.lookup("UIL2ConnectionFactory");
- log.info("Creating connection");
- outQueueConnection = qcf.createQueueConnection();
- try {
- log.info("Creating session");
- QueueSession qs = outQueueConnection.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
- TextMessage responseTextMessage =qs.createTextMessage(bankQuoteReplyXML);
- QueueSender queueSender = qs.createSender(outQueue);
- queueSender.send(responseTextMessage);
- } catch (JMSException je) {
- log.error(je.getMessage(),je);
- }finally {
- outQueueConnection.close();
- }
- } catch (Exception e) {
- log.error(e.getMessage(),e);
- }
- }
-
- public void close() throws JMSException{
- inQueueConnection.close();
- }
-
- public static void main(String[] args)
- {
+ logger.info("Got message: " + message);
+ try {
+ TextMessage textMessage = (TextMessage) message;
+ String xml = textMessage.getText();
+ XStream xstream = new XStream(new DomDriver());
+ BankQuoteRequest bankQuoteRequest = (BankQuoteRequest) xstream
+ .fromXML(xml);
+ Bank bank = new Bank(BANK_NAME, RATE_PREMIUM, MAXLOANTERM);
+ BankQuoteReply bankQuoteReply = bank
+ .processMessage(bankQuoteRequest);
+ String bankQuoteReplyXML = xstream.toXML(bankQuoteReply);
+ Queue outQueue = (Queue) ctx.lookup(QUEUE_OUT);
+ logger.log(Priority.INFO, "Looking up connection factory");
+ QueueConnectionFactory qcf = (QueueConnectionFactory) ctx
+ .lookup("UIL2ConnectionFactory");
+ logger.log(Priority.INFO, "Creating connection");
+ outQueueConnection = qcf.createQueueConnection();
+ try {
+ logger.log(Priority.INFO, "Creating session");
+ QueueSession qs = outQueueConnection.createQueueSession(false,
+ Session.DUPS_OK_ACKNOWLEDGE);
+ TextMessage responseTextMessage = qs
+ .createTextMessage(bankQuoteReplyXML);
+ QueueSender queueSender = qs.createSender(outQueue);
+ queueSender.send(responseTextMessage);
+ } catch (JMSException je) {
+ logger.log(Priority.ERROR, je.getMessage(), je);
+ } finally {
+ outQueueConnection.close();
+ }
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+ /**
+ * Closing the queue connection as to not leak connection resources.
+ */
+ public void close() throws JMSException {
+ inQueueConnection.close();
+ }
+ /**
+ * Invokes an instance of JMS based bank listener.
+ * @param args - provider url, queue_in, queue_out
+ */
+ public static void main(String[] args) {
+ if (args != null && args.length > 0) {
+ PROVIDER_URL = args[0];
+ if (args.length > 1) {
+ QUEUE_IN = args[1];
+ if (args.length > 2) {
+ QUEUE_OUT = args[2];
+ }
+ }
+ } else {
+ logger.log(Priority.INFO,
+ "Usage: ManagerJMS providerURL, queueIn, queueOut");
+ }
+ logger.log(Priority.INFO, "Starting JMS Bank Listener...");
+ logger.log(Priority.INFO, "Provider URL='" + PROVIDER_URL + "'.");
+ logger.log(Priority.INFO, "Listening to Queue '" + QUEUE_IN + "'.");
+ logger.log(Priority.INFO, "Responding to Queue '" + QUEUE_OUT + "'.");
DOMConfigurator.configure("log4j.xml");
ManagerJMS managerJMS = new ManagerJMS();
managerJMS.listen();
More information about the jboss-svn-commits
mailing list