This commit is contained in:
Clebert Suconic 2016-01-13 16:38:38 -05:00
parent 23aa933ad7
commit dddd0a1efe
4 changed files with 109 additions and 2 deletions

View File

@ -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<Pair<String, String>> 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);
}
}

View File

@ -27,7 +27,6 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import org.apache.commons.beanutils.BeanUtilsBean; import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.beanutils.FluentPropertyBeanIntrospector;
public abstract class URISchema<T, P> { public abstract class URISchema<T, P> {
@ -102,7 +101,7 @@ public abstract class URISchema<T, P> {
static { static {
// This is to customize the BeanUtils to use Fluent Proeprties as well // 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<String, String> parseQuery(String uri, public static Map<String, String> parseQuery(String uri,

View File

@ -66,6 +66,7 @@ import org.apache.activemq.artemis.uri.ServerLocatorParser;
import org.apache.activemq.artemis.utils.ActiveMQThreadFactory; import org.apache.activemq.artemis.utils.ActiveMQThreadFactory;
import org.apache.activemq.artemis.utils.ClassloadingUtil; import org.apache.activemq.artemis.utils.ClassloadingUtil;
import org.apache.activemq.artemis.utils.UUIDGenerator; 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 * 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 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; private static final long serialVersionUID = -1615857864410205260L;
// This is the default value // This is the default value

View File

@ -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.ClientSessionFactory;
import org.apache.activemq.artemis.api.core.client.MessageHandler; import org.apache.activemq.artemis.api.core.client.MessageHandler;
import org.apache.activemq.artemis.api.core.client.ServerLocator; 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.Packet;
import org.apache.activemq.artemis.core.protocol.core.impl.PacketImpl; import org.apache.activemq.artemis.core.protocol.core.impl.PacketImpl;
import org.apache.activemq.artemis.core.server.ActiveMQServer; import org.apache.activemq.artemis.core.server.ActiveMQServer;
@ -548,6 +549,26 @@ public class ConsumerTest extends ActiveMQTestBase {
session.close(); 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 // https://jira.jboss.org/jira/browse/HORNETQ-111
// Test that, on rollback credits are released for messages cleared in the buffer // Test that, on rollback credits are released for messages cleared in the buffer
@Test @Test