You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by eh...@apache.org on 2006/10/17 01:38:36 UTC

svn commit: r464725 - in /incubator/wicket/trunk/wicket/src/main/java/wicket: Session.java settings/IRequestCycleSettings.java settings/Settings.java

Author: ehillenius
Date: Mon Oct 16 16:38:36 2006
New Revision: 464725

URL: http://svn.apache.org/viewvc?view=rev&rev=464725
Log:
made timeout configurable. Currently timeout property of IRequestCycleSettings, but if anyone has a strong preference for some other place, that'd be ok too.

Modified:
    incubator/wicket/trunk/wicket/src/main/java/wicket/Session.java
    incubator/wicket/trunk/wicket/src/main/java/wicket/settings/IRequestCycleSettings.java
    incubator/wicket/trunk/wicket/src/main/java/wicket/settings/Settings.java

Modified: incubator/wicket/trunk/wicket/src/main/java/wicket/Session.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/Session.java?view=diff&rev=464725&r1=464724&r2=464725
==============================================================================
--- incubator/wicket/trunk/wicket/src/main/java/wicket/Session.java (original)
+++ incubator/wicket/trunk/wicket/src/main/java/wicket/Session.java Mon Oct 16 16:38:36 2006
@@ -41,6 +41,7 @@
 import wicket.util.convert.IConverter;
 import wicket.util.lang.Objects;
 import wicket.util.string.Strings;
