Author: mwebb
Date: Fri Dec 7 20:07:26 2007
New Revision: 602315
URL: http://svn.apache.org/viewvc?rev=602315&view=rev
Log:
added javadoc
Modified:
mina/trunk/core/src/main/java/org/apache/mina/util/ExpiringMap.java
Modified: mina/trunk/core/src/main/java/org/apache/mina/util/ExpiringMap.java
URL:
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/util/ExpiringMap.java?rev=602315&r1=602314&r2=602315&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/util/ExpiringMap.java
(original)
+++ mina/trunk/core/src/main/java/org/apache/mina/util/ExpiringMap.java Fri Dec
7 20:07:26 2007
@@ -28,14 +28,23 @@
import java.util.concurrent.locks.ReentrantReadWriteLock;
/**
- * A map with expiration.
+ * A map with expiration. This class contains a worker thread that will
+ * periodically check this class in order to determine if any objects
+ * should be removed based on the provided time-to-live value.
*
* @author The Apache MINA Project ([EMAIL PROTECTED])
* @version $Rev$, $Date$
*/
public class ExpiringMap<K, V> implements Map<K, V> {
+
+ /**
+ * The default value, 60
+ */
public static final int DEFAULT_TIME_TO_LIVE = 60;
+ /**
+ * The default value, 1
+ */
public static final int DEFAULT_EXPIRATION_INTERVAL = 1;
private static volatile int expirerCount = 1;
@@ -46,14 +55,35 @@
private final Expirer expirer;
+ /**
+ * Creates a new instance of ExpiringMap using the default values
+ * DEFAULT_TIME_TO_LIVE and DEFAULT_EXPIRATION_INTERVAL
+ *
+ */
public ExpiringMap() {
this(DEFAULT_TIME_TO_LIVE, DEFAULT_EXPIRATION_INTERVAL);
}
+ /**
+ * Creates a new instance of ExpiringMap using the supplied
+ * time-to-live value and the default value for DEFAULT_EXPIRATION_INTERVAL
+ *
+ * @param timeToLive
+ * The time-to-live value (seconds)
+ */
public ExpiringMap(int timeToLive) {
this(timeToLive, DEFAULT_EXPIRATION_INTERVAL);
}
+ /**
+ * Creates a new instance of ExpiringMap using the supplied values and
+ * a [EMAIL PROTECTED] ConcurrentHashMap} for the internal data structure.
+ *
+ * @param timeToLive
+ * The time-to-live value (seconds)
+ * @param expirationInterval
+ * The time between checks to see if a value should be removed (seconds)
+ */
public ExpiringMap(int timeToLive, int expirationInterval) {
this(new ConcurrentHashMap<K, ExpiringObject>(),
new CopyOnWriteArrayList<ExpirationListener<V>>(), timeToLive,
@@ -238,6 +268,13 @@
}
}
+ /**
+ * A Thread that monitors an [EMAIL PROTECTED] ExpiringMap} and will remove
+ * elements that have passed the threshold.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
public class Expirer implements Runnable {
private final ReadWriteLock stateLock = new ReentrantReadWriteLock();
@@ -249,6 +286,10 @@
private final Thread expirerThread;
+ /**
+ * Creates a new instance of Expirer.
+ *
+ */
public Expirer() {
expirerThread = new Thread(this, "ExpiringMapExpirer-"
+ expirerCount++);
@@ -287,6 +328,10 @@
}
}
+ /**
+ * Kick off this thread which will look for old objects and remove
them.
+ *
+ */
public void startExpiring() {
stateLock.writeLock().lock();
@@ -300,6 +345,10 @@
}
}
+ /**
+ * If this thread has not started, then start it.
+ * Otherwise just return;
+ */
public void startExpiringIfNotStarted() {
stateLock.readLock().lock();
try {
@@ -321,6 +370,9 @@
}
}
+ /**
+ * Stop the thread from monitoring the map.
+ */
public void stopExpiring() {
stateLock.writeLock().lock();
@@ -334,6 +386,12 @@
}
}
+ /**
+ * Checks to see if the thread is running
+ *
+ * @return
+ * If the thread is running, true. Otherwise false.
+ */
public boolean isRunning() {
stateLock.readLock().lock();
@@ -344,6 +402,12 @@
}
}
+ /**
+ * Returns the Time-to-live value.
+ *
+ * @return
+ * The time-to-live (seconds)
+ */
public int getTimeToLive() {
stateLock.readLock().lock();
@@ -354,6 +418,12 @@
}
}
+ /**
+ * Update the value for the time-to-live
+ *
+ * @param timeToLive
+ * The time-to-live (seconds)
+ */
public void setTimeToLive(long timeToLive) {
stateLock.writeLock().lock();
@@ -364,6 +434,13 @@
}
}
+ /**
+ * Get the interval in which an object will live in the map before
+ * it is removed.
+ *
+ * @return
+ * The time in seconds.
+ */
public int getExpirationInterval() {
stateLock.readLock().lock();
@@ -374,6 +451,13 @@
}
}
+ /**
+ * Set the interval in which an object will live in the map before
+ * it is removed.
+ *
+ * @param expirationInterval
+ * The time in seconds
+ */
public void setExpirationInterval(long expirationInterval) {
stateLock.writeLock().lock();