All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.activemq.artemis.uri.TCPTransportConfigurationSchema Maven / Gradle / Ivy

/*
 * 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.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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.SchemaConstants;
import org.apache.activemq.artemis.utils.uri.URISchema;

public class TCPTransportConfigurationSchema extends AbstractTransportConfigurationSchema {

   private final Set allowableProperties;

   public TCPTransportConfigurationSchema(Set allowableProperties) {
      this.allowableProperties = allowableProperties;
   }

   @Override
   public String getSchemaName() {
      return SchemaConstants.TCP;
   }

   @Override
   protected List internalNewObject(URI uri,
                                                            Map query,
                                                            String name) throws Exception {
      return getTransportConfigurations(uri, query, allowableProperties, name, getFactoryName(uri));
   }

   @Override
   protected URI internalNewURI(List bean) throws Exception {
      return null;
   }

   public static List getTransportConfigurations(URI uri,
                                                                         Map query,
                                                                         Set allowableProperties,
                                                                         String name,
                                                                         String factoryName) throws URISyntaxException {
      HashMap props = new HashMap<>();

      URISchema.setData(uri, props, allowableProperties, query);
      List transportConfigurations = new ArrayList<>();

      transportConfigurations.add(new TransportConfiguration(factoryName, props, name));
      String connectors = uri.getFragment();

      if (connectors != null && !connectors.trim().isEmpty()) {
         String[] split = connectors.split(",");
         for (String s : split) {
            URI extraUri = new URI(s);
            HashMap newProps = new HashMap<>();
            URISchema.setData(extraUri, newProps, allowableProperties, query);
            URISchema.setData(extraUri, newProps, allowableProperties, URISchema.parseQuery(extraUri.getQuery(), null));
            transportConfigurations.add(new TransportConfiguration(factoryName, newProps, name + ":" + extraUri.toString()));
         }
      }
      return transportConfigurations;
   }

   protected String getFactoryName(URI uri) {
      //here for backwards compatibility
      if (uri.getPath() != null && uri.getPath().contains("hornetq")) {
         return "org.hornetq.core.remoting.impl.netty.NettyConnectorFactory";
      }
      return NettyConnectorFactory.class.getName();
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy