You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2007/08/10 18:57:10 UTC
svn commit: r564679 [4/8] - in /activemq/trunk:
activemq-core/src/main/java/org/apache/activemq/
activemq-core/src/main/java/org/apache/activemq/broker/
activemq-core/src/main/java/org/apache/activemq/broker/jmx/
activemq-core/src/main/java/org/apache/...
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/MultiExpressionEvaluator.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/MultiExpressionEvaluator.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/MultiExpressionEvaluator.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/MultiExpressionEvaluator.java Fri Aug 10 09:57:01 2007
@@ -20,6 +20,8 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
import javax.jms.JMSException;
@@ -66,8 +68,8 @@
*/
public class MultiExpressionEvaluator {
- HashMap rootExpressions = new HashMap();
- HashMap cachedExpressions = new HashMap();
+ Map<String, ExpressionListenerSet> rootExpressions = new HashMap<String, ExpressionListenerSet>();
+ Map<Expression, CacheExpression> cachedExpressions = new HashMap<Expression, CacheExpression>();
int view;
@@ -104,8 +106,9 @@
}
public boolean equals(Object o) {
- if (o == null)
+ if (o == null) {
return false;
+ }
return ((CacheExpression)o).right.equals(right);
}
@@ -125,7 +128,7 @@
*/
static class ExpressionListenerSet {
Expression expression;
- ArrayList listeners = new ArrayList();
+ List<ExpressionListener> listeners = new ArrayList<ExpressionListener>();
}
/**
@@ -142,7 +145,7 @@
* Expression applied to the evaluated message.
*/
public void addExpressionListner(Expression selector, ExpressionListener c) {
- ExpressionListenerSet data = (ExpressionListenerSet)rootExpressions.get(selector.toString());
+ ExpressionListenerSet data = rootExpressions.get(selector.toString());
if (data == null) {
data = new ExpressionListenerSet();
data.expression = addToCache(selector);
@@ -157,19 +160,19 @@
*/
public boolean removeEventListner(String selector, ExpressionListener c) {
String expKey = selector;
- ExpressionListenerSet d = (ExpressionListenerSet)rootExpressions.get(expKey);
- if (d == null) // that selector had not been added.
- {
+ ExpressionListenerSet d = rootExpressions.get(expKey);
+ // that selector had not been added.
+ if (d == null) {
return false;
}
- if (!d.listeners.remove(c)) // that selector did not have that listner..
- {
+ // that selector did not have that listeners..
+ if (!d.listeners.remove(c)) {
return false;
}
- // If there are no more listners for this expression....
+ // If there are no more listeners for this expression....
if (d.listeners.size() == 0) {
- // Uncache it...
+ // Un-cache it...
removeFromCache((CacheExpression)d.expression);
rootExpressions.remove(expKey);
}
@@ -185,7 +188,7 @@
*/
private CacheExpression addToCache(Expression expr) {
- CacheExpression n = (CacheExpression)cachedExpressions.get(expr);
+ CacheExpression n = cachedExpressions.get(expr);
if (n == null) {
n = new CacheExpression(expr);
cachedExpressions.put(expr, n);
@@ -239,13 +242,13 @@
* @param message
*/
public void evaluate(MessageEvaluationContext message) {
- Collection expressionListeners = rootExpressions.values();
- for (Iterator iter = expressionListeners.iterator(); iter.hasNext();) {
- ExpressionListenerSet els = (ExpressionListenerSet)iter.next();
+ Collection<ExpressionListenerSet> expressionListeners = rootExpressions.values();
+ for (Iterator<ExpressionListenerSet> iter = expressionListeners.iterator(); iter.hasNext();) {
+ ExpressionListenerSet els = iter.next();
try {
Object result = els.expression.evaluate(message);
- for (Iterator iterator = els.listeners.iterator(); iterator.hasNext();) {
- ExpressionListener l = (ExpressionListener)iterator.next();
+ for (Iterator<ExpressionListener> iterator = els.listeners.iterator(); iterator.hasNext();) {
+ ExpressionListener l = iterator.next();
l.evaluateResultEvent(els.expression, message, result);
}
} catch (Throwable e) {
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/NoLocalExpression.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/NoLocalExpression.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/NoLocalExpression.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/NoLocalExpression.java Fri Aug 10 09:57:01 2007
@@ -27,13 +27,14 @@
private final String connectionId;
public NoLocalExpression(String connectionId) {
- this.connectionId = connectionId;
+ this.connectionId = connectionId;
}
-
+
public boolean matches(MessageEvaluationContext message) throws JMSException {
try {
- if( message.isDropped() )
+ if (message.isDropped()) {
return false;
+ }
return !connectionId.equals(message.getMessage().getMessageId().getProducerId().getConnectionId());
} catch (IOException e) {
throw JMSExceptionSupport.create(e);
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/PropertyExpression.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/PropertyExpression.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/PropertyExpression.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/PropertyExpression.java Fri Aug 10 09:57:01 2007
@@ -19,6 +19,7 @@
import java.io.IOException;
import java.util.HashMap;
+import java.util.Map;
import javax.jms.DeliveryMode;
import javax.jms.JMSException;
@@ -35,28 +36,32 @@
*/
public class PropertyExpression implements Expression {
+ private static final Map<String, SubExpression> JMS_PROPERTY_EXPRESSIONS = new HashMap<String, SubExpression>();
+
interface SubExpression {
Object evaluate(Message message);
}
- private static final HashMap JMS_PROPERTY_EXPRESSIONS = new HashMap();
static {
JMS_PROPERTY_EXPRESSIONS.put("JMSDestination", new SubExpression() {
public Object evaluate(Message message) {
ActiveMQDestination dest = message.getOriginalDestination();
- if (dest == null)
+ if (dest == null) {
dest = message.getDestination();
- if (dest == null)
+ }
+ if (dest == null) {
return null;
+ }
return dest.toString();
}
});
JMS_PROPERTY_EXPRESSIONS.put("JMSReplyTo", new SubExpression() {
public Object evaluate(Message message) {
- if (message.getReplyTo() == null)
+ if (message.getReplyTo() == null) {
return null;
+ }
return message.getReplyTo().toString();
}
});
@@ -69,8 +74,7 @@
JMS_PROPERTY_EXPRESSIONS.put("JMSDeliveryMode", new SubExpression() {
public Object evaluate(Message message) {
- return Integer.valueOf(message.isPersistent()
- ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
+ return Integer.valueOf(message.isPersistent() ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
}
});
JMS_PROPERTY_EXPRESSIONS.put("JMSPriority", new SubExpression() {
@@ -82,8 +86,9 @@
JMS_PROPERTY_EXPRESSIONS.put("JMSMessageID", new SubExpression() {
public Object evaluate(Message message) {
- if (message.getMessageId() == null)
+ if (message.getMessageId() == null) {
return null;
+ }
return message.getMessageId().toString();
}
});
@@ -133,10 +138,12 @@
public Object evaluate(Message message) {
TransactionId txId = message.getOriginalTransactionId();
- if (txId == null)
+ if (txId == null) {
txId = message.getTransactionId();
- if (txId == null)
+ }
+ if (txId == null) {
return null;
+ }
return new Integer(txId.toString());
}
});
@@ -159,21 +166,22 @@
public PropertyExpression(String name) {
this.name = name;
- jmsPropertyExpression = (SubExpression)JMS_PROPERTY_EXPRESSIONS.get(name);
+ jmsPropertyExpression = JMS_PROPERTY_EXPRESSIONS.get(name);
}
public Object evaluate(MessageEvaluationContext message) throws JMSException {
try {
- if (message.isDropped())
+ if (message.isDropped()) {
return null;
+ }
- if (jmsPropertyExpression != null)
+ if (jmsPropertyExpression != null) {
return jmsPropertyExpression.evaluate(message.getMessage());
+ }
try {
return message.getMessage().getProperty(name);
} catch (IOException ioe) {
- throw JMSExceptionSupport.create("Could not get property: " + name + " reason: "
- + ioe.getMessage(), ioe);
+ throw JMSExceptionSupport.create("Could not get property: " + name + " reason: " + ioe.getMessage(), ioe);
}
} catch (IOException e) {
throw JMSExceptionSupport.create(e);
@@ -182,8 +190,9 @@
}
public Object evaluate(Message message) throws JMSException {
- if (jmsPropertyExpression != null)
+ if (jmsPropertyExpression != null) {
return jmsPropertyExpression.evaluate(message);
+ }
try {
return message.getProperty(name);
} catch (IOException ioe) {
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/UnaryExpression.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/UnaryExpression.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/UnaryExpression.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/UnaryExpression.java Fri Aug 10 09:57:01 2007
@@ -34,6 +34,10 @@
private static final BigDecimal BD_LONG_MIN_VALUE = BigDecimal.valueOf(Long.MIN_VALUE);
protected Expression right;
+ public UnaryExpression(Expression left) {
+ this.right = left;
+ }
+
public static Expression createNegate(Expression left) {
return new UnaryExpression(left) {
public Object evaluate(MessageEvaluationContext message) throws JMSException {
@@ -53,17 +57,16 @@
};
}
- public static BooleanExpression createInExpression(PropertyExpression right, List elements,
- final boolean not) {
+ public static BooleanExpression createInExpression(PropertyExpression right, List<Object> elements, final boolean not) {
// Use a HashSet if there are many elements.
- Collection t;
- if (elements.size() == 0)
+ Collection<Object> t;
+ if (elements.size() == 0) {
t = null;
- else if (elements.size() < 5)
+ } else if (elements.size() < 5) {
t = elements;
- else {
- t = new HashSet(elements);
+ } else {
+ t = new HashSet<Object>(elements);
}
final Collection inList = t;
@@ -74,8 +77,9 @@
if (rvalue == null) {
return null;
}
- if (rvalue.getClass() != String.class)
+ if (rvalue.getClass() != String.class) {
return null;
+ }
if ((inList != null && inList.contains(rvalue)) ^ not) {
return Boolean.TRUE;
@@ -155,10 +159,12 @@
return new BooleanUnaryExpression(left) {
public Object evaluate(MessageEvaluationContext message) throws JMSException {
Object rvalue = right.evaluate(message);
- if (rvalue == null)
+ if (rvalue == null) {
return null;
- if (!rvalue.getClass().equals(Boolean.class))
+ }
+ if (!rvalue.getClass().equals(Boolean.class)) {
return Boolean.FALSE;
+ }
return ((Boolean)rvalue).booleanValue() ? Boolean.TRUE : Boolean.FALSE;
}
@@ -200,10 +206,6 @@
} else {
throw new RuntimeException("Don't know how to negate: " + left);
}
- }
-
- public UnaryExpression(Expression left) {
- this.right = left;
}
public Expression getRight() {
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/XPathExpression.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/XPathExpression.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/XPathExpression.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/XPathExpression.java Fri Aug 10 09:57:01 2007
@@ -45,8 +45,7 @@
try {
m = getXPathEvaluatorConstructor(cn);
} catch (Throwable e) {
- LOG.warn("Invalid " + XPathEvaluator.class.getName() + " implementation: " + cn
- + ", reason: " + e, e);
+ LOG.warn("Invalid " + XPathEvaluator.class.getName() + " implementation: " + cn + ", reason: " + e, e);
cn = DEFAULT_EVALUATOR_CLASS_NAME;
try {
m = getXPathEvaluatorConstructor(cn);
@@ -59,15 +58,6 @@
}
}
- private static Constructor getXPathEvaluatorConstructor(String cn) throws ClassNotFoundException,
- SecurityException, NoSuchMethodException {
- Class c = XPathExpression.class.getClassLoader().loadClass(cn);
- if (!XPathEvaluator.class.isAssignableFrom(c)) {
- throw new ClassCastException("" + c + " is not an instance of " + XPathEvaluator.class);
- }
- return c.getConstructor(new Class[] {String.class});
- }
-
private final String xpath;
private final XPathEvaluator evaluator;
@@ -80,6 +70,14 @@
this.evaluator = createEvaluator(xpath);
}
+ private static Constructor getXPathEvaluatorConstructor(String cn) throws ClassNotFoundException, SecurityException, NoSuchMethodException {
+ Class c = XPathExpression.class.getClassLoader().loadClass(cn);
+ if (!XPathEvaluator.class.isAssignableFrom(c)) {
+ throw new ClassCastException("" + c + " is not an instance of " + XPathEvaluator.class);
+ }
+ return c.getConstructor(new Class[] {String.class});
+ }
+
private XPathEvaluator createEvaluator(String xpath2) {
try {
return (XPathEvaluator)EVALUATOR_CONSTRUCTOR.newInstance(new Object[] {xpath});
@@ -96,8 +94,9 @@
public Object evaluate(MessageEvaluationContext message) throws JMSException {
try {
- if (message.isDropped())
+ if (message.isDropped()) {
return null;
+ }
return evaluator.evaluate(message.getMessage()) ? Boolean.TRUE : Boolean.FALSE;
} catch (IOException e) {
throw JMSExceptionSupport.create(e);
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/XalanXPathEvaluator.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/XalanXPathEvaluator.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/XalanXPathEvaluator.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/XalanXPathEvaluator.java Fri Aug 10 09:57:01 2007
@@ -25,14 +25,13 @@
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.traversal.NodeIterator;
+import org.xml.sax.InputSource;
+
import org.apache.activemq.command.Message;
import org.apache.activemq.util.ByteArrayInputStream;
import org.apache.xpath.CachedXPathAPI;
-
-import org.xml.sax.InputSource;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.traversal.NodeIterator;
public class XalanXPathEvaluator implements XPathExpression.XPathEvaluator {
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/jndi/ReadOnlyContext.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/jndi/ReadOnlyContext.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/jndi/ReadOnlyContext.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/jndi/ReadOnlyContext.java Fri Aug 10 09:57:01 2007
@@ -65,37 +65,37 @@
protected static final NameParser NAME_PARSER = new NameParserImpl();
private static final long serialVersionUID = -5754338187296859149L;
- protected final Hashtable environment; // environment for this context
- protected final Map bindings; // bindings at my level
- protected final Map treeBindings; // all bindings under me
+ protected final Hashtable<String, Object> environment; // environment for this context
+ protected final Map<String, Object> bindings; // bindings at my level
+ protected final Map<String, Object> treeBindings; // all bindings under me
private boolean frozen;
private String nameInNamespace = "";
public ReadOnlyContext() {
- environment = new Hashtable();
- bindings = new HashMap();
- treeBindings = new HashMap();
+ environment = new Hashtable<String, Object>();
+ bindings = new HashMap<String, Object>();
+ treeBindings = new HashMap<String, Object>();
}
public ReadOnlyContext(Hashtable env) {
if (env == null) {
- this.environment = new Hashtable();
+ this.environment = new Hashtable<String, Object>();
} else {
- this.environment = new Hashtable(env);
+ this.environment = new Hashtable<String, Object>(env);
}
this.bindings = Collections.EMPTY_MAP;
this.treeBindings = Collections.EMPTY_MAP;
}
- public ReadOnlyContext(Hashtable environment, Map bindings) {
+ public ReadOnlyContext(Hashtable environment, Map<String, Object> bindings) {
if (environment == null) {
- this.environment = new Hashtable();
+ this.environment = new Hashtable<String, Object>();
} else {
- this.environment = new Hashtable(environment);
+ this.environment = new Hashtable<String, Object>(environment);
}
this.bindings = bindings;
- treeBindings = new HashMap();
+ treeBindings = new HashMap<String, Object>();
frozen = true;
}
@@ -107,10 +107,10 @@
protected ReadOnlyContext(ReadOnlyContext clone, Hashtable env) {
this.bindings = clone.bindings;
this.treeBindings = clone.treeBindings;
- this.environment = new Hashtable(env);
+ this.environment = new Hashtable<String, Object>(env);
}
- protected ReadOnlyContext(ReadOnlyContext clone, Hashtable env, String nameInNamespace) {
+ protected ReadOnlyContext(ReadOnlyContext clone, Hashtable<String, Object> env, String nameInNamespace) {
this(clone, env);
this.nameInNamespace = nameInNamespace;
}
@@ -138,11 +138,11 @@
* @return
* @throws javax.naming.NamingException
*/
- protected Map internalBind(String name, Object value) throws NamingException {
+ protected Map<String, Object> internalBind(String name, Object value) throws NamingException {
assert name != null && name.length() > 0;
assert !frozen;
- Map newBindings = new HashMap();
+ Map<String, Object> newBindings = new HashMap<String, Object>();
int pos = name.indexOf('/');
if (pos == -1) {
if (treeBindings.put(name, value) != null) {
@@ -165,7 +165,7 @@
}
ReadOnlyContext readOnlyContext = (ReadOnlyContext)o;
String remainder = name.substring(pos + 1);
- Map subBindings = readOnlyContext.internalBind(remainder, value);
+ Map<String, Object> subBindings = readOnlyContext.internalBind(remainder, value);
for (Iterator iterator = subBindings.entrySet().iterator(); iterator.hasNext();) {
Map.Entry entry = (Map.Entry)iterator.next();
String subName = segment + "/" + (String)entry.getKey();
@@ -185,8 +185,8 @@
return environment.put(propName, propVal);
}
- public Hashtable getEnvironment() throws NamingException {
- return (Hashtable)environment.clone();
+ public Hashtable<String, Object> getEnvironment() throws NamingException {
+ return (Hashtable<String, Object>)environment.clone();
}
public Object removeFromEnvironment(String propName) throws NamingException {
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/IndexRootContainer.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/IndexRootContainer.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/IndexRootContainer.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/IndexRootContainer.java Fri Aug 10 09:57:01 2007
@@ -40,13 +40,15 @@
*/
class IndexRootContainer {
- private static final Log LOG = LogFactory.getLog(IndexRootContainer.class);
+
protected static final Marshaller ROOT_MARSHALLER = Store.OBJECT_MARSHALLER;
+ private static final Log LOG = LogFactory.getLog(IndexRootContainer.class);
+
protected IndexItem root;
protected IndexManager indexManager;
protected DataManager dataManager;
- protected Map map = new ConcurrentHashMap();
- protected LinkedList list = new LinkedList();
+ protected Map<Object, StoreEntry> map = new ConcurrentHashMap<Object, StoreEntry>();
+ protected LinkedList<StoreEntry> list = new LinkedList<StoreEntry>();
IndexRootContainer(IndexItem root, IndexManager im, DataManager dfm) throws IOException {
this.root = root;
@@ -64,7 +66,7 @@
}
}
- Set getKeys() {
+ Set<Object> getKeys() {
return map.keySet();
}
@@ -93,7 +95,7 @@
}
void removeRoot(IndexManager containerIndexManager, ContainerId key) throws IOException {
- StoreEntry oldRoot = (StoreEntry)map.remove(key);
+ StoreEntry oldRoot = map.remove(key);
if (oldRoot != null) {
dataManager.removeInterestInFile(oldRoot.getKeyFile());
// get the container root
@@ -119,7 +121,7 @@
}
IndexItem getRoot(IndexManager containerIndexManager, ContainerId key) throws IOException {
- StoreEntry index = (StoreEntry)map.get(key);
+ StoreEntry index = map.get(key);
if (index != null) {
return containerIndexManager.getIndex(index.getValueOffset());
}
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/KahaStore.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/KahaStore.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/KahaStore.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/KahaStore.java Fri Aug 10 09:57:01 2007
@@ -30,7 +30,6 @@
import org.apache.activemq.kaha.ContainerId;
import org.apache.activemq.kaha.ListContainer;
import org.apache.activemq.kaha.MapContainer;
-import org.apache.activemq.kaha.RuntimeStoreException;
import org.apache.activemq.kaha.Store;
import org.apache.activemq.kaha.StoreLocation;
import org.apache.activemq.kaha.impl.async.AsyncDataManager;
@@ -58,7 +57,7 @@
private static final boolean DISABLE_LOCKING = "true".equals(System.getProperty(PROPERTY_PREFIX + ".DisableLocking", "false"));
private static final Log LOG = LogFactory.getLog(KahaStore.class);
-
+
private final File directory;
private final String mode;
private IndexRootContainer mapsContainer;
@@ -74,7 +73,7 @@
private boolean useAsyncDataManager;
private long maxDataFileLength = 1024 * 1024 * 32;
private FileLock lock;
- private boolean persistentIndex;
+ private boolean persistentIndex=true;
private RandomAccessFile lockFile;
public KahaStore(String name, String mode) throws IOException {
@@ -108,8 +107,9 @@
iter.remove();
}
}
- if (lockFile != null)
+ if (lockFile != null) {
lockFile.close();
+ }
}
}
@@ -415,8 +415,9 @@
}
public synchronized void initialize() throws IOException {
- if (closed)
+ if (closed) {
throw new IOException("Store has been closed.");
+ }
if (!initialized) {
LOG.info("Kaha Store using data directory " + directory);
@@ -484,12 +485,6 @@
private String getPropertyKey() throws IOException {
// Is replaceAll() needed? Should test without it.
return getClass().getName() + ".lock." + directory.getCanonicalPath();
- }
-
- private void checkClosed() {
- if (closed) {
- throw new RuntimeStoreException("The store is closed");
- }
}
/**
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/AsyncDataManager.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/AsyncDataManager.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/AsyncDataManager.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/AsyncDataManager.java Fri Aug 10 09:57:01 2007
@@ -48,10 +48,7 @@
*/
public final class AsyncDataManager {
- private static final Log LOG = LogFactory.getLog(AsyncDataManager.class);
-
public static final int CONTROL_RECORD_MAX_LENGTH = 1024;
-
public static final int ITEM_HEAD_RESERVED_SPACE = 21;
// ITEM_HEAD_SPACE = length + type+ reserved space + SOR
public static final int ITEM_HEAD_SPACE = 4 + 1 + ITEM_HEAD_RESERVED_SPACE + 3;
@@ -60,8 +57,8 @@
public static final int ITEM_HEAD_FOOT_SPACE = ITEM_HEAD_SPACE + ITEM_FOOT_SPACE;
- static final byte[] ITEM_HEAD_SOR = new byte[] {'S', 'O', 'R'}; //
- static final byte[] ITEM_HEAD_EOR = new byte[] {'E', 'O', 'R'}; //
+ public static final byte[] ITEM_HEAD_SOR = new byte[] {'S', 'O', 'R'}; //
+ public static final byte[] ITEM_HEAD_EOR = new byte[] {'E', 'O', 'R'}; //
public static final byte DATA_ITEM_TYPE = 1;
public static final byte REDO_ITEM_TYPE = 2;
@@ -70,8 +67,16 @@
public static final String DEFAULT_FILE_PREFIX = "data-";
public static final int DEFAULT_MAX_FILE_LENGTH = 1024 * 1024 * 32;
+ private static final Log LOG = LogFactory.getLog(AsyncDataManager.class);
+
+ protected final Map<WriteKey, WriteCommand> inflightWrites = new ConcurrentHashMap<WriteKey, WriteCommand>();
+
File directory = new File(DEFAULT_DIRECTORY);
String filePrefix = DEFAULT_FILE_PREFIX;
+ ControlFile controlFile;
+ boolean started;
+ boolean useNio = true;
+
private int maxFileLength = DEFAULT_MAX_FILE_LENGTH;
private int preferedFileLength = DEFAULT_MAX_FILE_LENGTH - 1024 * 512;
@@ -80,15 +85,9 @@
private Map<Integer, DataFile> fileMap = new HashMap<Integer, DataFile>();
private DataFile currentWriteFile;
- ControlFile controlFile;
private Location mark;
private final AtomicReference<Location> lastAppendLocation = new AtomicReference<Location>();
- boolean started;
- boolean useNio = true;
-
- protected final ConcurrentHashMap<WriteKey, WriteCommand> inflightWrites = new ConcurrentHashMap<WriteKey, WriteCommand>();
-
private Runnable cleanupTask;
@SuppressWarnings("unchecked")
@@ -130,13 +129,13 @@
DataFile dataFile = new DataFile(file, num, preferedFileLength);
fileMap.put(dataFile.getDataFileId(), dataFile);
} catch (NumberFormatException e) {
- // Ignore file that do not match the patern.
+ // Ignore file that do not match the pattern.
}
}
// Sort the list so that we can link the DataFiles together in the
// right order.
- ArrayList<DataFile> l = new ArrayList<DataFile>(fileMap.values());
+ List<DataFile> l = new ArrayList<DataFile>(fileMap.values());
Collections.sort(l);
currentWriteFile = null;
for (DataFile df : l) {
@@ -534,7 +533,7 @@
this.filePrefix = filePrefix;
}
- public ConcurrentHashMap<WriteKey, WriteCommand> getInflightWrites() {
+ public Map<WriteKey, WriteCommand> getInflightWrites() {
return inflightWrites;
}
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/ControlFile.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/ControlFile.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/ControlFile.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/ControlFile.java Fri Aug 10 09:57:01 2007
@@ -56,8 +56,9 @@
* @throws IOException
*/
public void lock() throws IOException {
- if (DISABLE_FILE_LOCK)
+ if (DISABLE_FILE_LOCK) {
return;
+ }
if (lock == null) {
lock = randomAccessFile.getChannel().tryLock();
@@ -73,8 +74,9 @@
* @throws IOException
*/
public void unlock() throws IOException {
- if (DISABLE_FILE_LOCK)
+ if (DISABLE_FILE_LOCK) {
return;
+ }
if (lock != null) {
lock.release();
@@ -83,16 +85,17 @@
}
public void dispose() {
- if (disposed)
+ if (disposed) {
return;
+ }
disposed = true;
try {
unlock();
- } catch (IOException e) {
+ } catch (IOException ignore) {
}
try {
randomAccessFile.close();
- } catch (IOException e) {
+ } catch (IOException ignore) {
}
}
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/DataFile.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/DataFile.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/DataFile.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/DataFile.java Fri Aug 10 09:57:01 2007
@@ -33,7 +33,7 @@
private final Integer dataFileId;
private final int preferedSize;
- int length;
+ private int length;
private int referenceCount;
DataFile(File file, int number, int preferedSize) {
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/DataFileAccessor.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/DataFileAccessor.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/DataFileAccessor.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/DataFileAccessor.java Fri Aug 10 09:57:01 2007
@@ -18,6 +18,7 @@
import java.io.IOException;
import java.io.RandomAccessFile;
+import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.activemq.kaha.impl.async.DataFileAppender.WriteCommand;
@@ -33,7 +34,7 @@
final class DataFileAccessor {
private final DataFile dataFile;
- private final ConcurrentHashMap<WriteKey, WriteCommand> inflightWrites;
+ private final Map<WriteKey, WriteCommand> inflightWrites;
private final RandomAccessFile file;
private boolean disposed;
@@ -54,8 +55,9 @@
}
public void dispose() {
- if (disposed)
+ if (disposed) {
return;
+ }
disposed = true;
try {
dataFile.closeRandomAccessFile(file);
@@ -66,8 +68,9 @@
public ByteSequence readRecord(Location location) throws IOException {
- if (!location.isValid())
+ if (!location.isValid()) {
throw new IOException("Invalid location: " + location);
+ }
WriteCommand asyncWrite = (WriteCommand)inflightWrites.get(new WriteKey(location));
if (asyncWrite != null) {
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/DataFileAccessorPool.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/DataFileAccessorPool.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/DataFileAccessorPool.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/DataFileAccessorPool.java Fri Aug 10 09:57:01 2007
@@ -20,6 +20,8 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
/**
* Used to pool DataFileAccessors.
@@ -29,15 +31,14 @@
public class DataFileAccessorPool {
private final AsyncDataManager dataManager;
- private final HashMap<Integer, Pool> pools = new HashMap<Integer, Pool>();
+ private final Map<Integer, Pool> pools = new HashMap<Integer, Pool>();
private boolean closed;
-
- int maxOpenReadersPerFile = 5;
+ private int maxOpenReadersPerFile = 5;
class Pool {
private final DataFile file;
- private final ArrayList<DataFileAccessor> pool = new ArrayList<DataFileAccessor>();
+ private final List<DataFileAccessor> pool = new ArrayList<DataFileAccessor>();
private boolean used;
private int openCounter;
private boolean disposed;
@@ -149,8 +150,9 @@
}
public synchronized void close() {
- if (closed)
+ if (closed) {
return;
+ }
closed = true;
for (Iterator<Pool> iter = pools.values().iterator(); iter.hasNext();) {
Pool pool = iter.next();
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/DataFileAppender.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/DataFileAppender.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/DataFileAppender.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/DataFileAppender.java Fri Aug 10 09:57:01 2007
@@ -19,6 +19,7 @@
import java.io.IOException;
import java.io.InterruptedIOException;
import java.io.RandomAccessFile;
+import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
@@ -37,7 +38,19 @@
protected static final byte[] RESERVED_SPACE = new byte[AsyncDataManager.ITEM_HEAD_RESERVED_SPACE];
protected static final String SHUTDOWN_COMMAND = "SHUTDOWN";
- int maxWriteBatchSize = 1024 * 1024 * 4;
+
+ protected final AsyncDataManager dataManager;
+ protected final Map<WriteKey, WriteCommand> inflightWrites;
+ protected final Object enqueueMutex = new Object();
+ protected WriteBatch nextWriteBatch;
+
+ protected boolean shutdown;
+ protected IOException firstAsyncException;
+ protected final CountDownLatch shutdownDone = new CountDownLatch(1);
+ protected int maxWriteBatchSize = 1024 * 1024 * 4;
+
+ private boolean running;
+ private Thread thread;
public static class WriteKey {
private final int file;
@@ -78,10 +91,12 @@
}
public boolean canAppend(DataFile dataFile, WriteCommand write) {
- if (dataFile != this.dataFile)
+ if (dataFile != this.dataFile) {
return false;
- if (size + write.location.getSize() >= maxWriteBatchSize)
+ }
+ if (size + write.location.getSize() >= maxWriteBatchSize) {
return false;
+ }
return true;
}
@@ -103,18 +118,6 @@
}
}
- protected final AsyncDataManager dataManager;
-
- protected final ConcurrentHashMap<WriteKey, WriteCommand> inflightWrites;
-
- protected final Object enqueueMutex = new Object();
- protected WriteBatch nextWriteBatch;
-
- private boolean running;
- protected boolean shutdown;
- protected IOException firstAsyncException;
- protected final CountDownLatch shutdownDone = new CountDownLatch(1);
- private Thread thread;
/**
* Construct a Store writer
@@ -180,8 +183,9 @@
if (shutdown) {
throw new IOException("Async Writter Thread Shutdown");
}
- if (firstAsyncException != null)
+ if (firstAsyncException != null) {
throw firstAsyncException;
+ }
if (!running) {
running = true;
@@ -368,7 +372,7 @@
if (file != null) {
dataFile.closeRandomAccessFile(file);
}
- } catch (IOException e) {
+ } catch (Throwable ignore) {
}
shutdownDone.countDown();
}
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/DataManagerFacade.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/DataManagerFacade.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/DataManagerFacade.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/DataManagerFacade.java Fri Aug 10 09:57:01 2007
@@ -32,6 +32,12 @@
*/
public final class DataManagerFacade implements org.apache.activemq.kaha.impl.DataManager {
+ private static final ByteSequence FORCE_COMMAND = new ByteSequence(new byte[] {'F', 'O', 'R', 'C', 'E'});
+
+ private AsyncDataManager dataManager;
+ private final String name;
+ private Marshaller redoMarshaller;
+
private static class StoreLocationFacade implements StoreLocation {
private final Location location;
@@ -56,19 +62,27 @@
}
}
+ public DataManagerFacade(AsyncDataManager dataManager, String name) {
+ this.dataManager = dataManager;
+ this.name = name;
+ }
+
private static StoreLocation convertToStoreLocation(Location location) {
- if (location == null)
+ if (location == null) {
return null;
+ }
return new StoreLocationFacade(location);
}
private static Location convertFromStoreLocation(StoreLocation location) {
- if (location == null)
+ if (location == null) {
return null;
+ }
- if (location.getClass() == StoreLocationFacade.class)
+ if (location.getClass() == StoreLocationFacade.class) {
return ((StoreLocationFacade)location).getLocation();
+ }
Location l = new Location();
l.setOffset((int)location.getOffset());
@@ -77,16 +91,6 @@
return l;
}
- private static final ByteSequence FORCE_COMMAND = new ByteSequence(new byte[] {'F', 'O', 'R', 'C', 'E'});
-
- AsyncDataManager dataManager;
- private final String name;
- private Marshaller redoMarshaller;
-
- public DataManagerFacade(AsyncDataManager dataManager, String name) {
- this.dataManager = dataManager;
- this.name = name;
- }
public Object readItem(Marshaller marshaller, StoreLocation location) throws IOException {
ByteSequence sequence = dataManager.read(convertFromStoreLocation(location));
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/JournalFacade.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/JournalFacade.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/JournalFacade.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/JournalFacade.java Fri Aug 10 09:57:01 2007
@@ -33,6 +33,8 @@
*/
public final class JournalFacade implements Journal {
+ private final AsyncDataManager dataManager;
+
public static class RecordLocationFacade implements RecordLocation {
private final Location location;
@@ -51,26 +53,26 @@
}
}
+ public JournalFacade(AsyncDataManager dataManager) {
+ this.dataManager = dataManager;
+ }
+
private static RecordLocation convertToRecordLocation(Location location) {
- if (location == null)
+ if (location == null) {
return null;
+ }
return new RecordLocationFacade(location);
}
private static Location convertFromRecordLocation(RecordLocation location) {
- if (location == null)
+ if (location == null) {
return null;
+ }
return ((RecordLocationFacade)location).getLocation();
}
- AsyncDataManager dataManager;
-
- public JournalFacade(AsyncDataManager dataManager) {
- this.dataManager = dataManager;
- }
-
public void close() throws IOException {
dataManager.close();
}
@@ -79,24 +81,22 @@
return convertToRecordLocation(dataManager.getMark());
}
- public RecordLocation getNextRecordLocation(RecordLocation location)
- throws InvalidRecordLocationException, IOException, IllegalStateException {
+ public RecordLocation getNextRecordLocation(RecordLocation location) throws InvalidRecordLocationException, IOException, IllegalStateException {
return convertToRecordLocation(dataManager.getNextLocation(convertFromRecordLocation(location)));
}
- public Packet read(RecordLocation location) throws InvalidRecordLocationException, IOException,
- IllegalStateException {
+ public Packet read(RecordLocation location) throws InvalidRecordLocationException, IOException, IllegalStateException {
ByteSequence rc = dataManager.read(convertFromRecordLocation(location));
- if (rc == null)
+ if (rc == null) {
return null;
+ }
return new ByteArrayPacket(rc.getData(), rc.getOffset(), rc.getLength());
}
public void setJournalEventListener(JournalEventListener listener) throws IllegalStateException {
}
- public void setMark(RecordLocation location, boolean sync) throws InvalidRecordLocationException,
- IOException, IllegalStateException {
+ public void setMark(RecordLocation location, boolean sync) throws InvalidRecordLocationException, IOException, IllegalStateException {
dataManager.setMark(convertFromRecordLocation(location), sync);
}
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ContainerKeySet.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ContainerKeySet.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ContainerKeySet.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ContainerKeySet.java Fri Aug 10 09:57:01 2007
@@ -70,13 +70,12 @@
}
public boolean containsAll(Collection c) {
- boolean result = true;
for (Object key : c) {
- if (!(result &= container.containsKey(key))) {
- break;
+ if (!container.containsKey(key)) {
+ return false;
}
}
- return result;
+ return true;
}
public boolean addAll(Collection c) {
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ContainerKeySetIterator.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ContainerKeySetIterator.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ContainerKeySetIterator.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ContainerKeySetIterator.java Fri Aug 10 09:57:01 2007
@@ -26,10 +26,12 @@
* @version $Revision: 1.2 $
*/
public class ContainerKeySetIterator implements Iterator {
- private MapContainerImpl container;
- private IndexLinkedList list;
+
protected IndexItem nextItem;
protected IndexItem currentItem;
+
+ private MapContainerImpl container;
+ private IndexLinkedList list;
ContainerKeySetIterator(MapContainerImpl container) {
this.container = container;
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ListContainerImpl.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ListContainerImpl.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ListContainerImpl.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/container/ListContainerImpl.java Fri Aug 10 09:57:01 2007
@@ -323,15 +323,13 @@
*/
public synchronized boolean containsAll(Collection c) {
load();
- boolean result = false;
for (Iterator i = c.iterator(); i.hasNext();) {
Object obj = i.next();
- if (!(result = contains(obj))) {
- result = false;
- break;
+ if (!contains(obj)) {
+ return false;
}
}
- return result;
+ return true;
}
/*
@@ -872,8 +870,9 @@
Object o = i.next();
result.append(String.valueOf(o));
hasNext = i.hasNext();
- if (hasNext)
+ if (hasNext) {
result.append(", ");
+ }
}
result.append("]");
return result.toString();
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/data/DataFile.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/data/DataFile.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/data/DataFile.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/data/DataFile.java Fri Aug 10 09:57:01 2007
@@ -33,7 +33,7 @@
private int referenceCount;
private RandomAccessFile randomAcessFile;
private Object writerData;
- long length;
+ private long length;
private boolean dirty;
DataFile(File file, int number) {
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/data/DataManagerImpl.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/data/DataManagerImpl.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/data/DataManagerImpl.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/data/DataManagerImpl.java Fri Aug 10 09:57:01 2007
@@ -40,7 +40,11 @@
*/
public final class DataManagerImpl implements DataManager {
+ public static final int ITEM_HEAD_SIZE = 5; // type + length
+ public static final byte DATA_ITEM_TYPE = 1;
+ public static final byte REDO_ITEM_TYPE = 2;
public static final long MAX_FILE_LENGTH = 1024 * 1024 * 32;
+
private static final Log LOG = LogFactory.getLog(DataManagerImpl.class);
private static final String NAME_PREFIX = "data-";
@@ -50,13 +54,8 @@
private SyncDataFileWriter writer;
private DataFile currentWriteFile;
private long maxFileLength = MAX_FILE_LENGTH;
- Map fileMap = new HashMap();
-
- public static final int ITEM_HEAD_SIZE = 5; // type + length
- public static final byte DATA_ITEM_TYPE = 1;
- public static final byte REDO_ITEM_TYPE = 2;
-
- Marshaller redoMarshaller = RedoStoreIndexItem.MARSHALLER;
+ private Map<Integer, DataFile> fileMap = new HashMap<Integer, DataFile>();
+ private Marshaller redoMarshaller = RedoStoreIndexItem.MARSHALLER;
private String dataFilePrefix;
public DataManagerImpl(File dir, final String name) {
@@ -118,7 +117,7 @@
DataFile getDataFile(StoreLocation item) throws IOException {
Integer key = Integer.valueOf(item.getFile());
- DataFile dataFile = (DataFile)fileMap.get(key);
+ DataFile dataFile = fileMap.get(key);
if (dataFile == null) {
LOG.error("Looking for key " + key + " but not found in fileMap: " + fileMap);
throw new IOException("Could not locate data file " + NAME_PREFIX + name + "-" + item.getFile());
@@ -174,8 +173,9 @@
public synchronized void recoverRedoItems(RedoListener listener) throws IOException {
// Nothing to recover if there is no current file.
- if (currentWriteFile == null)
+ if (currentWriteFile == null) {
return;
+ }
DataItem item = new DataItem();
item.setFile(currentWriteFile.getNumber().intValue());
@@ -221,8 +221,8 @@
*/
public synchronized void close() throws IOException {
getWriter().close();
- for (Iterator i = fileMap.values().iterator(); i.hasNext();) {
- DataFile dataFile = (DataFile)i.next();
+ for (Iterator<DataFile> i = fileMap.values().iterator(); i.hasNext();) {
+ DataFile dataFile = i.next();
getWriter().force(dataFile);
dataFile.close();
}
@@ -235,8 +235,8 @@
* @see org.apache.activemq.kaha.impl.data.IDataManager#force()
*/
public synchronized void force() throws IOException {
- for (Iterator i = fileMap.values().iterator(); i.hasNext();) {
- DataFile dataFile = (DataFile)i.next();
+ for (Iterator<DataFile> i = fileMap.values().iterator(); i.hasNext();) {
+ DataFile dataFile = i.next();
getWriter().force(dataFile);
}
}
@@ -248,8 +248,8 @@
*/
public synchronized boolean delete() throws IOException {
boolean result = true;
- for (Iterator i = fileMap.values().iterator(); i.hasNext();) {
- DataFile dataFile = (DataFile)i.next();
+ for (Iterator<DataFile> i = fileMap.values().iterator(); i.hasNext();) {
+ DataFile dataFile = i.next();
result &= dataFile.delete();
}
fileMap.clear();
@@ -264,7 +264,7 @@
public synchronized void addInterestInFile(int file) throws IOException {
if (file >= 0) {
Integer key = Integer.valueOf(file);
- DataFile dataFile = (DataFile)fileMap.get(key);
+ DataFile dataFile = fileMap.get(key);
if (dataFile == null) {
dataFile = createAndAddDataFile(file);
}
@@ -286,7 +286,7 @@
public synchronized void removeInterestInFile(int file) throws IOException {
if (file >= 0) {
Integer key = Integer.valueOf(file);
- DataFile dataFile = (DataFile)fileMap.get(key);
+ DataFile dataFile = fileMap.get(key);
removeInterestInFile(dataFile);
}
}
@@ -307,15 +307,15 @@
* @see org.apache.activemq.kaha.impl.data.IDataManager#consolidateDataFiles()
*/
public synchronized void consolidateDataFiles() throws IOException {
- List purgeList = new ArrayList();
- for (Iterator i = fileMap.values().iterator(); i.hasNext();) {
- DataFile dataFile = (DataFile)i.next();
+ List<DataFile> purgeList = new ArrayList<DataFile>();
+ for (Iterator<DataFile> i = fileMap.values().iterator(); i.hasNext();) {
+ DataFile dataFile = i.next();
if (dataFile.isUnused() && dataFile != currentWriteFile) {
purgeList.add(dataFile);
}
}
for (int i = 0; i < purgeList.size(); i++) {
- DataFile dataFile = (DataFile)purgeList.get(i);
+ DataFile dataFile = purgeList.get(i);
removeDataFile(dataFile);
}
}
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/DiskIndexLinkedList.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/DiskIndexLinkedList.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/DiskIndexLinkedList.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/DiskIndexLinkedList.java Fri Aug 10 09:57:01 2007
@@ -52,8 +52,9 @@
* @return the first element in this list.
*/
public synchronized IndexItem getFirst() {
- if (size == 0)
+ if (size == 0) {
return null;
+ }
return getNextEntry(root);
}
@@ -63,8 +64,9 @@
* @return the last element in this list.
*/
public synchronized IndexItem getLast() {
- if (size == 0)
+ if (size == 0) {
return null;
+ }
if (last != null) {
last.next = null;
last.setNextItem(IndexItem.POSITION_NOT_SET);
@@ -92,8 +94,9 @@
* @return the last element from this list.
*/
public synchronized Object removeLast() {
- if (size == 0)
+ if (size == 0) {
return null;
+ }
StoreEntry result = last;
remove(last);
return result;
@@ -208,8 +211,9 @@
* Return the indexed entry.
*/
private IndexItem entry(int index) {
- if (index < 0 || index >= size)
+ if (index < 0 || index >= size) {
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
+ }
IndexItem e = root;
for (int i = 0; i <= index; i++) {
@@ -328,8 +332,9 @@
}
public synchronized void remove(IndexItem e) {
- if (e == root || e.equals(root))
+ if (e == root || e.equals(root)) {
return;
+ }
if (e == last || e.equals(last)) {
if (size > 1) {
last = (IndexItem)refreshEntry(last);
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/IndexItem.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/IndexItem.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/IndexItem.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/IndexItem.java Fri Aug 10 09:57:01 2007
@@ -34,11 +34,13 @@
public static final int INDEX_SIZE = 51;
public static final int INDEXES_ONLY_SIZE = 19;
+
+ protected long offset = POSITION_NOT_SET;
+
// used by linked list
IndexItem next;
IndexItem prev;
- protected long offset = POSITION_NOT_SET;
private long previousItem = POSITION_NOT_SET;
private long nextItem = POSITION_NOT_SET;
private boolean active = true;
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/IndexManager.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/IndexManager.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/IndexManager.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/IndexManager.java Fri Aug 10 09:57:01 2007
@@ -71,7 +71,8 @@
item.reset();
item.setActive(false);
if (lastFree == null) {
- firstFree = lastFree = item;
+ firstFree = item;
+ lastFree = item;
} else {
lastFree.setNextItem(item.getOffset());
}
@@ -124,7 +125,8 @@
}
public synchronized boolean delete() throws IOException {
- firstFree = lastFree = null;
+ firstFree = null;
+ lastFree = null;
if (indexFile != null) {
indexFile.close();
indexFile = null;
@@ -137,7 +139,8 @@
if (firstFree != null) {
if (firstFree.equals(lastFree)) {
result = firstFree;
- firstFree = lastFree = null;
+ firstFree = null;
+ lastFree = null;
} else {
result = firstFree;
firstFree = getIndex(firstFree.getNextItem());
@@ -177,7 +180,8 @@
updateIndexes(lastFree);
lastFree = index;
} else {
- lastFree = firstFree = index;
+ lastFree = index;
+ firstFree = index;
}
}
offset += IndexItem.INDEX_SIZE;
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/VMIndexLinkedList.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/VMIndexLinkedList.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/VMIndexLinkedList.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/VMIndexLinkedList.java Fri Aug 10 09:57:01 2007
@@ -32,7 +32,8 @@
*/
public VMIndexLinkedList(IndexItem header) {
this.root = header;
- this.root.next = root.prev = root;
+ this.root.next = root;
+ root.prev = root;
}
public IndexItem getRoot() {
@@ -45,8 +46,9 @@
* @see org.apache.activemq.kaha.impl.IndexLinkedList#getFirst()
*/
public IndexItem getFirst() {
- if (size == 0)
+ if (size == 0) {
return null;
+ }
return root.next;
}
@@ -56,8 +58,9 @@
* @see org.apache.activemq.kaha.impl.IndexLinkedList#getLast()
*/
public IndexItem getLast() {
- if (size == 0)
+ if (size == 0) {
return null;
+ }
return root.prev;
}
@@ -81,8 +84,9 @@
* @see org.apache.activemq.kaha.impl.IndexLinkedList#removeLast()
*/
public Object removeLast() {
- if (size == 0)
+ if (size == 0) {
return null;
+ }
StoreEntry result = root.prev;
remove(root.prev);
return result;
@@ -140,7 +144,8 @@
* @see org.apache.activemq.kaha.impl.IndexLinkedList#clear()
*/
public void clear() {
- root.next = root.prev = root;
+ root.next = root;
+ root.prev = root;
size = 0;
}
@@ -179,8 +184,9 @@
* Return the indexed entry.
*/
private IndexItem entry(int index) {
- if (index < 0 || index >= size)
+ if (index < 0 || index >= size) {
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
+ }
IndexItem e = root;
if (index < size / 2) {
for (int i = 0; i <= index; i++) {
@@ -249,8 +255,9 @@
* @see org.apache.activemq.kaha.impl.IndexLinkedList#remove(org.apache.activemq.kaha.impl.IndexItem)
*/
public void remove(IndexItem e) {
- if (e == root)
+ if (e == root) {
return;
+ }
e.prev.next = e.next;
e.next.prev = e.prev;
size--;
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashIndex.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashIndex.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashIndex.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashIndex.java Fri Aug 10 09:57:01 2007
@@ -59,7 +59,7 @@
private HashPage lastFree;
private AtomicBoolean loaded = new AtomicBoolean();
private LRUCache<Long, HashPage> pageCache;
- private boolean enablePageCaching = false;
+ private boolean enablePageCaching;
private int pageCacheSize = 10;
/**
@@ -88,8 +88,9 @@
this.name = name;
this.indexManager = indexManager;
int capacity = 1;
- while (capacity < numberOfBins)
+ while (capacity < numberOfBins) {
capacity <<= 1;
+ }
this.bins = new HashBin[capacity];
openIndexFile();
pageCache = new LRUCache<Long, HashPage>(pageCacheSize, pageCacheSize, 0.75f, true);
@@ -196,7 +197,8 @@
indexFile.write(dataOut.getData(), 0, HashPage.PAGE_HEADER_SIZE);
lastFree = page;
} else {
- lastFree = firstFree = page;
+ lastFree = page;
+ firstFree = page;
}
} else {
addToBin(page);
@@ -216,7 +218,8 @@
if (indexFile != null) {
indexFile.close();
indexFile = null;
- firstFree = lastFree = null;
+ firstFree = null;
+ lastFree = null;
bins = new HashBin[bins.length];
}
}
@@ -304,7 +307,8 @@
page.reset();
page.setActive(false);
if (lastFree == null) {
- firstFree = lastFree = page;
+ firstFree = page;
+ lastFree = page;
} else {
lastFree.setNextFreePageId(page.getId());
writePageHeader(lastFree);
@@ -317,7 +321,8 @@
if (firstFree != null) {
if (firstFree.equals(lastFree)) {
result = firstFree;
- firstFree = lastFree = null;
+ firstFree = null;
+ lastFree = null;
} else {
result = firstFree;
firstFree = getPageHeader(firstFree.getNextFreePageId());
@@ -419,9 +424,9 @@
static int hash(Object x) {
int h = x.hashCode();
h += ~(h << 9);
- h ^= (h >>> 14);
- h += (h << 4);
- h ^= (h >>> 10);
+ h ^= h >>> 14;
+ h += h << 4;
+ h ^= h >>> 10;
return h;
}
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashPage.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashPage.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashPage.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashPage.java Fri Aug 10 09:57:01 2007
@@ -32,8 +32,9 @@
* @version $Revision: 1.1.1.1 $
*/
class HashPage {
- private static final transient Log LOG = LogFactory.getLog(HashPage.class);
static final int PAGE_HEADER_SIZE = 17;
+ private static final transient Log LOG = LogFactory.getLog(HashPage.class);
+
private int maximumEntries;
private long id;
private int binId;
@@ -152,7 +153,7 @@
}
boolean isFull() {
- return (hashIndexEntries.size() >= maximumEntries);
+ return hashIndexEntries.size() >= maximumEntries;
}
boolean isUnderflowed() {
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/tree/TreeEntry.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/tree/TreeEntry.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/tree/TreeEntry.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/tree/TreeEntry.java Fri Aug 10 09:57:01 2007
@@ -56,7 +56,8 @@
}
void reset() {
- prevPageId = nextPageId = NOT_SET;
+ prevPageId = NOT_SET;
+ nextPageId = NOT_SET;
}
TreeEntry copy() {
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/tree/TreeIndex.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/tree/TreeIndex.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/tree/TreeIndex.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/tree/TreeIndex.java Fri Aug 10 09:57:01 2007
@@ -183,7 +183,8 @@
indexFile.write(dataOut.getData(), 0, TreePage.PAGE_HEADER_SIZE);
lastFree = page;
} else {
- lastFree = firstFree = page;
+ lastFree = page;
+ firstFree = page;
}
} else if (root == null && page.isRoot()) {
root = getFullPage(offset);
@@ -208,7 +209,8 @@
indexFile = null;
pageCache.clear();
root = null;
- firstFree = lastFree = null;
+ firstFree = null;
+ lastFree = null;
}
}
}
@@ -312,7 +314,8 @@
page.reset();
page.setActive(false);
if (lastFree == null) {
- firstFree = lastFree = page;
+ firstFree = page;
+ lastFree = page;
} else {
lastFree.setNextFreePageId(page.getId());
writePage(lastFree);
@@ -325,7 +328,8 @@
if (firstFree != null) {
if (firstFree.equals(lastFree)) {
result = firstFree;
- firstFree = lastFree = null;
+ firstFree = null;
+ lastFree = null;
} else {
result = firstFree;
firstFree = getPage(firstFree.getNextFreePageId());
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/tree/TreePage.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/tree/TreePage.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/tree/TreePage.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/tree/TreePage.java Fri Aug 10 09:57:01 2007
@@ -157,7 +157,7 @@
}
boolean isFull() {
- return (treeEntries.size() >= maximumEntries);
+ return treeEntries.size() >= maximumEntries;
}
boolean isRoot() {
@@ -354,7 +354,7 @@
} else {
// so we are the root and need to split
doInsertEntry(newEntry);
- int midIndex = (size() / 2);
+ int midIndex = size() / 2;
TreeEntry midEntry = removeTreeEntry(midIndex);
List<TreeEntry> subList = getSubList(midIndex, size());
removeAllTreeEntries(subList);
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/management/CountStatisticImpl.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/management/CountStatisticImpl.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/management/CountStatisticImpl.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/management/CountStatisticImpl.java Fri Aug 10 09:57:01 2007
@@ -118,10 +118,11 @@
*/
public double getPeriod() {
double count = counter.get();
- if (count == 0)
+ if (count == 0) {
return 0;
- double time = (System.currentTimeMillis() - getStartTime());
- return (time / (count * 1000.0));
+ }
+ double time = System.currentTimeMillis() - getStartTime();
+ return time / (count * 1000.0);
}
/**
@@ -130,8 +131,8 @@
*/
public double getFrequency() {
double count = counter.get();
- double time = (System.currentTimeMillis() - getStartTime());
- return (count * 1000.0 / time);
+ double time = System.currentTimeMillis() - getStartTime();
+ return count * 1000.0 / time;
}
}
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/management/PollCountStatisticImpl.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/management/PollCountStatisticImpl.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/management/PollCountStatisticImpl.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/management/PollCountStatisticImpl.java Fri Aug 10 09:57:01 2007
@@ -18,6 +18,7 @@
import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
import javax.management.j2ee.statistics.CountStatistic;
@@ -29,7 +30,7 @@
public class PollCountStatisticImpl extends StatisticImpl implements CountStatistic {
private PollCountStatisticImpl parent;
- private ArrayList children;
+ private List<PollCountStatisticImpl> children;
public PollCountStatisticImpl(PollCountStatisticImpl parent, String name, String description) {
this(name, description);
@@ -59,22 +60,25 @@
}
private synchronized void removeChild(PollCountStatisticImpl child) {
- if (children != null)
+ if (children != null) {
children.remove(child);
+ }
}
private synchronized void addChild(PollCountStatisticImpl child) {
- if (children == null)
- children = new ArrayList();
+ if (children == null) {
+ children = new ArrayList<PollCountStatisticImpl>();
+ }
children.add(child);
}
public synchronized long getCount() {
- if (children == null)
+ if (children == null) {
return 0;
+ }
long count = 0;
- for (Iterator iter = children.iterator(); iter.hasNext();) {
- PollCountStatisticImpl child = (PollCountStatisticImpl)iter.next();
+ for (Iterator<PollCountStatisticImpl> iter = children.iterator(); iter.hasNext();) {
+ PollCountStatisticImpl child = iter.next();
count += child.getCount();
}
return count;
@@ -92,10 +96,11 @@
*/
public double getPeriod() {
double count = getCount();
- if (count == 0)
+ if (count == 0) {
return 0;
- double time = (System.currentTimeMillis() - getStartTime());
- return (time / (count * 1000.0));
+ }
+ double time = System.currentTimeMillis() - getStartTime();
+ return time / (count * 1000.0);
}
/**
@@ -104,8 +109,8 @@
*/
public double getFrequency() {
double count = getCount();
- double time = (System.currentTimeMillis() - getStartTime());
- return (count * 1000.0 / time);
+ double time = System.currentTimeMillis() - getStartTime();
+ return count * 1000.0 / time;
}
}
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/management/StatsImpl.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/management/StatsImpl.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/management/StatsImpl.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/management/StatsImpl.java Fri Aug 10 09:57:01 2007
@@ -26,13 +26,13 @@
* @version $Revision: 1.2 $
*/
public class StatsImpl extends StatisticImpl implements Stats, Resettable {
- private Map map;
+ private Map<String, StatisticImpl> map;
public StatsImpl() {
this(new HashMap());
}
- public StatsImpl(Map map) {
+ public StatsImpl(Map<String, StatisticImpl> map) {
super("stats", "many", "Used only as container, not Statistic");
this.map = map;
}
@@ -49,18 +49,18 @@
}
public Statistic getStatistic(String name) {
- return (Statistic)map.get(name);
+ return map.get(name);
}
public String[] getStatisticNames() {
- Set keys = map.keySet();
+ Set<String> keys = map.keySet();
String[] answer = new String[keys.size()];
keys.toArray(answer);
return answer;
}
public Statistic[] getStatistics() {
- Collection values = map.values();
+ Collection<StatisticImpl> values = map.values();
Statistic[] answer = new Statistic[values.size()];
values.toArray(answer);
return answer;
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/memory/CacheEntry.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/memory/CacheEntry.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/memory/CacheEntry.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/memory/CacheEntry.java Fri Aug 10 09:57:01 2007
@@ -39,14 +39,16 @@
// Cannot remove if this is a tail pointer.
// Or not linked.
- if (owner == null || this.key == null || this.next == null)
+ if (owner == null || this.key == null || this.next == null) {
return false;
+ }
synchronized (owner.tail) {
this.next.previous = this.previous;
this.previous.next = this.next;
this.owner = null;
- this.next = this.previous = null;
+ this.next = null;
+ this.previous = null;
}
return true;
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/memory/CacheEntryList.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/memory/CacheEntryList.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/memory/CacheEntryList.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/memory/CacheEntryList.java Fri Aug 10 09:57:01 2007
@@ -27,7 +27,8 @@
public final CacheEntry tail = new CacheEntry(null, null);
public CacheEntryList() {
- tail.next = tail.previous = tail;
+ tail.next = tail;
+ tail.previous = tail;
}
public void add(CacheEntry ce) {
@@ -48,7 +49,8 @@
public void clear() {
synchronized (tail) {
- tail.next = tail.previous = tail;
+ tail.next = tail;
+ tail.previous = tail;
}
}
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/memory/CacheEvictionUsageListener.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/memory/CacheEvictionUsageListener.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/memory/CacheEvictionUsageListener.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/memory/CacheEvictionUsageListener.java Fri Aug 10 09:57:01 2007
@@ -18,6 +18,7 @@
import java.util.Iterator;
import java.util.LinkedList;
+import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.apache.activemq.thread.Task;
@@ -30,15 +31,14 @@
private static final Log LOG = LogFactory.getLog(CacheEvictionUsageListener.class);
- private final CopyOnWriteArrayList evictors = new CopyOnWriteArrayList();
+ private final List<CacheEvictor> evictors = new CopyOnWriteArrayList<CacheEvictor>();
private final int usageHighMark;
private final int usageLowMark;
private final TaskRunner evictionTask;
private final UsageManager usageManager;
- public CacheEvictionUsageListener(UsageManager usageManager, int usageHighMark, int usageLowMark,
- TaskRunnerFactory taskRunnerFactory) {
+ public CacheEvictionUsageListener(UsageManager usageManager, int usageHighMark, int usageLowMark, TaskRunnerFactory taskRunnerFactory) {
this.usageManager = usageManager;
this.usageHighMark = usageHighMark;
this.usageLowMark = usageLowMark;
@@ -51,20 +51,18 @@
boolean evictMessages() {
// Try to take the memory usage down below the low mark.
- try {
- LOG.debug("Evicting cache memory usage: " + usageManager.getPercentUsage());
+ LOG.debug("Evicting cache memory usage: " + usageManager.getPercentUsage());
- LinkedList list = new LinkedList(evictors);
- while (list.size() > 0 && usageManager.getPercentUsage() > usageLowMark) {
+ List<CacheEvictor> list = new LinkedList<CacheEvictor>(evictors);
+ while (list.size() > 0 && usageManager.getPercentUsage() > usageLowMark) {
- // Evenly evict messages from all evictors
- for (Iterator iter = list.iterator(); iter.hasNext();) {
- CacheEvictor evictor = (CacheEvictor)iter.next();
- if (evictor.evictCacheEntry() == null)
- iter.remove();
+ // Evenly evict messages from all evictors
+ for (Iterator<CacheEvictor> iter = list.iterator(); iter.hasNext();) {
+ CacheEvictor evictor = iter.next();
+ if (evictor.evictCacheEntry() == null) {
+ iter.remove();
}
}
- } finally {
}
return false;
}
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/memory/MapCache.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/memory/MapCache.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/memory/MapCache.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/memory/MapCache.java Fri Aug 10 09:57:01 2007
@@ -28,13 +28,13 @@
*/
public class MapCache implements Cache {
- protected final Map map;
+ protected final Map<Object, Object> map;
public MapCache() {
this(new ConcurrentHashMap());
}
- public MapCache(Map map) {
+ public MapCache(Map<Object, Object> map) {
this.map = map;
}
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/memory/UsageListener.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/memory/UsageListener.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/memory/UsageListener.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/memory/UsageListener.java Fri Aug 10 09:57:01 2007
@@ -17,5 +17,5 @@
package org.apache.activemq.memory;
public interface UsageListener {
- void onMemoryUseChanged( UsageManager memoryManager, int oldPercentUsage, int newPercentUsage );
+ void onMemoryUseChanged(UsageManager memoryManager, int oldPercentUsage, int newPercentUsage);
}
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/memory/UsageManager.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/memory/UsageManager.java?view=diff&rev=564679&r1=564678&r2=564679
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/memory/UsageManager.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/memory/UsageManager.java Fri Aug 10 09:57:01 2007
@@ -49,7 +49,7 @@
private final Object usageMutex = new Object();
- private final CopyOnWriteArrayList listeners = new CopyOnWriteArrayList();
+ private final List<UsageListener> listeners = new CopyOnWriteArrayList<UsageListener>();
private boolean sendFailIfNoSpace;
@@ -62,7 +62,7 @@
private String name = "";
private float usagePortion = 1.0f;
private List<UsageManager> children = new CopyOnWriteArrayList<UsageManager>();
- private final LinkedList<Runnable> callbacks = new LinkedList<Runnable>();
+ private final List<Runnable> callbacks = new LinkedList<Runnable>();
public UsageManager() {
this(null, "default");
@@ -112,8 +112,9 @@
* @throws InterruptedException
*/
public void waitForSpace() throws InterruptedException {
- if (parent != null)
+ if (parent != null) {
parent.waitForSpace();
+ }
synchronized (usageMutex) {
for (int i = 0; percentUsage >= 100; i++) {
usageMutex.wait();
@@ -128,8 +129,9 @@
*/
public boolean waitForSpace(long timeout) throws InterruptedException {
if (parent != null) {
- if (!parent.waitForSpace(timeout))
+ if (!parent.waitForSpace(timeout)) {
return false;
+ }
}
synchronized (usageMutex) {
if (percentUsage >= 100) {
@@ -145,10 +147,12 @@
* @param value
*/
public void increaseUsage(long value) {
- if (value == 0)
+ if (value == 0) {
return;
- if (parent != null)
+ }
+ if (parent != null) {
parent.increaseUsage(value);
+ }
int percentUsage;
synchronized (usageMutex) {
usage += value;
@@ -163,10 +167,12 @@
* @param value
*/
public void decreaseUsage(long value) {
- if (value == 0)
+ if (value == 0) {
return;
- if (parent != null)
+ }
+ if (parent != null) {
parent.decreaseUsage(value);
+ }
int percentUsage;
synchronized (usageMutex) {
usage -= value;
@@ -176,8 +182,9 @@
}
public boolean isFull() {
- if (parent != null && parent.isFull())
+ if (parent != null && parent.isFull()) {
return true;
+ }
synchronized (usageMutex) {
return percentUsage >= 100;
}
@@ -324,8 +331,9 @@
}
private int caclPercentUsage() {
- if (limit == 0)
+ if (limit == 0) {
return 0;
+ }
return (int)((((usage * 100) / limit) / percentUsageMinDelta) * percentUsageMinDelta);
}
@@ -337,16 +345,16 @@
if (oldPercentUsage >= 100 && newPercentUsage < 100) {
synchronized (usageMutex) {
usageMutex.notifyAll();
- for (Iterator iter = new ArrayList<Runnable>(callbacks).iterator(); iter.hasNext();) {
- Runnable callback = (Runnable)iter.next();
+ for (Iterator<Runnable> iter = new ArrayList<Runnable>(callbacks).iterator(); iter.hasNext();) {
+ Runnable callback = iter.next();
callback.run();
}
callbacks.clear();
}
}
// Let the listeners know
- for (Iterator iter = listeners.iterator(); iter.hasNext();) {
- UsageListener l = (UsageListener)iter.next();
+ for (Iterator<UsageListener> iter = listeners.iterator(); iter.hasNext();) {
+ UsageListener l = iter.next();
l.onMemoryUseChanged(this, oldPercentUsage, newPercentUsage);
}
}