org.apache.qpid.jms.provider.amqp.AmqpConnectionProperties Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of qpid-jms-client Show documentation
Show all versions of qpid-jms-client Show documentation
The core JMS Client implementation
/*
* 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.qpid.jms.provider.amqp;
import static org.apache.qpid.jms.provider.amqp.AmqpSupport.ANONYMOUS_RELAY;
import static org.apache.qpid.jms.provider.amqp.AmqpSupport.CONNECTION_OPEN_FAILED;
import static org.apache.qpid.jms.provider.amqp.AmqpSupport.DELAYED_DELIVERY;
import static org.apache.qpid.jms.provider.amqp.AmqpSupport.FAILOVER_SERVER_LIST;
import static org.apache.qpid.jms.provider.amqp.AmqpSupport.QUEUE_PREFIX;
import static org.apache.qpid.jms.provider.amqp.AmqpSupport.SHARED_SUBS;
import static org.apache.qpid.jms.provider.amqp.AmqpSupport.TOPIC_PREFIX;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.apache.qpid.jms.meta.JmsConnectionInfo;
import org.apache.qpid.proton.amqp.Symbol;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Class used to examine the capabilities and connection properties of the
* remote connection and provide that information to the client code in a
* simpler and more easy to digest manner.
*/
public class AmqpConnectionProperties {
private static final Logger LOG = LoggerFactory.getLogger(AmqpConnectionProperties.class);
private final JmsConnectionInfo connectionInfo;
private final AmqpProvider provider;
private boolean delayedDeliverySupported = false;
private boolean anonymousRelaySupported = false;
private boolean sharedSubsSupported = false;
private boolean connectionOpenFailed = false;
private final List failoverServerList = new ArrayList<>();
/**
* Creates a new instance of this class with default values read from the
* given JmsConnectionInfo object.
*
* @param connectionInfo
* the JmsConnectionInfo object used to populate defaults.
* @param provider
* the provider instance associated with this object
*/
public AmqpConnectionProperties(JmsConnectionInfo connectionInfo, AmqpProvider provider) {
this.connectionInfo = connectionInfo;
this.provider = provider;
}
/**
* Configure the properties using values provided from the remote peer.
*
* @param capabilities
* the capabilities offered by the remote connection.
* @param properties
* the properties offered by the remote connection.
*/
public void initialize(Symbol[] capabilities, Map properties) {
if (capabilities != null) {
processCapabilities(capabilities);
}
if (properties != null) {
processProperties(properties);
}
}
protected void processCapabilities(Symbol[] capabilities) {
List list = Arrays.asList(capabilities);
if (list.contains(ANONYMOUS_RELAY)) {
anonymousRelaySupported = true;
}
if (list.contains(DELAYED_DELIVERY)) {
delayedDeliverySupported = true;
}
if (list.contains(SHARED_SUBS)) {
sharedSubsSupported = true;
}
}
@SuppressWarnings("unchecked")
protected void processProperties(Map properties) {
if (properties.containsKey(QUEUE_PREFIX)) {
Object o = properties.get(QUEUE_PREFIX);
if (o instanceof String) {
LOG.trace("Remote sent Queue prefix value of: {}", o);
connectionInfo.setQueuePrefix((String) o);
}
}
if (properties.containsKey(TOPIC_PREFIX)) {
Object o = properties.get(TOPIC_PREFIX);
if (o instanceof String) {
LOG.trace("Remote sent Topic prefix value of: {}", o);
connectionInfo.setTopicPrefix((String) o);
}
}
if (properties.containsKey(CONNECTION_OPEN_FAILED)) {
LOG.trace("Remote sent Connection Establishment Failed marker.");
connectionOpenFailed = true;
}
if (properties.containsKey(FAILOVER_SERVER_LIST)) {
LOG.trace("Remote sent Failover Server List.");
Object o = properties.get(FAILOVER_SERVER_LIST);
if (o instanceof List) {
for (Map redirection : (List