You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2015/08/10 17:13:23 UTC
[24/53] [abbrv] [partial] activemq-artemis git commit: automatic
checkstyle change
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/ObjectInputStreamWithClassLoader.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/ObjectInputStreamWithClassLoader.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/ObjectInputStreamWithClassLoader.java
index 0c9fa91..ddc3564 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/ObjectInputStreamWithClassLoader.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/ObjectInputStreamWithClassLoader.java
@@ -26,8 +26,7 @@ import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
-public class ObjectInputStreamWithClassLoader extends ObjectInputStream
-{
+public class ObjectInputStreamWithClassLoader extends ObjectInputStream {
// Constants ------------------------------------------------------------------------------------
@@ -37,8 +36,7 @@ public class ObjectInputStreamWithClassLoader extends ObjectInputStream
// Constructors ---------------------------------------------------------------------------------
- public ObjectInputStreamWithClassLoader(final InputStream in) throws IOException
- {
+ public ObjectInputStreamWithClassLoader(final InputStream in) throws IOException {
super(in);
}
@@ -49,54 +47,40 @@ public class ObjectInputStreamWithClassLoader extends ObjectInputStream
// Protected ------------------------------------------------------------------------------------
@Override
- protected Class resolveClass(final ObjectStreamClass desc) throws IOException, ClassNotFoundException
- {
- if (System.getSecurityManager() == null)
- {
+ protected Class resolveClass(final ObjectStreamClass desc) throws IOException, ClassNotFoundException {
+ if (System.getSecurityManager() == null) {
return resolveClass0(desc);
}
- else
- {
- try
- {
- return AccessController.doPrivileged(new PrivilegedExceptionAction<Class>()
- {
+ else {
+ try {
+ return AccessController.doPrivileged(new PrivilegedExceptionAction<Class>() {
@Override
- public Class run() throws Exception
- {
+ public Class run() throws Exception {
return resolveClass0(desc);
}
});
}
- catch (PrivilegedActionException e)
- {
+ catch (PrivilegedActionException e) {
throw unwrapException(e);
}
}
}
@Override
- protected Class resolveProxyClass(final String[] interfaces) throws IOException, ClassNotFoundException
- {
- if (System.getSecurityManager() == null)
- {
+ protected Class resolveProxyClass(final String[] interfaces) throws IOException, ClassNotFoundException {
+ if (System.getSecurityManager() == null) {
return resolveProxyClass0(interfaces);
}
- else
- {
- try
- {
- return AccessController.doPrivileged(new PrivilegedExceptionAction<Class>()
- {
+ else {
+ try {
+ return AccessController.doPrivileged(new PrivilegedExceptionAction<Class>() {
@Override
- public Class run() throws Exception
- {
+ public Class run() throws Exception {
return resolveProxyClass0(interfaces);
}
});
}
- catch (PrivilegedActionException e)
- {
+ catch (PrivilegedActionException e) {
throw unwrapException(e);
}
}
@@ -104,89 +88,70 @@ public class ObjectInputStreamWithClassLoader extends ObjectInputStream
// Private --------------------------------------------------------------------------------------
- private Class resolveClass0(final ObjectStreamClass desc) throws IOException, ClassNotFoundException
- {
+ private Class resolveClass0(final ObjectStreamClass desc) throws IOException, ClassNotFoundException {
String name = desc.getName();
ClassLoader loader = Thread.currentThread().getContextClassLoader();
- try
- {
+ try {
// HORNETQ-747 https://issues.jboss.org/browse/HORNETQ-747
// Use Class.forName instead of ClassLoader.loadClass to avoid issues with loading arrays
Class clazz = Class.forName(name, false, loader);
// sanity check only.. if a classLoader can't find a clazz, it will throw an exception
- if (clazz == null)
- {
+ if (clazz == null) {
return super.resolveClass(desc);
}
- else
- {
+ else {
return clazz;
}
}
- catch (ClassNotFoundException e)
- {
+ catch (ClassNotFoundException e) {
return super.resolveClass(desc);
}
}
- private Class resolveProxyClass0(String[] interfaces) throws IOException, ClassNotFoundException
- {
+ private Class resolveProxyClass0(String[] interfaces) throws IOException, ClassNotFoundException {
ClassLoader latestLoader = Thread.currentThread().getContextClassLoader();
ClassLoader nonPublicLoader = null;
boolean hasNonPublicInterface = false;
// define proxy in class loader of non-public interface(s), if any
Class[] classObjs = new Class[interfaces.length];
- for (int i = 0; i < interfaces.length; i++)
- {
+ for (int i = 0; i < interfaces.length; i++) {
Class cl = Class.forName(interfaces[i], false, latestLoader);
- if ((cl.getModifiers() & Modifier.PUBLIC) == 0)
- {
- if (hasNonPublicInterface)
- {
- if (nonPublicLoader != cl.getClassLoader())
- {
+ if ((cl.getModifiers() & Modifier.PUBLIC) == 0) {
+ if (hasNonPublicInterface) {
+ if (nonPublicLoader != cl.getClassLoader()) {
throw new IllegalAccessError("conflicting non-public interface class loaders");
}
}
- else
- {
+ else {
nonPublicLoader = cl.getClassLoader();
hasNonPublicInterface = true;
}
}
classObjs[i] = cl;
}
- try
- {
+ try {
return Proxy.getProxyClass(hasNonPublicInterface ? nonPublicLoader : latestLoader, classObjs);
}
- catch (IllegalArgumentException e)
- {
+ catch (IllegalArgumentException e) {
throw new ClassNotFoundException(null, e);
}
}
- private RuntimeException unwrapException(PrivilegedActionException e) throws IOException, ClassNotFoundException
- {
+ private RuntimeException unwrapException(PrivilegedActionException e) throws IOException, ClassNotFoundException {
Throwable c = e.getCause();
- if (c instanceof IOException)
- {
- throw (IOException)c;
+ if (c instanceof IOException) {
+ throw (IOException) c;
}
- else if (c instanceof ClassNotFoundException)
- {
- throw (ClassNotFoundException)c;
+ else if (c instanceof ClassNotFoundException) {
+ throw (ClassNotFoundException) c;
}
- else if (c instanceof RuntimeException)
- {
- throw (RuntimeException)c;
+ else if (c instanceof RuntimeException) {
+ throw (RuntimeException) c;
}
- else if (c instanceof Error)
- {
- throw (Error)c;
+ else if (c instanceof Error) {
+ throw (Error) c;
}
- else
- {
+ else {
throw new RuntimeException(c);
}
}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/OrderedExecutorFactory.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/OrderedExecutorFactory.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/OrderedExecutorFactory.java
index b9f92fb..7e13fd6 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/OrderedExecutorFactory.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/OrderedExecutorFactory.java
@@ -22,12 +22,11 @@ import java.util.concurrent.Executor;
import org.apache.activemq.artemis.api.core.ActiveMQInterruptedException;
import org.apache.activemq.artemis.core.client.ActiveMQClientLogger;
-
/**
* A factory for producing executors that run all tasks in order, which delegate to a single common executor instance.
*/
-public final class OrderedExecutorFactory implements ExecutorFactory
-{
+public final class OrderedExecutorFactory implements ExecutorFactory {
+
private final Executor parent;
/**
@@ -35,8 +34,7 @@ public final class OrderedExecutorFactory implements ExecutorFactory
*
* @param parent the parent executor
*/
- public OrderedExecutorFactory(final Executor parent)
- {
+ public OrderedExecutorFactory(final Executor parent) {
this.parent = parent;
}
@@ -45,8 +43,7 @@ public final class OrderedExecutorFactory implements ExecutorFactory
*
* @return an ordered executor
*/
- public Executor getExecutor()
- {
+ public Executor getExecutor() {
return new OrderedExecutor(parent);
}
@@ -56,8 +53,8 @@ public final class OrderedExecutorFactory implements ExecutorFactory
* More specifically, any call B to the {@link #execute(Runnable)} method that happens-after another call A to the
* same method, will result in B's task running after A's.
*/
- private static final class OrderedExecutor implements Executor
- {
+ private static final class OrderedExecutor implements Executor {
+
private final ConcurrentLinkedQueue<Runnable> tasks = new ConcurrentLinkedQueue<Runnable>();
// @protected by tasks
@@ -72,45 +69,35 @@ public final class OrderedExecutorFactory implements ExecutorFactory
*
* @param parent the parent executor
*/
- public OrderedExecutor(final Executor parent)
- {
+ public OrderedExecutor(final Executor parent) {
this.parent = parent;
- runner = new Runnable()
- {
- public void run()
- {
- for (;;)
- {
+ runner = new Runnable() {
+ public void run() {
+ for (; ; ) {
// Optimization, first try without any locks
Runnable task = tasks.poll();
- if (task == null)
- {
- synchronized (tasks)
- {
+ if (task == null) {
+ synchronized (tasks) {
// if it's null we need to retry now holding the lock on tasks
// this is because running=false and tasks.empty must be an atomic operation
// so we have to retry before setting the tasks to false
// this is a different approach to the anti-pattern on synchronize-retry,
// as this is just guaranteeing the running=false and tasks.empty being an atomic operation
task = tasks.poll();
- if (task == null)
- {
+ if (task == null) {
running = false;
return;
}
}
}
- try
- {
+ try {
task.run();
}
- catch (ActiveMQInterruptedException e)
- {
+ catch (ActiveMQInterruptedException e) {
// This could happen during shutdowns. Nothing to be concerned about here
ActiveMQClientLogger.LOGGER.debug("Interrupted Thread", e);
}
- catch (Throwable t)
- {
+ catch (Throwable t) {
ActiveMQClientLogger.LOGGER.caughtunexpectedThrowable(t);
}
}
@@ -123,21 +110,17 @@ public final class OrderedExecutorFactory implements ExecutorFactory
*
* @param command the task to run.
*/
- public void execute(final Runnable command)
- {
- synchronized (tasks)
- {
+ public void execute(final Runnable command) {
+ synchronized (tasks) {
tasks.add(command);
- if (!running)
- {
+ if (!running) {
running = true;
parent.execute(runner);
}
}
}
- public String toString()
- {
+ public String toString() {
return "OrderedExecutor(running=" + running + ", tasks=" + tasks + ")";
}
}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/PriorityLinkedList.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/PriorityLinkedList.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/PriorityLinkedList.java
index e55a0b8..450f58a 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/PriorityLinkedList.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/PriorityLinkedList.java
@@ -16,13 +16,12 @@
*/
package org.apache.activemq.artemis.utils;
-
/**
* A type of linked list which maintains items according to a priority
* and allows adding and removing of elements at both ends, and peeking
*/
-public interface PriorityLinkedList<T>
-{
+public interface PriorityLinkedList<T> {
+
void addHead(T t, int priority);
void addTail(T t, int priority);
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/PriorityLinkedListImpl.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/PriorityLinkedListImpl.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/PriorityLinkedListImpl.java
index 72f4692..b4b6a51 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/PriorityLinkedListImpl.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/PriorityLinkedListImpl.java
@@ -24,8 +24,8 @@ import java.util.NoSuchElementException;
* <p>
* It implements this by maintaining an individual LinkedBlockingDeque for each priority level.
*/
-public class PriorityLinkedListImpl<T> implements PriorityLinkedList<T>
-{
+public class PriorityLinkedListImpl<T> implements PriorityLinkedList<T> {
+
protected LinkedListImpl<T>[] levels;
private int size;
@@ -36,39 +36,31 @@ public class PriorityLinkedListImpl<T> implements PriorityLinkedList<T>
private int lastPriority = -1;
- public PriorityLinkedListImpl(final int priorities)
- {
+ public PriorityLinkedListImpl(final int priorities) {
levels = (LinkedListImpl<T>[]) Array.newInstance(LinkedListImpl.class, priorities);
- for (int i = 0; i < priorities; i++)
- {
+ for (int i = 0; i < priorities; i++) {
levels[i] = new LinkedListImpl<T>();
}
}
- private void checkHighest(final int priority)
- {
- if (lastPriority != priority || priority > highestPriority)
- {
+ private void checkHighest(final int priority) {
+ if (lastPriority != priority || priority > highestPriority) {
lastPriority = priority;
- if (lastReset == Integer.MAX_VALUE)
- {
+ if (lastReset == Integer.MAX_VALUE) {
lastReset = 0;
}
- else
- {
+ else {
lastReset++;
}
}
- if (priority > highestPriority)
- {
+ if (priority > highestPriority) {
highestPriority = priority;
}
}
- public void addHead(final T t, final int priority)
- {
+ public void addHead(final T t, final int priority) {
checkHighest(priority);
levels[priority].addHead(t);
@@ -76,8 +68,7 @@ public class PriorityLinkedListImpl<T> implements PriorityLinkedList<T>
size++;
}
- public void addTail(final T t, final int priority)
- {
+ public void addTail(final T t, final int priority) {
checkHighest(priority);
levels[priority].addTail(t);
@@ -85,8 +76,7 @@ public class PriorityLinkedListImpl<T> implements PriorityLinkedList<T>
size++;
}
- public T poll()
- {
+ public T poll() {
T t = null;
// We are just using a simple prioritization algorithm:
@@ -95,22 +85,17 @@ public class PriorityLinkedListImpl<T> implements PriorityLinkedList<T>
// TODO - A better prioritization algorithm
- for (int i = highestPriority; i >= 0; i--)
- {
+ for (int i = highestPriority; i >= 0; i--) {
LinkedListImpl<T> ll = levels[i];
- if (ll.size() != 0)
- {
+ if (ll.size() != 0) {
t = ll.poll();
- if (t != null)
- {
+ if (t != null) {
size--;
- if (ll.size() == 0)
- {
- if (highestPriority == i)
- {
+ if (ll.size() == 0) {
+ if (highestPriority == i) {
highestPriority--;
}
}
@@ -123,33 +108,28 @@ public class PriorityLinkedListImpl<T> implements PriorityLinkedList<T>
return t;
}
- public void clear()
- {
- for (LinkedListImpl<T> list : levels)
- {
+ public void clear() {
+ for (LinkedListImpl<T> list : levels) {
list.clear();
}
size = 0;
}
- public int size()
- {
+ public int size() {
return size;
}
- public boolean isEmpty()
- {
+ public boolean isEmpty() {
return size == 0;
}
- public LinkedListIterator<T> iterator()
- {
+ public LinkedListIterator<T> iterator() {
return new PriorityLinkedListIterator();
}
- private class PriorityLinkedListIterator implements LinkedListIterator<T>
- {
+ private class PriorityLinkedListIterator implements LinkedListIterator<T> {
+
private int index;
private final LinkedListIterator<T>[] cachedIters = new LinkedListIterator[levels.length];
@@ -160,78 +140,63 @@ public class PriorityLinkedListImpl<T> implements PriorityLinkedList<T>
volatile boolean closed = false;
- PriorityLinkedListIterator()
- {
+ PriorityLinkedListIterator() {
index = levels.length - 1;
}
@Override
- protected void finalize()
- {
+ protected void finalize() {
close();
}
- public void repeat()
- {
- if (lastIter == null)
- {
+ public void repeat() {
+ if (lastIter == null) {
throw new NoSuchElementException();
}
lastIter.repeat();
}
- public void close()
- {
- if (!closed)
- {
+ public void close() {
+ if (!closed) {
closed = true;
lastIter = null;
- for (LinkedListIterator<T> iter : cachedIters)
- {
- if (iter != null)
- {
+ for (LinkedListIterator<T> iter : cachedIters) {
+ if (iter != null) {
iter.close();
}
}
}
}
- private void checkReset()
- {
- if (lastReset != resetCount)
- {
+ private void checkReset() {
+ if (lastReset != resetCount) {
index = highestPriority;
resetCount = lastReset;
}
}
- public boolean hasNext()
- {
+ public boolean hasNext() {
checkReset();
- while (index >= 0)
- {
+ while (index >= 0) {
lastIter = cachedIters[index];
- if (lastIter == null)
- {
+ if (lastIter == null) {
lastIter = cachedIters[index] = levels[index].iterator();
}
boolean b = lastIter.hasNext();
- if (b)
- {
+ if (b) {
return true;
}
index--;
- if (index < 0)
- {
+ if (index < 0) {
index = levels.length - 1;
break;
@@ -240,20 +205,16 @@ public class PriorityLinkedListImpl<T> implements PriorityLinkedList<T>
return false;
}
- public T next()
- {
- if (lastIter == null)
- {
+ public T next() {
+ if (lastIter == null) {
throw new NoSuchElementException();
}
return lastIter.next();
}
- public void remove()
- {
- if (lastIter == null)
- {
+ public void remove() {
+ if (lastIter == null) {
throw new NoSuchElementException();
}
@@ -266,8 +227,7 @@ public class PriorityLinkedListImpl<T> implements PriorityLinkedList<T>
// what would make us eventually having hasNext() returning false
// as a bug
// Part of the fix for HORNETQ-705
- for (int i = index; i >= 0 && levels[index].size() == 0; i--)
- {
+ for (int i = index; i >= 0 && levels[index].size() == 0; i--) {
highestPriority = i;
}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/Random.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/Random.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/Random.java
index eb53f43..b93fd7e 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/Random.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/Random.java
@@ -18,14 +18,13 @@ package org.apache.activemq.artemis.utils;
import java.io.Serializable;
-public class Random implements Serializable
-{
+public class Random implements Serializable {
+
private static int extraSeed;
private static final long serialVersionUID = 40335522290950498L;
- private static synchronized long getSeed()
- {
+ private static synchronized long getSeed() {
long seed = System.currentTimeMillis() + Random.extraSeed++;
return seed;
@@ -33,8 +32,7 @@ public class Random implements Serializable
private final java.util.Random random = new java.util.Random(Random.getSeed());
- public java.util.Random getRandom()
- {
+ public java.util.Random getRandom() {
return random;
}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/SecurityFormatter.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/SecurityFormatter.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/SecurityFormatter.java
index deac083..d79f7d6 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/SecurityFormatter.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/SecurityFormatter.java
@@ -23,10 +23,15 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
-public class SecurityFormatter
-{
- public static Set<Role> createSecurity(String sendRoles, String consumeRoles, String createDurableQueueRoles, String deleteDurableQueueRoles, String createNonDurableQueueRoles, String deleteNonDurableQueueRoles, String manageRoles)
- {
+public class SecurityFormatter {
+
+ public static Set<Role> createSecurity(String sendRoles,
+ String consumeRoles,
+ String createDurableQueueRoles,
+ String deleteDurableQueueRoles,
+ String createNonDurableQueueRoles,
+ String deleteNonDurableQueueRoles,
+ String manageRoles) {
List<String> createDurableQueue = toList(createDurableQueueRoles);
List<String> deleteDurableQueue = toList(deleteDurableQueueRoles);
List<String> createNonDurableQueue = toList(createNonDurableQueueRoles);
@@ -45,31 +50,19 @@ public class SecurityFormatter
allRoles.addAll(manage);
Set<Role> roles = new HashSet<Role>(allRoles.size());
- for (String role : allRoles)
- {
- roles.add(new Role(role,
- send.contains(role),
- consume.contains(role),
- createDurableQueue.contains(role),
- deleteDurableQueue.contains(role),
- createNonDurableQueue.contains(role),
- deleteNonDurableQueue.contains(role),
- manageRoles.contains(role)));
+ for (String role : allRoles) {
+ roles.add(new Role(role, send.contains(role), consume.contains(role), createDurableQueue.contains(role), deleteDurableQueue.contains(role), createNonDurableQueue.contains(role), deleteNonDurableQueue.contains(role), manageRoles.contains(role)));
}
return roles;
}
-
- private static List<String> toList(final String commaSeparatedString)
- {
+ private static List<String> toList(final String commaSeparatedString) {
List<String> list = new ArrayList<String>();
- if (commaSeparatedString == null || commaSeparatedString.trim().length() == 0)
- {
+ if (commaSeparatedString == null || commaSeparatedString.trim().length() == 0) {
return list;
}
String[] values = commaSeparatedString.split(",");
- for (int i = 0; i < values.length; i++)
- {
+ for (int i = 0; i < values.length; i++) {
list.add(values[i].trim());
}
return list;
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/SimpleIDGenerator.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/SimpleIDGenerator.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/SimpleIDGenerator.java
index f8b0477..06a26c7 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/SimpleIDGenerator.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/SimpleIDGenerator.java
@@ -16,28 +16,24 @@
*/
package org.apache.activemq.artemis.utils;
-public class SimpleIDGenerator implements IDGenerator
-{
+public class SimpleIDGenerator implements IDGenerator {
+
private long idSequence;
private boolean wrapped;
- public SimpleIDGenerator(final long startID)
- {
+ public SimpleIDGenerator(final long startID) {
idSequence = startID;
}
- public synchronized long generateID()
- {
+ public synchronized long generateID() {
long id = idSequence++;
- if (idSequence == Long.MIN_VALUE)
- {
+ if (idSequence == Long.MIN_VALUE) {
wrapped = true;
}
- if (wrapped)
- {
+ if (wrapped) {
// Wrap - Very unlikely to happen
throw new IllegalStateException("Exhausted ids to use!");
}
@@ -45,8 +41,7 @@ public class SimpleIDGenerator implements IDGenerator
return id;
}
- public synchronized long getCurrentID()
- {
+ public synchronized long getCurrentID() {
return idSequence;
}
}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/SizeFormatterUtil.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/SizeFormatterUtil.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/SizeFormatterUtil.java
index b1694d6..71698b4 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/SizeFormatterUtil.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/SizeFormatterUtil.java
@@ -16,8 +16,7 @@
*/
package org.apache.activemq.artemis.utils;
-public class SizeFormatterUtil
-{
+public class SizeFormatterUtil {
// Constants -----------------------------------------------------
@@ -31,22 +30,18 @@ public class SizeFormatterUtil
// Static --------------------------------------------------------
- public static String sizeof(final long size)
- {
+ public static String sizeof(final long size) {
double s = Long.valueOf(size).doubleValue();
String suffix = "B";
- if (s > SizeFormatterUtil.oneGiB)
- {
+ if (s > SizeFormatterUtil.oneGiB) {
s /= SizeFormatterUtil.oneGiB;
suffix = "GiB";
}
- else if (s > SizeFormatterUtil.oneMiB)
- {
+ else if (s > SizeFormatterUtil.oneMiB) {
s /= SizeFormatterUtil.oneMiB;
suffix = "MiB";
}
- else if (s > SizeFormatterUtil.oneKiB)
- {
+ else if (s > SizeFormatterUtil.oneKiB) {
s /= SizeFormatterUtil.oneKiB;
suffix = "kiB";
}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/SoftValueHashMap.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/SoftValueHashMap.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/SoftValueHashMap.java
index de588b3..4eaf106 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/SoftValueHashMap.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/SoftValueHashMap.java
@@ -30,8 +30,8 @@ import java.util.concurrent.atomic.AtomicLong;
import org.apache.activemq.artemis.core.client.ActiveMQClientLogger;
-public class SoftValueHashMap<K, V extends SoftValueHashMap.ValueCache> implements Map<K, V>
-{
+public class SoftValueHashMap<K, V extends SoftValueHashMap.ValueCache> implements Map<K, V> {
+
private final boolean isTrace = ActiveMQClientLogger.LOGGER.isTraceEnabled();
// The soft references that are already good.
@@ -50,36 +50,32 @@ public class SoftValueHashMap<K, V extends SoftValueHashMap.ValueCache> implemen
// Static --------------------------------------------------------
- public abstract interface ValueCache
- {
+ public abstract interface ValueCache {
+
boolean isLive();
}
// Constructors --------------------------------------------------
- public SoftValueHashMap(final int maxElements)
- {
+ public SoftValueHashMap(final int maxElements) {
this.maxElements = maxElements;
}
// Public --------------------------------------------------------
- public void setMaxElements(final int maxElements)
- {
+ public void setMaxElements(final int maxElements) {
this.maxElements = maxElements;
checkCacheSize();
}
- public int getMaxEelements()
- {
+ public int getMaxEelements() {
return this.maxElements;
}
/**
* @see java.util.Map#size()
*/
- public int size()
- {
+ public int size() {
processQueue();
return mapDelegate.size();
}
@@ -87,8 +83,7 @@ public class SoftValueHashMap<K, V extends SoftValueHashMap.ValueCache> implemen
/**
* @see java.util.Map#isEmpty()
*/
- public boolean isEmpty()
- {
+ public boolean isEmpty() {
processQueue();
return mapDelegate.isEmpty();
}
@@ -97,8 +92,7 @@ public class SoftValueHashMap<K, V extends SoftValueHashMap.ValueCache> implemen
* @param key
* @see java.util.Map#containsKey(java.lang.Object)
*/
- public boolean containsKey(final Object key)
- {
+ public boolean containsKey(final Object key) {
processQueue();
return mapDelegate.containsKey(key);
}
@@ -107,14 +101,11 @@ public class SoftValueHashMap<K, V extends SoftValueHashMap.ValueCache> implemen
* @param value
* @see java.util.Map#containsValue(java.lang.Object)
*/
- public boolean containsValue(final Object value)
- {
+ public boolean containsValue(final Object value) {
processQueue();
- for (AggregatedSoftReference valueIter : mapDelegate.values())
- {
+ for (AggregatedSoftReference valueIter : mapDelegate.values()) {
V valueElement = valueIter.get();
- if (valueElement != null && value.equals(valueElement))
- {
+ if (valueElement != null && value.equals(valueElement)) {
return true;
}
@@ -126,17 +117,14 @@ public class SoftValueHashMap<K, V extends SoftValueHashMap.ValueCache> implemen
* @param key
* @see java.util.Map#get(java.lang.Object)
*/
- public V get(final Object key)
- {
+ public V get(final Object key) {
processQueue();
AggregatedSoftReference value = mapDelegate.get(key);
- if (value != null)
- {
+ if (value != null) {
value.used();
return value.get();
}
- else
- {
+ else {
return null;
}
}
@@ -146,52 +134,41 @@ public class SoftValueHashMap<K, V extends SoftValueHashMap.ValueCache> implemen
* @param value
* @see java.util.Map#put(java.lang.Object, java.lang.Object)
*/
- public V put(final K key, final V value)
- {
+ public V put(final K key, final V value) {
processQueue();
AggregatedSoftReference newRef = createReference(key, value);
AggregatedSoftReference oldRef = mapDelegate.put(key, newRef);
checkCacheSize();
newRef.used();
- if (oldRef != null)
- {
+ if (oldRef != null) {
return oldRef.get();
}
- else
- {
+ else {
return null;
}
}
- private void checkCacheSize()
- {
- if (maxElements > 0 && mapDelegate.size() > maxElements)
- {
+ private void checkCacheSize() {
+ if (maxElements > 0 && mapDelegate.size() > maxElements) {
TreeSet<AggregatedSoftReference> usedReferences = new TreeSet<AggregatedSoftReference>(new ComparatorAgregated());
- for (AggregatedSoftReference ref : mapDelegate.values())
- {
+ for (AggregatedSoftReference ref : mapDelegate.values()) {
V v = ref.get();
- if (v != null && !v.isLive())
- {
+ if (v != null && !v.isLive()) {
usedReferences.add(ref);
}
}
- for (AggregatedSoftReference ref : usedReferences)
- {
- if (ref.used > 0)
- {
+ for (AggregatedSoftReference ref : usedReferences) {
+ if (ref.used > 0) {
Object removed = mapDelegate.remove(ref.key);
- if (isTrace)
- {
+ if (isTrace) {
ActiveMQClientLogger.LOGGER.trace("Removing " + removed + " with id = " + ref.key + " from SoftValueHashMap");
}
- if (mapDelegate.size() <= maxElements)
- {
+ if (mapDelegate.size() <= maxElements) {
break;
}
}
@@ -199,33 +176,27 @@ public class SoftValueHashMap<K, V extends SoftValueHashMap.ValueCache> implemen
}
}
- class ComparatorAgregated implements Comparator<AggregatedSoftReference>
- {
- public int compare(AggregatedSoftReference o1, AggregatedSoftReference o2)
- {
+ class ComparatorAgregated implements Comparator<AggregatedSoftReference> {
+
+ public int compare(AggregatedSoftReference o1, AggregatedSoftReference o2) {
long k = o1.used - o2.used;
- if (k > 0)
- {
+ if (k > 0) {
return 1;
}
- else if (k < 0)
- {
+ else if (k < 0) {
return -1;
}
k = o1.hashCode() - o2.hashCode();
- if (k > 0)
- {
+ if (k > 0) {
return 1;
}
- else if (k < 0)
- {
+ else if (k < 0) {
return -1;
}
- else
- {
+ else {
return 0;
}
}
@@ -235,16 +206,13 @@ public class SoftValueHashMap<K, V extends SoftValueHashMap.ValueCache> implemen
* @param key
* @see java.util.Map#remove(java.lang.Object)
*/
- public V remove(final Object key)
- {
+ public V remove(final Object key) {
processQueue();
AggregatedSoftReference ref = mapDelegate.remove(key);
- if (ref != null)
- {
+ if (ref != null) {
return ref.get();
}
- else
- {
+ else {
return null;
}
}
@@ -253,11 +221,9 @@ public class SoftValueHashMap<K, V extends SoftValueHashMap.ValueCache> implemen
* @param m
* @see java.util.Map#putAll(java.util.Map)
*/
- public void putAll(final Map<? extends K, ? extends V> m)
- {
+ public void putAll(final Map<? extends K, ? extends V> m) {
processQueue();
- for (Map.Entry<? extends K, ? extends V> e : m.entrySet())
- {
+ for (Map.Entry<? extends K, ? extends V> e : m.entrySet()) {
put(e.getKey(), e.getValue());
}
}
@@ -265,16 +231,14 @@ public class SoftValueHashMap<K, V extends SoftValueHashMap.ValueCache> implemen
/**
* @see java.util.Map#clear()
*/
- public void clear()
- {
+ public void clear() {
mapDelegate.clear();
}
/**
* @see java.util.Map#keySet()
*/
- public Set<K> keySet()
- {
+ public Set<K> keySet() {
processQueue();
return mapDelegate.keySet();
}
@@ -282,16 +246,13 @@ public class SoftValueHashMap<K, V extends SoftValueHashMap.ValueCache> implemen
/**
* @see java.util.Map#values()
*/
- public Collection<V> values()
- {
+ public Collection<V> values() {
processQueue();
ArrayList<V> list = new ArrayList<V>();
- for (AggregatedSoftReference refs : mapDelegate.values())
- {
+ for (AggregatedSoftReference refs : mapDelegate.values()) {
V value = refs.get();
- if (value != null)
- {
+ if (value != null) {
list.add(value);
}
}
@@ -302,15 +263,12 @@ public class SoftValueHashMap<K, V extends SoftValueHashMap.ValueCache> implemen
/**
* @see java.util.Map#entrySet()
*/
- public Set<java.util.Map.Entry<K, V>> entrySet()
- {
+ public Set<java.util.Map.Entry<K, V>> entrySet() {
processQueue();
HashSet<Map.Entry<K, V>> set = new HashSet<Map.Entry<K, V>>();
- for (Map.Entry<K, AggregatedSoftReference> pair : mapDelegate.entrySet())
- {
+ for (Map.Entry<K, AggregatedSoftReference> pair : mapDelegate.entrySet()) {
V value = pair.getValue().get();
- if (value != null)
- {
+ if (value != null) {
set.add(new EntryElement<K, V>(pair.getKey(), value));
}
}
@@ -322,8 +280,7 @@ public class SoftValueHashMap<K, V extends SoftValueHashMap.ValueCache> implemen
* @see java.util.Map#equals(java.lang.Object)
*/
@Override
- public boolean equals(final Object o)
- {
+ public boolean equals(final Object o) {
processQueue();
return mapDelegate.equals(o);
}
@@ -332,8 +289,7 @@ public class SoftValueHashMap<K, V extends SoftValueHashMap.ValueCache> implemen
* @see java.util.Map#hashCode()
*/
@Override
- public int hashCode()
- {
+ public int hashCode() {
return mapDelegate.hashCode();
}
@@ -344,60 +300,52 @@ public class SoftValueHashMap<K, V extends SoftValueHashMap.ValueCache> implemen
// Private -------------------------------------------------------
@SuppressWarnings("unchecked")
- private void processQueue()
- {
+ private void processQueue() {
AggregatedSoftReference ref = null;
- while ((ref = (AggregatedSoftReference)this.refQueue.poll()) != null)
- {
+ while ((ref = (AggregatedSoftReference) this.refQueue.poll()) != null) {
mapDelegate.remove(ref.key);
}
}
- private AggregatedSoftReference createReference(final K key, final V value)
- {
+ private AggregatedSoftReference createReference(final K key, final V value) {
AggregatedSoftReference ref = new AggregatedSoftReference(key, value);
return ref;
}
// Inner classes -------------------------------------------------
- class AggregatedSoftReference extends SoftReference<V>
- {
+ class AggregatedSoftReference extends SoftReference<V> {
+
final K key;
long used = 0;
- public long getUsed()
- {
+ public long getUsed() {
return used;
}
- public void used()
- {
+ public void used() {
used = usedCounter.incrementAndGet();
}
- public AggregatedSoftReference(final K key, final V referent)
- {
+ public AggregatedSoftReference(final K key, final V referent) {
super(referent, refQueue);
this.key = key;
}
@Override
- public String toString()
- {
+ public String toString() {
return "AggregatedSoftReference [key=" + key + ", used=" + used + "]";
}
}
- static final class EntryElement<K, V> implements Map.Entry<K, V>
- {
+ static final class EntryElement<K, V> implements Map.Entry<K, V> {
+
final K key;
volatile V value;
- EntryElement(final K key, final V value)
- {
+ EntryElement(final K key, final V value) {
this.key = key;
this.value = value;
}
@@ -405,24 +353,21 @@ public class SoftValueHashMap<K, V extends SoftValueHashMap.ValueCache> implemen
/* (non-Javadoc)
* @see java.util.Map.Entry#getKey()
*/
- public K getKey()
- {
+ public K getKey() {
return key;
}
/* (non-Javadoc)
* @see java.util.Map.Entry#getValue()
*/
- public V getValue()
- {
+ public V getValue() {
return value;
}
/* (non-Javadoc)
* @see java.util.Map.Entry#setValue(java.lang.Object)
*/
- public V setValue(final V value)
- {
+ public V setValue(final V value) {
this.value = value;
return value;
}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/TimeAndCounterIDGenerator.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/TimeAndCounterIDGenerator.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/TimeAndCounterIDGenerator.java
index 1bfd561..96cdb8c 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/TimeAndCounterIDGenerator.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/TimeAndCounterIDGenerator.java
@@ -24,8 +24,7 @@ import java.util.concurrent.atomic.AtomicLong;
* This IDGenerator doesn't support more than 16777215 IDs per 16 millisecond. It would throw an exception if this happens.
* </p>
*/
-public class TimeAndCounterIDGenerator implements IDGenerator
-{
+public class TimeAndCounterIDGenerator implements IDGenerator {
// Constants ----------------------------------------------------
/**
@@ -53,8 +52,7 @@ public class TimeAndCounterIDGenerator implements IDGenerator
// Constructors --------------------------------------------------
- public TimeAndCounterIDGenerator()
- {
+ public TimeAndCounterIDGenerator() {
refresh();
}
@@ -62,25 +60,21 @@ public class TimeAndCounterIDGenerator implements IDGenerator
// Public --------------------------------------------------------
- public long generateID()
- {
+ public long generateID() {
long idReturn = counter.incrementAndGet();
- if ((idReturn & TimeAndCounterIDGenerator.ID_MASK) == 0)
- {
+ if ((idReturn & TimeAndCounterIDGenerator.ID_MASK) == 0) {
final long timePortion = idReturn & TimeAndCounterIDGenerator.TIME_ID_MASK;
// Wrapping ID logic
- if (timePortion >= newTM())
- {
+ if (timePortion >= newTM()) {
// Unlikely to happen
wrapped = true;
}
- else
- {
+ else {
// Else.. no worry... we will just accept the new time portion being added
// This time-mark would have been generated some time ago, so this is ok.
// tmMark is just a cache to validate the MaxIDs, so there is no need to make it atomic (synchronized)
@@ -88,49 +82,42 @@ public class TimeAndCounterIDGenerator implements IDGenerator
}
}
- if (wrapped)
- {
+ if (wrapped) {
// This will only happen if a computer can generate more than ID_MASK ids (16 million IDs per 16
// milliseconds)
// If this wrapping code starts to happen, it needs revision
throw new IllegalStateException("The IDGenerator is being overlaped, and it needs revision as the system generated more than " + TimeAndCounterIDGenerator.ID_MASK +
- " ids per 16 milliseconds which exceeded the IDgenerator limit");
+ " ids per 16 milliseconds which exceeded the IDgenerator limit");
}
return idReturn;
}
- public long getCurrentID()
- {
+ public long getCurrentID() {
return counter.get();
}
// for use in testcases
- public long getInternalTimeMark()
- {
+ public long getInternalTimeMark() {
return tmMark;
}
// for use in testcases
- public void setInternalID(final long id)
- {
+ public void setInternalID(final long id) {
counter.set(tmMark | id);
}
// for use in testcases
- public void setInternalDate(final long date)
- {
+ public void setInternalDate(final long date) {
tmMark = (date & TimeAndCounterIDGenerator.MASK_TIME) << TimeAndCounterIDGenerator.BITS_TO_MOVE;
counter.set(tmMark);
}
- public synchronized void refresh()
- {
+ public synchronized void refresh() {
long oldTm = tmMark;
long newTm = newTM();
- while (newTm <= oldTm)
- {
+ while (newTm <= oldTm) {
newTm = newTM();
}
tmMark = newTm;
@@ -138,15 +125,14 @@ public class TimeAndCounterIDGenerator implements IDGenerator
}
@Override
- public String toString()
- {
+ public String toString() {
long currentCounter = counter.get();
return "SequenceGenerator(tmMark=" + hex(tmMark) +
- ", CurrentCounter = " +
- currentCounter +
- ", HexCurrentCounter = " +
- hex(currentCounter) +
- ")";
+ ", CurrentCounter = " +
+ currentCounter +
+ ", HexCurrentCounter = " +
+ hex(currentCounter) +
+ ")";
}
// Package protected ---------------------------------------------
@@ -155,13 +141,11 @@ public class TimeAndCounterIDGenerator implements IDGenerator
// Private -------------------------------------------------------
- private long newTM()
- {
+ private long newTM() {
return (System.currentTimeMillis() & TimeAndCounterIDGenerator.MASK_TIME) << TimeAndCounterIDGenerator.BITS_TO_MOVE;
}
- private String hex(final long x)
- {
+ private String hex(final long x) {
return String.format("%1$X", x);
}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/TokenBucketLimiter.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/TokenBucketLimiter.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/TokenBucketLimiter.java
index 0f50eec..d9a0ea6 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/TokenBucketLimiter.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/TokenBucketLimiter.java
@@ -21,12 +21,14 @@ package org.apache.activemq.artemis.utils;
* href="http://en.wikipedia.org/wiki/Token_bucket">Token Bucket metaphor</a>.
* <p>
* The rate is specified in cycles per second (or 'Hertz').
+ *
* @see <a href="http://en.wikipedia.org/wiki/Token_bucket">Token bucket</a>
*/
-public interface TokenBucketLimiter
-{
+public interface TokenBucketLimiter {
+
/**
* Returns the rate in cycles per second (which is the same as saying 'in Hertz').
+ *
* @see <a href="https://en.wikipedia.org/wiki/Hertz">Hertz</a>
*/
int getRate();
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/TokenBucketLimiterImpl.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/TokenBucketLimiterImpl.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/TokenBucketLimiterImpl.java
index 450eb5c..011ac58 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/TokenBucketLimiterImpl.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/TokenBucketLimiterImpl.java
@@ -18,8 +18,8 @@ package org.apache.activemq.artemis.utils;
import java.util.concurrent.TimeUnit;
-public class TokenBucketLimiterImpl implements TokenBucketLimiter
-{
+public class TokenBucketLimiterImpl implements TokenBucketLimiter {
+
private final int rate;
private final long window;
@@ -27,24 +27,22 @@ public class TokenBucketLimiterImpl implements TokenBucketLimiter
private final boolean spin;
/**
- Even thought we don't use TokenBucket in multiThread
- the implementation should keep this volatile for correctness
- */
+ * Even thought we don't use TokenBucket in multiThread
+ * the implementation should keep this volatile for correctness
+ */
private volatile long last;
/**
- Even thought we don't use TokenBucket in multiThread
- the implementation should keep this volatile for correctness
- */
+ * Even thought we don't use TokenBucket in multiThread
+ * the implementation should keep this volatile for correctness
+ */
private int tokens;
- public TokenBucketLimiterImpl(final int rate, final boolean spin)
- {
+ public TokenBucketLimiterImpl(final int rate, final boolean spin) {
this(rate, spin, TimeUnit.SECONDS, 1);
}
- public TokenBucketLimiterImpl(final int rate, final boolean spin, TimeUnit unit, int unitAmount)
- {
+ public TokenBucketLimiterImpl(final int rate, final boolean spin, TimeUnit unit, int unitAmount) {
this.rate = rate;
this.spin = spin;
@@ -52,64 +50,51 @@ public class TokenBucketLimiterImpl implements TokenBucketLimiter
this.window = unit.toMillis(unitAmount);
}
- public int getRate()
- {
+ public int getRate() {
return rate;
}
- public boolean isSpin()
- {
+ public boolean isSpin() {
return spin;
}
- public void limit()
- {
- while (!check())
- {
- if (spin)
- {
+ public void limit() {
+ while (!check()) {
+ if (spin) {
Thread.yield();
}
- else
- {
- try
- {
+ else {
+ try {
Thread.sleep(1);
}
- catch (Exception e)
- {
+ catch (Exception e) {
// Ignore
}
}
}
}
- private boolean check()
- {
+ private boolean check() {
long now = System.currentTimeMillis();
- if (last == 0)
- {
+ if (last == 0) {
last = now;
}
long diff = now - last;
- if (diff >= window)
- {
+ if (diff >= window) {
last = System.currentTimeMillis();
tokens = rate;
}
- if (tokens > 0)
- {
+ if (tokens > 0) {
tokens--;
return true;
}
- else
- {
+ else {
return false;
}
}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/VersionLoader.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/VersionLoader.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/VersionLoader.java
index 0dcf955..6e54c5d 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/VersionLoader.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/VersionLoader.java
@@ -36,8 +36,8 @@ import org.apache.activemq.artemis.core.version.impl.VersionImpl;
/**
* This loads the version info in from a version.properties file.
*/
-public final class VersionLoader
-{
+public final class VersionLoader {
+
public static final String VERSION_PROP_FILE_KEY = "activemq.version.property.filename";
public static final String DEFAULT_PROP_FILE_NAME = "activemq-version.properties";
@@ -46,88 +46,70 @@ public final class VersionLoader
private static Version[] versions;
- static
- {
- try
- {
-
- try
- {
- PROP_FILE_NAME = AccessController.doPrivileged(new PrivilegedAction<String>()
- {
- public String run()
- {
+ static {
+ try {
+
+ try {
+ PROP_FILE_NAME = AccessController.doPrivileged(new PrivilegedAction<String>() {
+ public String run() {
return System.getProperty(VersionLoader.VERSION_PROP_FILE_KEY);
}
});
}
- catch (Throwable e)
- {
+ catch (Throwable e) {
ActiveMQClientLogger.LOGGER.warn(e.getMessage(), e);
PROP_FILE_NAME = null;
}
- if (PROP_FILE_NAME == null)
- {
+ if (PROP_FILE_NAME == null) {
PROP_FILE_NAME = VersionLoader.DEFAULT_PROP_FILE_NAME;
}
VersionLoader.versions = VersionLoader.load();
}
- catch (Throwable e)
- {
+ catch (Throwable e) {
VersionLoader.versions = null;
ActiveMQClientLogger.LOGGER.error(e.getMessage(), e);
}
}
- public static Version[] getClientVersions()
- {
- if (VersionLoader.versions == null)
- {
+ public static Version[] getClientVersions() {
+ if (VersionLoader.versions == null) {
throw new RuntimeException(VersionLoader.PROP_FILE_NAME + " is not available");
}
return VersionLoader.versions;
}
- public static Version getVersion()
- {
- if (VersionLoader.versions == null)
- {
+ public static Version getVersion() {
+ if (VersionLoader.versions == null) {
throw new RuntimeException(VersionLoader.PROP_FILE_NAME + " is not available");
}
return VersionLoader.versions[0];
}
- public static String getClasspathString()
- {
+ public static String getClasspathString() {
StringBuffer classpath = new StringBuffer();
ClassLoader applicationClassLoader = VersionImpl.class.getClassLoader();
URL[] urls = ((URLClassLoader) applicationClassLoader).getURLs();
- for (URL url : urls)
- {
+ for (URL url : urls) {
classpath.append(url.getFile()).append("\r\n");
}
return classpath.toString();
}
- private static Version[] load()
- {
+ private static Version[] load() {
Properties versionProps = new Properties();
final InputStream in = VersionImpl.class.getClassLoader().getResourceAsStream(VersionLoader.PROP_FILE_NAME);
- try
- {
- if (in == null)
- {
+ try {
+ if (in == null) {
ActiveMQClientLogger.LOGGER.noVersionOnClasspath(getClasspathString());
throw new RuntimeException(VersionLoader.PROP_FILE_NAME + " is not available");
}
- try
- {
+ try {
versionProps.load(in);
String versionName = versionProps.getProperty("activemq.version.versionName");
int majorVersion = Integer.valueOf(versionProps.getProperty("activemq.version.majorVersion"));
@@ -136,109 +118,84 @@ public final class VersionLoader
int[] incrementingVersions = parseCompatibleVersionList(versionProps.getProperty("activemq.version.incrementingVersion"));
int[] compatibleVersionArray = parseCompatibleVersionList(versionProps.getProperty("activemq.version.compatibleVersionList"));
List<Version> definedVersions = new ArrayList<Version>(incrementingVersions.length);
- for (int incrementingVersion : incrementingVersions)
- {
- definedVersions.add(new VersionImpl(versionName,
- majorVersion,
- minorVersion,
- microVersion,
- incrementingVersion,
- compatibleVersionArray));
+ for (int incrementingVersion : incrementingVersions) {
+ definedVersions.add(new VersionImpl(versionName, majorVersion, minorVersion, microVersion, incrementingVersion, compatibleVersionArray));
}
//We want the higher version to be the first
- Collections.sort(definedVersions, new Comparator<Version>()
- {
+ Collections.sort(definedVersions, new Comparator<Version>() {
@Override
- public int compare(Version version1, Version version2)
- {
+ public int compare(Version version1, Version version2) {
return version2.getIncrementingVersion() - version1.getIncrementingVersion();
}
});
return definedVersions.toArray(new Version[incrementingVersions.length]);
}
- catch (IOException e)
- {
+ catch (IOException e) {
// if we get here then the messaging hasn't been built properly and the version.properties is skewed in some
// way
throw new RuntimeException("unable to load " + VersionLoader.PROP_FILE_NAME, e);
}
}
- finally
- {
- try
- {
+ finally {
+ try {
if (in != null)
in.close();
}
- catch (Throwable ignored)
- {
+ catch (Throwable ignored) {
}
}
}
- private static int[] parseCompatibleVersionList(String property) throws IOException
- {
+ private static int[] parseCompatibleVersionList(String property) throws IOException {
int[] verArray = new int[0];
StringTokenizer tokenizer = new StringTokenizer(property, ",");
- while (tokenizer.hasMoreTokens())
- {
+ while (tokenizer.hasMoreTokens()) {
int from = -1, to = -1;
String token = tokenizer.nextToken();
int cursor = 0;
char firstChar = token.charAt(0);
- if (firstChar == '-')
- {
+ if (firstChar == '-') {
// "-n" pattern
from = 0;
cursor++;
- for (; cursor < token.length() && Character.isDigit(token.charAt(cursor)); cursor++)
- {
+ for (; cursor < token.length() && Character.isDigit(token.charAt(cursor)); cursor++) {
// do nothing
}
- if (cursor > 1)
- {
+ if (cursor > 1) {
to = Integer.parseInt(token.substring(1, cursor));
}
}
- else if (Character.isDigit(firstChar))
- {
- for (; cursor < token.length() && Character.isDigit(token.charAt(cursor)); cursor++)
- {
+ else if (Character.isDigit(firstChar)) {
+ for (; cursor < token.length() && Character.isDigit(token.charAt(cursor)); cursor++) {
// do nothing
}
from = Integer.parseInt(token.substring(0, cursor));
- if (cursor == token.length())
- {
+ if (cursor == token.length()) {
// just "n" pattern
to = from;
}
- else if (token.charAt(cursor) == '-')
- {
+ else if (token.charAt(cursor) == '-') {
cursor++;
- if (cursor == token.length())
- {
+ if (cursor == token.length()) {
// "n-" pattern
to = Integer.MAX_VALUE;
}
- else
- {
+ else {
// "n-n" pattern
to = Integer.parseInt(token.substring(cursor));
}
}
}
- if (from != -1 && to != -1)
- {
+ if (from != -1 && to != -1) {
// merge version array
int[] newArray = new int[verArray.length + to - from + 1];
System.arraycopy(verArray, 0, newArray, 0, verArray.length);
- for (int i = 0; i < to - from + 1; i++)
- {
+ for (int i = 0; i < to - from + 1; i++) {
newArray[verArray.length + i] = from + i;
}
verArray = newArray;
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/XMLUtil.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/XMLUtil.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/XMLUtil.java
index e9749fe..e022a0d 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/XMLUtil.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/XMLUtil.java
@@ -43,43 +43,35 @@ import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
-public final class XMLUtil
-{
+public final class XMLUtil {
- private XMLUtil()
- {
+ private XMLUtil() {
// Utility class
}
- public static Element stringToElement(final String s) throws Exception
- {
+ public static Element stringToElement(final String s) throws Exception {
return XMLUtil.readerToElement(new StringReader(s));
}
- public static Element urlToElement(final URL url) throws Exception
- {
+ public static Element urlToElement(final URL url) throws Exception {
return XMLUtil.readerToElement(new InputStreamReader(url.openStream()));
}
- public static String readerToString(final Reader r) throws Exception
- {
+ public static String readerToString(final Reader r) throws Exception {
// Read into string
StringBuilder buff = new StringBuilder();
int c;
- while ((c = r.read()) != -1)
- {
+ while ((c = r.read()) != -1) {
buff.append((char) c);
}
return buff.toString();
}
- public static Element readerToElement(final Reader r) throws Exception
- {
+ public static Element readerToElement(final Reader r) throws Exception {
// Read into string
StringBuffer buff = new StringBuffer();
int c;
- while ((c = r.read()) != -1)
- {
+ while ((c = r.read()) != -1) {
buff.append((char) c);
}
@@ -96,20 +88,17 @@ public final class XMLUtil
return doc.getDocumentElement();
}
- public static String elementToString(final Node n)
- {
+ public static String elementToString(final Node n) {
String name = n.getNodeName();
short type = n.getNodeType();
- if (Node.CDATA_SECTION_NODE == type)
- {
+ if (Node.CDATA_SECTION_NODE == type) {
return "<![CDATA[" + n.getNodeValue() + "]]>";
}
- if (name.startsWith("#"))
- {
+ if (name.startsWith("#")) {
return "";
}
@@ -117,10 +106,8 @@ public final class XMLUtil
sb.append('<').append(name);
NamedNodeMap attrs = n.getAttributes();
- if (attrs != null)
- {
- for (int i = 0; i < attrs.getLength(); i++)
- {
+ if (attrs != null) {
+ for (int i = 0; i < attrs.getLength(); i++) {
Node attr = attrs.item(i);
sb.append(' ').append(attr.getNodeName()).append("=\"").append(attr.getNodeValue()).append("\"");
}
@@ -129,33 +116,26 @@ public final class XMLUtil
String textContent = null;
NodeList children = n.getChildNodes();
- if (children.getLength() == 0)
- {
- if ((textContent = XMLUtil.getTextContent(n)) != null && !"".equals(textContent))
- {
+ if (children.getLength() == 0) {
+ if ((textContent = XMLUtil.getTextContent(n)) != null && !"".equals(textContent)) {
sb.append(textContent).append("</").append(name).append('>');
}
- else
- {
+ else {
sb.append("/>").append('\n');
}
}
- else
- {
+ else {
sb.append('>').append('\n');
boolean hasValidChildren = false;
- for (int i = 0; i < children.getLength(); i++)
- {
+ for (int i = 0; i < children.getLength(); i++) {
String childToString = XMLUtil.elementToString(children.item(i));
- if (!"".equals(childToString))
- {
+ if (!"".equals(childToString)) {
sb.append(childToString);
hasValidChildren = true;
}
}
- if (!hasValidChildren && (textContent = XMLUtil.getTextContent(n)) != null)
- {
+ if (!hasValidChildren && (textContent = XMLUtil.getTextContent(n)) != null) {
sb.append(textContent);
}
@@ -176,40 +156,31 @@ public final class XMLUtil
* <p>
* TODO implementation of this method is a hack. Implement it properly.
*/
- public static String getTextContent(final Node n)
- {
- if (n.hasChildNodes())
- {
+ public static String getTextContent(final Node n) {
+ if (n.hasChildNodes()) {
StringBuffer sb = new StringBuffer();
NodeList nl = n.getChildNodes();
- for (int i = 0; i < nl.getLength(); i++)
- {
+ for (int i = 0; i < nl.getLength(); i++) {
sb.append(XMLUtil.elementToString(nl.item(i)));
- if (i < nl.getLength() - 1)
- {
+ if (i < nl.getLength() - 1) {
sb.append('\n');
}
}
String s = sb.toString();
- if (s.length() != 0)
- {
+ if (s.length() != 0) {
return s;
}
}
Method[] methods = Node.class.getMethods();
- for (Method getTextContext : methods)
- {
- if ("getTextContent".equals(getTextContext.getName()))
- {
- try
- {
+ for (Method getTextContext : methods) {
+ if ("getTextContent".equals(getTextContext.getName())) {
+ try {
return (String) getTextContext.invoke(n, XMLUtil.EMPTY_ARRAY);
}
- catch (Exception e)
- {
+ catch (Exception e) {
ActiveMQClientLogger.LOGGER.errorOnXMLTransform(e, n);
return null;
}
@@ -218,31 +189,24 @@ public final class XMLUtil
String textContent = null;
- if (n.hasChildNodes())
- {
+ if (n.hasChildNodes()) {
NodeList nl = n.getChildNodes();
- for (int i = 0; i < nl.getLength(); i++)
- {
+ for (int i = 0; i < nl.getLength(); i++) {
Node c = nl.item(i);
- if (c.getNodeType() == Node.TEXT_NODE)
- {
+ if (c.getNodeType() == Node.TEXT_NODE) {
textContent = n.getNodeValue();
- if (textContent == null)
- {
+ if (textContent == null) {
// TODO This is a hack. Get rid of it and implement this properly
String s = c.toString();
int idx = s.indexOf("#text:");
- if (idx != -1)
- {
+ if (idx != -1) {
textContent = s.substring(idx + 6).trim();
- if (textContent.endsWith("]"))
- {
+ if (textContent.endsWith("]")) {
textContent = textContent.substring(0, textContent.length() - 1);
}
}
}
- if (textContent == null)
- {
+ if (textContent == null) {
break;
}
}
@@ -252,8 +216,7 @@ public final class XMLUtil
String s = n.toString();
int i = s.indexOf('>');
int i2 = s.indexOf("</");
- if (i != -1 && i2 != -1)
- {
+ if (i != -1 && i2 != -1) {
textContent = s.substring(i + 1, i2);
}
}
@@ -261,57 +224,47 @@ public final class XMLUtil
return textContent;
}
- public static void assertEquivalent(final Node node, final Node node2)
- {
- if (node == null)
- {
+ public static void assertEquivalent(final Node node, final Node node2) {
+ if (node == null) {
throw ActiveMQClientMessageBundle.BUNDLE.firstNodeNull();
}
- if (node2 == null)
- {
+ if (node2 == null) {
throw ActiveMQClientMessageBundle.BUNDLE.secondNodeNull();
}
- if (!node.getNodeName().equals(node2.getNodeName()))
- {
+ if (!node.getNodeName().equals(node2.getNodeName())) {
throw ActiveMQClientMessageBundle.BUNDLE.nodeHaveDifferentNames();
}
int attrCount = 0;
NamedNodeMap attrs = node.getAttributes();
- if (attrs != null)
- {
+ if (attrs != null) {
attrCount = attrs.getLength();
}
int attrCount2 = 0;
NamedNodeMap attrs2 = node2.getAttributes();
- if (attrs2 != null)
- {
+ if (attrs2 != null) {
attrCount2 = attrs2.getLength();
}
- if (attrCount != attrCount2)
- {
+ if (attrCount != attrCount2) {
throw ActiveMQClientMessageBundle.BUNDLE.nodeHaveDifferentAttNumber();
}
outer:
- for (int i = 0; i < attrCount; i++)
- {
+ for (int i = 0; i < attrCount; i++) {
Node n = attrs.item(i);
String name = n.getNodeName();
String value = n.getNodeValue();
- for (int j = 0; j < attrCount; j++)
- {
+ for (int j = 0; j < attrCount; j++) {
Node n2 = attrs2.item(j);
String name2 = n2.getNodeName();
String value2 = n2.getNodeValue();
- if (name.equals(name2) && value.equals(value2))
- {
+ if (name.equals(name2) && value.equals(value2)) {
continue outer;
}
}
@@ -320,13 +273,11 @@ public final class XMLUtil
boolean hasChildren = node.hasChildNodes();
- if (hasChildren != node2.hasChildNodes())
- {
+ if (hasChildren != node2.hasChildNodes()) {
throw ActiveMQClientMessageBundle.BUNDLE.oneNodeHasChildren();
}
- if (hasChildren)
- {
+ if (hasChildren) {
NodeList nl = node.getChildNodes();
NodeList nl2 = node2.getChildNodes();
@@ -336,13 +287,11 @@ public final class XMLUtil
int length = nodes.size();
- if (length != nodes2.size())
- {
+ if (length != nodes2.size()) {
throw ActiveMQClientMessageBundle.BUNDLE.nodeHasDifferentChildNumber();
}
- for (int i = 0; i < length; i++)
- {
+ for (int i = 0; i < length; i++) {
Node n = nodes.get(i);
Node n2 = nodes2.get(i);
XMLUtil.assertEquivalent(n, n2);
@@ -350,15 +299,12 @@ public final class XMLUtil
}
}
- public static String stripCDATA(String s)
- {
+ public static String stripCDATA(String s) {
s = s.trim();
- if (s.startsWith("<![CDATA["))
- {
+ if (s.startsWith("<![CDATA[")) {
s = s.substring(9);
int i = s.indexOf("]]>");
- if (i == -1)
- {
+ if (i == -1) {
throw new IllegalStateException("argument starts with <![CDATA[ but cannot find pairing ]]>");
}
s = s.substring(0, i);
@@ -382,21 +328,17 @@ public final class XMLUtil
}
return xml;
}*/
- public static String replaceSystemProps(String xml)
- {
- while (xml.contains("${"))
- {
+ public static String replaceSystemProps(String xml) {
+ while (xml.contains("${")) {
int start = xml.indexOf("${");
int end = xml.indexOf("}") + 1;
- if (end < 0)
- {
+ if (end < 0) {
break;
}
String subString = xml.substring(start, end);
String prop = subString.substring(2, subString.length() - 1).trim();
String val = "";
- if (prop.contains(":"))
- {
+ if (prop.contains(":")) {
String[] parts = prop.split(":", 2);
prop = parts[0].trim();
val = parts[1].trim();
@@ -409,95 +351,76 @@ public final class XMLUtil
return xml;
}
- public static long parseLong(final Node elem)
- {
+ public static long parseLong(final Node elem) {
String value = elem.getTextContent().trim();
- try
- {
+ try {
return Long.parseLong(value);
}
- catch (NumberFormatException e)
- {
+ catch (NumberFormatException e) {
throw ActiveMQClientMessageBundle.BUNDLE.mustBeLong(elem, value);
}
}
- public static int parseInt(final Node elem)
- {
+ public static int parseInt(final Node elem) {
String value = elem.getTextContent().trim();
- try
- {
+ try {
return Integer.parseInt(value);
}
- catch (NumberFormatException e)
- {
+ catch (NumberFormatException e) {
throw ActiveMQClientMessageBundle.BUNDLE.mustBeInteger(elem, value);
}
}
- public static boolean parseBoolean(final Node elem)
- {
+ public static boolean parseBoolean(final Node elem) {
String value = elem.getTextContent().trim();
- try
- {
+ try {
return Boolean.parseBoolean(value);
}
- catch (NumberFormatException e)
- {
+ catch (NumberFormatException e) {
throw ActiveMQClientMessageBundle.BUNDLE.mustBeBoolean(elem, value);
}
}
- public static double parseDouble(final Node elem)
- {
+ public static double parseDouble(final Node elem) {
String value = elem.getTextContent().trim();
- try
- {
+ try {
return Double.parseDouble(value);
}
- catch (NumberFormatException e)
- {
+ catch (NumberFormatException e) {
throw ActiveMQClientMessageBundle.BUNDLE.mustBeDouble(elem, value);
}
}
- public static void validate(final Node node, final String schemaFile) throws Exception
- {
+ public static void validate(final Node node, final String schemaFile) throws Exception {
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = factory.newSchema(findResource(schemaFile));
Validator validator = schema.newValidator();
// validate the DOM tree
- try
- {
+ try {
validator.validate(new DOMSource(node));
}
- catch (SAXException e)
- {
+ catch (SAXException e) {
ActiveMQClientLogger.LOGGER.errorOnXMLTransformInvalidConf(e);
throw new IllegalStateException("Invalid configuration", e);
}
}
- private static List<Node> filter(final NodeList nl, final short[] typesToFilter)
- {
+ private static List<Node> filter(final NodeList nl, final short[] typesToFilter) {
List<Node> nodes = new ArrayList<Node>();
outer:
- for (int i = 0; i < nl.getLength(); i++)
- {
+ for (int i = 0; i < nl.getLength(); i++) {
Node n = nl.item(i);
short type = n.getNodeType();
- for (int j = 0; j < typesToFilter.length; j++)
- {
- if (typesToFilter[j] == type)
- {
+ for (int j = 0; j < typesToFilter.length; j++) {
+ if (typesToFilter[j] == type) {
continue outer;
}
}
@@ -506,18 +429,14 @@ public final class XMLUtil
return nodes;
}
- private static URL findResource(final String resourceName)
- {
- return AccessController.doPrivileged(new PrivilegedAction<URL>()
- {
- public URL run()
- {
+ private static URL findResource(final String resourceName) {
+ return AccessController.doPrivileged(new PrivilegedAction<URL>() {
+ public URL run() {
return ClassloadingUtil.findResource(resourceName);
}
});
}
-
// Inner classes --------------------------------------------------------------------------------
}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/bac96047/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/XidCodecSupport.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/XidCodecSupport.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/XidCodecSupport.java
index 59bfcb3..6a09164 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/XidCodecSupport.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/XidCodecSupport.java
@@ -21,8 +21,7 @@ import javax.transaction.xa.Xid;
import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
import org.apache.activemq.artemis.core.transaction.impl.XidImpl;
-public class XidCodecSupport
-{
+public class XidCodecSupport {
// Constants -----------------------------------------------------
@@ -30,8 +29,7 @@ public class XidCodecSupport
// Static --------------------------------------------------------
- public static void encodeXid(final Xid xid, final ActiveMQBuffer out)
- {
+ public static void encodeXid(final Xid xid, final ActiveMQBuffer out) {
out.writeInt(xid.getFormatId());
out.writeInt(xid.getBranchQualifier().length);
out.writeBytes(xid.getBranchQualifier());
@@ -39,8 +37,7 @@ public class XidCodecSupport
out.writeBytes(xid.getGlobalTransactionId());
}
- public static Xid decodeXid(final ActiveMQBuffer in)
- {
+ public static Xid decodeXid(final ActiveMQBuffer in) {
int formatID = in.readInt();
byte[] bq = new byte[in.readInt()];
in.readBytes(bq);
@@ -50,8 +47,7 @@ public class XidCodecSupport
return xid;
}
- public static int getXidEncodeLength(final Xid xid)
- {
+ public static int getXidEncodeLength(final Xid xid) {
return DataConstants.SIZE_INT * 3 + xid.getBranchQualifier().length + xid.getGlobalTransactionId().length;
}