geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hogst...@apache.org
Subject svn commit: r581048 - in /geronimo/daytrader/trunk/modules: ejb/src/main/java/org/apache/geronimo/samples/daytrader/ ejb/src/main/java/org/apache/geronimo/samples/daytrader/direct/ web/src/main/java/org/apache/geronimo/samples/daytrader/web/ web/src/ma...
Date Mon, 01 Oct 2007 19:50:57 GMT
Author: hogstrom
Date: Mon Oct  1 12:50:55 2007
New Revision: 581048

URL: http://svn.apache.org/viewvc?rev=581048&view=rev
Log:
MarketSummary Interval changes:

1. Changed the represention of the MarketSummary to be seconds in TradeConfig rather than
millseconds.
2. Corrected configuration page to ensure MarketSummaryInterval gets updated correctly when
modified via the browser.
3. Included the values for PrimitiveIterations when making config updates.  This was missing
previously.



Modified:
    geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/TradeConfig.java
    geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/direct/TradeDirect.java
    geronimo/daytrader/trunk/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeConfigServlet.java
    geronimo/daytrader/trunk/modules/web/src/main/webapp/config.jsp
    geronimo/daytrader/trunk/modules/web/src/main/webapp/configure.html

Modified: geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/TradeConfig.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/TradeConfig.java?rev=581048&r1=581047&r2=581048&view=diff
==============================================================================
--- geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/TradeConfig.java
(original)
+++ geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/TradeConfig.java
Mon Oct  1 12:50:55 2007
@@ -112,11 +112,11 @@
 	/**
 	 *   -1 means every operation
 	 *    0 means never perform a market summary
-	 *  > 0 means number of millseconds between summaries.  These will be
-	 *      synchronized so only one tran in this period will create a summary and will
-	 *      cache its results.
+	 *  > 0 means number of seconds between summaries.  These will be
+	 *      synchronized so only one tran in this period will create a summary and 
+	 *      will cache its results.
 	 */
