Author: iocanel
Date: Sun Jan 30 14:22:37 2011
New Revision: 1065289
URL: http://svn.apache.org/viewvc?rev=1065289&view=rev
Log:
[SM-2047] Moved Entry class outside TimeoutMemoryStore to avoid duplication.
Added:
servicemix/utils/trunk/src/main/java/org/apache/servicemix/store/Entry.java
Modified:
servicemix/utils/trunk/src/main/java/org/apache/servicemix/store/memory/TimeoutMemoryStore.java
Added:
servicemix/utils/trunk/src/main/java/org/apache/servicemix/store/Entry.java
URL:
http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/store/Entry.java?rev=1065289&view=auto
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/store/Entry.java
(added)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/store/Entry.java
Sun Jan 30 14:22:37 2011
@@ -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;
+ }
+
+
+}
Modified:
servicemix/utils/trunk/src/main/java/org/apache/servicemix/store/memory/TimeoutMemoryStore.java
URL:
http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/store/memory/TimeoutMemoryStore.java?rev=1065289&r1=1065288&r2=1065289&view=diff
==============================================================================
---
servicemix/utils/trunk/src/main/java/org/apache/servicemix/store/memory/TimeoutMemoryStore.java
(original)
+++
servicemix/utils/trunk/src/main/java/org/apache/servicemix/store/memory/TimeoutMemoryStore.java
Sun Jan 30 14:22:37 2011
@@ -23,6 +23,7 @@ import java.util.concurrent.ConcurrentMa
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 @@ public class TimeoutMemoryStore extends
super(idGenerator);
this.timeout = timeout;
}
-
+
/**
* {@inheritDoc}
*/
@@ -46,7 +47,7 @@ public class TimeoutMemoryStore extends
LOG.debug("Storing object with id: " + id);
datas.put(id, new Entry(data));
}
-
+
/**
* {@inheritDoc}
*
@@ -57,29 +58,17 @@ public class TimeoutMemoryStore extends
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;
- }
- }
}