From dddd0a1efe13953719250e48a811778051638333 Mon Sep 17 00:00:00 2001 From: Clebert Suconic Date: Wed, 13 Jan 2016 16:38:38 -0500 Subject: [PATCH] https://issues.apache.org/jira/browse/ARTEMIS-345 fixing URI for inVM throwing a log.warn --- ...ntPropertyBeanIntrospectorWithIgnores.java | 81 +++++++++++++++++++ .../activemq/artemis/utils/uri/URISchema.java | 3 +- .../core/client/impl/ServerLocatorImpl.java | 6 ++ .../integration/client/ConsumerTest.java | 21 +++++ 4 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/FluentPropertyBeanIntrospectorWithIgnores.java diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/FluentPropertyBeanIntrospectorWithIgnores.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/FluentPropertyBeanIntrospectorWithIgnores.java new file mode 100644 index 0000000000..d0e70f41d4 --- /dev/null +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/FluentPropertyBeanIntrospectorWithIgnores.java @@ -0,0 +1,81 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.activemq.artemis.utils.uri; + +import java.beans.IntrospectionException; +import java.beans.PropertyDescriptor; +import java.lang.reflect.Method; +import java.util.Locale; + +import org.apache.activemq.artemis.api.core.Pair; +import org.apache.activemq.artemis.utils.ConcurrentHashSet; +import org.apache.commons.beanutils.FluentPropertyBeanIntrospector; +import org.apache.commons.beanutils.IntrospectionContext; +import org.jboss.logging.Logger; + +public class FluentPropertyBeanIntrospectorWithIgnores extends FluentPropertyBeanIntrospector { + static Logger logger = Logger.getLogger(FluentPropertyBeanIntrospectorWithIgnores.class); + + private static ConcurrentHashSet> ignores = new ConcurrentHashSet<>(); + + public static void addIgnore(String className, String propertyName) { + logger.trace("Adding ignore on " + className + "/" + propertyName); + ignores.add(new Pair<>(className, propertyName)); + } + + public static boolean isIgnored(String className, String propertyName) { + return ignores.contains(new Pair<>(className, propertyName)); + } + + @Override + public void introspect(IntrospectionContext icontext) throws IntrospectionException { + for (Method m : icontext.getTargetClass().getMethods()) { + if (m.getName().startsWith(getWriteMethodPrefix())) { + String propertyName = propertyName(m); + PropertyDescriptor pd = icontext.getPropertyDescriptor(propertyName); + + if (isIgnored(icontext.getTargetClass().getName(), m.getName())) { + logger.trace(m.getName() + " Ignored for " + icontext.getTargetClass().getName()); + continue; + } + try { + if (pd == null) { + icontext.addPropertyDescriptor(createFluentPropertyDescritor(m, propertyName)); + } + else if (pd.getWriteMethod() == null) { + pd.setWriteMethod(m); + } + } + catch (IntrospectionException e) { + logger.debug(e.getMessage(), e); + } + } + } + } + + private PropertyDescriptor createFluentPropertyDescritor(Method m, + String propertyName) throws IntrospectionException { + return new PropertyDescriptor(propertyName(m), null, m); + } + + private String propertyName(Method m) { + String methodName = m.getName().substring(getWriteMethodPrefix().length()); + return (methodName.length() > 1) ? Character.toLowerCase(methodName.charAt(0)) + methodName.substring(1) : methodName.toLowerCase(Locale.ENGLISH); + } + +} diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/URISchema.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/URISchema.java index b76ceb1944..9ee206b560 100644 --- a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/URISchema.java +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/URISchema.java @@ -27,7 +27,6 @@ import java.util.Map; import java.util.Set; import org.apache.commons.beanutils.BeanUtilsBean; -import org.apache.commons.beanutils.FluentPropertyBeanIntrospector; public abstract class URISchema { @@ -102,7 +101,7 @@ public abstract class URISchema { static { // This is to customize the BeanUtils to use Fluent Proeprties as well - beanUtils.getPropertyUtils().addBeanIntrospector(new FluentPropertyBeanIntrospector()); + beanUtils.getPropertyUtils().addBeanIntrospector(new FluentPropertyBeanIntrospectorWithIgnores()); } public static Map parseQuery(String uri, diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ServerLocatorImpl.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ServerLocatorImpl.java index 77e1e669b9..59a4c78ba5 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ServerLocatorImpl.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ServerLocatorImpl.java @@ -66,6 +66,7 @@ import org.apache.activemq.artemis.uri.ServerLocatorParser; import org.apache.activemq.artemis.utils.ActiveMQThreadFactory; import org.apache.activemq.artemis.utils.ClassloadingUtil; import org.apache.activemq.artemis.utils.UUIDGenerator; +import org.apache.activemq.artemis.utils.uri.FluentPropertyBeanIntrospectorWithIgnores; /** * This is the implementation of {@link org.apache.activemq.artemis.api.core.client.ServerLocator} and all @@ -77,6 +78,11 @@ public final class ServerLocatorImpl implements ServerLocatorInternal, Discovery INITIALIZED, CLOSED, CLOSING } + static { + // this is not really a property, needs to be ignored + FluentPropertyBeanIntrospectorWithIgnores.addIgnore(ServerLocatorImpl.class.getName(), "setThreadPools"); + } + private static final long serialVersionUID = -1615857864410205260L; // This is the default value diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/ConsumerTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/ConsumerTest.java index 3be464e5ea..e9918fc192 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/ConsumerTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/ConsumerTest.java @@ -34,6 +34,7 @@ import org.apache.activemq.artemis.api.core.client.ClientSession; import org.apache.activemq.artemis.api.core.client.ClientSessionFactory; import org.apache.activemq.artemis.api.core.client.MessageHandler; import org.apache.activemq.artemis.api.core.client.ServerLocator; +import org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl; import org.apache.activemq.artemis.core.protocol.core.Packet; import org.apache.activemq.artemis.core.protocol.core.impl.PacketImpl; import org.apache.activemq.artemis.core.server.ActiveMQServer; @@ -548,6 +549,26 @@ public class ConsumerTest extends ActiveMQTestBase { session.close(); } + // https://jira.jboss.org/jira/browse/HORNETQ-111 + // Test that, on rollback credits are released for messages cleared in the buffer + @Test + public void testInVMURI() throws Exception { + locator.close(); + ServerLocator locator = addServerLocator(ServerLocatorImpl.newLocator("vm:/1")); + ClientSessionFactory factory = locator.createSessionFactory(); + ClientSession session = factory.createSession(); + session.createQueue(QUEUE, QUEUE); + ClientProducer producer = session.createProducer(QUEUE); + producer.send(session.createMessage(true)); + + ClientConsumer consumer = session.createConsumer(QUEUE); + session.start(); + Assert.assertNotNull(consumer.receiveImmediate()); + session.close(); + factory.close(); + + } + // https://jira.jboss.org/jira/browse/HORNETQ-111 // Test that, on rollback credits are released for messages cleared in the buffer @Test