geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r411511 - /geronimo/daytrader/trunk/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/prims/PingServlet2MDBQueue.java
Date Sun, 04 Jun 2006 03:41:37 GMT
Author: djencks
Date: Sat Jun  3 20:41:36 2006
New Revision: 411511

URL: http://svn.apache.org/viewvc?rev=411511&view=rev
Log:
GERONIMO-2081 Don't share jms connections across threads

Modified:
    geronimo/daytrader/trunk/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/prims/PingServlet2MDBQueue.java

Modified: geronimo/daytrader/trunk/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/prims/PingServlet2MDBQueue.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/prims/PingServlet2MDBQueue.java?rev=411511&r1=411510&r2=411511&view=diff
==============================================================================
--- geronimo/daytrader/trunk/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/prims/PingServlet2MDBQueue.java
(original)
+++ geronimo/daytrader/trunk/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/prims/PingServlet2MDBQueue.java
Sat Jun  3 20:41:36 2006
@@ -17,170 +17,146 @@
 
 package org.apache.geronimo.samples.daytrader.web.prims;
 
-import java.io.*;
-import javax.servlet.*;
-import javax.servlet.http.*;
-import javax.naming.*;
-import javax.jms.*;
+import java.io.IOException;
 
-import org.apache.geronimo.samples.daytrader.ejb.*;
-import org.apache.geronimo.samples.daytrader.util.*;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
-import org.apache.geronimo.samples.daytrader.*;
+import org.apache.geronimo.samples.daytrader.TradeConfig;
+import org.apache.geronimo.samples.daytrader.util.Log;
 
 /**
- *
  * This primitive is designed to run inside the TradeApplication and relies upon
- * the {@link trade_client.TradeConfig} class to set configuration parameters.
- * PingServlet2MDBQueue tests key functionality of a servlet call to a 
+ * the {@link org.apache.geronimo.samples.daytrader.TradeConfig} class to set configuration
parameters.
+ * PingServlet2MDBQueue tests key functionality of a servlet call to a
  * post a message to an MDB Queue. The TradeBrokerMDB receives the message
- * This servlet makes use of the MDB EJB {@link org.apache.geronimo.samples.daytrader.ejb.TradeBrokerMDB}

+ * This servlet makes use of the MDB EJB {@link org.apache.geronimo.samples.daytrader.ejb.TradeBrokerMDB}
  * by posting a message to the MDB Queue
- *
  */
 public class PingServlet2MDBQueue extends HttpServlet {
 
-	private static String initTime;
-	private static int hitCount;
-	private static Connection conn;
-	private static ConnectionFactory connFactory;
-	private static Queue queue;
+    private static String initTime;
+    private static int hitCount;
+    private static ConnectionFactory connFactory;
+    private static Queue queue;
+
+    /**
+     * forwards post requests to the doGet method
+     * Creation date: (11/6/2000 10:52:39 AM)
+     *
+     * @param req javax.servlet.http.HttpServletRequest
+     * @param res javax.servlet.http.HttpServletResponse
+     */
+    public void doPost(HttpServletRequest req, HttpServletResponse res)
+            throws ServletException, IOException {
+        doGet(req, res);
+    }
+
+
+    /**
+     * this is the main method of the servlet that will service all get requests.
+     *
+     * @param req HttpServletRequest
+     * @param res HttpServletResponce
+     */
+
+    public void doGet(HttpServletRequest req, HttpServletResponse res)
+            throws IOException, ServletException {
+
+        res.setContentType("text/html");
+        java.io.PrintWriter out = res.getWriter();
+        //use a stringbuffer to avoid concatenation of Strings
+        StringBuffer output = new StringBuffer(100);
+        output.append(
+                "<html><head><title>PingServlet2MDBQueue</title></head>"
+                        + "<body><HR><FONT size=\"+2\" color=\"#000066\">PingServlet2MDBQueue<BR></FONT>"
+                        + "<FONT size=\"-1\" color=\"#000066\">"
+                        + "Tests the basic operation of a servlet posting a message to an
EJB MDB through a JMS Queue.");
+
+        try {
+
+            Connection conn = connFactory.createConnection();
+
+            try {
+                TextMessage message = null;
+                int iter = TradeConfig.getPrimIterations();
+                for (int ii = 0; ii < iter; ii++) {
+                    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+                    MessageProducer producer = sess.createProducer(queue);
+
+                    message = sess.createTextMessage();
+
+                    String command = "ping";
+                    message.setStringProperty("command", command);
+                    message.setLongProperty("publishTime", System.currentTimeMillis());
+                    message.setText("Ping message for queue java:comp/env/jms/TradeBrokerQueue
sent from PingServlet2MDBQueue at " + new java.util.Date());
+                    producer.send(message);
+                    sess.close();
+                }
+
+                //write out the output
+                output.append("<HR>initTime: ").append(initTime);
+                output.append("<BR>Hit Count: ").append(hitCount++);
+                output.append("<HR>Posted Text message to java:comp/env/jms/TradeBrokerQueue
destination");
+                output.append("<BR>Message: ").append(message);
+                output.append("<BR><BR>Message text: ").append(message.getText());
+                output.append(
+                        "<BR><HR></FONT></BODY></HTML>");
+                out.println(output.toString());
+
+            }
+            catch (Exception e) {
+                Log.error("PingServlet2MDBQueue.doGet(...):exception posting message to TradeBrokerQueue
destination ");
+                throw e;
+            }
+        } //this is where I actually handle the exceptions
+        catch (Exception e) {
+            Log.error(e, "PingServlet2MDBQueue.doGet(...): error");
+            res.sendError(500, "PingServlet2MDBQueue.doGet(...): error, " + e.toString());
+
+        }
+    }
+
+
+    /**
+     * returns a string of information about the servlet
+     *
+     * @return info String: contains info about the servlet
+     */
+
+    public String getServletInfo() {
+        return "web primitive, configured with trade runtime configs, tests Servlet to Session
EJB path";
+
+    }
+
+    /**
+     * called when the class is loaded to initialize the servlet
+     *
+     * @param config ServletConfig:
+     */
+    public void init(ServletConfig config) throws ServletException {
+        super.init(config);
+        hitCount = 0;
+        initTime = new java.util.Date().toString();
+        try {
+            InitialContext context = new InitialContext();
+            connFactory = (ConnectionFactory) context.lookup("java:comp/env/jms/QueueConnectionFactory");
+            queue = (Queue) context.lookup("java:comp/env/jms/TradeBrokerQueue");
+        } catch (NamingException e) {
+            Log.error("PingServlet2MDBQueue:init() -- error on intialization of JMS factories,
queues", e);
+            throw new ServletException(e);
+        }
+    }
 
-/**
- * forwards post requests to the doGet method
- * Creation date: (11/6/2000 10:52:39 AM)
- * @param res javax.servlet.http.HttpServletRequest
- * @param res2 javax.servlet.http.HttpServletResponse
- */
-public void doPost(HttpServletRequest req, HttpServletResponse res)
-	throws ServletException, IOException {
-	doGet(req, res);
-}
- 
- 
-/**
-* this is the main method of the servlet that will service all get requests.
-* @param request HttpServletRequest
-* @param responce HttpServletResponce
-**/
-
-public void doGet(HttpServletRequest req, HttpServletResponse res)
-	throws IOException, ServletException {
-
-	res.setContentType("text/html");
-	java.io.PrintWriter out = res.getWriter();
-	Trade trade = null;
-	//use a stringbuffer to avoid concatenation of Strings
-	StringBuffer output = new StringBuffer(100);
-	output.append(
-		"<html><head><title>PingServlet2MDBQueue</title></head>"
-			+ "<body><HR><FONT size=\"+2\" color=\"#000066\">PingServlet2MDBQueue<BR></FONT>"
-			+ "<FONT size=\"-1\" color=\"#000066\">"
-			+ "Tests the basic operation of a servlet posting a message to an EJB MDB through a JMS
Queue."); 
-
-	//we only want to look up the JMS resources once	
-	try
-	{
-		
-		if (conn == null)
-		{
-		
-			synchronized (lock)
-			{
-				if (conn == null)
-				{
-			
-					try 
-					{
-						output.append("<HR><B>Performing JNDI lookups and creating JMS Resources</B>");
					
-						InitialContext context = new InitialContext();
-						connFactory = (ConnectionFactory) context.lookup("java:comp/env/jms/QueueConnectionFactory");
-						queue = (Queue) context.lookup("java:comp/env/jms/TradeBrokerQueue");
-						// TODO: Is this wrong as it only creates one shared connecton?
-						conn = connFactory.createConnection();
-		
-					}
-					catch (Exception e)
-					{
-						Log.error("PingServlet2MDBQueue:doGet() -- error on intialization of JMS factories,
queues", e);
-						throw e;
-					}		
-				}
-			}
-		}
-		
-		try
-		{
-			TextMessage message = null;
-			int iter = TradeConfig.getPrimIterations();
-			for (int ii = 0; ii < iter; ii++) {
-				Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-				MessageProducer producer = sess.createProducer(queue);
-	
-				message = sess.createTextMessage();
-	
-				String command= "ping";
-				message.setStringProperty("command", command);
-				message.setLongProperty("publishTime", System.currentTimeMillis());			
-				message.setText("Ping message for queue java:comp/env/jms/TradeBrokerQueue sent from
PingServlet2MDBQueue at " + new java.util.Date());
-				producer.send(message);
-				sess.close();
-			}
-			
-			//write out the output
-			output.append("<HR>initTime: " + initTime);
-			output.append("<BR>Hit Count: " + hitCount++);
-			output.append("<HR>Posted Text message to java:comp/env/jms/TradeBrokerQueue destination");
-			output.append("<BR>Message: " + message);
-			output.append("<BR><BR>Message text: " + message.getText());						
-			output.append(
-				"<BR><HR></FONT></BODY></HTML>"); 
-			out.println(output.toString());
-
-		}
-		catch (Exception e)
-		{
-			Log.error("PingServlet2MDBQueue.doGet(...):exception posting message to TradeBrokerQueue
destination "); 
-			throw e;
-		}
-	} //this is where I actually handle the exceptions
-	catch (Exception e)
-	{
-		Log.error(e, "PingServlet2MDBQueue.doGet(...): error"); 
-		res.sendError(500, "PingServlet2MDBQueue.doGet(...): error, " + e.toString());
-
-	}
-}                           
-
-
-
-
-/** 
- * returns a string of information about the servlet
- * @return info String: contains info about the servlet
- **/
-
-public String getServletInfo()
-{
-	return "web primitive, configured with trade runtime configs, tests Servlet to Session EJB
path"; 
-
-}      
-/**
-* called when the class is loaded to initialize the servlet
-* @param config ServletConfig:
-**/
-public void init(ServletConfig config) throws ServletException {
-	super.init(config);
-	hitCount = 0;
-	initTime = new java.util.Date().toString();
-	//for synchronization
-	lock = new Integer(99);
-}      
-
-
-
-
-;
-
-
-	private java.lang.Integer lock;}
\ No newline at end of file
+}
\ No newline at end of file



Mime
View raw message