You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2012/03/28 08:56:01 UTC

git commit: WICKET-4479 Маке ModificationWatcher easier for extending

Updated Branches:
  refs/heads/master 384cb3a4d -> 855b6c872


WICKET-4479 Маке ModificationWatcher easier for extending


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/855b6c87
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/855b6c87
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/855b6c87

Branch: refs/heads/master
Commit: 855b6c872c71743826ebe69c44908237a24c2628
Parents: 384cb3a
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Tue Mar 27 20:40:15 2012 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Wed Mar 28 08:55:51 2012 +0200

----------------------------------------------------------------------
 .../java/org/apache/wicket/markup/MarkupCache.java |    2 +-
 .../java/org/apache/wicket/util/thread/Task.java   |    4 +-
 .../wicket/util/watch/ModificationWatcher.java     |   67 +++++++--------
 3 files changed, 36 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/855b6c87/wicket-core/src/main/java/org/apache/wicket/markup/MarkupCache.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/MarkupCache.java b/wicket-core/src/main/java/org/apache/wicket/markup/MarkupCache.java
index 1e3101d..217f1c2 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/MarkupCache.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/MarkupCache.java
@@ -331,7 +331,7 @@ public class MarkupCache implements IMarkupCache
 	 * @param markup
 	 *            Markup.NO_MARKUP
 	 * @return Same as parameter "markup"
-	 * @see org.apache.wicket.settings.IResourceSettings#setResourceStreamLocator(org.apache.wicket.util.resource.locator.IResourceStreamLocator)
+	 * @see org.apache.wicket.settings.IResourceSettings#setResourceStreamLocator(org.apache.wicket.core.util.resource.locator.IResourceStreamLocator)
 	 */
 	protected Markup onMarkupNotFound(final String cacheKey, final MarkupContainer container,
 		final Markup markup)

http://git-wip-us.apache.org/repos/asf/wicket/blob/855b6c87/wicket-util/src/main/java/org/apache/wicket/util/thread/Task.java
----------------------------------------------------------------------
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/thread/Task.java b/wicket-util/src/main/java/org/apache/wicket/util/thread/Task.java
index 6f39062..4ebbf4a 100755
--- a/wicket-util/src/main/java/org/apache/wicket/util/thread/Task.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/thread/Task.java
@@ -106,7 +106,7 @@ public final class Task
 
 							if (log.isTraceEnabled())
 							{
-								log.trace("Run the job: '{}'", code.toString());
+								log.trace("Run the job: '{}'", code);
 							}
 
 							try
@@ -122,7 +122,7 @@ public final class Task
 
 							if (log.isTraceEnabled())
 							{
-								log.trace("Finished with job: '{}'", code.toString());
+								log.trace("Finished with job: '{}'", code);
 							}
 
 							// Sleep until the period is over (or not at all if it's

http://git-wip-us.apache.org/repos/asf/wicket/blob/855b6c87/wicket-util/src/main/java/org/apache/wicket/util/watch/ModificationWatcher.java
----------------------------------------------------------------------
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/watch/ModificationWatcher.java b/wicket-util/src/main/java/org/apache/wicket/util/watch/ModificationWatcher.java
index 8abe543..7af1621 100644
--- a/wicket-util/src/main/java/org/apache/wicket/util/watch/ModificationWatcher.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/watch/ModificationWatcher.java
@@ -20,6 +20,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
+import org.apache.wicket.util.lang.Generics;
 import org.apache.wicket.util.listener.ChangeListenerSet;
 import org.apache.wicket.util.listener.IChangeListener;
 import org.apache.wicket.util.thread.ICode;
@@ -43,7 +44,7 @@ public class ModificationWatcher implements IModificationWatcher
 	private static final Logger log = LoggerFactory.getLogger(ModificationWatcher.class);
 
 	/** maps <code>IModifiable</code> objects to <code>Entry</code> objects */
-	private final Map<IModifiable, Entry> modifiableToEntry = new ConcurrentHashMap<IModifiable, Entry>();
+	private final Map<IModifiable, Entry> modifiableToEntry = Generics.newConcurrentHashMap();
 
 	/** the <code>Task</code> to run */
 	private Task task;
