activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [1/2] activemq-artemis git commit: More use of try-with-resources
Date Fri, 30 Sep 2016 17:19:16 GMT
Repository: activemq-artemis
Updated Branches:
  refs/heads/master f698a7f81 -> 8cd677b20


More use of try-with-resources


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/082b75bb
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/082b75bb
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/082b75bb

Branch: refs/heads/master
Commit: 082b75bb3dc0a76506927d4435ea924f5077359b
Parents: f698a7f
Author: Ville Skyttä <ville.skytta@iki.fi>
Authored: Fri Sep 30 09:31:38 2016 +0300
Committer: Clebert Suconic <clebertsuconic@apache.org>
Committed: Fri Sep 30 13:17:26 2016 -0400

----------------------------------------------------------------------
 .../cli/commands/tools/XmlDataImporter.java     | 76 ++++++++++----------
 .../activemq/artemis/api/core/JsonUtil.java     |  7 +-
 .../converter/jms/ServerJMSObjectMessage.java   |  9 +--
 .../rest/queue/ConsumedObjectMessage.java       |  3 +-
 .../artemis/rest/util/HttpMessageHelper.java    |  3 +-
 .../core/server/impl/ScaleDownHandler.java      | 17 ++---
 .../example/ldap/InMemorySchemaPartition.java   |  7 +-
 7 files changed, 61 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/082b75bb/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/XmlDataImporter.java