-	private static long  marketSummaryInterval = 60000;
+	private static int  marketSummaryInterval = 60;
 
 	/*
 	 * Penny stocks is a problem where the random price change factor gets a stock
@@ -869,12 +869,12 @@
         return publishQuotePriceChange;
     }
 
-    public static void setMarketSummaryInterval(long millis) {
-        TradeConfig.marketSummaryInterval = millis;
+    public static void setMarketSummaryInterval(int seconds) {
+        TradeConfig.marketSummaryInterval = seconds;
     }
     
-    public static long getMarketSummaryInterval() {
-        return marketSummaryInterval;
+    public static  int getMarketSummaryInterval() {
+        return TradeConfig.marketSummaryInterval;
     }
 
 

Modified: geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/direct/TradeDirect.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/direct/TradeDirect.java?rev=581048&r1=581047&r2=581048&view=diff
==============================================================================
--- geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/direct/TradeDirect.java
(original)
+++ geronimo/daytrader/trunk/modules/ejb/src/main/java/org/apache/geronimo/samples/daytrader/direct/TradeDirect.java
Mon Oct  1 12:50:55 2007
@@ -59,6 +59,10 @@
 public class TradeDirect implements TradeServices
 
 {
+	// This lock is used to serialize market summary operations.
+	private static Integer marketSummaryLock = new Integer(0);
+	private static long nextMarketSummary = 0;
+	private static MarketSummaryDataBean cachedMSDB = MarketSummaryDataBean.getRandomInstance();
 
 	private static String dsName = TradeConfig.DATASOURCE;
 
@@ -89,6 +93,38 @@
      * @see TradeServices#getMarketSummary()
      */
 	public MarketSummaryDataBean getMarketSummary() throws Exception {
+		boolean fetch = false;
+		if (TradeConfig.getMarketSummaryInterval() == 0) return getMarketSummaryInternal();
+		if (TradeConfig.getMarketSummaryInterval() < 0) return cachedMSDB;
+		
+		/**
+		 * This is a little funky.  If its time to fetch a new Market summary then we'll synchronize
+		 * access to make sure only one requester does it.  Others will merely return the old copy
until
+		 * the new MarketSummary has been executed.
+		 */
+		if (System.currentTimeMillis() > nextMarketSummary) {
+			synchronized (marketSummaryLock) {
+				if (System.currentTimeMillis() > nextMarketSummary)  fetch = true;
+				if (nextMarketSummary == 0) nextMarketSummary = System.currentTimeMillis();
+				nextMarketSummary += TradeConfig.getMarketSummaryInterval()*1000;
+			}
+
+			/**
+			 * If we're the lucky one reset the trap and get a new MarketSummaryObject.
+			 */
+			if (fetch) {
+				fetch = false;
+				cachedMSDB = getMarketSummaryInternal();
+			}
+		}
+		return cachedMSDB;
+	}
+
+
+	/**
+     * @see TradeServices#getMarketSummary()
+     */
+	public MarketSummaryDataBean getMarketSummaryInternal() throws Exception {
 
 		MarketSummaryDataBean marketSummaryData = null;
 		Connection conn = null;

Modified: geronimo/daytrader/trunk/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeConfigServlet.java
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeConfigServlet.java?rev=581048&r1=581047&r2=581048&view=diff
==============================================================================
--- geronimo/daytrader/trunk/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeConfigServlet.java
(original)
+++ geronimo/daytrader/trunk/modules/web/src/main/java/org/apache/geronimo/samples/daytrader/web/TradeConfigServlet.java
Mon Oct  1 12:50:55 2007
@@ -291,6 +291,22 @@
 		currentConfigStr += "\t\t#Trade  Users:\t\t" + TradeConfig.getMAX_USERS()  + "\n";		
 		currentConfigStr += "\t\t#Trade Quotes:\t\t" + TradeConfig.getMAX_QUOTES()  + "\n";		
 		
+                parm = req.getParameter("marketSummaryInterval");
+                if ((parm != null) && (parm.length() > 0)) {
+                        try {
+                                TradeConfig.setMarketSummaryInterval(Integer.parseInt(parm));
+                        }
+                        catch (Exception e) {
+                                Log.error(
+                                        e, 
+                                        "TradeConfigServlet: minor exception caught", 
+                                        "trying to set marketSummaryInterval, error on parsing
int " + parm, 
+                                        "reverting to current value " + TradeConfig.getMarketSummaryInterval());
+
+                        }
+                }
+                currentConfigStr += "\t\tMarket Summary Interval:\t\t" + TradeConfig.getMarketSummaryInterval()
 + "\n";
+		
 		parm = req.getParameter("primIterations");
 		if ((parm != null) && (parm.length() > 0)) {
 			try {
@@ -305,8 +321,10 @@
 
 			}
 		}
-
+		currentConfigStr += "\t\tPrimitive Iterations:\t\t" + TradeConfig.getPrimIterations() 
+ "\n";
+                
 		String enablePublishQuotePriceChange = req.getParameter("EnablePublishQuotePriceChange");
+		
 		if (enablePublishQuotePriceChange != null)
 			TradeConfig.setPublishQuotePriceChange(true);
 		else 

Modified: geronimo/daytrader/trunk/modules/web/src/main/webapp/config.jsp
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/web/src/main/webapp/config.jsp?rev=581048&r1=581047&r2=581048&view=diff
==============================================================================
--- geronimo/daytrader/trunk/modules/web/src/main/webapp/config.jsp (original)
+++ geronimo/daytrader/trunk/modules/web/src/main/webapp/config.jsp Mon Oct  1 12:50:55 2007
@@ -248,6 +248,14 @@
 			</TD>
 		</TR>
 		<TR>
+			<TD align="left"><B>Market Summary Interval</B><BR>
+			<INPUT size="25" type="text" name="marketSummaryInterval"
+				value="<%=TradeConfig.getMarketSummaryInterval()%>"></TD>
+			<TD>&lt; 0 Do not perform Market Summary Operations.
+			<br>= 0 Perform market Summary on every request.</br>
+			<br>&gt; 0 number of seconds between Market Summary Operations</br></TD>
+		</TR>
+		<TR>
 			<TD align="left"><B>Primitive Iteration</B><BR>
 			<INPUT size="25" type="text" name="primIterations"
 				value="<%=TradeConfig.getPrimIterations()%>"></TD>

Modified: geronimo/daytrader/trunk/modules/web/src/main/webapp/configure.html
URL: http://svn.apache.org/viewvc/geronimo/daytrader/trunk/modules/web/src/main/webapp/configure.html?rev=581048&r1=581047&r2=581048&view=diff
==============================================================================
--- geronimo/daytrader/trunk/modules/web/src/main/webapp/configure.html (original)
+++ geronimo/daytrader/trunk/modules/web/src/main/webapp/configure.html Mon Oct  1 12:50:55
2007
@@ -56,7 +56,7 @@
                 Password for a remote or protected database when using JDBC.</TD>
         </TR>
         <TR>
-            <TD><A href="config?action=buildDBTables" target="_blank"><FONT
+            <TD><A href="config?action=buildDBTables"><FONT
                     face="Times New Roman" size="-1">(Re)-create
                 &nbsp;DayTrader&nbsp;Database Tables and Indexes</FONT></A></TD>
             <TD>This link is used to (a) initially create or (b) drop and re-create
the
@@ -67,7 +67,7 @@
                 DayTrader Database" link below to repopulate the new database tables.</b></TD>
         </TR>
         <TR>
-            <TD><A href="config?action=buildDB" target="_blank"><FONT
+            <TD><A href="config?action=buildDB"><FONT
                     face="Times New Roman" size="-1">(Re)-populate
                 &nbsp;DayTrader&nbsp;Database</FONT></A></TD>
             <TD>This link is used to initially populate or re-populate the



Mime
View raw message