You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ge...@apache.org on 2008/08/21 15:13:45 UTC
svn commit: r687740 - in /servicemix/smx3/branches/servicemix-3.2:
core/servicemix-services/src/main/java/org/apache/servicemix/store/memory/
core/servicemix-services/src/test/java/org/apache/servicemix/store/memory/
deployables/serviceengines/servicem...
Author: gertv
Date: Thu Aug 21 06:13:44 2008
New Revision: 687740
URL: http://svn.apache.org/viewvc?rev=687740&view=rev
Log:
SM-1518: Fixing CheckStyle errors after previous commit
Added:
servicemix/smx3/branches/servicemix-3.2/core/servicemix-services/src/main/java/org/apache/servicemix/store/memory/TimeoutMemoryStore.java
Modified:
servicemix/smx3/branches/servicemix-3.2/core/servicemix-services/src/test/java/org/apache/servicemix/store/memory/TimeoutMemoryStoreTest.java
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-eip/src/main/java/org/apache/servicemix/eip/support/AbstractAggregator.java
Added: servicemix/smx3/branches/servicemix-3.2/core/servicemix-services/src/main/java/org/apache/servicemix/store/memory/TimeoutMemoryStore.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/core/servicemix-services/src/main/java/org/apache/servicemix/store/memory/TimeoutMemoryStore.java?rev=687740&view=auto
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/core/servicemix-services/src/main/java/org/apache/servicemix/store/memory/TimeoutMemoryStore.java (added)
+++ servicemix/smx3/branches/servicemix-3.2/core/servicemix-services/src/main/java/org/apache/servicemix/store/memory/TimeoutMemoryStore.java Thu Aug 21 06:13:44 2008
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+package org.apache.servicemix.store.memory;
+
+import java.io.IOException;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.id.IdGenerator;
+
+/**
+ * {@link MemoryStore} which removes entries from the store after the specified timeout
+ * to free memory.
+ */
+public class TimeoutMemoryStore extends MemoryStore {
+
+ private static final Log LOG = LogFactory.getLog(TimeoutMemoryStore.class);
+ private ConcurrentMap<String, Entry> datas = new ConcurrentHashMap<String, Entry>();
+ private final long timeout;
+
+ protected TimeoutMemoryStore(IdGenerator idGenerator, long timeout) {
+ super(idGenerator);
+ this.timeout = timeout;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void store(String id, Object data) throws IOException {
+ LOG.debug("Storing object with id: " + id);
+ datas.put(id, new Entry(data));
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Before attempting to load the object, all data older than the specified timeout will first be
+ * removed from the store.
+ */
+ public Object load(String id) throws IOException {
+ evict();
+ LOG.debug("Loading object with id:" + id);
+ Entry entry = datas.remove(id);
+ return entry == null ? null : entry.data;
+ }
+
+ private void evict() {
+ long now = System.currentTimeMillis();
+ for (String key : datas.keySet()) {
+ long age = now - datas.get(key).time;
+ 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;
+ }
+ }
+}
Modified: servicemix/smx3/branches/servicemix-3.2/core/servicemix-services/src/test/java/org/apache/servicemix/store/memory/TimeoutMemoryStoreTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/core/servicemix-services/src/test/java/org/apache/servicemix/store/memory/TimeoutMemoryStoreTest.java?rev=687740&r1=687739&r2=687740&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/core/servicemix-services/src/test/java/org/apache/servicemix/store/memory/TimeoutMemoryStoreTest.java (original)
+++ servicemix/smx3/branches/servicemix-3.2/core/servicemix-services/src/test/java/org/apache/servicemix/store/memory/TimeoutMemoryStoreTest.java Thu Aug 21 06:13:44 2008
@@ -25,7 +25,7 @@
*/
public class TimeoutMemoryStoreTest extends TestCase {
- private static final long TIMEOUT = 250l;
+ private static final long TIMEOUT = 250L;
private Store store;
private final MemoryStoreFactory factory = new MemoryStoreFactory();
Modified: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-eip/src/main/java/org/apache/servicemix/eip/support/AbstractAggregator.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-eip/src/main/java/org/apache/servicemix/eip/support/AbstractAggregator.java?rev=687740&r1=687739&r2=687740&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-eip/src/main/java/org/apache/servicemix/eip/support/AbstractAggregator.java (original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-eip/src/main/java/org/apache/servicemix/eip/support/AbstractAggregator.java Thu Aug 21 06:13:44 2008
@@ -33,7 +33,6 @@
import org.apache.servicemix.jbi.util.MessageUtil;
import org.apache.servicemix.store.Store;
import org.apache.servicemix.store.StoreFactory;
-import org.apache.servicemix.store.memory.MemoryStore;
import org.apache.servicemix.store.memory.MemoryStoreFactory;
import org.apache.servicemix.timers.Timer;
import org.apache.servicemix.timers.TimerListener;