----------------------------------------------------------------------
diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/XmlDataImporter.java
b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/XmlDataImporter.java
index f0b8c3c..8cd0784 100644
--- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/XmlDataImporter.java
+++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/XmlDataImporter.java
@@ -326,17 +326,17 @@ public final class XmlDataImporter extends ActionAbstract {
             // Get the ID of the queues involved so the message can be routed properly. 
This is done because we cannot
             // send directly to a queue, we have to send to an address instead but not all
the queues related to the
             // address may need the message
-            ClientRequestor requestor = new ClientRequestor(managementSession, "jms.queue.activemq.management");
-            ClientMessage managementMessage = managementSession.createMessage(false);
-            ManagementHelper.putAttribute(managementMessage, "core.queue." + queue, "ID");
-            managementSession.start();
-            if (logger.isDebugEnabled()) {
-               logger.debug("Requesting ID for: " + queue);
+            try (ClientRequestor requestor = new ClientRequestor(managementSession, "jms.queue.activemq.management"))
{
+               ClientMessage managementMessage = managementSession.createMessage(false);
+               ManagementHelper.putAttribute(managementMessage, "core.queue." + queue, "ID");
+               managementSession.start();
+               if (logger.isDebugEnabled()) {
+                  logger.debug("Requesting ID for: " + queue);
+               }
+               ClientMessage reply = requestor.request(managementMessage);
+               Number idObject = (Number) ManagementHelper.getResult(reply);
+               queueID = idObject.longValue();
             }
-            ClientMessage reply = requestor.request(managementMessage);
-            Number idObject = (Number) ManagementHelper.getResult(reply);
-            queueID = idObject.longValue();
-            requestor.close();
             if (logger.isDebugEnabled()) {
                logger.debug("ID for " + queue + " is: " + queueID);
             }
@@ -825,21 +825,20 @@ public final class XmlDataImporter extends ActionAbstract {
          reader.next();
       }
 
-      ClientRequestor requestor = new ClientRequestor(managementSession, "jms.queue.activemq.management");
-      ClientMessage managementMessage = managementSession.createMessage(false);
-      ManagementHelper.putOperationInvocation(managementMessage, ResourceNames.JMS_SERVER,
"createConnectionFactory", name, Boolean.parseBoolean(ha), discoveryGroupName.length() >
0, Integer.parseInt(type), connectors, entries, clientId, Long.parseLong(clientFailureCheckPeriod),
Long.parseLong(connectionTtl), Long.parseLong(callTimeout), Long.parseLong(callFailoverTimeout),
Integer.parseInt(minLargeMessageSize), Boolean.parseBoolean(compressLargeMessages), Integer.parseInt(consumerWindowSize),
Integer.parseInt(consumerMaxRate), Integer.parseInt(confirmationWindowSize), Integer.parseInt(producerWindowSize),
Integer.parseInt(producerMaxRate), Boolean.parseBoolean(blockOnAcknowledge), Boolean.parseBoolean(blockOnDurableSend),
Boolean.parseBoolean(blockOnNonDurableSend), Boolean.parseBoolean(autoGroup), Boolean.parseBoolean(preacknowledge),
loadBalancingPolicyClassName, Integer.parseInt(transactionBatchSize), Integer.parseInt(dupsOkBatchSize),
Boolean.parseBoolean(useGlobalPools), Integ
 er.parseInt(scheduledThreadMaxPoolSize), Integer.parseInt(threadMaxPoolSize), Long.parseLong(retryInterval),
Double.parseDouble(retryIntervalMultiplier), Long.parseLong(maxRetryInterval), Integer.parseInt(reconnectAttempts),
Boolean.parseBoolean(failoverOnInitialConnection), groupId);
-      //Boolean.parseBoolean(cacheLargeMessagesClient));
-      managementSession.start();
-      ClientMessage reply = requestor.request(managementMessage);
-      if (ManagementHelper.hasOperationSucceeded(reply)) {
-         if (logger.isDebugEnabled()) {
-            logger.debug("Created connection factory " + name);
+      try (ClientRequestor requestor = new ClientRequestor(managementSession, "jms.queue.activemq.management"))
{
+         ClientMessage managementMessage = managementSession.createMessage(false);
+         ManagementHelper.putOperationInvocation(managementMessage, ResourceNames.JMS_SERVER,
"createConnectionFactory", name, Boolean.parseBoolean(ha), discoveryGroupName.length() >
0, Integer.parseInt(type), connectors, entries, clientId, Long.parseLong(clientFailureCheckPeriod),
Long.parseLong(connectionTtl), Long.parseLong(callTimeout), Long.parseLong(callFailoverTimeout),
Integer.parseInt(minLargeMessageSize), Boolean.parseBoolean(compressLargeMessages), Integer.parseInt(consumerWindowSize),
Integer.parseInt(consumerMaxRate), Integer.parseInt(confirmationWindowSize), Integer.parseInt(producerWindowSize),
Integer.parseInt(producerMaxRate), Boolean.parseBoolean(blockOnAcknowledge), Boolean.parseBoolean(blockOnDurableSend),
Boolean.parseBoolean(blockOnNonDurableSend), Boolean.parseBoolean(autoGroup), Boolean.parseBoolean(preacknowledge),
loadBalancingPolicyClassName, Integer.parseInt(transactionBatchSize), Integer.parseInt(dupsOkBatchSize),
Boolean.parseBoolean(useGlobalPools), In
 teger.parseInt(scheduledThreadMaxPoolSize), Integer.parseInt(threadMaxPoolSize), Long.parseLong(retryInterval),
Double.parseDouble(retryIntervalMultiplier), Long.parseLong(maxRetryInterval), Integer.parseInt(reconnectAttempts),
Boolean.parseBoolean(failoverOnInitialConnection), groupId);
+         //Boolean.parseBoolean(cacheLargeMessagesClient));
+         managementSession.start();
+         ClientMessage reply = requestor.request(managementMessage);
+         if (ManagementHelper.hasOperationSucceeded(reply)) {
+            if (logger.isDebugEnabled()) {
+               logger.debug("Created connection factory " + name);
+            }
+         } else {
+            ActiveMQServerLogger.LOGGER.error("Problem creating " + name);
          }
-      } else {
-         ActiveMQServerLogger.LOGGER.error("Problem creating " + name);
       }
-
-      requestor.close();
    }
 
    private void createJmsDestination() throws Exception {
@@ -884,24 +883,23 @@ public final class XmlDataImporter extends ActionAbstract {
          reader.next();
       }
 
-      ClientRequestor requestor = new ClientRequestor(managementSession, "jms.queue.activemq.management");
-      ClientMessage managementMessage = managementSession.createMessage(false);
-      if ("Queue".equals(type)) {
-         ManagementHelper.putOperationInvocation(managementMessage, ResourceNames.JMS_SERVER,
"createQueue", name, entries, selector);
-      } else if ("Topic".equals(type)) {
-         ManagementHelper.putOperationInvocation(managementMessage, ResourceNames.JMS_SERVER,
"createTopic", name, entries);
-      }
-      managementSession.start();
-      ClientMessage reply = requestor.request(managementMessage);
-      if (ManagementHelper.hasOperationSucceeded(reply)) {
-         if (logger.isDebugEnabled()) {
-            logger.debug("Created " + type.toLowerCase() + " " + name);
+      try (ClientRequestor requestor = new ClientRequestor(managementSession, "jms.queue.activemq.management"))
{
+         ClientMessage managementMessage = managementSession.createMessage(false);
+         if ("Queue".equals(type)) {
+            ManagementHelper.putOperationInvocation(managementMessage, ResourceNames.JMS_SERVER,
"createQueue", name, entries, selector);
+         } else if ("Topic".equals(type)) {
+            ManagementHelper.putOperationInvocation(managementMessage, ResourceNames.JMS_SERVER,
"createTopic", name, entries);
+         }
+         managementSession.start();
+         ClientMessage reply = requestor.request(managementMessage);
+         if (ManagementHelper.hasOperationSucceeded(reply)) {
+            if (logger.isDebugEnabled()) {
+               logger.debug("Created " + type.toLowerCase() + " " + name);
+            }
+         } else {
+            ActiveMQServerLogger.LOGGER.error("Problem creating " + name);
          }
-      } else {
-         ActiveMQServerLogger.LOGGER.error("Problem creating " + name);
       }
-
-      requestor.close();
    }
 
    private String getEntries() throws Exception {

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/082b75bb/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JsonUtil.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JsonUtil.java
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JsonUtil.java
index a8463c4..5fefbbc 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JsonUtil.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JsonUtil.java
@@ -144,9 +144,10 @@ public final class JsonUtil {
                   CompositeData[] cds = new CompositeData[data.length];
                   for (int i1 = 0; i1 < data.length; i1++) {
                      String dataConverted = convertJsonValue(data[i1], String.class).toString();
-                     ObjectInputStreamWithClassLoader ois = new ObjectInputStreamWithClassLoader(new
ByteArrayInputStream(Base64.decode(dataConverted)));
-                     ois.setWhiteList("java.util,java.lang,javax.management");
-                     cds[i1] = (CompositeDataSupport) ois.readObject();
+                     try (ObjectInputStreamWithClassLoader ois = new ObjectInputStreamWithClassLoader(new
ByteArrayInputStream(Base64.decode(dataConverted)))) {
+                        ois.setWhiteList("java.util,java.lang,javax.management");
+                        cds[i1] = (CompositeDataSupport) ois.readObject();
+                     }
                   }
                   innerVal = cds;
                }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/082b75bb/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSObjectMessage.java
----------------------------------------------------------------------
diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSObjectMessage.java
b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSObjectMessage.java
index 349934b..7f0906e 100644
--- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSObjectMessage.java
+++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSObjectMessage.java
@@ -73,9 +73,10 @@ public class ServerJMSObjectMessage extends ServerJMSMessage implements
ObjectMe
       int size = getInnerMessage().getBodyBuffer().readInt();
       byte[] bytes = new byte[size];
       getInnerMessage().getBodyBuffer().readBytes(bytes);
-      ObjectInputStreamWithClassLoader ois = new ObjectInputStreamWithClassLoader(new ByteArrayInputStream(bytes));
-      ois.setWhiteList(DEFAULT_WHITELIST);
-      ois.setBlackList(DEFAULT_BLACKLIST);
-      object = (Serializable) ois.readObject();
+      try (ObjectInputStreamWithClassLoader ois = new ObjectInputStreamWithClassLoader(new
ByteArrayInputStream(bytes))) {
+         ois.setWhiteList(DEFAULT_WHITELIST);
+         ois.setBlackList(DEFAULT_BLACKLIST);
+         object = (Serializable) ois.readObject();
+      }
    }
 }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/082b75bb/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/ConsumedObjectMessage.java
----------------------------------------------------------------------
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/ConsumedObjectMessage.java
b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/ConsumedObjectMessage.java
index 2cd5f9f..9481feb 100644
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/ConsumedObjectMessage.java
+++ b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/queue/ConsumedObjectMessage.java
@@ -45,8 +45,7 @@ public class ConsumedObjectMessage extends ConsumedMessage {
             byte[] body = new byte[size];
             message.getBodyBuffer().readBytes(body);
             ByteArrayInputStream bais = new ByteArrayInputStream(body);
-            try {
-               ObjectInputStreamWithClassLoader ois = new ObjectInputStreamWithClassLoader(bais);
+            try (ObjectInputStreamWithClassLoader ois = new ObjectInputStreamWithClassLoader(bais))
{
                if (options != null) {
                   ois.setWhiteList(options.getDeserializationWhiteList());
                   ois.setBlackList(options.getDeserializationBlackList());

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/082b75bb/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/util/HttpMessageHelper.java
----------------------------------------------------------------------
diff --git a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/util/HttpMessageHelper.java
b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/util/HttpMessageHelper.java
index 05ca387..a1e14bd 100644
--- a/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/util/HttpMessageHelper.java
+++ b/artemis-rest/src/main/java/org/apache/activemq/artemis/rest/util/HttpMessageHelper.java
@@ -74,8 +74,7 @@ public class HttpMessageHelper {
             message.getBodyBuffer().readBytes(body);
             ByteArrayInputStream bais = new ByteArrayInputStream(body);
             Object obj = null;
-            try {
-               ObjectInputStreamWithClassLoader ois = new ObjectInputStreamWithClassLoader(bais);
+            try (ObjectInputStreamWithClassLoader ois = new ObjectInputStreamWithClassLoader(bais))
{
                if (jmsOptions != null) {
                   ois.setBlackList(jmsOptions.getDeserializationBlackList());
                   ois.setWhiteList(jmsOptions.getDeserializationWhiteList());

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/082b75bb/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ScaleDownHandler.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ScaleDownHandler.java
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ScaleDownHandler.java
index 3e6f005..b763ff2 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ScaleDownHandler.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ScaleDownHandler.java
@@ -438,17 +438,18 @@ public class ScaleDownHandler {
 
    private Integer getQueueID(ClientSession session, SimpleString queueName) throws Exception
{
       Integer queueID = -1;
-      ClientRequestor requestor = new ClientRequestor(session, "jms.queue.activemq.management");
-      ClientMessage managementMessage = session.createMessage(false);
-      ManagementHelper.putAttribute(managementMessage, "core.queue." + queueName, "ID");
-      session.start();
-      logger.debug("Requesting ID for: " + queueName);
-      ClientMessage reply = requestor.request(managementMessage);
-      Object result = ManagementHelper.getResult(reply);
+      Object result;
+      try (ClientRequestor requestor = new ClientRequestor(session, "jms.queue.activemq.management"))
{
+         ClientMessage managementMessage = session.createMessage(false);
+         ManagementHelper.putAttribute(managementMessage, "core.queue." + queueName, "ID");
+         session.start();
+         logger.debug("Requesting ID for: " + queueName);
+         ClientMessage reply = requestor.request(managementMessage);
+         result = ManagementHelper.getResult(reply);
+      }
       if (result != null && result instanceof Number) {
          queueID = ((Number) result).intValue();
       }
-      requestor.close();
       return queueID;
    }
 

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/082b75bb/examples/features/standard/security-ldap/src/main/java/org/apache/activemq/artemis/jms/example/ldap/InMemorySchemaPartition.java
----------------------------------------------------------------------
diff --git a/examples/features/standard/security-ldap/src/main/java/org/apache/activemq/artemis/jms/example/ldap/InMemorySchemaPartition.java
b/examples/features/standard/security-ldap/src/main/java/org/apache/activemq/artemis/jms/example/ldap/InMemorySchemaPartition.java
index 28f39e8..256a281 100644
--- a/examples/features/standard/security-ldap/src/main/java/org/apache/activemq/artemis/jms/example/ldap/InMemorySchemaPartition.java
+++ b/examples/features/standard/security-ldap/src/main/java/org/apache/activemq/artemis/jms/example/ldap/InMemorySchemaPartition.java
@@ -73,9 +73,10 @@ public class InMemorySchemaPartition extends AbstractLdifPartition {
       for (String resourcePath : new TreeSet<>(resMap.keySet())) {
          if (resourcePath.endsWith(".ldif")) {
             URL resource = DefaultSchemaLdifExtractor.getUniqueResource(resourcePath, "Schema
LDIF file");
-            LdifReader reader = new LdifReader(resource.openStream());
-            LdifEntry ldifEntry = reader.next();
-            reader.close();
+            LdifEntry ldifEntry;
+            try (LdifReader reader = new LdifReader(resource.openStream())) {
+               ldifEntry = reader.next();
+            }
 
             Entry entry = new DefaultEntry(schemaManager, ldifEntry.getEntry());
             // add mandatory attributes


Mime
View raw message