+import wicket.util.time.Duration;
 
 /**
  * Holds information about a user session, including some fixed number of most
@@ -456,11 +457,13 @@
 				pageMapName));
 		if (pageMap != null)
 		{
-			synchronized (usedPageMaps) // get a lock so be sure that only one is made 
+			synchronized (usedPageMaps) // get a lock so be sure that only one
+										// is made
 			{
-				if(pageMapsUsedInRequest == null)
+				if (pageMapsUsedInRequest == null)
 				{
-					// TODO!! this is not synchronized.. it should be (on session?)
+					// TODO!! this is not synchronized.. it should be (on
+					// session?)
 					pageMapsUsedInRequest = new HashMap<PageMap, Thread>(3);
 				}
 			}
@@ -468,15 +471,18 @@
 			{
 				long startTime = System.currentTimeMillis();
 
+				// TODO For now only use the setting. Might be extended with
+				// something overridable on request/ page/ request target level
+				// later
+				Duration timeout = Application.get().getRequestCycleSettings().getTimeout();
+
 				// Get page entry for id and version
 				Thread t = pageMapsUsedInRequest.get(pageMap);
 				while (t != null && t != Thread.currentThread())
 				{
 					try
 					{
-						// TODO make longer and configurable
-						pageMapsUsedInRequest.wait(20000); // wait 20 seconds
-						// max.
+						pageMapsUsedInRequest.wait(timeout.getMilliseconds());
 					}
 					catch (InterruptedException ex)
 					{
@@ -484,13 +490,13 @@
 					}
 					t = pageMapsUsedInRequest.get(pageMap);
 					if (t != null && t != Thread.currentThread()
-							&& (startTime + 20000) < System.currentTimeMillis())
+							&& (startTime + timeout.getMilliseconds()) < System.currentTimeMillis())
 					{
 						// if it is still not the right thread..
-						// This must be a wicket bug or some other (dead)lock in
-						// the code.
-						throw new WicketRuntimeException("After 20s the Pagemap " + pageMapName
-								+ " is still locked by: " + t
+						// This either points to long running code (a report
+						// page?) or a deadlock or such
+						throw new WicketRuntimeException("After " + timeout + " the Pagemap "
+								+ pageMapName + " is still locked by: " + t
 								+ ", giving up trying to get the page for path: " + path);
 					}
 				}
@@ -1096,12 +1102,13 @@
 	 */
 	final void requestDetached()
 	{
-		if(pageMapsUsedInRequest != null)
+		if (pageMapsUsedInRequest != null)
 		{
 			synchronized (pageMapsUsedInRequest)
 			{
 				Thread t = Thread.currentThread();
-				Iterator<Map.Entry<PageMap, Thread>> it = pageMapsUsedInRequest.entrySet().iterator();
+				Iterator<Map.Entry<PageMap, Thread>> it = pageMapsUsedInRequest.entrySet()
+						.iterator();
 				while (it.hasNext())
 				{
 					Entry<PageMap, Thread> entry = it.next();

Modified: incubator/wicket/trunk/wicket/src/main/java/wicket/settings/IRequestCycleSettings.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/settings/IRequestCycleSettings.java?view=diff&rev=464725&r1=464724&r2=464725
==============================================================================
--- incubator/wicket/trunk/wicket/src/main/java/wicket/settings/IRequestCycleSettings.java (original)
+++ incubator/wicket/trunk/wicket/src/main/java/wicket/settings/IRequestCycleSettings.java Mon Oct 16 16:38:36 2006
@@ -7,6 +7,7 @@
 import wicket.markup.html.pages.BrowserInfoPage;
 import wicket.protocol.http.WebRequestCycle;
 import wicket.settings.IApplicationSettings.UnexpectedExceptionDisplay;
+import wicket.util.time.Duration;
 
 /**
  * Inteface for request related settings
@@ -187,6 +188,14 @@
 	String getResponseRequestEncoding();
 
 	/**
+	 * Gets the time that a request will by default be waiting for the previous
+	 * request to be handled before giving up.
+	 * 
+	 * @return The time out
+	 */
+	Duration getTimeout();
+
+	/**
 	 * @see wicket.settings.IExceptionSettings#getUnexpectedExceptionDisplay()
 	 * 
 	 * @return UnexpectedExceptionDisplay
@@ -272,6 +281,14 @@
 	 *            The request and response encoding to be used.
 	 */
 	void setResponseRequestEncoding(final String responseRequestEncoding);
+
+	/**
+	 * Sets the time that a request will by default be waiting for the previous
+	 * request to be handled before giving up.
+	 * 
+	 * @param timeout
+	 */
+	void setTimeout(Duration timeout);
 
 	/**
 	 * @see wicket.settings.IExceptionSettings#setUnexpectedExceptionDisplay(wicket.settings.Settings.UnexpectedExceptionDisplay)

Modified: incubator/wicket/trunk/wicket/src/main/java/wicket/settings/Settings.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/settings/Settings.java?view=diff&rev=464725&r1=464724&r2=464725
==============================================================================
--- incubator/wicket/trunk/wicket/src/main/java/wicket/settings/Settings.java (original)
+++ incubator/wicket/trunk/wicket/src/main/java/wicket/settings/Settings.java Mon Oct 16 16:38:36 2006
@@ -262,6 +262,12 @@
 	/** Flags used to determine how to behave if resources are not found */
 	private boolean throwExceptionOnMissingResource = true;
 
+	/**
+	 * The time that a request will by default be waiting for the previous
+	 * request to be handled before giving up. Defaults to one minute.
+	 */
+	private Duration timeout = Duration.ONE_MINUTE;
+
 	/** Authorizer for component instantiations */
 	private IUnauthorizedComponentInstantiationListener unauthorizedComponentInstantiationListener = new IUnauthorizedComponentInstantiationListener()
 	{
@@ -769,6 +775,7 @@
 		return this.stripXmlDeclarationFromOutput;
 	}
 
+
 	/**
 	 * @see wicket.settings.IResourceSettings#getThrowExceptionOnMissingResource()
 	 */
@@ -777,6 +784,13 @@
 		return throwExceptionOnMissingResource;
 	}
 
+	/**
+	 * @see wicket.settings.IRequestCycleSettings#getTimeout()
+	 */
+	public Duration getTimeout()
+	{
+		return timeout;
+	}
 
 	/**
 	 * @see wicket.settings.ISecuritySettings#getUnauthorizedComponentInstantiationListener()
@@ -1193,6 +1207,18 @@
 	public void setThrowExceptionOnMissingResource(final boolean throwExceptionOnMissingResource)
 	{
 		this.throwExceptionOnMissingResource = throwExceptionOnMissingResource;
+	}
+
+	/**
+	 * @see wicket.settings.IRequestCycleSettings#setTimeout(wicket.util.time.Duration)
+	 */
+	public void setTimeout(Duration timeout)
+	{
+		if (timeout == null)
+		{
+			throw new IllegalArgumentException("timeout cannot be null");
+		}
+		this.timeout = timeout;
 	}
 
 	/**