This closes #393

This commit is contained in:
jbertram 2016-02-18 10:14:27 -06:00
commit 42b20ebf51
60 changed files with 687 additions and 406 deletions

View File

@ -0,0 +1,148 @@
/**
* 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.PropertyDescriptor;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.beanutils.Converter;
public class BeanSupport {
private static final BeanUtilsBean beanUtils = new BeanUtilsBean();
static {
// This is to customize the BeanUtils to use Fluent Proeprties as well
beanUtils.getPropertyUtils().addBeanIntrospector(new FluentPropertyBeanIntrospectorWithIgnores());
}
public static void registerConverter(Converter converter, Class type) {
synchronized (beanUtils) {
beanUtils.getConvertUtils().register(converter, type);
}
}
public static <P> P copyData(P source, P target) throws Exception {
synchronized (beanUtils) {
beanUtils.copyProperties(source, target);
}
return target;
}
public static <P> P setData(URI uri, P obj, Map<String, String> query) throws Exception {
synchronized (beanUtils) {
beanUtils.setProperty(obj, "host", uri.getHost());
beanUtils.setProperty(obj, "port", uri.getPort());
beanUtils.setProperty(obj, "userInfo", uri.getUserInfo());
beanUtils.populate(obj, query);
}
return obj;
}
public static <P> P setData( P obj, Map<String, Object> data) throws Exception {
synchronized (beanUtils) {
beanUtils.populate(obj, data);
}
return obj;
}
public static void setData(URI uri,
HashMap<String, Object> properties,
Set<String> allowableProperties,
Map<String, String> query,
Map<String, Object> extraProps) {
if (allowableProperties.contains("host")) {
properties.put("host", "" + uri.getHost());
}
if (allowableProperties.contains("port")) {
properties.put("port", "" + uri.getPort());
}
if (allowableProperties.contains("userInfo")) {
properties.put("userInfo", "" + uri.getUserInfo());
}
for (Map.Entry<String, String> entry : query.entrySet()) {
if (allowableProperties.contains(entry.getKey())) {
properties.put(entry.getKey(), entry.getValue());
}
else {
extraProps.put(entry.getKey(), entry.getValue());
}
}
}
public static String getData(List<String> ignored, Object... beans) throws Exception {
StringBuilder sb = new StringBuilder();
boolean empty = true;
synchronized (beanUtils) {
for (Object bean : beans) {
if (bean != null) {
PropertyDescriptor[] descriptors = beanUtils.getPropertyUtils().getPropertyDescriptors(bean);
for (PropertyDescriptor descriptor : descriptors) {
if (descriptor.getReadMethod() != null && isWriteable(descriptor, ignored)) {
String value = beanUtils.getProperty(bean, descriptor.getName());
if (value != null) {
if (!empty) {
sb.append("&");
}
empty = false;
sb.append(descriptor.getName()).append("=").append(encodeURI(value));
}
}
}
}
}
}
return sb.toString();
}
private static boolean isWriteable(PropertyDescriptor descriptor, List<String> ignored) {
if (ignored != null && ignored.contains(descriptor.getName())) {
return false;
}
Class<?> type = descriptor.getPropertyType();
return (type == Double.class) ||
(type == double.class) ||
(type == Long.class) ||
(type == long.class) ||
(type == Integer.class) ||
(type == int.class) ||
(type == Float.class) ||
(type == float.class) ||
(type == Boolean.class) ||
(type == boolean.class) ||
(type == String.class);
}
public static String decodeURI(String value) throws UnsupportedEncodingException {
return URLDecoder.decode(value, "UTF-8");
}
public static String encodeURI(String value) throws UnsupportedEncodingException {
return URLEncoder.encode(value, "UTF-8");
}
}

View File

@ -16,19 +16,11 @@
*/
package org.apache.activemq.artemis.utils.uri;
import java.beans.PropertyDescriptor;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.beanutils.Converter;
public abstract class URISchema<T, P> {
@ -39,7 +31,7 @@ public abstract class URISchema<T, P> {
}
public void populateObject(URI uri, T bean) throws Exception {
setData(uri, bean, parseQuery(uri.getQuery(), null));
BeanSupport.setData(uri, bean, parseQuery(uri.getQuery(), null));
}
public URI newURI(T bean) throws Exception {
@ -97,38 +89,17 @@ public abstract class URISchema<T, P> {
protected abstract T internalNewObject(URI uri, Map<String, String> query, P param) throws Exception;
/** This is the default implementation.
* Sub classes are should provide a proper implementation for their schemas. */
/**
* This is the default implementation.
* Sub classes are should provide a proper implementation for their schemas.
*/
protected URI internalNewURI(T bean) throws Exception {
String query = URISchema.getData(null, bean);
String query = BeanSupport.getData(null, bean);
return new URI(getSchemaName(),
null,
"//", query, null);
return new URI(getSchemaName(), null, "//", query, null);
}
private static final BeanUtilsBean beanUtils = new BeanUtilsBean();
public static void registerConverter(Converter converter, Class type) {
synchronized (beanUtils) {
beanUtils.getConvertUtils().register(converter, type);
}
}
public static String decodeURI(String value) throws UnsupportedEncodingException {
return URLDecoder.decode(value, "UTF-8");
}
public static String encodeURI(String value) throws UnsupportedEncodingException {
return URLEncoder.encode(value, "UTF-8");
}
static {
// This is to customize the BeanUtils to use Fluent Proeprties as well
beanUtils.getPropertyUtils().addBeanIntrospector(new FluentPropertyBeanIntrospectorWithIgnores());
}
public static Map<String, String> parseQuery(String uri,
Map<String, String> propertyOverrides) throws URISyntaxException {
try {
@ -138,8 +109,8 @@ public abstract class URISchema<T, P> {
for (int i = 0; i < parameters.length; i++) {
int p = parameters[i].indexOf("=");
if (p >= 0) {
String name = decodeURI(parameters[i].substring(0, p));
String value = decodeURI(parameters[i].substring(p + 1));
String name = BeanSupport.decodeURI(parameters[i].substring(0, p));
String value = BeanSupport.decodeURI(parameters[i].substring(p + 1));
rc.put(name, value);
}
else {
@ -171,84 +142,4 @@ public abstract class URISchema<T, P> {
return buffer.toString();
}
protected static <P> P copyData(P source, P target) throws Exception {
synchronized (beanUtils) {
beanUtils.copyProperties(source, target);
}
return target;
}
protected static <P> P setData(URI uri, P obj, Map<String, String> query) throws Exception {
synchronized (beanUtils) {
beanUtils.setProperty(obj, "host", uri.getHost());
beanUtils.setProperty(obj, "port", uri.getPort());
beanUtils.setProperty(obj, "userInfo", uri.getUserInfo());
beanUtils.populate(obj, query);
}
return obj;
}
public static void setData(URI uri,
HashMap<String, Object> properties,
Set<String> allowableProperties,
Map<String, String> query) {
if (allowableProperties.contains("host")) {
properties.put("host", "" + uri.getHost());
}
if (allowableProperties.contains("port")) {
properties.put("port", "" + uri.getPort());
}
if (allowableProperties.contains("userInfo")) {
properties.put("userInfo", "" + uri.getUserInfo());
}
for (Map.Entry<String, String> entry : query.entrySet()) {
if (allowableProperties.contains(entry.getKey())) {
properties.put(entry.getKey(), entry.getValue());
}
}
}
public static String getData(List<String> ignored, Object... beans) throws Exception {
StringBuilder sb = new StringBuilder();
boolean empty = true;
synchronized (beanUtils) {
for (Object bean : beans) {
if (bean != null) {
PropertyDescriptor[] descriptors = beanUtils.getPropertyUtils().getPropertyDescriptors(bean);
for (PropertyDescriptor descriptor : descriptors) {
if (descriptor.getReadMethod() != null && isWriteable(descriptor, ignored)) {
String value = beanUtils.getProperty(bean, descriptor.getName());
if (value != null) {
if (!empty) {
sb.append("&");
}
empty = false;
sb.append(descriptor.getName()).append("=").append(encodeURI(value));
}
}
}
}
}
}
return sb.toString();
}
private static boolean isWriteable(PropertyDescriptor descriptor, List<String> ignored) {
if (ignored != null && ignored.contains(descriptor.getName())) {
return false;
}
Class<?> type = descriptor.getPropertyType();
return (type == Double.class) ||
(type == double.class) ||
(type == Long.class) ||
(type == long.class) ||
(type == Integer.class) ||
(type == int.class) ||
(type == Float.class) ||
(type == float.class) ||
(type == Boolean.class) ||
(type == boolean.class) ||
(type == String.class);
}
}

View File

@ -18,10 +18,13 @@
package org.apache.activemq.artemis.utils;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import org.apache.activemq.artemis.utils.uri.BeanSupport;
import org.apache.activemq.artemis.utils.uri.URIFactory;
import org.apache.activemq.artemis.utils.uri.URISchema;
import org.apache.activemq.artemis.utils.uri.URISupport;
import org.junit.Assert;
import org.junit.Test;
@ -99,6 +102,30 @@ public class URIParserTest {
Assert.assertEquals("something", fruit.getFluentName());
}
@Test
public void testQueryConversion() throws Exception {
Map<String, String> query = new HashMap<String, String>();
String queryString = URISupport.createQueryString(query);
System.out.println("queryString1: " + queryString);
Assert.assertTrue(queryString.isEmpty());
query.put("key1", "value1");
queryString = URISupport.createQueryString(query);
System.out.println("queryString2: " + queryString);
Assert.assertEquals("key1=value1", queryString);
query.put("key2", "value2");
queryString = URISupport.createQueryString(query);
System.out.println("queryString3: " + queryString);
Assert.assertEquals("key1=value1&key2=value2", queryString);
query.put("key3", "value3");
queryString = URISupport.createQueryString(query);
System.out.println("queryString4: " + queryString);
Assert.assertEquals("key1=value1&key2=value2&key3=value3", queryString);
}
class FruitParser extends URIFactory<FruitBase, String> {
FruitParser() {
@ -116,7 +143,7 @@ public class URIParserTest {
@Override
public FruitBase internalNewObject(URI uri, Map<String, String> query, String fruitName) throws Exception {
return setData(uri, new Fruit(getSchemaName()), query);
return BeanSupport.setData(uri, new Fruit(getSchemaName()), query);
}
}
@ -130,7 +157,7 @@ public class URIParserTest {
@Override
public FruitBase internalNewObject(URI uri, Map<String, String> query, String fruitName) throws Exception {
return setData(uri, new FruitBase(getSchemaName()), query);
return BeanSupport.setData(uri, new FruitBase(getSchemaName()), query);
}
}

View File

@ -51,6 +51,8 @@ public class TransportConfiguration implements Serializable {
private Map<String, Object> params;
private Map<String, Object> extraProps;
private static final byte TYPE_BOOLEAN = 0;
private static final byte TYPE_INT = 1;
@ -93,6 +95,19 @@ public class TransportConfiguration implements Serializable {
* @param name The name of this TransportConfiguration
*/
public TransportConfiguration(final String className, final Map<String, Object> params, final String name) {
this(className, params, name, null);
}
/**
* Creates a TransportConfiguration with a specific name providing the class name of the {@link org.apache.activemq.artemis.spi.core.remoting.ConnectorFactory}
* and any parameters needed.
*
* @param className The class name of the ConnectorFactory
* @param params The parameters needed by the ConnectorFactory
* @param name The name of this TransportConfiguration
* @param extraProps The extra properties that specific to protocols
*/
public TransportConfiguration(final String className, final Map<String, Object> params, final String name, final Map<String, Object> extraProps) {
factoryClassName = className;
if (params == null || params.isEmpty()) {
@ -103,6 +118,7 @@ public class TransportConfiguration implements Serializable {
}
this.name = name;
this.extraProps = extraProps;
}
public TransportConfiguration newTransportConfig(String newName) {
@ -156,6 +172,9 @@ public class TransportConfiguration implements Serializable {
return params;
}
public Map<String, Object> getExtraParams() {
return extraProps;
}
@Override
public int hashCode() {
@ -249,10 +268,52 @@ public class TransportConfiguration implements Serializable {
first = false;
}
if (extraProps != null) {
for (Map.Entry<String, Object> entry : extraProps.entrySet()) {
if (!first) {
str.append("&");
}
String key = entry.getKey();
String val = entry.getValue() == null ? "null" : entry.getValue().toString();
str.append(replaceWildcardChars(key)).append('=').append(replaceWildcardChars(val));
first = false;
}
}
}
return str.toString();
}
private void encodeMap(final ActiveMQBuffer buffer, final Map<String, Object> map) {
for (Map.Entry<String, Object> entry : map.entrySet()) {
buffer.writeString(entry.getKey());
Object val = entry.getValue();
if (val instanceof Boolean) {
buffer.writeByte(TransportConfiguration.TYPE_BOOLEAN);
buffer.writeBoolean((Boolean) val);
}
else if (val instanceof Integer) {
buffer.writeByte(TransportConfiguration.TYPE_INT);
buffer.writeInt((Integer) val);
}
else if (val instanceof Long) {
buffer.writeByte(TransportConfiguration.TYPE_LONG);
buffer.writeLong((Long) val);
}
else if (val instanceof String) {
buffer.writeByte(TransportConfiguration.TYPE_STRING);
buffer.writeString((String) val);
}
else {
throw ActiveMQClientMessageBundle.BUNDLE.invalidEncodeType(val);
}
}
}
/**
* Encodes this TransportConfiguration into a buffer.
* <p>
@ -267,31 +328,10 @@ public class TransportConfiguration implements Serializable {
buffer.writeInt(params == null ? 0 : params.size());
if (params != null) {
for (Map.Entry<String, Object> entry : params.entrySet()) {
buffer.writeString(entry.getKey());
Object val = entry.getValue();
if (val instanceof Boolean) {
buffer.writeByte(TransportConfiguration.TYPE_BOOLEAN);
buffer.writeBoolean((Boolean) val);
}
else if (val instanceof Integer) {
buffer.writeByte(TransportConfiguration.TYPE_INT);
buffer.writeInt((Integer) val);
}
else if (val instanceof Long) {
buffer.writeByte(TransportConfiguration.TYPE_LONG);
buffer.writeLong((Long) val);
}
else if (val instanceof String) {
buffer.writeByte(TransportConfiguration.TYPE_STRING);
buffer.writeString((String) val);
}
else {
throw ActiveMQClientMessageBundle.BUNDLE.invalidEncodeType(val);
}
}
encodeMap(buffer, params);
}
if (extraProps != null) {
encodeMap(buffer, extraProps);
}
}

View File

@ -53,9 +53,9 @@ import org.apache.activemq.artemis.core.remoting.impl.TransportConfigurationUtil
import org.apache.activemq.artemis.core.server.ActiveMQComponent;
import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection;
import org.apache.activemq.artemis.spi.core.remoting.BufferHandler;
import org.apache.activemq.artemis.spi.core.remoting.ClientConnectionLifeCycleListener;
import org.apache.activemq.artemis.spi.core.remoting.ClientProtocolManager;
import org.apache.activemq.artemis.spi.core.remoting.Connection;
import org.apache.activemq.artemis.spi.core.remoting.ConnectionLifeCycleListener;
import org.apache.activemq.artemis.spi.core.remoting.Connector;
import org.apache.activemq.artemis.spi.core.remoting.ConnectorFactory;
import org.apache.activemq.artemis.spi.core.remoting.SessionContext;
@ -67,7 +67,7 @@ import org.apache.activemq.artemis.utils.ExecutorFactory;
import org.apache.activemq.artemis.utils.OrderedExecutorFactory;
import org.apache.activemq.artemis.utils.UUIDGenerator;
public class ClientSessionFactoryImpl implements ClientSessionFactoryInternal, ConnectionLifeCycleListener {
public class ClientSessionFactoryImpl implements ClientSessionFactoryInternal, ClientConnectionLifeCycleListener {
// Constants
// ------------------------------------------------------------------------------------
@ -350,7 +350,7 @@ public class ClientSessionFactoryImpl implements ClientSessionFactoryInternal, C
@Override
public void connectionCreated(final ActiveMQComponent component,
final Connection connection,
final String protocol) {
final ClientProtocolManager protocol) {
}
@Override

View File

@ -25,8 +25,8 @@ import org.apache.activemq.artemis.api.core.ActiveMQException;
import org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper;
import org.apache.activemq.artemis.core.client.ActiveMQClientLogger;
import org.apache.activemq.artemis.core.client.ActiveMQClientMessageBundle;
import org.apache.activemq.artemis.spi.core.remoting.BaseConnectionLifeCycleListener;
import org.apache.activemq.artemis.spi.core.remoting.BufferHandler;
import org.apache.activemq.artemis.spi.core.remoting.ConnectionLifeCycleListener;
/**
* Common handler implementation for client and server side handler.
@ -37,13 +37,13 @@ public class ActiveMQChannelHandler extends ChannelDuplexHandler {
private final BufferHandler handler;
private final ConnectionLifeCycleListener listener;
private final BaseConnectionLifeCycleListener listener;
volatile boolean active;
protected ActiveMQChannelHandler(final ChannelGroup group,
final BufferHandler handler,
final ConnectionLifeCycleListener listener) {
final BaseConnectionLifeCycleListener listener) {
this.group = group;
this.handler = handler;
this.listener = listener;

View File

@ -37,8 +37,8 @@ import org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper;
import org.apache.activemq.artemis.core.client.ActiveMQClientLogger;
import org.apache.activemq.artemis.core.security.ActiveMQPrincipal;
import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection;
import org.apache.activemq.artemis.spi.core.remoting.BaseConnectionLifeCycleListener;
import org.apache.activemq.artemis.spi.core.remoting.Connection;
import org.apache.activemq.artemis.spi.core.remoting.ConnectionLifeCycleListener;
import org.apache.activemq.artemis.spi.core.remoting.ReadyListener;
import org.apache.activemq.artemis.utils.IPV6Util;
@ -53,7 +53,7 @@ public class NettyConnection implements Connection {
private boolean closed;
private final ConnectionLifeCycleListener listener;
private final BaseConnectionLifeCycleListener listener;
private final boolean batchingEnabled;
@ -79,7 +79,7 @@ public class NettyConnection implements Connection {
public NettyConnection(final Map<String, Object> configuration,
final Channel channel,
final ConnectionLifeCycleListener listener,
final BaseConnectionLifeCycleListener listener,
boolean batchingEnabled,
boolean directDeliver) {
this.configuration = configuration;

View File

@ -94,10 +94,11 @@ import org.apache.activemq.artemis.core.protocol.core.impl.ActiveMQClientProtoco
import org.apache.activemq.artemis.core.remoting.impl.ssl.SSLSupport;
import org.apache.activemq.artemis.core.server.ActiveMQComponent;
import org.apache.activemq.artemis.spi.core.remoting.AbstractConnector;
import org.apache.activemq.artemis.spi.core.remoting.BaseConnectionLifeCycleListener;
import org.apache.activemq.artemis.spi.core.remoting.BufferHandler;
import org.apache.activemq.artemis.spi.core.remoting.ClientConnectionLifeCycleListener;
import org.apache.activemq.artemis.spi.core.remoting.ClientProtocolManager;
import org.apache.activemq.artemis.spi.core.remoting.Connection;
import org.apache.activemq.artemis.spi.core.remoting.ConnectionLifeCycleListener;
import org.apache.activemq.artemis.utils.ConfigurationHelper;
import org.apache.activemq.artemis.utils.FutureLatch;
@ -151,7 +152,7 @@ public class NettyConnector extends AbstractConnector {
private final BufferHandler handler;
private final ConnectionLifeCycleListener listener;
private final BaseConnectionLifeCycleListener listener;
private boolean sslEnabled = TransportConstants.DEFAULT_SSL_ENABLED;
@ -231,7 +232,7 @@ public class NettyConnector extends AbstractConnector {
// Public --------------------------------------------------------
public NettyConnector(final Map<String, Object> configuration,
final BufferHandler handler,
final ConnectionLifeCycleListener listener,
final BaseConnectionLifeCycleListener listener,
final Executor closeExecutor,
final Executor threadPool,
final ScheduledExecutorService scheduledThreadPool) {
@ -240,7 +241,7 @@ public class NettyConnector extends AbstractConnector {
public NettyConnector(final Map<String, Object> configuration,
final BufferHandler handler,
final ConnectionLifeCycleListener listener,
final BaseConnectionLifeCycleListener listener,
final Executor closeExecutor,
final Executor threadPool,
final ScheduledExecutorService scheduledThreadPool,
@ -681,7 +682,7 @@ public class NettyConnector extends AbstractConnector {
// No acceptor on a client connection
Listener connectionListener = new Listener();
NettyConnection conn = new NettyConnection(configuration, ch, connectionListener, !httpEnabled && batchDelay > 0, false);
connectionListener.connectionCreated(null, conn, protocolManager.getName());
connectionListener.connectionCreated(null, conn, protocolManager);
return conn;
}
else {
@ -709,7 +710,7 @@ public class NettyConnector extends AbstractConnector {
ActiveMQClientChannelHandler(final ChannelGroup group,
final BufferHandler handler,
final ConnectionLifeCycleListener listener) {
final ClientConnectionLifeCycleListener listener) {
super(group, handler, listener);
}
}
@ -899,12 +900,12 @@ public class NettyConnector extends AbstractConnector {
}
}
private class Listener implements ConnectionLifeCycleListener {
private class Listener implements ClientConnectionLifeCycleListener {
@Override
public void connectionCreated(final ActiveMQComponent component,
final Connection connection,
final String protocol) {
final ClientProtocolManager protocol) {
if (connections.putIfAbsent(connection.getID(), connection) != null) {
throw ActiveMQClientMessageBundle.BUNDLE.connectionExists(connection.getID());
}

View File

@ -21,8 +21,8 @@ import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledExecutorService;
import org.apache.activemq.artemis.spi.core.remoting.BufferHandler;
import org.apache.activemq.artemis.spi.core.remoting.ClientConnectionLifeCycleListener;
import org.apache.activemq.artemis.spi.core.remoting.ClientProtocolManager;
import org.apache.activemq.artemis.spi.core.remoting.ConnectionLifeCycleListener;
import org.apache.activemq.artemis.spi.core.remoting.Connector;
import org.apache.activemq.artemis.spi.core.remoting.ConnectorFactory;
@ -31,7 +31,7 @@ public class NettyConnectorFactory implements ConnectorFactory {
@Override
public Connector createConnector(final Map<String, Object> configuration,
final BufferHandler handler,
final ConnectionLifeCycleListener listener,
final ClientConnectionLifeCycleListener listener,
final Executor closeExecutor,
final Executor threadPool,
final ScheduledExecutorService scheduledThreadPool,

View File

@ -0,0 +1,60 @@
/*
* 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.spi.core.remoting;
import org.apache.activemq.artemis.api.core.ActiveMQException;
import org.apache.activemq.artemis.core.server.ActiveMQComponent;
/**
* A ConnectionLifeCycleListener is called by the remoting implementation to notify of connection events.
*/
public interface BaseConnectionLifeCycleListener<ProtocolClass> {
/**
* This method is used both by client connector creation and server connection creation through
* acceptors. On the client side the {@code component} parameter is normally passed as
* {@code null}.
* <p>
* Leaving this method here and adding a different one at
* {@code ServerConnectionLifeCycleListener} is a compromise for a reasonable split between the
* activemq-server and activemq-client packages while avoiding to pull too much into activemq-core.
* The pivotal point keeping us from removing the method is {@link ConnectorFactory} and the
* usage of it.
*
* @param component This will probably be an {@code Acceptor} and only used on the server side.
* @param connection the connection that has been created
* @param protocol the messaging protocol type this connection uses
*/
void connectionCreated(ActiveMQComponent component, Connection connection, ProtocolClass protocol);
/**
* Called when a connection is destroyed.
*
* @param connectionID the connection being destroyed.
*/
void connectionDestroyed(Object connectionID);
/**
* Called when an error occurs on the connection.
*
* @param connectionID the id of the connection.
* @param me the exception.
*/
void connectionException(Object connectionID, ActiveMQException me);
void connectionReadyForWrites(Object connectionID, boolean ready);
}

View File

@ -0,0 +1,22 @@
/**
* 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.spi.core.remoting;
public interface ClientConnectionLifeCycleListener extends BaseConnectionLifeCycleListener<ClientProtocolManager> {
}

View File

@ -16,45 +16,11 @@
*/
package org.apache.activemq.artemis.spi.core.remoting;
import org.apache.activemq.artemis.api.core.ActiveMQException;
import org.apache.activemq.artemis.core.server.ActiveMQComponent;
/**
* A ConnectionLifeCycleListener is called by the remoting implementation to notify of connection events.
* @deprecated use {@link ClientConnectionLifeCycleListener} instead.
*/
public interface ConnectionLifeCycleListener {
@Deprecated
public interface ConnectionLifeCycleListener extends BaseConnectionLifeCycleListener<String> {
/**
* This method is used both by client connector creation and server connection creation through
* acceptors. On the client side the {@code component} parameter is normally passed as
* {@code null}.
* <p>
* Leaving this method here and adding a different one at
* {@code ServerConnectionLifeCycleListener} is a compromise for a reasonable split between the
* activemq-server and activemq-client packages while avoiding to pull too much into activemq-core.
* The pivotal point keeping us from removing the method is {@link ConnectorFactory} and the
* usage of it.
*
* @param component This will probably be an {@code Acceptor} and only used on the server side.
* @param connection the connection that has been created
* @param protocol the messaging protocol type this connection uses
*/
void connectionCreated(ActiveMQComponent component, Connection connection, String protocol);
/**
* Called when a connection is destroyed.
*
* @param connectionID the connection being destroyed.
*/
void connectionDestroyed(Object connectionID);
/**
* Called when an error occurs on the connection.
*
* @param connectionID the id of the connection.
* @param me the exception.
*/
void connectionException(Object connectionID, ActiveMQException me);
void connectionReadyForWrites(Object connectionID, boolean ready);
}

View File

@ -42,7 +42,7 @@ public interface ConnectorFactory extends TransportConfigurationHelper {
*/
Connector createConnector(Map<String, Object> configuration,
BufferHandler handler,
ConnectionLifeCycleListener listener,
ClientConnectionLifeCycleListener listener,
Executor closeExecutor,
Executor threadPool,
ScheduledExecutorService scheduledThreadPool,

View File

@ -26,6 +26,7 @@ import java.util.Set;
import org.apache.activemq.artemis.api.core.TransportConfiguration;
import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory;
import org.apache.activemq.artemis.utils.uri.BeanSupport;
import org.apache.activemq.artemis.utils.uri.SchemaConstants;
public class TCPTransportConfigurationSchema extends AbstractTransportConfigurationSchema {
@ -60,10 +61,13 @@ public class TCPTransportConfigurationSchema extends AbstractTransportConfigurat
String factoryName) throws URISyntaxException {
HashMap<String, Object> props = new HashMap<>();
setData(uri, props, allowableProperties, query);
Map<String, Object> extraProps = new HashMap<>();
BeanSupport.setData(uri, props, allowableProperties, query, extraProps);
List<TransportConfiguration> transportConfigurations = new ArrayList<>();
transportConfigurations.add(new TransportConfiguration(factoryName, props, name));
TransportConfiguration config = new TransportConfiguration(factoryName, props, name, extraProps);
transportConfigurations.add(config);
String connectors = uri.getFragment();
if (connectors != null && !connectors.trim().isEmpty()) {
@ -71,9 +75,10 @@ public class TCPTransportConfigurationSchema extends AbstractTransportConfigurat
for (String s : split) {
URI extraUri = new URI(s);
HashMap<String, Object> newProps = new HashMap<>();
setData(extraUri, newProps, allowableProperties, query);
setData(extraUri, newProps, allowableProperties, parseQuery(extraUri.getQuery(), null));
transportConfigurations.add(new TransportConfiguration(factoryName, newProps, name + ":" + extraUri.toString()));
extraProps = new HashMap<>();
BeanSupport.setData(extraUri, newProps, allowableProperties, query, extraProps);
BeanSupport.setData(extraUri, newProps, allowableProperties, parseQuery(extraUri.getQuery(), null), extraProps);
transportConfigurations.add(new TransportConfiguration(factoryName, newProps, name + ":" + extraUri.toString(), extraProps));
}
}
return transportConfigurations;

View File

@ -17,6 +17,7 @@
package org.apache.activemq.artemis.uri.schema.serverLocator;
import org.apache.activemq.artemis.api.core.client.ServerLocator;
import org.apache.activemq.artemis.utils.uri.BeanSupport;
import org.apache.activemq.artemis.utils.uri.URISchema;
import java.net.URI;
@ -25,6 +26,6 @@ import java.util.Map;
public abstract class AbstractServerLocatorSchema extends URISchema<ServerLocator, String> {
protected ConnectionOptions newConnectionOptions(URI uri, Map<String, String> query) throws Exception {
return setData(uri, new ConnectionOptions(), query);
return BeanSupport.setData(uri, new ConnectionOptions(), query);
}
}

View File

@ -20,6 +20,7 @@ import org.apache.activemq.artemis.api.core.TransportConfiguration;
import org.apache.activemq.artemis.api.core.client.ActiveMQClient;
import org.apache.activemq.artemis.api.core.client.ServerLocator;
import org.apache.activemq.artemis.uri.schema.connector.InVMTransportConfigurationSchema;
import org.apache.activemq.artemis.utils.uri.BeanSupport;
import org.apache.activemq.artemis.utils.uri.SchemaConstants;
import java.net.URI;
@ -37,7 +38,7 @@ public class InVMServerLocatorSchema extends AbstractServerLocatorSchema {
protected ServerLocator internalNewObject(URI uri, Map<String, String> query, String name) throws Exception {
TransportConfiguration tc = InVMTransportConfigurationSchema.createTransportConfiguration(uri, query, name, "org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory");
ServerLocator factory = ActiveMQClient.createServerLocatorWithoutHA(tc);
return setData(uri, factory, query);
return BeanSupport.setData(uri, factory, query);
}
@Override

View File

@ -22,6 +22,7 @@ import org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory;
import org.apache.activemq.artemis.api.core.JGroupsPropertiesBroadcastEndpointFactory;
import org.apache.activemq.artemis.api.core.client.ActiveMQClient;
import org.apache.activemq.artemis.api.core.client.ServerLocator;
import org.apache.activemq.artemis.utils.uri.BeanSupport;
import org.apache.activemq.artemis.utils.uri.SchemaConstants;
import java.io.NotSerializableException;
@ -63,7 +64,7 @@ public class JGroupsServerLocatorSchema extends AbstractServerLocatorSchema {
else {
throw new NotSerializableException(endpoint + "not serializable");
}
String query = getData(null, bean, dgc, endpoint);
String query = BeanSupport.getData(null, bean, dgc, endpoint);
dgc.setBroadcastEndpointFactory(endpoint);
return new URI(SchemaConstants.JGROUPS, null, auth, -1, null, query, null);
}
@ -79,11 +80,11 @@ public class JGroupsServerLocatorSchema extends AbstractServerLocatorSchema {
endpointFactory = new JGroupsPropertiesBroadcastEndpointFactory().setChannelName(uri.getAuthority());
}
setData(uri, endpointFactory, query);
BeanSupport.setData(uri, endpointFactory, query);
DiscoveryGroupConfiguration dcConfig = new DiscoveryGroupConfiguration().setName(name).setBroadcastEndpointFactory(endpointFactory);
setData(uri, dcConfig, query);
BeanSupport.setData(uri, dcConfig, query);
return dcConfig;
}
}

View File

@ -27,6 +27,7 @@ import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactor
import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants;
import org.apache.activemq.artemis.uri.schema.connector.TCPTransportConfigurationSchema;
import org.apache.activemq.artemis.utils.IPV6Util;
import org.apache.activemq.artemis.utils.uri.BeanSupport;
import org.apache.activemq.artemis.utils.uri.SchemaConstants;
public class TCPServerLocatorSchema extends AbstractServerLocatorSchema {
@ -52,7 +53,7 @@ public class TCPServerLocatorSchema extends AbstractServerLocatorSchema {
@Override
protected URI internalNewURI(ServerLocator bean) throws Exception {
String query = getData(null, bean);
String query = BeanSupport.getData(null, bean);
TransportConfiguration[] staticConnectors = bean.getStaticTransportConfigurations();
return getURI(query, staticConnectors);
}
@ -122,9 +123,9 @@ public class TCPServerLocatorSchema extends AbstractServerLocatorSchema {
else {
empty = false;
}
cb.append(encodeURI(entry.getKey()));
cb.append(BeanSupport.encodeURI(entry.getKey()));
cb.append("=");
cb.append(encodeURI(entry.getValue().toString()));
cb.append(BeanSupport.encodeURI(entry.getValue().toString()));
}
}
return cb.toString();

View File

@ -25,6 +25,7 @@ import org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration;
import org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory;
import org.apache.activemq.artemis.api.core.client.ActiveMQClient;
import org.apache.activemq.artemis.api.core.client.ServerLocator;
import org.apache.activemq.artemis.utils.uri.BeanSupport;
import org.apache.activemq.artemis.utils.uri.SchemaConstants;
public class UDPServerLocatorSchema extends AbstractServerLocatorSchema {
@ -60,7 +61,7 @@ public class UDPServerLocatorSchema extends AbstractServerLocatorSchema {
DiscoveryGroupConfiguration dgc = bean.getDiscoveryGroupConfiguration();
UDPBroadcastEndpointFactory endpoint = (UDPBroadcastEndpointFactory) dgc.getBroadcastEndpointFactory();
dgc.setBroadcastEndpointFactory(endpoint);
String query = getData(IGNORED, bean, dgc, endpoint);
String query = BeanSupport.getData(IGNORED, bean, dgc, endpoint);
return new URI(SchemaConstants.UDP, null, endpoint.getGroupAddress(), endpoint.getGroupPort(), null, query, null);
}
@ -71,11 +72,11 @@ public class UDPServerLocatorSchema extends AbstractServerLocatorSchema {
String name) throws Exception {
UDPBroadcastEndpointFactory endpointFactoryConfiguration = new UDPBroadcastEndpointFactory().setGroupAddress(host).setGroupPort(port);
setData(uri, endpointFactoryConfiguration, query);
BeanSupport.setData(uri, endpointFactoryConfiguration, query);
DiscoveryGroupConfiguration dgc = setData(uri, new DiscoveryGroupConfiguration(), query).setName(name).setBroadcastEndpointFactory(endpointFactoryConfiguration);
DiscoveryGroupConfiguration dgc = BeanSupport.setData(uri, new DiscoveryGroupConfiguration(), query).setName(name).setBroadcastEndpointFactory(endpointFactoryConfiguration);
setData(uri, dgc, query);
BeanSupport.setData(uri, dgc, query);
return dgc;
}
}

View File

@ -22,6 +22,7 @@ import java.util.Map;
import org.apache.activemq.artemis.core.client.ActiveMQClientLogger;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
import org.apache.activemq.artemis.utils.uri.BeanSupport;
import org.apache.activemq.artemis.utils.uri.URISchema;
public abstract class AbstractCFSchema extends URISchema<ActiveMQConnectionFactory, String> {
@ -32,7 +33,7 @@ public abstract class AbstractCFSchema extends URISchema<ActiveMQConnectionFacto
if (JMSConnectionOptions.convertCFType(type) == null) {
ActiveMQClientLogger.LOGGER.invalidCFType(type, uri.toString());
}
return setData(uri, new JMSConnectionOptions(), query);
return BeanSupport.setData(uri, new JMSConnectionOptions(), query);
}
}

View File

@ -20,6 +20,7 @@ import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
import org.apache.activemq.artemis.uri.schema.serverLocator.InVMServerLocatorSchema;
import org.apache.activemq.artemis.uri.schema.connector.InVMTransportConfigurationSchema;
import org.apache.activemq.artemis.utils.uri.BeanSupport;
import org.apache.activemq.artemis.utils.uri.SchemaConstants;
import java.net.URI;
@ -38,7 +39,7 @@ public class InVMSchema extends AbstractCFSchema {
String name) throws Exception {
JMSConnectionOptions options = newConectionOptions(uri, query);
ActiveMQConnectionFactory factory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(options.getFactoryTypeEnum(), InVMTransportConfigurationSchema.createTransportConfiguration(uri, query, name, "org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory"));
return setData(uri, factory, query);
return BeanSupport.setData(uri, factory, query);
}
@Override

View File

@ -28,8 +28,8 @@ import org.apache.activemq.artemis.api.core.JGroupsPropertiesBroadcastEndpointFa
import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
import org.apache.activemq.artemis.uri.schema.serverLocator.JGroupsServerLocatorSchema;
import org.apache.activemq.artemis.utils.uri.BeanSupport;
import org.apache.activemq.artemis.utils.uri.SchemaConstants;
import org.apache.activemq.artemis.utils.uri.URISchema;
public class JGroupsSchema extends AbstractCFSchema {
@ -53,7 +53,7 @@ public class JGroupsSchema extends AbstractCFSchema {
else {
factory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(dcConfig, options.getFactoryTypeEnum());
}
return URISchema.setData(uri, factory, query);
return BeanSupport.setData(uri, factory, query);
}
@Override
@ -70,7 +70,7 @@ public class JGroupsSchema extends AbstractCFSchema {
else {
throw new NotSerializableException(endpoint + "not serializable");
}
String query = URISchema.getData(null, bean, dgc, endpoint);
String query = BeanSupport.getData(null, bean, dgc, endpoint);
dgc.setBroadcastEndpointFactory(endpoint);
return new URI(SchemaConstants.JGROUPS, null, auth, -1, null, query, null);
}

View File

@ -23,8 +23,8 @@ import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
import org.apache.activemq.artemis.uri.schema.serverLocator.TCPServerLocatorSchema;
import org.apache.activemq.artemis.uri.schema.connector.TCPTransportConfigurationSchema;
import org.apache.activemq.artemis.utils.uri.BeanSupport;
import org.apache.activemq.artemis.utils.uri.SchemaConstants;
import org.apache.activemq.artemis.utils.uri.URISchema;
import java.net.URI;
import java.util.List;
@ -58,12 +58,12 @@ public class TCPSchema extends AbstractCFSchema {
factory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(options.getFactoryTypeEnum(), tcs);
}
return URISchema.setData(uri, factory, query);
return BeanSupport.setData(uri, factory, query);
}
@Override
protected URI internalNewURI(ActiveMQConnectionFactory bean) throws Exception {
String query = URISchema.getData(null, bean);
String query = BeanSupport.getData(null, bean);
TransportConfiguration[] staticConnectors = bean.getStaticConnectors();
return TCPServerLocatorSchema.getURI(query, staticConnectors);
}

View File

@ -25,8 +25,8 @@ import org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory;
import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
import org.apache.activemq.artemis.uri.schema.serverLocator.UDPServerLocatorSchema;
import org.apache.activemq.artemis.utils.uri.BeanSupport;
import org.apache.activemq.artemis.utils.uri.SchemaConstants;
import org.apache.activemq.artemis.utils.uri.URISchema;
public class UDPSchema extends AbstractCFSchema {
@ -50,14 +50,14 @@ public class UDPSchema extends AbstractCFSchema {
else {
factory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(dgc, options.getFactoryTypeEnum());
}
return URISchema.setData(uri, factory, query);
return BeanSupport.setData(uri, factory, query);
}
@Override
protected URI internalNewURI(ActiveMQConnectionFactory bean) throws Exception {
DiscoveryGroupConfiguration dgc = bean.getDiscoveryGroupConfiguration();
UDPBroadcastEndpointFactory endpoint = (UDPBroadcastEndpointFactory) dgc.getBroadcastEndpointFactory();
String query = URISchema.getData(UDPServerLocatorSchema.IGNORED, bean, dgc, endpoint);
String query = BeanSupport.getData(UDPServerLocatorSchema.IGNORED, bean, dgc, endpoint);
dgc.setBroadcastEndpointFactory(endpoint);
return new URI(SchemaConstants.UDP, null, endpoint.getGroupAddress(), endpoint.getGroupPort(), null, query, null);
}

View File

@ -18,6 +18,7 @@ package org.apache.activemq.artemis.jms.server.embedded;
import javax.naming.Context;
import org.apache.activemq.artemis.core.config.Configuration;
import org.apache.activemq.artemis.core.config.FileDeploymentManager;
import org.apache.activemq.artemis.core.registry.JndiBindingRegistry;
import org.apache.activemq.artemis.core.registry.MapBindingRegistry;
@ -80,13 +81,19 @@ public class EmbeddedJMS extends EmbeddedActiveMQ {
return this;
}
/**
* Lookup in the registry for registered object, i.e. a ConnectionFactory.
* <p>
* This is a convenience method.
*
* @param name
*/
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
*/
public Object lookup(String name) {
return serverManager.getRegistry().lookup(name);
}

View File

@ -22,10 +22,12 @@ import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.spi.core.protocol.AbstractProtocolManagerFactory;
import org.apache.activemq.artemis.spi.core.protocol.ProtocolManager;
import org.apache.activemq.artemis.spi.core.protocol.ProtocolManagerFactory;
import org.apache.activemq.artemis.utils.uri.BeanSupport;
import org.osgi.service.component.annotations.Component;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@Component(service = ProtocolManagerFactory.class)
public class ProtonProtocolManagerFactory extends AbstractProtocolManagerFactory<Interceptor> {
@ -38,9 +40,10 @@ public class ProtonProtocolManagerFactory extends AbstractProtocolManagerFactory
@Override
public ProtocolManager createProtocolManager(ActiveMQServer server,
List<Interceptor> incomingInterceptors,
List<Interceptor> outgoingInterceptors) {
return new ProtonProtocolManager(this, server);
final Map<String, Object> parameters,
List<BaseInterceptor> incomingInterceptors,
List<BaseInterceptor> outgoingInterceptors) throws Exception {
return BeanSupport.setData(new ProtonProtocolManager(this, server), parameters);
}
@Override

View File

@ -17,7 +17,9 @@
package org.apache.activemq.artemis.core.protocol.hornetq;
import java.util.List;
import java.util.Map;
import org.apache.activemq.artemis.api.core.BaseInterceptor;
import org.apache.activemq.artemis.api.core.Interceptor;
import org.apache.activemq.artemis.core.protocol.core.impl.CoreProtocolManagerFactory;
import org.apache.activemq.artemis.core.server.ActiveMQServer;
@ -36,11 +38,17 @@ public class HornetQProtocolManagerFactory extends CoreProtocolManagerFactory {
@Override
public ProtocolManager createProtocolManager(final ActiveMQServer server,
final List<Interceptor> incomingInterceptors,
List<Interceptor> outgoingInterceptors) {
incomingInterceptors.add(new HQPropertiesConversionInterceptor(true));
outgoingInterceptors.add(new HQPropertiesConversionInterceptor(false));
return new HornetQProtocolManager(this, server, incomingInterceptors, outgoingInterceptors);
final Map<String, Object> parameters,
final List<BaseInterceptor> incomingInterceptors,
List<BaseInterceptor> outgoingInterceptors) {
List<Interceptor> hqIncoming = filterInterceptors(incomingInterceptors);
List<Interceptor> hqOutgoing = filterInterceptors(outgoingInterceptors);
hqIncoming.add(new HQPropertiesConversionInterceptor(true));
hqOutgoing.add(new HQPropertiesConversionInterceptor(false));
return new HornetQProtocolManager(this, server, hqIncoming, hqOutgoing);
}
@Override

View File

@ -18,14 +18,16 @@
package org.apache.activemq.artemis.core.protocol.mqtt;
import java.util.List;
import java.util.Map;
import org.apache.activemq.artemis.api.core.BaseInterceptor;
import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.spi.core.protocol.ProtocolManager;
import org.apache.activemq.artemis.spi.core.protocol.ProtocolManagerFactory;
import org.osgi.service.component.annotations.Component;
@Component(service = ProtocolManagerFactory.class)
public class MQTTProtocolManagerFactory implements ProtocolManagerFactory {
public class MQTTProtocolManagerFactory implements ProtocolManagerFactory<BaseInterceptor> {
public static final String MQTT_PROTOCOL_NAME = "MQTT";
@ -35,8 +37,9 @@ public class MQTTProtocolManagerFactory implements ProtocolManagerFactory {
@Override
public ProtocolManager createProtocolManager(ActiveMQServer server,
List incomingInterceptors,
List outgoingInterceptors) {
final Map<String, Object> parameters,
List<BaseInterceptor> incomingInterceptors,
List<BaseInterceptor> outgoingInterceptors) {
return new MQTTProtocolManager(server);
}

View File

@ -18,6 +18,7 @@ package org.apache.activemq.artemis.core.protocol.openwire;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.apache.activemq.artemis.api.core.BaseInterceptor;
import org.apache.activemq.artemis.api.core.Interceptor;
@ -25,6 +26,7 @@ import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.spi.core.protocol.AbstractProtocolManagerFactory;
import org.apache.activemq.artemis.spi.core.protocol.ProtocolManager;
import org.apache.activemq.artemis.spi.core.protocol.ProtocolManagerFactory;
import org.apache.activemq.artemis.utils.uri.BeanSupport;
import org.osgi.service.component.annotations.Component;
@Component(service = ProtocolManagerFactory.class)
@ -38,9 +40,10 @@ public class OpenWireProtocolManagerFactory extends AbstractProtocolManagerFacto
@Override
public ProtocolManager createProtocolManager(final ActiveMQServer server,
final List<Interceptor> incomingInterceptors,
List<Interceptor> outgoingInterceptors) {
return new OpenWireProtocolManager(this, server);
Map<String, Object> parameters,
final List<BaseInterceptor> incomingInterceptors,
List<BaseInterceptor> outgoingInterceptors) throws Exception {
return BeanSupport.setData(new OpenWireProtocolManager(this, server), parameters);
}
@Override

View File

@ -62,7 +62,6 @@ import org.apache.activemq.artemis.spi.core.protocol.SessionCallback;
import org.apache.activemq.wireformat.WireFormat;
public class AMQSession implements SessionCallback {
private AMQServerSession coreSession;
private ConnectionInfo connInfo;
private SessionInfo sessInfo;

View File

@ -29,7 +29,6 @@ import org.apache.qpid.proton.codec.DecoderImpl;
import org.apache.qpid.proton.codec.EncoderImpl;
import org.apache.qpid.proton.codec.WritableBuffer;
import org.apache.qpid.proton.message.MessageError;
import org.apache.qpid.proton.message.MessageFormat;
import org.apache.qpid.proton.message.ProtonJMessage;
/**
@ -454,36 +453,6 @@ public class ProtonServerMessage implements ProtonJMessage {
return 0;
}
@Override
public void load(Object data) {
}
@Override
public Object save() {
return null;
}
@Override
public String toAMQPFormat(Object value) {
return null;
}
@Override
public Object parseAMQPFormat(String value) {
return null;
}
@Override
public void setMessageFormat(MessageFormat format) {
}
@Override
public MessageFormat getMessageFormat() {
return null;
}
@Override
public void clear() {

View File

@ -17,12 +17,14 @@
package org.apache.activemq.artemis.core.protocol.stomp;
import java.util.List;
import java.util.Map;
import org.apache.activemq.artemis.api.core.BaseInterceptor;
import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.spi.core.protocol.AbstractProtocolManagerFactory;
import org.apache.activemq.artemis.spi.core.protocol.ProtocolManager;
import org.apache.activemq.artemis.spi.core.protocol.ProtocolManagerFactory;
import org.apache.activemq.artemis.utils.uri.BeanSupport;
import org.osgi.service.component.annotations.Component;
@Component(service = ProtocolManagerFactory.class)
@ -36,14 +38,15 @@ public class StompProtocolManagerFactory extends AbstractProtocolManagerFactory<
@Override
public ProtocolManager createProtocolManager(final ActiveMQServer server,
final List<StompFrameInterceptor> incomingInterceptors,
List<StompFrameInterceptor> outgoingInterceptors) {
return new StompProtocolManager(this, server, incomingInterceptors, outgoingInterceptors);
final Map<String, Object> parameters,
final List<BaseInterceptor> incomingInterceptors,
List<BaseInterceptor> outgoingInterceptors) throws Exception {
return BeanSupport.setData(new StompProtocolManager(this, server, filterInterceptors(incomingInterceptors), filterInterceptors(outgoingInterceptors)), parameters);
}
@Override
public List<StompFrameInterceptor> filterInterceptors(List<BaseInterceptor> interceptors) {
return filterInterceptors(StompFrameInterceptor.class, interceptors);
return internalFilterInterceptors(StompFrameInterceptor.class, interceptors);
}
@Override

View File

@ -84,6 +84,10 @@ public class ProtocolHandler {
}
}
public ProtocolManager getProtocol(String name) {
return this.protocolMap.get(name);
}
class ProtocolDecoder extends ByteToMessageDecoder {
private final boolean http;

View File

@ -17,6 +17,7 @@
package org.apache.activemq.artemis.core.protocol.core.impl;
import java.util.List;
import java.util.Map;
import org.apache.activemq.artemis.api.core.BaseInterceptor;
import org.apache.activemq.artemis.api.core.Interceptor;
@ -24,6 +25,7 @@ import org.apache.activemq.artemis.api.core.client.ActiveMQClient;
import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.spi.core.protocol.AbstractProtocolManagerFactory;
import org.apache.activemq.artemis.spi.core.protocol.ProtocolManager;
import org.apache.activemq.artemis.utils.uri.BeanSupport;
public class CoreProtocolManagerFactory extends AbstractProtocolManagerFactory<Interceptor> {
@ -41,9 +43,10 @@ public class CoreProtocolManagerFactory extends AbstractProtocolManagerFactory<I
*/
@Override
public ProtocolManager createProtocolManager(final ActiveMQServer server,
final List<Interceptor> incomingInterceptors,
List<Interceptor> outgoingInterceptors) {
return new CoreProtocolManager(this, server, incomingInterceptors, outgoingInterceptors);
Map<String, Object> parameters,
final List<BaseInterceptor> incomingInterceptors,
List<BaseInterceptor> outgoingInterceptors) throws Exception {
return BeanSupport.setData(new CoreProtocolManager(this, server, filterInterceptors(incomingInterceptors), filterInterceptors(outgoingInterceptors)), parameters);
}
@Override
@ -51,7 +54,7 @@ public class CoreProtocolManagerFactory extends AbstractProtocolManagerFactory<I
// This is using this tool method
// it wouldn't be possible to write a generic method without this class parameter
// and I didn't want to bloat the cllaers for this
return filterInterceptors(Interceptor.class, interceptors);
return internalFilterInterceptors(Interceptor.class, interceptors);
}
@Override

View File

@ -0,0 +1,44 @@
/**
* 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.core.remoting.impl;
import java.util.List;
import java.util.Map;
import org.apache.activemq.artemis.api.core.BaseInterceptor;
import org.apache.activemq.artemis.spi.core.protocol.ProtocolManager;
import org.apache.activemq.artemis.spi.core.remoting.Acceptor;
public abstract class AbstractAcceptor implements Acceptor {
protected final Map<String, ProtocolManager> protocolMap;
public AbstractAcceptor(Map<String, ProtocolManager> protocolMap) {
this.protocolMap = protocolMap;
}
/**
* This will update the list of interceptors for each ProtocolManager inside the acceptor.
* */
public void updateInterceptors(List<BaseInterceptor> incomingInterceptors, List<BaseInterceptor> outgoingInterceptors) {
for (ProtocolManager manager : protocolMap.values()) {
manager.updateInterceptors(incomingInterceptors, outgoingInterceptors);
}
}
}

View File

@ -25,28 +25,29 @@ import org.apache.activemq.artemis.api.core.ActiveMQException;
import org.apache.activemq.artemis.api.core.SimpleString;
import org.apache.activemq.artemis.api.core.client.ActiveMQClient;
import org.apache.activemq.artemis.api.core.management.CoreNotificationType;
import org.apache.activemq.artemis.core.remoting.impl.AbstractAcceptor;
import org.apache.activemq.artemis.core.security.ActiveMQPrincipal;
import org.apache.activemq.artemis.core.server.ActiveMQComponent;
import org.apache.activemq.artemis.core.server.ActiveMQMessageBundle;
import org.apache.activemq.artemis.core.server.cluster.ClusterConnection;
import org.apache.activemq.artemis.core.server.management.Notification;
import org.apache.activemq.artemis.core.server.management.NotificationService;
import org.apache.activemq.artemis.spi.core.remoting.Acceptor;
import org.apache.activemq.artemis.spi.core.protocol.ProtocolManager;
import org.apache.activemq.artemis.spi.core.remoting.BufferHandler;
import org.apache.activemq.artemis.spi.core.remoting.Connection;
import org.apache.activemq.artemis.spi.core.remoting.ConnectionLifeCycleListener;
import org.apache.activemq.artemis.spi.core.remoting.ServerConnectionLifeCycleListener;
import org.apache.activemq.artemis.utils.ConfigurationHelper;
import org.apache.activemq.artemis.utils.ExecutorFactory;
import org.apache.activemq.artemis.utils.OrderedExecutorFactory;
import org.apache.activemq.artemis.utils.TypedProperties;
public final class InVMAcceptor implements Acceptor {
public final class InVMAcceptor extends AbstractAcceptor {
private final int id;
private final BufferHandler handler;
private final ConnectionLifeCycleListener listener;
private final ServerConnectionLifeCycleListener listener;
private final ConcurrentMap<String, Connection> connections = new ConcurrentHashMap<>();
@ -72,8 +73,10 @@ public final class InVMAcceptor implements Acceptor {
final ClusterConnection clusterConnection,
final Map<String, Object> configuration,
final BufferHandler handler,
final ConnectionLifeCycleListener listener,
final ServerConnectionLifeCycleListener listener,
final Map<String, ProtocolManager> protocolMap,
final Executor threadPool) {
super(protocolMap);
this.name = name;
@ -219,7 +222,7 @@ public final class InVMAcceptor implements Acceptor {
InVMConnection inVMConnection = new InVMConnection(id, connectionID, remoteHandler, connectionListener, clientExecutor, defaultActiveMQPrincipal);
connectionListener.connectionCreated(this, inVMConnection, ActiveMQClient.DEFAULT_CORE_PROTOCOL);
connectionListener.connectionCreated(this, inVMConnection, protocolMap.get(ActiveMQClient.DEFAULT_CORE_PROTOCOL));
}
public void disconnect(final String connectionID) {
@ -249,7 +252,7 @@ public final class InVMAcceptor implements Acceptor {
this.defaultActiveMQPrincipal = defaultActiveMQPrincipal;
}
private class Listener implements ConnectionLifeCycleListener {
private class Listener implements ServerConnectionLifeCycleListener {
//private static Listener instance = new Listener();
private final InVMConnector connector;
@ -261,7 +264,7 @@ public final class InVMAcceptor implements Acceptor {
@Override
public void connectionCreated(final ActiveMQComponent component,
final Connection connection,
final String protocol) {
final ProtocolManager protocol) {
if (connections.putIfAbsent((String) connection.getID(), connection) != null) {
throw ActiveMQMessageBundle.BUNDLE.connectionExists(connection.getID());
}

View File

@ -25,7 +25,7 @@ import org.apache.activemq.artemis.spi.core.protocol.ProtocolManager;
import org.apache.activemq.artemis.spi.core.remoting.Acceptor;
import org.apache.activemq.artemis.spi.core.remoting.AcceptorFactory;
import org.apache.activemq.artemis.spi.core.remoting.BufferHandler;
import org.apache.activemq.artemis.spi.core.remoting.ConnectionLifeCycleListener;
import org.apache.activemq.artemis.spi.core.remoting.ServerConnectionLifeCycleListener;
public class InVMAcceptorFactory implements AcceptorFactory {
@ -34,10 +34,10 @@ public class InVMAcceptorFactory implements AcceptorFactory {
final ClusterConnection clusterConnection,
final Map<String, Object> configuration,
final BufferHandler handler,
final ConnectionLifeCycleListener listener,
final ServerConnectionLifeCycleListener listener,
final Executor threadPool,
final ScheduledExecutorService scheduledThreadPool,
final Map<String, ProtocolManager> protocolHandler) {
return new InVMAcceptor(name, clusterConnection, configuration, handler, listener, threadPool);
final Map<String, ProtocolManager> protocolMap) {
return new InVMAcceptor(name, clusterConnection, configuration, handler, listener, protocolMap, threadPool);
}
}

View File

@ -31,9 +31,9 @@ import org.apache.activemq.artemis.api.core.TransportConfiguration;
import org.apache.activemq.artemis.core.security.ActiveMQPrincipal;
import org.apache.activemq.artemis.core.server.ActiveMQServerLogger;
import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection;
import org.apache.activemq.artemis.spi.core.remoting.BaseConnectionLifeCycleListener;
import org.apache.activemq.artemis.spi.core.remoting.BufferHandler;
import org.apache.activemq.artemis.spi.core.remoting.Connection;
import org.apache.activemq.artemis.spi.core.remoting.ConnectionLifeCycleListener;
import org.apache.activemq.artemis.spi.core.remoting.ReadyListener;
import org.apache.activemq.artemis.utils.UUIDGenerator;
@ -43,7 +43,7 @@ public class InVMConnection implements Connection {
private final BufferHandler handler;
private final ConnectionLifeCycleListener listener;
private final BaseConnectionLifeCycleListener listener;
private final String id;
@ -64,7 +64,7 @@ public class InVMConnection implements Connection {
public InVMConnection(final int serverID,
final BufferHandler handler,
final ConnectionLifeCycleListener listener,
final BaseConnectionLifeCycleListener listener,
final Executor executor) {
this(serverID, UUIDGenerator.getInstance().generateSimpleStringUUID().toString(), handler, listener, executor);
}
@ -72,7 +72,7 @@ public class InVMConnection implements Connection {
public InVMConnection(final int serverID,
final String id,
final BufferHandler handler,
final ConnectionLifeCycleListener listener,
final BaseConnectionLifeCycleListener listener,
final Executor executor) {
this(serverID, id, handler, listener, executor, null);
}
@ -80,7 +80,7 @@ public class InVMConnection implements Connection {
public InVMConnection(final int serverID,
final String id,
final BufferHandler handler,
final ConnectionLifeCycleListener listener,
final BaseConnectionLifeCycleListener listener,
final Executor executor,
final ActiveMQPrincipal defaultActiveMQPrincipal) {
this.serverID = serverID;

View File

@ -29,7 +29,9 @@ import org.apache.activemq.artemis.core.server.ActiveMQServerLogger;
import org.apache.activemq.artemis.core.server.ActiveMQMessageBundle;
import org.apache.activemq.artemis.spi.core.remoting.AbstractConnector;
import org.apache.activemq.artemis.spi.core.remoting.Acceptor;
import org.apache.activemq.artemis.spi.core.remoting.BaseConnectionLifeCycleListener;
import org.apache.activemq.artemis.spi.core.remoting.BufferHandler;
import org.apache.activemq.artemis.spi.core.remoting.ClientConnectionLifeCycleListener;
import org.apache.activemq.artemis.spi.core.remoting.ClientProtocolManager;
import org.apache.activemq.artemis.spi.core.remoting.Connection;
import org.apache.activemq.artemis.spi.core.remoting.ConnectionLifeCycleListener;
@ -72,7 +74,7 @@ public class InVMConnector extends AbstractConnector {
private final BufferHandler handler;
private final ConnectionLifeCycleListener listener;
private final BaseConnectionLifeCycleListener listener;
private final InVMAcceptor acceptor;
@ -86,7 +88,7 @@ public class InVMConnector extends AbstractConnector {
public InVMConnector(final Map<String, Object> configuration,
final BufferHandler handler,
final ConnectionLifeCycleListener listener,
final ClientConnectionLifeCycleListener listener,
final Executor closeExecutor,
final Executor threadPool,
ClientProtocolManager protocolManager) {
@ -181,11 +183,11 @@ public class InVMConnector extends AbstractConnector {
// This may be an injection point for mocks on tests
protected Connection internalCreateConnection(final BufferHandler handler,
final ConnectionLifeCycleListener listener,
final ClientConnectionLifeCycleListener listener,
final Executor serverExecutor) {
// No acceptor on a client connection
InVMConnection inVMConnection = new InVMConnection(id, handler, listener, serverExecutor);
listener.connectionCreated(null, inVMConnection, protocolManager.getName());
listener.connectionCreated(null, inVMConnection, protocolManager);
return inVMConnection;
}
@ -195,17 +197,23 @@ public class InVMConnector extends AbstractConnector {
return id == serverId;
}
private class Listener implements ConnectionLifeCycleListener {
private class Listener implements ClientConnectionLifeCycleListener {
@Override
public void connectionCreated(final ActiveMQComponent component,
final Connection connection,
final String protocol) {
final ClientProtocolManager protocol) {
if (connections.putIfAbsent((String) connection.getID(), connection) != null) {
throw ActiveMQMessageBundle.BUNDLE.connectionExists(connection.getID());
}
listener.connectionCreated(component, connection, protocol);
if (listener instanceof ConnectionLifeCycleListener) {
listener.connectionCreated(component, connection, protocol.getName());
}
else {
listener.connectionCreated(component, connection, protocol);
}
}
@Override

View File

@ -21,8 +21,8 @@ import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledExecutorService;
import org.apache.activemq.artemis.spi.core.remoting.BufferHandler;
import org.apache.activemq.artemis.spi.core.remoting.ClientConnectionLifeCycleListener;
import org.apache.activemq.artemis.spi.core.remoting.ClientProtocolManager;
import org.apache.activemq.artemis.spi.core.remoting.ConnectionLifeCycleListener;
import org.apache.activemq.artemis.spi.core.remoting.Connector;
import org.apache.activemq.artemis.spi.core.remoting.ConnectorFactory;
@ -31,7 +31,7 @@ public class InVMConnectorFactory implements ConnectorFactory {
@Override
public Connector createConnector(final Map<String, Object> configuration,
final BufferHandler handler,
final ConnectionLifeCycleListener listener,
final ClientConnectionLifeCycleListener listener,
final Executor closeExecutor,
final Executor threadPool,
final ScheduledExecutorService scheduledThreadPool,

View File

@ -62,6 +62,7 @@ import org.apache.activemq.artemis.api.core.TransportConfiguration;
import org.apache.activemq.artemis.api.core.management.CoreNotificationType;
import org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl;
import org.apache.activemq.artemis.core.protocol.ProtocolHandler;
import org.apache.activemq.artemis.core.remoting.impl.AbstractAcceptor;
import org.apache.activemq.artemis.core.remoting.impl.ssl.SSLSupport;
import org.apache.activemq.artemis.core.security.ActiveMQPrincipal;
import org.apache.activemq.artemis.core.server.ActiveMQComponent;
@ -71,18 +72,17 @@ import org.apache.activemq.artemis.core.server.cluster.ClusterConnection;
import org.apache.activemq.artemis.core.server.management.Notification;
import org.apache.activemq.artemis.core.server.management.NotificationService;
import org.apache.activemq.artemis.spi.core.protocol.ProtocolManager;
import org.apache.activemq.artemis.spi.core.remoting.Acceptor;
import org.apache.activemq.artemis.spi.core.remoting.BufferHandler;
import org.apache.activemq.artemis.spi.core.remoting.Connection;
import org.apache.activemq.artemis.spi.core.remoting.ConnectionLifeCycleListener;
import org.apache.activemq.artemis.spi.core.remoting.ServerConnectionLifeCycleListener;
import org.apache.activemq.artemis.utils.ConfigurationHelper;
import org.apache.activemq.artemis.utils.ActiveMQThreadFactory;
import org.apache.activemq.artemis.utils.TypedProperties;
/**
* A Netty TCP Acceptor that supports SSL
* A Netty TCP Acceptor that is embedding Netty.
*/
public class NettyAcceptor implements Acceptor {
public class NettyAcceptor extends AbstractAcceptor {
static {
// Disable resource leak detection for performance reasons by default
@ -107,7 +107,7 @@ public class NettyAcceptor implements Acceptor {
private final BufferHandler handler;
private final ConnectionLifeCycleListener listener;
private final ServerConnectionLifeCycleListener listener;
private final boolean sslEnabled;
@ -173,9 +173,11 @@ public class NettyAcceptor implements Acceptor {
final ClusterConnection clusterConnection,
final Map<String, Object> configuration,
final BufferHandler handler,
final ConnectionLifeCycleListener listener,
final ServerConnectionLifeCycleListener listener,
final ScheduledExecutorService scheduledThreadPool,
final Map<String, ProtocolManager> protocolMap) {
super(protocolMap);
this.name = name;
this.clusterConnection = clusterConnection;
@ -604,7 +606,7 @@ public class NettyAcceptor implements Acceptor {
ActiveMQServerChannelHandler(final ChannelGroup group,
final BufferHandler handler,
final ConnectionLifeCycleListener listener) {
final ServerConnectionLifeCycleListener listener) {
super(group, handler, listener);
}
@ -618,7 +620,7 @@ public class NettyAcceptor implements Acceptor {
NettyServerConnection nc = new NettyServerConnection(configuration, ctx.channel(), connectionListener, !httpEnabled && batchDelay > 0, directDeliver);
connectionListener.connectionCreated(NettyAcceptor.this, nc, protocol);
connectionListener.connectionCreated(NettyAcceptor.this, nc, protocolHandler.getProtocol(protocol));
SslHandler sslHandler = ctx.pipeline().get(SslHandler.class);
if (sslHandler != null) {
@ -648,12 +650,12 @@ public class NettyAcceptor implements Acceptor {
}
}
private class Listener implements ConnectionLifeCycleListener {
private class Listener implements ServerConnectionLifeCycleListener {
@Override
public void connectionCreated(final ActiveMQComponent component,
final Connection connection,
final String protocol) {
final ProtocolManager protocol) {
if (connections.putIfAbsent(connection.getID(), (NettyServerConnection) connection) != null) {
throw ActiveMQMessageBundle.BUNDLE.connectionExists(connection.getID());
}

View File

@ -25,7 +25,7 @@ import org.apache.activemq.artemis.spi.core.protocol.ProtocolManager;
import org.apache.activemq.artemis.spi.core.remoting.Acceptor;
import org.apache.activemq.artemis.spi.core.remoting.AcceptorFactory;
import org.apache.activemq.artemis.spi.core.remoting.BufferHandler;
import org.apache.activemq.artemis.spi.core.remoting.ConnectionLifeCycleListener;
import org.apache.activemq.artemis.spi.core.remoting.ServerConnectionLifeCycleListener;
public class NettyAcceptorFactory implements AcceptorFactory {
@ -34,7 +34,7 @@ public class NettyAcceptorFactory implements AcceptorFactory {
final ClusterConnection connection,
final Map<String, Object> configuration,
final BufferHandler handler,
final ConnectionLifeCycleListener listener,
final ServerConnectionLifeCycleListener listener,
final Executor threadPool,
final ScheduledExecutorService scheduledThreadPool,
final Map<String, ProtocolManager> protocolMap) {

View File

@ -21,13 +21,13 @@ import java.util.Map;
import io.netty.channel.Channel;
import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
import org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper;
import org.apache.activemq.artemis.spi.core.remoting.ConnectionLifeCycleListener;
import org.apache.activemq.artemis.spi.core.remoting.ServerConnectionLifeCycleListener;
public class NettyServerConnection extends NettyConnection {
public NettyServerConnection(Map<String, Object> configuration,
Channel channel,
ConnectionLifeCycleListener listener,
ServerConnectionLifeCycleListener listener,
boolean batchingEnabled,
boolean directDeliver) {
super(configuration, channel, listener, batchingEnabled, directDeliver);

View File

@ -65,12 +65,12 @@ import org.apache.activemq.artemis.spi.core.remoting.Acceptor;
import org.apache.activemq.artemis.spi.core.remoting.AcceptorFactory;
import org.apache.activemq.artemis.spi.core.remoting.BufferHandler;
import org.apache.activemq.artemis.spi.core.remoting.Connection;
import org.apache.activemq.artemis.spi.core.remoting.ConnectionLifeCycleListener;
import org.apache.activemq.artemis.spi.core.remoting.ServerConnectionLifeCycleListener;
import org.apache.activemq.artemis.utils.ActiveMQThreadFactory;
import org.apache.activemq.artemis.utils.ConfigurationHelper;
import org.apache.activemq.artemis.utils.ReusableLatch;
public class RemotingServiceImpl implements RemotingService, ConnectionLifeCycleListener {
public class RemotingServiceImpl implements RemotingService, ServerConnectionLifeCycleListener {
// Constants -----------------------------------------------------
private static final boolean isTrace = ActiveMQServerLogger.LOGGER.isTraceEnabled();
@ -107,7 +107,7 @@ public class RemotingServiceImpl implements RemotingService, ConnectionLifeCycle
private final ClusterManager clusterManager;
private final Map<String, ProtocolManager> protocolMap = new ConcurrentHashMap();
private final Map<String, ProtocolManagerFactory> protocolMap = new ConcurrentHashMap();
private ActiveMQPrincipal defaultInvmSecurityPrincipal;
@ -144,7 +144,8 @@ public class RemotingServiceImpl implements RemotingService, ConnectionLifeCycle
this.flushExecutor = flushExecutor;
ActiveMQServerLogger.LOGGER.addingProtocolSupport(coreProtocolManagerFactory.getProtocols()[0], coreProtocolManagerFactory.getModuleName());
this.protocolMap.put(coreProtocolManagerFactory.getProtocols()[0], coreProtocolManagerFactory.createProtocolManager(server, coreProtocolManagerFactory.filterInterceptors(incomingInterceptors), coreProtocolManagerFactory.filterInterceptors(outgoingInterceptors)));
// this.protocolMap.put(coreProtocolManagerFactory.getProtocols()[0], coreProtocolManagerFactory.createProtocolManager(server, coreProtocolManagerFactory.filterInterceptors(incomingInterceptors), coreProtocolManagerFactory.filterInterceptors(outgoingInterceptors)));
this.protocolMap.put(coreProtocolManagerFactory.getProtocols()[0], coreProtocolManagerFactory);
if (config.isResolveProtocols()) {
resolveProtocols(server, this.getClass().getClassLoader());
@ -157,9 +158,10 @@ public class RemotingServiceImpl implements RemotingService, ConnectionLifeCycle
if (protocolManagerFactories != null) {
for (ProtocolManagerFactory protocolManagerFactory : protocolManagerFactories) {
String[] protocols = protocolManagerFactory.getProtocols();
for (String protocol : protocols) {
ActiveMQServerLogger.LOGGER.addingProtocolSupport(protocol, protocolManagerFactory.getModuleName());
protocolMap.put(protocol, protocolManagerFactory.createProtocolManager(server, incomingInterceptors, outgoingInterceptors));
for (String protocolName : protocols) {
ActiveMQServerLogger.LOGGER.addingProtocolSupport(protocolName, protocolManagerFactory.getModuleName());
// protocolMap.put(protocol, protocolManagerFactory.createProtocolManager(server, incomingInterceptors, outgoingInterceptors));
protocolMap.put(protocolName, protocolManagerFactory);
}
}
}
@ -172,7 +174,8 @@ public class RemotingServiceImpl implements RemotingService, ConnectionLifeCycle
String[] protocols = next.getProtocols();
for (String protocol : protocols) {
ActiveMQServerLogger.LOGGER.addingProtocolSupport(protocol, next.getModuleName());
protocolMap.put(protocol, next.createProtocolManager(server, next.filterInterceptors(incomingInterceptors), next.filterInterceptors(outgoingInterceptors)));
// protocolMap.put(protocol, next.createProtocolManager(server, next.filterInterceptors(incomingInterceptors), next.filterInterceptors(outgoingInterceptors)));
protocolMap.put(protocol, next);
}
}
}
@ -210,45 +213,35 @@ public class RemotingServiceImpl implements RemotingService, ConnectionLifeCycle
try {
AcceptorFactory factory = server.getServiceRegistry().getAcceptorFactory(info.getName(), info.getFactoryClassName());
Map<String, ProtocolManager> supportedProtocols = new ConcurrentHashMap();
Map<String, ProtocolManagerFactory> selectedProtocolFactories = new ConcurrentHashMap();
@SuppressWarnings("deprecation")
String protocol = ConfigurationHelper.getStringProperty(TransportConstants.PROTOCOL_PROP_NAME, null, info.getParams());
if (protocol != null) {
ActiveMQServerLogger.LOGGER.warnDeprecatedProtocol();
ProtocolManager protocolManager = protocolMap.get(protocol);
if (protocolManager == null) {
ActiveMQServerLogger.LOGGER.noProtocolManagerFound(protocol, info.toString());
}
else {
supportedProtocols.put(protocol, protocolManager);
}
locateProtocols(protocol, info, selectedProtocolFactories);
}
String protocols = ConfigurationHelper.getStringProperty(TransportConstants.PROTOCOLS_PROP_NAME, null, info.getParams());
if (protocols != null) {
String[] actualProtocols = protocols.split(",");
if (actualProtocols != null) {
for (String actualProtocol : actualProtocols) {
ProtocolManager protocolManager = protocolMap.get(actualProtocol);
if (protocolManager == null) {
ActiveMQServerLogger.LOGGER.noProtocolManagerFound(actualProtocol, info.toString());
}
else {
supportedProtocols.put(actualProtocol, protocolManager);
}
}
}
locateProtocols(protocols, info, selectedProtocolFactories);
}
ClusterConnection clusterConnection = lookupClusterConnection(info);
Acceptor acceptor = factory.createAcceptor(info.getName(), clusterConnection, info.getParams(), new DelegatingBufferHandler(), this, threadPool, scheduledThreadPool, supportedProtocols.isEmpty() ? protocolMap : supportedProtocols);
// If empty: we get the default list
if (selectedProtocolFactories.isEmpty()) {
selectedProtocolFactories = protocolMap;
}
Map<String, ProtocolManager> selectedProtocols = new ConcurrentHashMap();
for (Map.Entry<String, ProtocolManagerFactory> entry: selectedProtocolFactories.entrySet()) {
selectedProtocols.put(entry.getKey(), entry.getValue().createProtocolManager(server, info.getExtraParams(), incomingInterceptors, outgoingInterceptors));
}
Acceptor acceptor = factory.createAcceptor(info.getName(), clusterConnection, info.getParams(), new DelegatingBufferHandler(), this, threadPool, scheduledThreadPool, selectedProtocols);
if (defaultInvmSecurityPrincipal != null && acceptor.isUnsecurable()) {
acceptor.setDefaultActiveMQPrincipal(defaultInvmSecurityPrincipal);
@ -280,6 +273,25 @@ public class RemotingServiceImpl implements RemotingService, ConnectionLifeCycle
started = true;
}
private void locateProtocols(String protocolList,
Object transportConfig,
Map<String, ProtocolManagerFactory> protocolMap) {
String[] protocolsSplit = protocolList.split(",");
if (protocolsSplit != null) {
for (String protocolItem : protocolsSplit) {
ProtocolManagerFactory protocolManagerFactory = protocolMap.get(protocolItem);
if (protocolManagerFactory == null) {
ActiveMQServerLogger.LOGGER.noProtocolManagerFound(protocolItem, transportConfig.toString());
}
else {
protocolMap.put(protocolItem, protocolManagerFactory);
}
}
}
}
@Override
public synchronized void startAcceptors() throws Exception {
if (isStarted()) {
@ -469,25 +481,19 @@ public class RemotingServiceImpl implements RemotingService, ConnectionLifeCycle
// ConnectionLifeCycleListener implementation -----------------------------------
private ProtocolManager getProtocolManager(String protocol) {
private ProtocolManagerFactory getProtocolManager(String protocol) {
return protocolMap.get(protocol);
}
@Override
public void connectionCreated(final ActiveMQComponent component,
final Connection connection,
final String protocol) {
final ProtocolManager protocol) {
if (server == null) {
throw new IllegalStateException("Unable to create connection, server hasn't finished starting up");
}
ProtocolManager pmgr = this.getProtocolManager(protocol.toString());
if (pmgr == null) {
throw ActiveMQMessageBundle.BUNDLE.unknownProtocol(protocol);
}
ConnectionEntry entry = pmgr.createConnectionEntry((Acceptor) component, connection);
ConnectionEntry entry = protocol.createConnectionEntry((Acceptor) component, connection);
if (isTrace) {
ActiveMQServerLogger.LOGGER.trace("Connection created " + connection);
@ -720,10 +726,9 @@ public class RemotingServiceImpl implements RemotingService, ConnectionLifeCycle
}
protected void updateProtocols() {
for (ProtocolManager<?> protocolManager : this.protocolMap.values()) {
protocolManager.updateInterceptors(incomingInterceptors, outgoingInterceptors);
for (Acceptor acceptor : this.acceptors.values()) {
acceptor.updateInterceptors(incomingInterceptors, outgoingInterceptors);
}
}
}

View File

@ -16,7 +16,7 @@
*/
package org.apache.activemq.artemis.core.server.cluster.impl;
import org.apache.activemq.artemis.utils.uri.URISchema;
import org.apache.activemq.artemis.utils.uri.BeanSupport;
import org.apache.commons.beanutils.Converter;
public enum MessageLoadBalancingType {
@ -24,7 +24,7 @@ public enum MessageLoadBalancingType {
static {
// for URI support on ClusterConnection
URISchema.registerConverter(new MessageLoadBalancingTypeConverter(), MessageLoadBalancingType.class);
BeanSupport.registerConverter(new MessageLoadBalancingTypeConverter(), MessageLoadBalancingType.class);
}
static class MessageLoadBalancingTypeConverter implements Converter {

View File

@ -34,7 +34,7 @@ public abstract class AbstractProtocolManagerFactory<P extends BaseInterceptor>
* @param listIn
* @return
*/
protected List<P> filterInterceptors(Class<P> type, List<? extends BaseInterceptor> listIn) {
protected List<P> internalFilterInterceptors(Class<P> type, List<? extends BaseInterceptor> listIn) {
if (listIn == null) {
return Collections.emptyList();
}

View File

@ -17,6 +17,7 @@
package org.apache.activemq.artemis.spi.core.protocol;
import java.util.List;
import java.util.Map;
import org.apache.activemq.artemis.api.core.BaseInterceptor;
import org.apache.activemq.artemis.core.server.ActiveMQServer;
@ -34,8 +35,9 @@ public interface ProtocolManagerFactory<P extends BaseInterceptor> {
* @return
*/
ProtocolManager createProtocolManager(ActiveMQServer server,
List<P> incomingInterceptors,
List<P> outgoingInterceptors);
Map<String, Object> parameters,
List<BaseInterceptor> incomingInterceptors,
List<BaseInterceptor> outgoingInterceptors) throws Exception;
/**
* This should get the entire list and only return the ones this factory can deal with *

View File

@ -16,8 +16,10 @@
*/
package org.apache.activemq.artemis.spi.core.remoting;
import java.util.List;
import java.util.Map;
import org.apache.activemq.artemis.api.core.BaseInterceptor;
import org.apache.activemq.artemis.core.security.ActiveMQPrincipal;
import org.apache.activemq.artemis.core.server.ActiveMQComponent;
import org.apache.activemq.artemis.core.server.cluster.ClusterConnection;
@ -38,6 +40,11 @@ public interface Acceptor extends ActiveMQComponent {
*/
void pause();
/**
* This will update the list of interceptors for each ProtocolManager inside the acceptor.
* */
void updateInterceptors(List<BaseInterceptor> incomingInterceptors, List<BaseInterceptor> outgoingInterceptors);
/**
* @return the cluster connection associated with this Acceptor
*/

View File

@ -46,7 +46,7 @@ public interface AcceptorFactory {
ClusterConnection clusterConnection,
Map<String, Object> configuration,
BufferHandler handler,
ConnectionLifeCycleListener listener,
ServerConnectionLifeCycleListener listener,
Executor threadPool,
ScheduledExecutorService scheduledThreadPool,
Map<String, ProtocolManager> protocolMap);

View File

@ -16,15 +16,7 @@
*/
package org.apache.activemq.artemis.spi.core.remoting;
public interface ServerConnectionLifeCycleListener extends ConnectionLifeCycleListener {
import org.apache.activemq.artemis.spi.core.protocol.ProtocolManager;
/**
* This method is used both by client connector creation and server connection creation through acceptors.
* the acceptor will be set to null on client operations
*
* @param acceptor The acceptor here will be always null on a client connection created event.
* @param connection the connection that has been created
* @param protocol the protocol to use
*/
void connectionCreated(Acceptor acceptor, Connection connection, String protocol);
public interface ServerConnectionLifeCycleListener extends BaseConnectionLifeCycleListener<ProtocolManager> {
}

View File

@ -21,6 +21,7 @@ import java.net.URI;
import java.util.Map;
import org.apache.activemq.artemis.core.config.ClusterConnectionConfiguration;
import org.apache.activemq.artemis.utils.uri.BeanSupport;
import org.apache.activemq.artemis.utils.uri.URISupport;
public class ClusterConnectionMulticastSchema extends ClusterConnectionStaticSchema {
@ -40,7 +41,7 @@ public class ClusterConnectionMulticastSchema extends ClusterConnectionStaticSch
else {
bean.setDiscoveryGroupName(uri.getHost());
Map<String, String> parameters = URISupport.parseParameters(uri);
setData(uri, bean, parameters);
BeanSupport.setData(uri, bean, parameters);
}
}

View File

@ -21,6 +21,7 @@ import java.net.URI;
import java.util.Map;
import org.apache.activemq.artemis.core.config.ClusterConnectionConfiguration;
import org.apache.activemq.artemis.utils.uri.BeanSupport;
import org.apache.activemq.artemis.utils.uri.URISchema;
import org.apache.activemq.artemis.utils.uri.URISupport;
@ -50,7 +51,7 @@ public class ClusterConnectionStaticSchema extends URISchema<ClusterConnectionCo
URISupport.CompositeData compositeData = URISupport.parseComposite(uri);
bean.setCompositeMembers(compositeData);
setData(uri, bean, compositeData.getParameters());
BeanSupport.setData(uri, bean, compositeData.getParameters());
}

View File

@ -0,0 +1,39 @@
/**
* 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.uri;
import java.net.URI;
import java.util.List;
import org.apache.activemq.artemis.api.core.TransportConfiguration;
import org.junit.Assert;
import org.junit.Test;
public class AcceptorParserTest {
@Test
public void testAcceptor() throws Exception {
AcceptorTransportConfigurationParser parser = new AcceptorTransportConfigurationParser();
List<TransportConfiguration> configs = parser.newObject(new URI("tcp://localhost:8080?tcpSendBufferSize=1048576&tcpReceiveBufferSize=1048576&protocols=openwire&banana=x"), "test");
for (TransportConfiguration config : configs) {
System.out.println("config:" + config);
Assert.assertTrue(config.getExtraParams().get("banana").equals("x"));
}
}
}

View File

@ -41,7 +41,6 @@ public class ClusterConnectionConfigurationTest {
ClusterConnectionConfigurationParser parser = new ClusterConnectionConfigurationParser();
ClusterConnectionConfiguration configuration = parser.newObject(new URI("static://(tcp://localhost:6556,tcp://localhost:6557)?minLargeMessageSize=132;messageLoadBalancingType=OFF"), null);
Assert.assertEquals(132, configuration.getMinLargeMessageSize());
Assert.assertEquals(MessageLoadBalancingType.OFF, configuration.getMessageLoadBalancingType());
Assert.assertEquals(2, configuration.getCompositeMembers().getComponents().length);
Assert.assertEquals("tcp://localhost:6556", configuration.getCompositeMembers().getComponents()[0].toString());
Assert.assertEquals("tcp://localhost:6557", configuration.getCompositeMembers().getComponents()[1].toString());

View File

@ -39,7 +39,7 @@ under the License.
<dependency>
<groupId>org.apache.qpid</groupId>
<artifactId>qpid-jms-client</artifactId>
<version>0.5.0</version>
<version>0.7.0</version>
</dependency>
</dependencies>

View File

@ -81,7 +81,7 @@
${project.version}(${activemq.version.incrementingVersion})
</ActiveMQ-Version>
<resteasy.version>3.0.14.Final</resteasy.version>
<proton.version>0.10</proton.version>
<proton.version>0.12.0</proton.version>
<activemq5-version>5.12.0</activemq5-version>
<fuse.mqtt.client.version>1.10</fuse.mqtt.client.version>
<apache.derby.version>10.11.1.1</apache.derby.version>

View File

@ -188,7 +188,7 @@
<dependency>
<groupId>org.apache.qpid</groupId>
<artifactId>qpid-jms-client</artifactId>
<version>0.5.0</version>
<version>0.7.0</version>
</dependency>
<dependency>
<groupId>org.apache.qpid</groupId>

View File

@ -26,10 +26,11 @@ import org.apache.activemq.artemis.api.core.ActiveMQException;
import org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptor;
import org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptorFactory;
import org.apache.activemq.artemis.core.server.ActiveMQComponent;
import org.apache.activemq.artemis.spi.core.protocol.ProtocolManager;
import org.apache.activemq.artemis.spi.core.remoting.Acceptor;
import org.apache.activemq.artemis.spi.core.remoting.BufferHandler;
import org.apache.activemq.artemis.spi.core.remoting.Connection;
import org.apache.activemq.artemis.spi.core.remoting.ConnectionLifeCycleListener;
import org.apache.activemq.artemis.spi.core.remoting.ServerConnectionLifeCycleListener;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
import org.junit.Assert;
import org.junit.Test;
@ -48,7 +49,7 @@ public class NettyAcceptorFactoryTest extends ActiveMQTestBase {
}
};
ConnectionLifeCycleListener listener = new ConnectionLifeCycleListener() {
ServerConnectionLifeCycleListener listener = new ServerConnectionLifeCycleListener() {
@Override
public void connectionException(final Object connectionID, final ActiveMQException me) {
@ -61,7 +62,7 @@ public class NettyAcceptorFactoryTest extends ActiveMQTestBase {
@Override
public void connectionCreated(ActiveMQComponent component,
final Connection connection,
final String protocol) {
final ProtocolManager protocol) {
}
@Override

View File

@ -25,13 +25,14 @@ import java.util.concurrent.TimeUnit;
import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration;
import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
import org.apache.activemq.artemis.api.core.ActiveMQException;
import org.apache.activemq.artemis.spi.core.protocol.ProtocolManager;
import org.apache.activemq.artemis.spi.core.remoting.ServerConnectionLifeCycleListener;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
import org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptor;
import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants;
import org.apache.activemq.artemis.core.server.ActiveMQComponent;
import org.apache.activemq.artemis.spi.core.remoting.BufferHandler;
import org.apache.activemq.artemis.spi.core.remoting.Connection;
import org.apache.activemq.artemis.spi.core.remoting.ConnectionLifeCycleListener;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@ -72,7 +73,7 @@ public class NettyAcceptorTest extends ActiveMQTestBase {
};
Map<String, Object> params = new HashMap<>();
ConnectionLifeCycleListener listener = new ConnectionLifeCycleListener() {
ServerConnectionLifeCycleListener listener = new ServerConnectionLifeCycleListener() {
@Override
public void connectionException(final Object connectionID, final ActiveMQException me) {
@ -85,7 +86,7 @@ public class NettyAcceptorTest extends ActiveMQTestBase {
@Override
public void connectionCreated(final ActiveMQComponent component,
final Connection connection,
final String protocol) {
final ProtocolManager protocol) {
}
@Override

View File

@ -16,10 +16,12 @@
*/
package org.apache.activemq.artemis.tests.unit.core.remoting.server.impl.fake;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledExecutorService;
import org.apache.activemq.artemis.api.core.BaseInterceptor;
import org.apache.activemq.artemis.core.security.ActiveMQPrincipal;
import org.apache.activemq.artemis.core.server.cluster.ClusterConnection;
import org.apache.activemq.artemis.core.server.management.NotificationService;
@ -27,7 +29,7 @@ import org.apache.activemq.artemis.spi.core.protocol.ProtocolManager;
import org.apache.activemq.artemis.spi.core.remoting.Acceptor;
import org.apache.activemq.artemis.spi.core.remoting.AcceptorFactory;
import org.apache.activemq.artemis.spi.core.remoting.BufferHandler;
import org.apache.activemq.artemis.spi.core.remoting.ConnectionLifeCycleListener;
import org.apache.activemq.artemis.spi.core.remoting.ServerConnectionLifeCycleListener;
public class FakeAcceptorFactory implements AcceptorFactory {
@ -38,7 +40,7 @@ public class FakeAcceptorFactory implements AcceptorFactory {
ClusterConnection clusterConnection,
Map<String, Object> configuration,
BufferHandler handler,
ConnectionLifeCycleListener listener,
ServerConnectionLifeCycleListener listener,
Executor threadPool,
ScheduledExecutorService scheduledThreadPool,
Map<String, ProtocolManager> protocolMap) {
@ -57,6 +59,11 @@ public class FakeAcceptorFactory implements AcceptorFactory {
}
@Override
public void updateInterceptors(List<BaseInterceptor> incomingInterceptors,
List<BaseInterceptor> outgoingInterceptors) {
}
@Override
public ClusterConnection getClusterConnection() {
return null;