@@ -51,16 +52,16 @@ public class ModificationWatcher implements IModificationWatcher
 	/**
 	 * Container class for holding modifiable entries to watch.
 	 */
-	private static final class Entry
+	protected static final class Entry
 	{
 		// The most recent lastModificationTime polled on the object
-		Time lastModifiedTime;
+		public Time lastModifiedTime;
 
 		// The set of listeners to call when the modifiable changes
-		final ChangeListenerSet listeners = new ChangeListenerSet();
+		public final ChangeListenerSet listeners = new ChangeListenerSet();
 
 		// The modifiable thing
-		IModifiable modifiable;
+		public IModifiable modifiable;
 	}
 
 	/**
@@ -81,10 +82,7 @@ public class ModificationWatcher implements IModificationWatcher
 		start(pollFrequency);
 	}
 
-	/**
-	 * @see org.apache.wicket.util.watch.IModificationWatcher#add(org.apache.wicket.util.watch.IModifiable,
-	 *      org.apache.wicket.util.listener.IChangeListener)
-	 */
+	@Override
 	public final boolean add(final IModifiable modifiable, final IChangeListener listener)
 	{
 		// Look up entry for modifiable
@@ -121,9 +119,7 @@ public class ModificationWatcher implements IModificationWatcher
 		}
 	}
 
-	/**
-	 * @see org.apache.wicket.util.watch.IModificationWatcher#remove(org.apache.wicket.util.watch.IModifiable)
-	 */
+	@Override
 	public IModifiable remove(final IModifiable modifiable)
 	{
 		final Entry entry = modifiableToEntry.remove(modifiable);
@@ -134,9 +130,7 @@ public class ModificationWatcher implements IModificationWatcher
 		return null;
 	}
 
-	/**
-	 * @see org.apache.wicket.util.watch.IModificationWatcher#start(org.apache.wicket.util.time.Duration)
-	 */
+	@Override
 	public void start(final Duration pollFrequency)
 	{
 		// Construct task with the given polling frequency
@@ -144,30 +138,37 @@ public class ModificationWatcher implements IModificationWatcher
 
 		task.run(pollFrequency, new ICode()
 		{
+			@Override
 			public void run(final Logger log)
 			{
-				for (Entry entry : modifiableToEntry.values())
-				{
-					// If the modifiable has been modified after the last known
-					// modification time
-					final Time modifiableLastModified = entry.modifiable.lastModifiedTime();
-					if ((modifiableLastModified != null) &&
-						modifiableLastModified.after(entry.lastModifiedTime))
-					{
-						// Notify all listeners that the modifiable was modified
-						entry.listeners.notifyListeners();
-
-						// Update timestamp
-						entry.lastModifiedTime = modifiableLastModified;
-					}
-				}
+				checkModified();
 			}
 		});
 	}
 
 	/**
-	 * @see org.apache.wicket.util.watch.IModificationWatcher#destroy()
+	 * Checks which IModifiables were modified and notifies their listeners
 	 */
+	protected void checkModified()
+	{
+		for (Entry entry : modifiableToEntry.values())
+		{
+			// If the modifiable has been modified after the last known
+			// modification time
+			final Time modifiableLastModified = entry.modifiable.lastModifiedTime();
+			if ((modifiableLastModified != null) &&
+					modifiableLastModified.after(entry.lastModifiedTime))
+			{
+				// Notify all listeners that the modifiable was modified
+				entry.listeners.notifyListeners();
+
+				// Update timestamp
+				entry.lastModifiedTime = modifiableLastModified;
+			}
+		}
+	}
+
+	@Override
 	public void destroy()
 	{
 		if (task != null)
@@ -177,9 +178,7 @@ public class ModificationWatcher implements IModificationWatcher
 		}
 	}
 
-	/**
-	 * @see org.apache.wicket.util.watch.IModificationWatcher#getEntries()
-	 */
+	@Override
 	public final Set<IModifiable> getEntries()
 	{
 		return modifiableToEntry.keySet();