http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/ec48f9ed/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/server/embedded/EmbeddedJMS.java ---------------------------------------------------------------------- diff --git a/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/server/embedded/EmbeddedJMS.java b/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/server/embedded/EmbeddedJMS.java index 57430b8..5efffe6 100644 --- a/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/server/embedded/EmbeddedJMS.java +++ b/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/server/embedded/EmbeddedJMS.java @@ -81,20 +81,19 @@ public class EmbeddedJMS extends EmbeddedActiveMQ { return this; } - @Override public EmbeddedJMS setConfiguration(Configuration configuration) { super.setConfiguration(configuration); return this; } - /** - * Lookup in the registry for registered object, i.e. a ConnectionFactory. - * <p> - * This is a convenience method. - * - * @param name - */ + /** + * Lookup in the registry for registered object, i.e. a ConnectionFactory. + * <p> + * This is a convenience method. + * + * @param name + */ public Object lookup(String name) { return serverManager.getRegistry().lookup(name); } @@ -104,14 +103,12 @@ public class EmbeddedJMS extends EmbeddedActiveMQ { super.initStart(); if (jmsConfiguration != null) { serverManager = new JMSServerManagerImpl(activeMQServer, jmsConfiguration); - } - else { + } else { FileJMSConfiguration fileConfiguration = new FileJMSConfiguration(); FileDeploymentManager deploymentManager; if (configResourcePath != null) { deploymentManager = new FileDeploymentManager(configResourcePath); - } - else { + } else { deploymentManager = new FileDeploymentManager(); } deploymentManager.addDeployable(fileConfiguration);
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/ec48f9ed/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/server/impl/JMSServerManagerImpl.java ---------------------------------------------------------------------- diff --git a/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/server/impl/JMSServerManagerImpl.java b/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/server/impl/JMSServerManagerImpl.java index 392a7d9..dfa9218 100644 --- a/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/server/impl/JMSServerManagerImpl.java +++ b/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/server/impl/JMSServerManagerImpl.java @@ -215,9 +215,7 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback recoverBindings(); - - } - catch (Exception e) { + } catch (Exception e) { active = false; ActiveMQJMSServerLogger.LOGGER.jmsDeployerStartError(e); } @@ -266,8 +264,7 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback active = false; } - } - catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); } } @@ -548,7 +545,6 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback return true; } - @Override public synchronized boolean createTopic(final boolean storeConfig, final String topicName, @@ -734,8 +730,7 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback if (removeFromBindings(topicBindings, name, bindings)) { storage.deleteBindings(PersistedType.Topic, name, bindings); return true; - } - else { + } else { return false; } } @@ -815,8 +810,7 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback sendNotification(JMSNotificationType.QUEUE_DESTROYED, name); return true; - } - else { + } else { return false; } } @@ -856,12 +850,10 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback sendNotification(JMSNotificationType.TOPIC_DESTROYED, name); return true; - } - else { + } else { return false; } - } - else { + } else { return false; } } @@ -1054,8 +1046,7 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback Notification notif = new Notification(null, type, prop); try { server.getManagementService().sendNotification(notif); - } - catch (Exception e) { + } catch (Exception e) { ActiveMQJMSServerLogger.LOGGER.failedToSendNotification(notif.toString()); } } @@ -1073,8 +1064,7 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback List<String> result = map.get(name); if (result == null) { return new String[0]; - } - else { + } else { String[] strings = new String[result.size()]; result.toArray(strings); return strings; @@ -1082,19 +1072,18 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback } private synchronized boolean internalCreateQueue(final String queueName, - final String selectorString, - final boolean durable) throws Exception { + final String selectorString, + final boolean durable) throws Exception { return internalCreateQueue(queueName, selectorString, durable, false); } private synchronized boolean internalCreateQueue(final String queueName, - final String selectorString, - final boolean durable, - final boolean autoCreated) throws Exception { + final String selectorString, + final boolean durable, + final boolean autoCreated) throws Exception { if (queues.get(queueName) != null) { return false; - } - else { + } else { ActiveMQQueue activeMQQueue = ActiveMQDestination.createQueue(queueName); // Convert from JMS selector to core filter @@ -1116,8 +1105,6 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback } } - - /** * Performs the internal creation without activating any storage. * The storage load will call this method @@ -1130,12 +1117,12 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback return internalCreateTopic(topicName, false); } - private synchronized boolean internalCreateTopic(final String topicName, final boolean autoCreated) throws Exception { + private synchronized boolean internalCreateTopic(final String topicName, + final boolean autoCreated) throws Exception { if (topics.get(topicName) != null) { return false; - } - else { + } else { ActiveMQTopic activeMQTopic = ActiveMQDestination.createTopic(topicName); // We create a dummy subscription on the topic, that never receives messages - this is so we can perform JMS // checks when routing messages to a topic that @@ -1189,12 +1176,10 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback if (cfConfig.isHA()) { cf = ActiveMQJMSClient.createConnectionFactoryWithHA(groupConfig, cfConfig.getFactoryType()); - } - else { + } else { cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(groupConfig, cfConfig.getFactoryType()); } - } - else { + } else { if (cfConfig.getConnectorNames() == null || cfConfig.getConnectorNames().size() == 0) { throw ActiveMQJMSServerBundle.BUNDLE.noConnectorNameOnCF(); } @@ -1213,8 +1198,7 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback if (cfConfig.isHA()) { cf = ActiveMQJMSClient.createConnectionFactoryWithHA(cfConfig.getFactoryType(), configs); - } - else { + } else { cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(cfConfig.getFactoryType(), configs); } } @@ -1521,8 +1505,7 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback for (String key : elementList) { try { registry.unbind(key); - } - catch (Exception e) { + } catch (Exception e) { ActiveMQJMSServerLogger.LOGGER.bindingsUnbindError(e, key); } } @@ -1551,8 +1534,7 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback for (PersistedDestination destination : destinations) { if (destination.getType() == PersistedType.Queue) { internalCreateQueue(destination.getName(), destination.getSelector(), destination.isDurable()); - } - else if (destination.getType() == PersistedType.Topic) { + } else if (destination.getType() == PersistedType.Topic) { internalCreateTopic(destination.getName()); } } @@ -1565,12 +1547,10 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback if (storage == null) { if (coreConfig.isPersistenceEnabled()) { storage = new JMSJournalStorageManagerImpl(new TimeAndCounterIDGenerator(), server.getConfiguration(), server.getReplicationManager()); - } - else { + } else { storage = new NullJMSStorageManagerImpl(); } - } - else { + } else { if (storage.isStarted()) { storage.stop(); } @@ -1586,8 +1566,7 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback List<String> registryBindings = bindingsMap.remove(name); if (registryBindings == null || registryBindings.size() == 0) { return false; - } - else { + } else { keys.remove(name); } if (registry != null) { @@ -1613,8 +1592,7 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback if (registryBindings.remove(bindings)) { registry.unbind(bindings); return true; - } - else { + } else { return false; } } @@ -1623,8 +1601,7 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback if (active) { runnable.runException(); return true; - } - else { + } else { ActiveMQJMSServerLogger.LOGGER.serverCachingCommand(runnable); if (!cachedCommands.contains(runnable)) cachedCommands.add(runnable); @@ -1638,8 +1615,7 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback public void run() { try { runException(); - } - catch (Exception e) { + } catch (Exception e) { ActiveMQJMSServerLogger.LOGGER.jmsServerError(e); } } @@ -1657,8 +1633,7 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback String newHost = InetAddress.getLocalHost().getHostName(); ActiveMQJMSServerLogger.LOGGER.invalidHostForConnector(transportConfiguration.getName(), newHost); params.put(TransportConstants.HOST_PROP_NAME, newHost); - } - catch (UnknownHostException e) { + } catch (UnknownHostException e) { ActiveMQJMSServerLogger.LOGGER.failedToCorrectHost(e, transportConfiguration.getName()); } } @@ -1669,22 +1644,22 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback * to a non-existent JMS queue or topic */ class JMSDestinationCreator implements QueueCreator { + @Override public boolean create(SimpleString address) throws Exception { AddressSettings settings = server.getAddressSettingsRepository().getMatch(address.toString()); if (address.toString().startsWith(ActiveMQDestination.JMS_QUEUE_ADDRESS_PREFIX) && settings.isAutoCreateJmsQueues()) { return internalCreateJMSQueue(false, address.toString().substring(ActiveMQDestination.JMS_QUEUE_ADDRESS_PREFIX.length()), null, true, true); - } - else if (address.toString().startsWith(ActiveMQDestination.JMS_TOPIC_ADDRESS_PREFIX) && settings.isAutoCreateJmsTopics()) { + } else if (address.toString().startsWith(ActiveMQDestination.JMS_TOPIC_ADDRESS_PREFIX) && settings.isAutoCreateJmsTopics()) { return createTopic(false, address.toString().substring(ActiveMQDestination.JMS_TOPIC_ADDRESS_PREFIX.length()), true); - } - else { + } else { return false; } } } class JMSQueueDeleter implements QueueDeleter { + @Override public boolean delete(SimpleString queueName) throws Exception { Queue queue = server.locateQueue(queueName); @@ -1699,8 +1674,7 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback } return destroyQueue(queueName.toString().substring(ActiveMQDestination.JMS_QUEUE_ADDRESS_PREFIX.length()), false); - } - else { + } else { return false; } } @@ -1712,6 +1686,7 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback * autoCreateJmsTopics = true. */ class JMSPostQueueCreationCallback implements PostQueueCreationCallback { + @Override public void callback(SimpleString queueName) throws Exception { Queue queue = server.locateQueue(queueName); @@ -1734,6 +1709,7 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback * for that topic. */ class JMSPostQueueDeletionCallback implements PostQueueDeletionCallback { + @Override public void callback(SimpleString address, SimpleString queueName) throws Exception { Queue queue = server.locateQueue(address); @@ -1744,8 +1720,7 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback if (address.toString().startsWith(ActiveMQDestination.JMS_TOPIC_ADDRESS_PREFIX) && settings.isAutoDeleteJmsTopics() && bindings.size() == 1 && queue != null && queue.isAutoCreated()) { try { destroyTopic(address.toString().substring(ActiveMQDestination.JMS_TOPIC_ADDRESS_PREFIX.length())); - } - catch (IllegalStateException e) { + } catch (IllegalStateException e) { /* * During shutdown the callback can be invoked after the JMSServerManager is already shut down so we just * ignore the exception in that case @@ -1759,6 +1734,7 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback } private final class JMSReloader implements ReloadCallback { + @Override public void reload(URL url) throws Exception { ActiveMQServerLogger.LOGGER.reloadingConfiguration("jms"); @@ -1772,13 +1748,11 @@ public class JMSServerManagerImpl implements JMSServerManager, ActivateCallback Element e = XMLUtil.stringToElement(xml); if (config instanceof FileJMSConfiguration) { - ((FileJMSConfiguration)config).parse(e, url); + ((FileJMSConfiguration) config).parse(e, url); JMSServerManagerImpl.this.deploy(); } - - } } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/ec48f9ed/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/transaction/JMSTransactionDetail.java ---------------------------------------------------------------------- diff --git a/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/transaction/JMSTransactionDetail.java b/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/transaction/JMSTransactionDetail.java index cd09f4a..6cf20ff 100644 --- a/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/transaction/JMSTransactionDetail.java +++ b/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/transaction/JMSTransactionDetail.java @@ -16,9 +16,8 @@ */ package org.apache.activemq.artemis.jms.transaction; -import java.util.Map; - import javax.transaction.xa.Xid; +import java.util.Map; import org.apache.activemq.artemis.core.server.ServerMessage; import org.apache.activemq.artemis.core.transaction.Transaction; @@ -61,8 +60,7 @@ public class JMSTransactionDetail extends TransactionDetail { public Map<String, Object> decodeMessageProperties(ServerMessage msg) { try { return ActiveMQMessage.coreMaptoJMSMap(msg.toMap()); - } - catch (Throwable t) { + } catch (Throwable t) { return null; } } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/ec48f9ed/artemis-journal/pom.xml ---------------------------------------------------------------------- diff --git a/artemis-journal/pom.xml b/artemis-journal/pom.xml index ccd1dfd..ab79918 100644 --- a/artemis-journal/pom.xml +++ b/artemis-journal/pom.xml @@ -14,7 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/ec48f9ed/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/AbstractSequentialFile.java ---------------------------------------------------------------------- diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/AbstractSequentialFile.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/AbstractSequentialFile.java index 487d8a5..5665e57 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/AbstractSequentialFile.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/AbstractSequentialFile.java @@ -29,11 +29,11 @@ import org.apache.activemq.artemis.api.core.ActiveMQBuffer; import org.apache.activemq.artemis.api.core.ActiveMQBuffers; import org.apache.activemq.artemis.api.core.ActiveMQException; import org.apache.activemq.artemis.api.core.ActiveMQIOErrorException; +import org.apache.activemq.artemis.core.io.buffer.TimedBuffer; +import org.apache.activemq.artemis.core.io.buffer.TimedBufferObserver; import org.apache.activemq.artemis.core.io.util.FileIOUtil; import org.apache.activemq.artemis.core.journal.EncodingSupport; import org.apache.activemq.artemis.core.journal.impl.SimpleWaitIOCallback; -import org.apache.activemq.artemis.core.io.buffer.TimedBuffer; -import org.apache.activemq.artemis.core.io.buffer.TimedBufferObserver; import org.apache.activemq.artemis.journal.ActiveMQJournalBundle; import org.apache.activemq.artemis.journal.ActiveMQJournalLogger; @@ -117,8 +117,7 @@ public abstract class AbstractSequentialFile implements SequentialFile { FileIOUtil.copyData(this, newFileName, buffer); newFileName.close(); this.close(); - } - catch (IOException e) { + } catch (IOException e) { factory.onIOError(new ActiveMQIOErrorException(e.getMessage(), e), e.getMessage(), this); throw e; } @@ -141,8 +140,7 @@ public abstract class AbstractSequentialFile implements SequentialFile { public final void renameTo(final String newFileName) throws IOException, InterruptedException, ActiveMQException { try { close(); - } - catch (IOException e) { + } catch (IOException e) { factory.onIOError(new ActiveMQIOErrorException(e.getMessage(), e), e.getMessage(), this); throw e; } @@ -183,8 +181,7 @@ public abstract class AbstractSequentialFile implements SequentialFile { public final boolean fits(final int size) { if (timedBuffer == null) { return position.get() + size <= fileSize; - } - else { + } else { return timedBuffer.checkSize(size); } } @@ -208,8 +205,7 @@ public abstract class AbstractSequentialFile implements SequentialFile { if (timedBuffer != null) { bytes.setIndex(0, bytes.capacity()); timedBuffer.addBytes(bytes, sync, callback); - } - else { + } else { ByteBuffer buffer = factory.newBuffer(bytes.capacity()); buffer.put(bytes.toByteBuffer().array()); buffer.rewind(); @@ -226,8 +222,7 @@ public abstract class AbstractSequentialFile implements SequentialFile { write(bytes, true, completion); completion.waitCompletion(); - } - else { + } else { write(bytes, false, DummyCallback.getInstance()); } } @@ -236,8 +231,7 @@ public abstract class AbstractSequentialFile implements SequentialFile { public void write(final EncodingSupport bytes, final boolean sync, final IOCallback callback) { if (timedBuffer != null) { timedBuffer.addBytes(bytes, sync, callback); - } - else { + } else { ByteBuffer buffer = factory.newBuffer(bytes.getEncodeSize()); // If not using the TimedBuffer, a final copy is necessary @@ -259,8 +253,7 @@ public abstract class AbstractSequentialFile implements SequentialFile { write(bytes, true, completion); completion.waitCompletion(); - } - else { + } else { write(bytes, false, DummyCallback.getInstance()); } } @@ -282,8 +275,7 @@ public abstract class AbstractSequentialFile implements SequentialFile { for (IOCallback callback : delegates) { try { callback.done(); - } - catch (Throwable e) { + } catch (Throwable e) { ActiveMQJournalLogger.LOGGER.errorCompletingCallback(e); } } @@ -294,8 +286,7 @@ public abstract class AbstractSequentialFile implements SequentialFile { for (IOCallback callback : delegates) { try { callback.onError(errorCode, errorMessage); - } - catch (Throwable e) { + } catch (Throwable e) { ActiveMQJournalLogger.LOGGER.errorCallingErrorCallback(e); } } @@ -319,8 +310,7 @@ public abstract class AbstractSequentialFile implements SequentialFile { if (buffer.limit() == 0) { factory.releaseBuffer(buffer); - } - else { + } else { writeDirect(buffer, requestedSync, new DelegateCallback(callbacks)); } } @@ -334,8 +324,7 @@ public abstract class AbstractSequentialFile implements SequentialFile { public int getRemainingBytes() { if (fileSize - position.get() > Integer.MAX_VALUE) { return Integer.MAX_VALUE; - } - else { + } else { return (int) (fileSize - position.get()); } } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/ec48f9ed/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/AbstractSequentialFileFactory.java ---------------------------------------------------------------------- diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/AbstractSequentialFileFactory.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/AbstractSequentialFileFactory.java index 9f9a883..6e61c86 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/AbstractSequentialFileFactory.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/AbstractSequentialFileFactory.java @@ -72,8 +72,7 @@ public abstract class AbstractSequentialFileFactory implements SequentialFileFac if (buffered && bufferTimeout > 0) { timedBuffer = new TimedBuffer(bufferSize, bufferTimeout, logRates); - } - else { + } else { timedBuffer = null; } this.bufferSize = bufferSize; @@ -95,8 +94,7 @@ public abstract class AbstractSequentialFileFactory implements SequentialFileFac if (!writeExecutor.awaitTermination(AbstractSequentialFileFactory.EXECUTOR_TIMEOUT, TimeUnit.SECONDS)) { ActiveMQJournalLogger.LOGGER.timeoutOnWriterShutdown(new Exception("trace")); } - } - catch (InterruptedException e) { + } catch (InterruptedException e) { throw new ActiveMQInterruptedException(e); } } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/ec48f9ed/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/SequentialFile.java ---------------------------------------------------------------------- diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/SequentialFile.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/SequentialFile.java index ab61b8d..8f7cfb5 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/SequentialFile.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/SequentialFile.java @@ -22,8 +22,8 @@ import java.nio.ByteBuffer; import org.apache.activemq.artemis.api.core.ActiveMQBuffer; import org.apache.activemq.artemis.api.core.ActiveMQException; -import org.apache.activemq.artemis.core.journal.EncodingSupport; import org.apache.activemq.artemis.core.io.buffer.TimedBuffer; +import org.apache.activemq.artemis.core.journal.EncodingSupport; public interface SequentialFile { http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/ec48f9ed/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/aio/AIOSequentialFile.java ---------------------------------------------------------------------- diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/aio/AIOSequentialFile.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/aio/AIOSequentialFile.java index 1a109cb..a0d20d2 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/aio/AIOSequentialFile.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/aio/AIOSequentialFile.java @@ -26,9 +26,9 @@ import java.util.concurrent.atomic.AtomicLong; import org.apache.activemq.artemis.api.core.ActiveMQException; import org.apache.activemq.artemis.api.core.ActiveMQNativeIOError; -import org.apache.activemq.artemis.core.io.IOCallback; import org.apache.activemq.artemis.core.io.AbstractSequentialFile; import org.apache.activemq.artemis.core.io.DummyCallback; +import org.apache.activemq.artemis.core.io.IOCallback; import org.apache.activemq.artemis.core.io.SequentialFile; import org.apache.activemq.artemis.core.journal.impl.SimpleWaitIOCallback; import org.apache.activemq.artemis.jlibaio.LibaioFile; @@ -139,8 +139,7 @@ public class AIOSequentialFile extends AbstractSequentialFile { try { aioFile = aioFactory.libaioContext.openFile(getFile(), true); - } - catch (IOException e) { + } catch (IOException e) { factory.onIOError(e, e.getMessage(), this); throw new ActiveMQNativeIOError(e.getMessage(), e); } @@ -164,8 +163,7 @@ public class AIOSequentialFile extends AbstractSequentialFile { // because we want the buffer available. // Sending it through the callback would make it released aioFile.read(positionToRead, bytesToRead, bytes, getCallback(callback, null)); - } - catch (IOException e) { + } catch (IOException e) { factory.onIOError(e, e.getMessage(), this); throw new ActiveMQNativeIOError(e.getMessage(), e); } @@ -192,8 +190,7 @@ public class AIOSequentialFile extends AbstractSequentialFile { writeDirect(bytes, true, completion); completion.waitCompletion(); - } - else { + } else { writeDirect(bytes, false, DummyCallback.getInstance()); } } @@ -205,8 +202,7 @@ public class AIOSequentialFile extends AbstractSequentialFile { public void writeDirect(final ByteBuffer bytes, final boolean sync, final IOCallback callback) { try { checkOpened(); - } - catch (Exception e) { + } catch (Exception e) { ActiveMQJournalLogger.LOGGER.warn(e.getMessage(), e); callback.onError(-1, e.getMessage()); return; @@ -220,8 +216,7 @@ public class AIOSequentialFile extends AbstractSequentialFile { runnableCallback.initWrite(positionToWrite, bytesToWrite); if (writerExecutor != null) { writerExecutor.execute(runnableCallback); - } - else { + } else { runnableCallback.run(); } } @@ -244,8 +239,7 @@ public class AIOSequentialFile extends AbstractSequentialFile { callback.sequentialDone(); pendingCallbacks.countDown(); flushCallbacks(); - } - else { + } else { pendingCallbackList.add(callback); } @@ -269,8 +263,7 @@ public class AIOSequentialFile extends AbstractSequentialFile { public long size() throws Exception { if (aioFile == null) { return getFile().length(); - } - else { + } else { return aioFile.getSize(); } } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/ec48f9ed/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/aio/AIOSequentialFileFactory.java ---------------------------------------------------------------------- diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/aio/AIOSequentialFileFactory.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/aio/AIOSequentialFileFactory.java index f3f12a5..da0d079 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/aio/AIOSequentialFileFactory.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/aio/AIOSequentialFileFactory.java @@ -120,18 +120,18 @@ public final class AIOSequentialFileFactory extends AbstractSequentialFileFactor int fd = LibaioContext.open(aioTestFile.getAbsolutePath(), true); LibaioContext.close(fd); aioTestFile.delete(); - } - catch (Exception e) { + } catch (Exception e) { // try to handle the file using plain Java // return false if and only if we can create/remove the file using // plain Java but not using AIO try { if (!aioTestFile.exists()) { - if (!aioTestFile.createNewFile()) return true; + if (!aioTestFile.createNewFile()) + return true; } - if (!aioTestFile.delete()) return true; - } - catch (Exception ie) { + if (!aioTestFile.delete()) + return true; + } catch (Exception ie) { // we can not even create the test file using plain java return true; } @@ -236,8 +236,7 @@ public final class AIOSequentialFileFactory extends AbstractSequentialFileFactor if (pollerThread.isAlive()) { ActiveMQJournalLogger.LOGGER.timeoutOnPollerShutdown(new Exception("trace")); } - } - catch (InterruptedException e) { + } catch (InterruptedException e) { throw new ActiveMQInterruptedException(e); } } @@ -285,8 +284,7 @@ public final class AIOSequentialFileFactory extends AbstractSequentialFileFactor public void run() { try { libaioFile.write(position, bytes, buffer, this); - } - catch (IOException e) { + } catch (IOException e) { callback.onError(-1, e.getMessage()); } } @@ -295,11 +293,9 @@ public final class AIOSequentialFileFactory extends AbstractSequentialFileFactor public int compareTo(AIOSequentialCallback other) { if (this == other || this.writeSequence == other.writeSequence) { return 0; - } - else if (other.writeSequence < this.writeSequence) { + } else if (other.writeSequence < this.writeSequence) { return 1; - } - else { + } else { return -1; } } @@ -342,8 +338,7 @@ public final class AIOSequentialFileFactory extends AbstractSequentialFileFactor if (error) { callback.onError(errorCode, errorMessage); errorMessage = null; - } - else { + } else { if (callback != null) { callback.done(); } @@ -368,8 +363,7 @@ public final class AIOSequentialFileFactory extends AbstractSequentialFileFactor while (running.get()) { try { libaioContext.poll(); - } - catch (Throwable e) { + } catch (Throwable e) { ActiveMQJournalLogger.LOGGER.warn(e.getMessage(), e); } } @@ -394,7 +388,7 @@ public final class AIOSequentialFileFactory extends AbstractSequentialFileFactor if (bufferSize > 0 && System.currentTimeMillis() - bufferReuseLastTime > 10000) { if (logger.isTraceEnabled()) { logger.trace("Clearing reuse buffers queue with " + reuseBuffersQueue.size() + - " elements"); + " elements"); } bufferReuseLastTime = System.currentTimeMillis(); @@ -406,8 +400,7 @@ public final class AIOSequentialFileFactory extends AbstractSequentialFileFactor // buffer. if (size > bufferSize) { return LibaioContext.newAlignedBuffer(size, 512); - } - else { + } else { // We need to allocate buffers following the rules of the storage // being used (AIO/NIO) int alignedSize = calculateBlockSize(size); @@ -420,8 +413,7 @@ public final class AIOSequentialFileFactory extends AbstractSequentialFileFactor buffer = LibaioContext.newAlignedBuffer(size, 512); buffer.limit(alignedSize); - } - else { + } else { clearBuffer(buffer); // set the limit of the buffer to the bufferSize being required @@ -452,16 +444,14 @@ public final class AIOSequentialFileFactory extends AbstractSequentialFileFactor if (stopped) { releaseBuffer(buffer); - } - else { + } else { bufferReuseLastTime = System.currentTimeMillis(); // If a buffer has any other than the configured bufferSize, the buffer // will be just sent to GC if (buffer.capacity() == bufferSize) { reuseBuffersQueue.offer(buffer); - } - else { + } else { releaseBuffer(buffer); } } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/ec48f9ed/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/buffer/TimedBuffer.java ---------------------------------------------------------------------- diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/buffer/TimedBuffer.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/buffer/TimedBuffer.java index 23e0981..91e5e12 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/buffer/TimedBuffer.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/buffer/TimedBuffer.java @@ -133,8 +133,7 @@ public class TimedBuffer { // Need to start with the spin limiter acquired try { spinLimiter.acquire(); - } - catch (InterruptedException e) { + } catch (InterruptedException e) { throw new ActiveMQInterruptedException(e); } @@ -173,8 +172,7 @@ public class TimedBuffer { while (timerThread.isAlive()) { try { timerThread.join(); - } - catch (InterruptedException e) { + } catch (InterruptedException e) { throw new ActiveMQInterruptedException(e); } } @@ -217,8 +215,7 @@ public class TimedBuffer { if (sizeChecked > remainingInFile) { return false; - } - else { + } else { // There is enough space in the file for this size // Need to re-calculate buffer limit @@ -227,8 +224,7 @@ public class TimedBuffer { return true; } - } - else { + } else { delayFlush = true; return true; @@ -380,8 +376,7 @@ public class TimedBuffer { // if using sleep, we will always flush flush(); lastFlushTime = System.nanoTime(); - } - else if (bufferObserver != null && System.nanoTime() > lastFlushTime + timeout) { + } else if (bufferObserver != null && System.nanoTime() > lastFlushTime + timeout) { // if not using flush we will spin and do the time checks manually flush(); lastFlushTime = System.nanoTime(); @@ -397,8 +392,7 @@ public class TimedBuffer { Thread.yield(); spinLimiter.release(); - } - catch (InterruptedException e) { + } catch (InterruptedException e) { throw new ActiveMQInterruptedException(e); } } @@ -417,11 +411,9 @@ public class TimedBuffer { try { sleep(sleepMillis, sleepNanos); - } - catch (InterruptedException e) { + } catch (InterruptedException e) { throw new ActiveMQInterruptedException(e); - } - catch (Exception e) { + } catch (Exception e) { setUseSleep(false); ActiveMQJournalLogger.LOGGER.warn(e.getMessage() + ", disabling sleep on TimedBuffer, using spin now", e); } @@ -469,8 +461,7 @@ public class TimedBuffer { // We acquire the spinLimiter semaphore - this prevents the timer flush thread unnecessarily spinning // when the buffer is inactive spinLimiter.acquire(); - } - catch (InterruptedException e) { + } catch (InterruptedException e) { throw new ActiveMQInterruptedException(e); } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/ec48f9ed/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedByteBufferCache.java ---------------------------------------------------------------------- diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedByteBufferCache.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedByteBufferCache.java index 5bba391..73384c8 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedByteBufferCache.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedByteBufferCache.java @@ -119,8 +119,7 @@ final class MappedByteBufferCache implements AutoCloseable { } } } - } - catch (IOException ioe) { + } catch (IOException ioe) { throw new IOException("Failed to resize to " + minSize, ioe); } } @@ -146,8 +145,7 @@ final class MappedByteBufferCache implements AutoCloseable { if (mbb != null) { try { PlatformDependent.freeDirectBuffer(mbb); - } - catch (Throwable t) { + } catch (Throwable t) { //TO_FIX: force releasing of the other buffers } } @@ -165,27 +163,21 @@ final class MappedByteBufferCache implements AutoCloseable { } } } - } - catch (IOException ioe) { + } catch (IOException ioe) { throw new IllegalStateException("Failed to resize to " + length, ioe); } } - } - catch (IOException ex) { + } catch (IOException ex) { throw new IllegalStateException("Failed to get size", ex); - } - finally { + } finally { try { fileChannel.close(); - } - catch (IOException e) { + } catch (IOException e) { throw new IllegalStateException("Failed to close channel", e); - } - finally { + } finally { try { raf.close(); - } - catch (IOException e) { + } catch (IOException e) { throw new IllegalStateException("Failed to close RandomAccessFile", e); } } @@ -208,8 +200,7 @@ final class MappedByteBufferCache implements AutoCloseable { if (mbb != null) { try { PlatformDependent.freeDirectBuffer(mbb); - } - catch (Throwable t) { + } catch (Throwable t) { //TO_FIX: force releasing of the other buffers } } @@ -218,15 +209,12 @@ final class MappedByteBufferCache implements AutoCloseable { this.byteBuffers.clear(); try { fileChannel.close(); - } - catch (IOException e) { + } catch (IOException e) { throw new IllegalStateException("Failed to close channel", e); - } - finally { + } finally { try { raf.close(); - } - catch (IOException e) { + } catch (IOException e) { throw new IllegalStateException("Failed to close RandomAccessFile", e); } } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/ec48f9ed/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedFile.java ---------------------------------------------------------------------- diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedFile.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedFile.java index 6dca716..0aa9866 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedFile.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedFile.java @@ -70,15 +70,12 @@ final class MappedFile implements AutoCloseable { lastMappedLimit = mappedLimit; final int bufferPosition = (int) (offset - mappedPosition); return bufferPosition; - } - catch (IllegalStateException e) { + } catch (IllegalStateException e) { throw new IOException(e); - } - catch (IllegalArgumentException e) { + } catch (IllegalArgumentException e) { throw new BufferUnderflowException(); } - } - else { + } else { final int bufferPosition = (int) (offset - lastMappedStart); return bufferPosition; } @@ -101,12 +98,10 @@ final class MappedFile implements AutoCloseable { if (dst.hasMemoryAddress()) { final long dstAddress = dst.memoryAddress() + dstStart; PlatformDependent.copyMemory(srcAddress, dstAddress, dstLength); - } - else if (dst.hasArray()) { + } else if (dst.hasArray()) { final byte[] dstArray = dst.array(); PlatformDependent.copyMemory(srcAddress, dstArray, dstStart, dstLength); - } - else { + } else { throw new IllegalArgumentException("unsupported byte buffer"); } position += dstLength; @@ -127,8 +122,7 @@ final class MappedFile implements AutoCloseable { if (dst.isDirect()) { final long dstAddress = PlatformDependent.directBufferAddress(dst) + dstStart; PlatformDependent.copyMemory(srcAddress, dstAddress, dstLength); - } - else { + } else { final byte[] dstArray = dst.array(); PlatformDependent.copyMemory(srcAddress, dstArray, dstStart, dstLength); } @@ -153,12 +147,10 @@ final class MappedFile implements AutoCloseable { if (dst.hasMemoryAddress()) { final long dstAddress = dst.memoryAddress() + dstStart; PlatformDependent.copyMemory(srcAddress, dstAddress, read); - } - else if (dst.hasArray()) { + } else if (dst.hasArray()) { final byte[] dstArray = dst.array(); PlatformDependent.copyMemory(srcAddress, dstArray, dstStart, read); - } - else { + } else { throw new IllegalArgumentException("unsupported byte buffer"); } position += read; @@ -179,8 +171,7 @@ final class MappedFile implements AutoCloseable { if (dst.isDirect()) { final long dstAddress = PlatformDependent.directBufferAddress(dst) + dstStart; PlatformDependent.copyMemory(srcAddress, dstAddress, read); - } - else { + } else { final byte[] dstArray = dst.array(); PlatformDependent.copyMemory(srcAddress, dstArray, dstStart, read); } @@ -199,12 +190,10 @@ final class MappedFile implements AutoCloseable { if (src.hasMemoryAddress()) { final long srcAddress = src.memoryAddress() + srcStart; PlatformDependent.copyMemory(srcAddress, destAddress, srcLength); - } - else if (src.hasArray()) { + } else if (src.hasArray()) { final byte[] srcArray = src.array(); PlatformDependent.copyMemory(srcArray, srcStart, destAddress, srcLength); - } - else { + } else { throw new IllegalArgumentException("unsupported byte buffer"); } position += srcLength; @@ -224,8 +213,7 @@ final class MappedFile implements AutoCloseable { if (src.isDirect()) { final long srcAddress = PlatformDependent.directBufferAddress(src) + srcStart; PlatformDependent.copyMemory(srcAddress, destAddress, srcLength); - } - else { + } else { final byte[] srcArray = src.array(); PlatformDependent.copyMemory(srcArray, srcStart, destAddress, srcLength); } @@ -246,12 +234,10 @@ final class MappedFile implements AutoCloseable { if (src.hasMemoryAddress()) { final long srcAddress = src.memoryAddress() + srcStart; PlatformDependent.copyMemory(srcAddress, destAddress, srcLength); - } - else if (src.hasArray()) { + } else if (src.hasArray()) { final byte[] srcArray = src.array(); PlatformDependent.copyMemory(srcArray, srcStart, destAddress, srcLength); - } - else { + } else { throw new IllegalArgumentException("unsupported byte buffer"); } position += srcLength; @@ -271,8 +257,7 @@ final class MappedFile implements AutoCloseable { if (src.isDirect()) { final long srcAddress = PlatformDependent.directBufferAddress(src) + srcStart; PlatformDependent.copyMemory(srcAddress, destAddress, srcLength); - } - else { + } else { final byte[] srcArray = src.array(); PlatformDependent.copyMemory(srcArray, srcStart, destAddress, srcLength); } @@ -328,4 +313,4 @@ final class MappedFile implements AutoCloseable { public void closeAndResize(long length) { cache.closeAndResize(length); } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/ec48f9ed/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedSequentialFile.java ---------------------------------------------------------------------- diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedSequentialFile.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedSequentialFile.java index c890ff4..522dbd1 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedSequentialFile.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedSequentialFile.java @@ -160,8 +160,7 @@ final class MappedSequentialFile implements SequentialFile { } } callback.done(); - } - catch (IOException e) { + } catch (IOException e) { if (this.criticalErrorListener != null) { this.criticalErrorListener.onIOException(new ActiveMQIOErrorException(e.getMessage(), e), e.getMessage(), this); } @@ -188,8 +187,7 @@ final class MappedSequentialFile implements SequentialFile { private ActiveMQBuffer acquiresActiveMQBufferWithAtLeast(int size) { if (this.pooledActiveMQBuffer == null || this.pooledActiveMQBuffer.capacity() < size) { this.pooledActiveMQBuffer = new ChannelBufferWrapper(Unpooled.directBuffer(size, size).order(ByteOrder.nativeOrder())); - } - else { + } else { this.pooledActiveMQBuffer.clear(); } return pooledActiveMQBuffer; @@ -216,8 +214,7 @@ final class MappedSequentialFile implements SequentialFile { } } callback.done(); - } - catch (IOException e) { + } catch (IOException e) { if (this.criticalErrorListener != null) { this.criticalErrorListener.onIOException(new ActiveMQIOErrorException(e.getMessage(), e), e.getMessage(), this); } @@ -261,8 +258,7 @@ final class MappedSequentialFile implements SequentialFile { } } callback.done(); - } - catch (IOException e) { + } catch (IOException e) { if (this.criticalErrorListener != null) { this.criticalErrorListener.onIOException(new ActiveMQIOErrorException(e.getMessage(), e), e.getMessage(), this); } @@ -304,8 +300,7 @@ final class MappedSequentialFile implements SequentialFile { return bytesRead; } return 0; - } - catch (IOException e) { + } catch (IOException e) { if (this.criticalErrorListener != null) { this.criticalErrorListener.onIOException(new ActiveMQIOErrorException(e.getMessage(), e), e.getMessage(), this); } @@ -360,8 +355,7 @@ final class MappedSequentialFile implements SequentialFile { public long size() { if (this.mappedFile != null) { return this.mappedFile.length(); - } - else { + } else { return this.file.length(); } } @@ -376,8 +370,7 @@ final class MappedSequentialFile implements SequentialFile { final File newFile = new File(this.directory, newFileName); if (!file.renameTo(newFile)) { throw ActiveMQJournalBundle.BUNDLE.ioRenameFileError(file.getName(), newFileName); - } - else { + } else { this.file = newFile; this.fileName = newFileName; this.absoluteFile = null; @@ -431,4 +424,4 @@ final class MappedSequentialFile implements SequentialFile { } return this.absoluteFile; } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/ec48f9ed/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedSequentialFileFactory.java ---------------------------------------------------------------------- diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedSequentialFileFactory.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedSequentialFileFactory.java index 4dc3206..23af0b6 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedSequentialFileFactory.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/mapped/MappedSequentialFileFactory.java @@ -164,13 +164,11 @@ public final class MappedSequentialFileFactory implements SequentialFileFactory buffer.clear(); if (buffer.isDirect()) { BytesUtils.zerosDirect(buffer); - } - else if (buffer.hasArray()) { + } else if (buffer.hasArray()) { final byte[] array = buffer.array(); //SIMD OPTIMIZATION Arrays.fill(array, (byte) 0); - } - else { + } else { //TODO VERIFY IF IT COULD HAPPENS final int capacity = buffer.capacity(); for (int i = 0; i < capacity; i++) { @@ -201,4 +199,4 @@ public final class MappedSequentialFileFactory implements SequentialFileFactory public void flush() { } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/ec48f9ed/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/nio/NIOSequentialFile.java ---------------------------------------------------------------------- diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/nio/NIOSequentialFile.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/nio/NIOSequentialFile.java index e60c21c..40e0544 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/nio/NIOSequentialFile.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/nio/NIOSequentialFile.java @@ -30,8 +30,8 @@ import org.apache.activemq.artemis.api.core.ActiveMQException; import org.apache.activemq.artemis.api.core.ActiveMQExceptionType; import org.apache.activemq.artemis.api.core.ActiveMQIOErrorException; import org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException; -import org.apache.activemq.artemis.core.io.IOCallback; import org.apache.activemq.artemis.core.io.AbstractSequentialFile; +import org.apache.activemq.artemis.core.io.IOCallback; import org.apache.activemq.artemis.core.io.SequentialFile; import org.apache.activemq.artemis.core.io.SequentialFileFactory; import org.apache.activemq.artemis.journal.ActiveMQJournalBundle; @@ -93,11 +93,9 @@ public final class NIOSequentialFile extends AbstractSequentialFile { channel = rfile.getChannel(); fileSize = channel.size(); - } - catch (ClosedChannelException e) { + } catch (ClosedChannelException e) { throw e; - } - catch (IOException e) { + } catch (IOException e) { factory.onIOError(new ActiveMQIOErrorException(e.getMessage(), e), e.getMessage(), this); throw e; } @@ -120,11 +118,9 @@ public final class NIOSequentialFile extends AbstractSequentialFile { channel.write(bb); channel.force(false); channel.position(0); - } - catch (ClosedChannelException e) { + } catch (ClosedChannelException e) { throw e; - } - catch (IOException e) { + } catch (IOException e) { factory.onIOError(new ActiveMQIOErrorException(e.getMessage(), e), e.getMessage(), this); throw e; } @@ -157,11 +153,9 @@ public final class NIOSequentialFile extends AbstractSequentialFile { if (rfile != null) { rfile.close(); } - } - catch (ClosedChannelException e) { + } catch (ClosedChannelException e) { throw e; - } - catch (IOException e) { + } catch (IOException e) { factory.onIOError(new ActiveMQIOErrorException(e.getMessage(), e), e.getMessage(), this); throw e; } @@ -193,11 +187,9 @@ public final class NIOSequentialFile extends AbstractSequentialFile { bytes.flip(); return bytesRead; - } - catch (ClosedChannelException e) { + } catch (ClosedChannelException e) { throw e; - } - catch (IOException e) { + } catch (IOException e) { if (callback != null) { callback.onError(ActiveMQExceptionType.IO_ERROR.getCode(), e.getLocalizedMessage()); } @@ -213,11 +205,9 @@ public final class NIOSequentialFile extends AbstractSequentialFile { if (channel != null) { try { channel.force(false); - } - catch (ClosedChannelException e) { + } catch (ClosedChannelException e) { throw e; - } - catch (IOException e) { + } catch (IOException e) { factory.onIOError(new ActiveMQIOErrorException(e.getMessage(), e), e.getMessage(), this); throw e; } @@ -232,11 +222,9 @@ public final class NIOSequentialFile extends AbstractSequentialFile { try { return channel.size(); - } - catch (ClosedChannelException e) { + } catch (ClosedChannelException e) { throw e; - } - catch (IOException e) { + } catch (IOException e) { factory.onIOError(new ActiveMQIOErrorException(e.getMessage(), e), e.getMessage(), this); throw e; } @@ -247,11 +235,9 @@ public final class NIOSequentialFile extends AbstractSequentialFile { try { super.position(pos); channel.position(pos); - } - catch (ClosedChannelException e) { + } catch (ClosedChannelException e) { throw e; - } - catch (IOException e) { + } catch (IOException e) { factory.onIOError(new ActiveMQIOErrorException(e.getMessage(), e), e.getMessage(), this); throw e; } @@ -275,8 +261,7 @@ public final class NIOSequentialFile extends AbstractSequentialFile { try { internalWrite(bytes, sync, callback); - } - catch (Exception e) { + } catch (Exception e) { callback.onError(ActiveMQExceptionType.GENERIC_EXCEPTION.getCode(), e.getMessage()); } } @@ -305,8 +290,7 @@ public final class NIOSequentialFile extends AbstractSequentialFile { if (!isOpen()) { if (callback != null) { callback.onError(ActiveMQExceptionType.IO_ERROR.getCode(), "File not opened"); - } - else { + } else { throw ActiveMQJournalBundle.BUNDLE.fileNotOpened(); } return; @@ -318,15 +302,12 @@ public final class NIOSequentialFile extends AbstractSequentialFile { // if maxIOSemaphore == null, that means we are not using executors and the writes are synchronous try { doInternalWrite(bytes, sync, callback); - } - catch (ClosedChannelException e) { + } catch (ClosedChannelException e) { throw e; - } - catch (IOException e) { + } catch (IOException e) { factory.onIOError(new ActiveMQIOErrorException(e.getMessage(), e), e.getMessage(), this); } - } - else { + } else { // This is a flow control on writing, just like maxAIO on libaio maxIOSemaphore.acquire(); @@ -336,21 +317,17 @@ public final class NIOSequentialFile extends AbstractSequentialFile { try { try { doInternalWrite(bytes, sync, callback); - } - catch (ClosedChannelException e) { + } catch (ClosedChannelException e) { ActiveMQJournalLogger.LOGGER.errorSubmittingWrite(e); - } - catch (IOException e) { + } catch (IOException e) { ActiveMQJournalLogger.LOGGER.errorSubmittingWrite(e); factory.onIOError(new ActiveMQIOErrorException(e.getMessage(), e), e.getMessage(), NIOSequentialFile.this); callback.onError(ActiveMQExceptionType.IO_ERROR.getCode(), e.getMessage()); - } - catch (Throwable e) { + } catch (Throwable e) { ActiveMQJournalLogger.LOGGER.errorSubmittingWrite(e); callback.onError(ActiveMQExceptionType.IO_ERROR.getCode(), e.getMessage()); } - } - finally { + } finally { maxIOSemaphore.release(); } } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/ec48f9ed/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/nio/NIOSequentialFileFactory.java ---------------------------------------------------------------------- diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/nio/NIOSequentialFileFactory.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/nio/NIOSequentialFileFactory.java index a5884b9..f90bebf 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/nio/NIOSequentialFileFactory.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/nio/NIOSequentialFileFactory.java @@ -70,8 +70,7 @@ public class NIOSequentialFileFactory extends AbstractSequentialFileFactory { ByteBuffer buffer2 = null; try { buffer2 = ByteBuffer.allocateDirect(size); - } - catch (OutOfMemoryError error) { + } catch (OutOfMemoryError error) { // This is a workaround for the way the JDK will deal with native buffers. // the main portion is outside of the VM heap // and the JDK will not have any reference about it to take GC into account @@ -83,8 +82,7 @@ public class NIOSequentialFileFactory extends AbstractSequentialFileFactory { System.gc(); Thread.sleep(100); } - } - catch (InterruptedException e) { + } catch (InterruptedException e) { } buffer2 = ByteBuffer.allocateDirect(size); http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/ec48f9ed/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/util/FileIOUtil.java ---------------------------------------------------------------------- diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/util/FileIOUtil.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/util/FileIOUtil.java index 70ddb24..705aaaa 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/util/FileIOUtil.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/util/FileIOUtil.java @@ -62,18 +62,15 @@ public class FileIOUtil { break; } } - } - finally { + } finally { if (!fromIsOpen) { from.close(); - } - else { + } else { from.position(from.size()); } if (!toIsOpen) { to.close(); - } - else { + } else { to.position(to.size()); } } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/ec48f9ed/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/AbstractJournalUpdateTask.java ---------------------------------------------------------------------- diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/AbstractJournalUpdateTask.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/AbstractJournalUpdateTask.java index a8ffebc..8bbecd2 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/AbstractJournalUpdateTask.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/AbstractJournalUpdateTask.java @@ -96,8 +96,7 @@ public abstract class AbstractJournalUpdateTask implements JournalReaderCallback if (files == null) { filesToRename.writeInt(0); - } - else { + } else { filesToRename.writeInt(files.size()); for (JournalFile file : files) { @@ -109,8 +108,7 @@ public abstract class AbstractJournalUpdateTask implements JournalReaderCallback if (newFiles == null) { filesToRename.writeInt(0); - } - else { + } else { filesToRename.writeInt(newFiles.size()); for (JournalFile file : newFiles) { @@ -121,8 +119,7 @@ public abstract class AbstractJournalUpdateTask implements JournalReaderCallback // Renames from clean up third if (renames == null) { filesToRename.writeInt(0); - } - else { + } else { filesToRename.writeInt(renames.size()); for (Pair<String, String> rename : renames) { filesToRename.writeUTF(rename.getA()); @@ -147,8 +144,7 @@ public abstract class AbstractJournalUpdateTask implements JournalReaderCallback controlFile.writeDirect(writeBuffer, true); return controlFile; - } - finally { + } finally { controlFile.close(); } } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/ec48f9ed/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/FileWrapperJournal.java ---------------------------------------------------------------------- diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/FileWrapperJournal.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/FileWrapperJournal.java index 2be9200..51fb154 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/FileWrapperJournal.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/FileWrapperJournal.java @@ -25,6 +25,7 @@ import java.util.concurrent.locks.ReentrantLock; import org.apache.activemq.artemis.api.core.ActiveMQException; import org.apache.activemq.artemis.api.core.ActiveMQUnsupportedPacketException; +import org.apache.activemq.artemis.core.io.SequentialFileFactory; import org.apache.activemq.artemis.core.journal.EncodingSupport; import org.apache.activemq.artemis.core.journal.IOCompletion; import org.apache.activemq.artemis.core.journal.Journal; @@ -32,7 +33,6 @@ import org.apache.activemq.artemis.core.journal.JournalLoadInformation; import org.apache.activemq.artemis.core.journal.LoaderCallback; import org.apache.activemq.artemis.core.journal.PreparedTransactionInfo; import org.apache.activemq.artemis.core.journal.RecordInfo; -import org.apache.activemq.artemis.core.io.SequentialFileFactory; import org.apache.activemq.artemis.core.journal.TransactionFailureCallback; import org.apache.activemq.artemis.core.journal.impl.dataformat.JournalAddRecord; import org.apache.activemq.artemis.core.journal.impl.dataformat.JournalAddRecordTX; @@ -115,12 +115,10 @@ public final class FileWrapperJournal extends JournalBase { if (callback != null) { currentFile.getFile().write(encoder, sync, callback); - } - else { + } else { currentFile.getFile().write(encoder, sync); } - } - finally { + } finally { lockAppend.unlock(); } } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/ec48f9ed/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalCompactor.java ---------------------------------------------------------------------- diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalCompactor.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalCompactor.java index 40926e0..b95d641 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalCompactor.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalCompactor.java @@ -27,9 +27,9 @@ import java.util.concurrent.ConcurrentHashMap; import org.apache.activemq.artemis.api.core.ActiveMQBuffer; import org.apache.activemq.artemis.api.core.ActiveMQBuffers; import org.apache.activemq.artemis.api.core.Pair; -import org.apache.activemq.artemis.core.journal.RecordInfo; import org.apache.activemq.artemis.core.io.SequentialFile; import org.apache.activemq.artemis.core.io.SequentialFileFactory; +import org.apache.activemq.artemis.core.journal.RecordInfo; import org.apache.activemq.artemis.core.journal.impl.dataformat.ByteArrayEncoding; import org.apache.activemq.artemis.core.journal.impl.dataformat.JournalAddRecord; import org.apache.activemq.artemis.core.journal.impl.dataformat.JournalAddRecordTX; @@ -81,8 +81,7 @@ public class JournalCompactor extends AbstractJournalUpdateTask implements Journ if (records.size() == 0) { return null; - } - else { + } else { ActiveMQBuffer input = ActiveMQBuffers.wrappedBuffer(records.get(0).data); int numberDataFiles = input.readInt(); @@ -107,8 +106,7 @@ public class JournalCompactor extends AbstractJournalUpdateTask implements Journ } return controlFile; - } - else { + } else { return null; } } @@ -197,8 +195,7 @@ public class JournalCompactor extends AbstractJournalUpdateTask implements Journ // will need to open a file either way openFile(); } - } - else { + } else { if (compactCount >= 0) { if (checkCompact(compactCount)) { // The file was already moved on this case, no need to check for the size. @@ -230,8 +227,7 @@ public class JournalCompactor extends AbstractJournalUpdateTask implements Journ splitted = false; openFile(); return true; - } - else { + } else { return false; } } @@ -243,8 +239,7 @@ public class JournalCompactor extends AbstractJournalUpdateTask implements Journ for (CompactCommand command : pendingCommands) { try { command.execute(); - } - catch (Exception e) { + } catch (Exception e) { ActiveMQJournalLogger.LOGGER.errorReplayingCommands(e); } } @@ -291,8 +286,7 @@ public class JournalCompactor extends AbstractJournalUpdateTask implements Journ if (pendingTransactions.get(transactionID) != null) { // Sanity check, this should never happen ActiveMQJournalLogger.LOGGER.inconsistencyDuringCompacting(transactionID); - } - else { + } else { JournalTransaction newTransaction = newTransactions.remove(transactionID); if (newTransaction != null) { JournalInternalRecord commitRecord = new JournalCompleteRecordTX(TX_RECORD_TYPE.COMMIT, transactionID, null); @@ -361,8 +355,7 @@ public class JournalCompactor extends AbstractJournalUpdateTask implements Journ // Sanity check, this should never happen throw new IllegalStateException("Inconsistency during compacting: RollbackRecord ID = " + transactionID + " for an already rolled back transaction during compacting"); - } - else { + } else { JournalTransaction newTransaction = newTransactions.remove(transactionID); if (newTransaction != null) { @@ -391,8 +384,7 @@ public class JournalCompactor extends AbstractJournalUpdateTask implements Journ if (newRecord == null) { ActiveMQJournalLogger.LOGGER.compactingWithNoAddRecord(info.id); - } - else { + } else { newRecord.addUpdateFile(currentFile, updateRecord.getEncodeSize()); } @@ -414,8 +406,7 @@ public class JournalCompactor extends AbstractJournalUpdateTask implements Journ writeEncoder(updateRecordTX); newTransaction.addPositive(currentFile, info.id, updateRecordTX.getEncodeSize()); - } - else { + } else { onReadUpdateRecord(info); } } @@ -454,8 +445,7 @@ public class JournalCompactor extends AbstractJournalUpdateTask implements Journ JournalRecord deleteRecord = journal.getRecords().remove(id); if (deleteRecord == null) { ActiveMQJournalLogger.LOGGER.noRecordDuringCompactReplay(id); - } - else { + } else { deleteRecord.delete(usedFile); } } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/ec48f9ed/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalConstants.java ---------------------------------------------------------------------- diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalConstants.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalConstants.java index 037e319..052b84b 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalConstants.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalConstants.java @@ -21,6 +21,6 @@ import org.apache.activemq.artemis.ArtemisConstants; @Deprecated /** * @deprecated Use ArtemisConstants instead. - */ -public final class JournalConstants extends ArtemisConstants { + */ public final class JournalConstants extends ArtemisConstants { + } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/ec48f9ed/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFileImpl.java ---------------------------------------------------------------------- diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFileImpl.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFileImpl.java index 210fcd6..45d33cc 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFileImpl.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFileImpl.java @@ -104,8 +104,7 @@ public class JournalFileImpl implements JournalFile { if (count == null) { return 0; - } - else { + } else { return count.intValue(); } } @@ -152,8 +151,7 @@ public class JournalFileImpl implements JournalFile { public String toString() { try { return "JournalFileImpl: (" + file.getFileName() + " id = " + fileID + ", recordID = " + recordID + ")"; - } - catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); return "Error:" + e.toString(); } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/ec48f9ed/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFilesRepository.java ---------------------------------------------------------------------- diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFilesRepository.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFilesRepository.java index af01b86..8440d93 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFilesRepository.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/JournalFilesRepository.java @@ -88,8 +88,7 @@ public class JournalFilesRepository { public void run() { try { pushOpenedFile(); - } - catch (Exception e) { + } catch (Exception e) { ActiveMQJournalLogger.LOGGER.errorPushingFile(e); } } @@ -140,8 +139,7 @@ public class JournalFilesRepository { for (JournalFile file : openedFiles) { try { file.getFile().close(); - } - catch (Exception e) { + } catch (Exception e) { ActiveMQJournalLogger.LOGGER.errorClosingFile(e); } } @@ -208,8 +206,7 @@ public class JournalFilesRepository { public void openFile(final JournalFile file, final boolean multiAIO) throws Exception { if (multiAIO) { file.getFile().open(); - } - else { + } else { file.getFile().open(1, false); } @@ -348,15 +345,13 @@ public class JournalFilesRepository { long calculatedSize = 0; try { calculatedSize = file.getFile().size(); - } - catch (Exception e) { + } catch (Exception e) { throw new IllegalStateException(e.getMessage() + " file: " + file); } if (calculatedSize != fileSize) { ActiveMQJournalLogger.LOGGER.deletingFile(file); file.getFile().delete(); - } - else if (!checkDelete || (freeFilesCount.get() + dataFiles.size() + 1 + openedFiles.size() < poolSize) || (poolSize < 0)) { + } else if (!checkDelete || (freeFilesCount.get() + dataFiles.size() + 1 + openedFiles.size() < poolSize) || (poolSize < 0)) { // Re-initialise it if (logger.isTraceEnabled()) { @@ -371,16 +366,15 @@ public class JournalFilesRepository { freeFiles.add(jf); freeFilesCount.getAndIncrement(); - } - else { + } else { if (logger.isTraceEnabled()) { logger.trace("DataFiles.size() = " + dataFiles.size()); logger.trace("openedFiles.size() = " + openedFiles.size()); logger.trace("minfiles = " + minFiles + ", poolSize = " + poolSize); logger.trace("Free Files = " + freeFilesCount.get()); logger.trace("File " + file + " being deleted as freeFiles.size() + dataFiles.size() + 1 + openedFiles.size() (" + - (freeFilesCount.get() + dataFiles.size() + 1 + openedFiles.size()) + - ") < minFiles (" + minFiles + ")"); + (freeFilesCount.get() + dataFiles.size() + 1 + openedFiles.size()) + + ") < minFiles (" + minFiles + ")"); } file.getFile().delete(); } @@ -420,8 +414,7 @@ public class JournalFilesRepository { if (openFilesExecutor == null) { pushOpenRunnable.run(); - } - else { + } else { openFilesExecutor.execute(pushOpenRunnable); } @@ -495,8 +488,7 @@ public class JournalFilesRepository { if (nextFile == null) { nextFile = createFile(keepOpened, multiAIO, initFile, tmpCompactExtension, -1); - } - else { + } else { if (tmpCompactExtension) { SequentialFile sequentialFile = nextFile.getFile(); sequentialFile.renameTo(sequentialFile.getFileName() + ".cmp"); @@ -535,8 +527,7 @@ public class JournalFilesRepository { final long fileIdPreSet) throws Exception { if (System.getSecurityManager() == null) { return createFile0(keepOpened, multiAIO, init, tmpCompact, fileIdPreSet); - } - else { + } else { try { return AccessController.doPrivileged(new PrivilegedExceptionAction<JournalFile>() { @Override @@ -544,8 +535,7 @@ public class JournalFilesRepository { return createFile0(keepOpened, multiAIO, init, tmpCompact, fileIdPreSet); } }); - } - catch (PrivilegedActionException e) { + } catch (PrivilegedActionException e) { throw unwrapException(e); } } @@ -555,11 +545,9 @@ public class JournalFilesRepository { Throwable c = e.getCause(); if (c instanceof RuntimeException) { throw (RuntimeException) c; - } - else if (c instanceof Error) { + } else if (c instanceof Error) { throw (Error) c; - } - else { + } else { throw new RuntimeException(c); } } @@ -602,8 +590,7 @@ public class JournalFilesRepository { if (keepOpened) { if (multiAIO) { sequentialFile.open(); - } - else { + } else { sequentialFile.open(1, false); } sequentialFile.position(position); @@ -621,8 +608,7 @@ public class JournalFilesRepository { String fileName; if (tmpCompact) { fileName = filePrefix + "-" + fileID + "." + fileExtension + ".cmp"; - } - else { + } else { fileName = filePrefix + "-" + fileID + "." + fileExtension; } return fileName; @@ -638,8 +624,7 @@ public class JournalFilesRepository { private long getFileNameID(final String fileName) { try { return Long.parseLong(fileName.substring(filePrefix.length() + 1, fileName.indexOf('.'))); - } - catch (Throwable e) { + } catch (Throwable e) { ActiveMQJournalLogger.LOGGER.errorRetrievingID(e, fileName); return 0; }
