[SM-2047] Moved Entry class outside TimeoutMemoryStore to avoid duplication.
git-svn-id: https://svn.apache.org/repos/asf/servicemix/utils/trunk@1065289 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/servicemix/store/Entry.java b/src/main/java/org/apache/servicemix/store/Entry.java
new file mode 100644
index 0000000..fd74258
--- /dev/null
+++ b/src/main/java/org/apache/servicemix/store/Entry.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2011 iocanel.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * under the License.
+ */
+package org.apache.servicemix.store;
+
+import java.io.Serializable;
+
+/**
+ *
+ * @author iocanel
+ */
+public class Entry implements Serializable {
+
+ private final long time = System.currentTimeMillis();
+ private final Object data;
+
+ public Entry(Object data) {
+ this.data = data;
+ }
+
+ public long getTime() {
+ return time;
+ }
+
+ public Object getData() {
+ return data;
+ }
+
+ @Override
+ public String toString() {
+ return "Entry{" + "time=" + time + ", data=" + data + '}';
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final Entry other = (Entry) obj;
+ if (this.time != other.time) {
+ return false;
+ }
+ if (this.data != other.data && (this.data == null || !this.data.equals(other.data))) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 7;
+ hash = 53 * hash + (int) (this.time ^ (this.time >>> 32));
+ hash = 53 * hash + (this.data != null ? this.data.hashCode() : 0);
+ return hash;
+ }
+
+
+}
diff --git a/src/main/java/org/apache/servicemix/store/memory/TimeoutMemoryStore.java b/src/main/java/org/apache/servicemix/store/memory/TimeoutMemoryStore.java
index ff7a5f8..991ac54 100644
--- a/src/main/java/org/apache/servicemix/store/memory/TimeoutMemoryStore.java
+++ b/src/main/java/org/apache/servicemix/store/memory/TimeoutMemoryStore.java
@@ -23,6 +23,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.servicemix.id.IdGenerator;
+import org.apache.servicemix.store.Entry;
/**
* {@link MemoryStore} which removes entries from the store after the specified timeout
@@ -38,7 +39,7 @@
super(idGenerator);
this.timeout = timeout;
}
-
+
/**
* {@inheritDoc}
*/
@@ -46,7 +47,7 @@
LOG.debug("Storing object with id: " + id);
datas.put(id, new Entry(data));
}
-
+
/**
* {@inheritDoc}
*
@@ -57,29 +58,17 @@
evict();
LOG.debug("Loading object with id:" + id);
Entry entry = datas.remove(id);
- return entry == null ? null : entry.data;
+ return entry == null ? null : entry.getTime();
}
-
+
private void evict() {
long now = System.currentTimeMillis();
for (String key : datas.keySet()) {
- long age = now - datas.get(key).time;
+ long age = now - datas.get(key).getTime();
if (age > timeout) {
LOG.debug("Removing object with id " + key + " from store after " + age + " ms");
datas.remove(key);
}
}
}
-
- /*
- * A single store entry
- */
- private final class Entry {
- private final long time = System.currentTimeMillis();
- private final Object data;
-
- private Entry(Object data) {
- this.data = data;
- }
- }
}