From commits-return-20476-archive-asf-public=cust-asf.ponee.io@pulsar.apache.org Mon Jan 14 20:12:41 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 9966F180675 for ; Mon, 14 Jan 2019 20:12:40 +0100 (CET) Received: (qmail 69261 invoked by uid 500); 14 Jan 2019 19:12:39 -0000 Mailing-List: contact commits-help@pulsar.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@pulsar.apache.org Delivered-To: mailing list commits@pulsar.apache.org Received: (qmail 69252 invoked by uid 99); 14 Jan 2019 19:12:39 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Jan 2019 19:12:39 +0000 From: GitBox To: commits@pulsar.apache.org Subject: [GitHub] ivankelly commented on a change in pull request #3249: [client] Issue 3218: Support specifying multiple hosts in pulsar service url and web url Message-ID: <154749315915.17631.7127795678742488624.gitbox@gitbox.apache.org> Date: Mon, 14 Jan 2019 19:12:39 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit ivankelly commented on a change in pull request #3249: [client] Issue 3218: Support specifying multiple hosts in pulsar service url and web url URL: https://github.com/apache/pulsar/pull/3249#discussion_r247620616 ########## File path: pulsar-common/src/main/java/org/apache/pulsar/common/net/ServiceURI.java ########## @@ -0,0 +1,205 @@ +/** + * 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.pulsar.common.net; + + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.base.CharMatcher; +import com.google.common.base.Splitter; +import com.google.common.base.Strings; +import java.net.URI; +import java.util.List; +import java.util.stream.Collectors; +import lombok.AccessLevel; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang.StringUtils; + +/** + * ServiceURI represents service uri within pulsar cluster. + * + *

This file is based on + * {@link https://github.com/apache/bookkeeper/blob/master/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/net/ServiceURI.java} + */ +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@EqualsAndHashCode +public class ServiceURI { + + private static final String BINARY_SERVICE = "pulsar"; + private static final String HTTP_SERVICE = "http"; + private static final String HTTPS_SERVICE = "https"; + private static final String SSL_SERVICE = "ssl"; + + private static final int BINARY_PORT = 6650; + private static final int BINARY_TLS_PORT = 6651; + private static final int HTTP_PORT = 8080; + private static final int HTTPS_PORT = 8443; + + /** + * Create a service uri instance from a uri string. + * + * @param uriStr service uri string + * @return a service uri instance + * @throws NullPointerException if {@code uriStr} is null + * @throws IllegalArgumentException if the given string violates RFC 2396 + */ + public static ServiceURI create(String uriStr) { + checkNotNull(uriStr, "service uri string is null"); + + // a service uri first should be a valid java.net.URI + URI uri = URI.create(uriStr); + + return create(uri); + } + + /** + * Create a service uri instance from a {@link URI} instance. + * + * @param uri {@link URI} instance + * @return a service uri instance + * @throws NullPointerException if {@code uriStr} is null + * @throws IllegalArgumentException if the given string violates RFC 2396 + */ + public static ServiceURI create(URI uri) { + checkNotNull(uri, "service uri instance is null"); + + String serviceName; + final String[] serviceInfos; + String scheme = uri.getScheme(); + if (null != scheme) { + scheme = scheme.toLowerCase(); + final String serviceSep = "+"; + String[] schemeParts = StringUtils.split(scheme, serviceSep); + serviceName = schemeParts[0]; + serviceInfos = new String[schemeParts.length - 1]; + System.arraycopy(schemeParts, 1, serviceInfos, 0, serviceInfos.length); + } else { + serviceName = null; + serviceInfos = new String[0]; + } + + String userAndHostInformation = uri.getAuthority(); + checkArgument(!Strings.isNullOrEmpty(userAndHostInformation), + "authority component is missing in service uri : " + uri); + + String serviceUser; + List serviceHosts; + int atIndex = userAndHostInformation.indexOf('@'); + Splitter splitter = Splitter.on(CharMatcher.anyOf(",;")); Review comment: What you are saying rings a bell, but comma does work in URI. The URI rfc even says it should work (it's a sub-delim) ``` jshell> import java.net.URI jshell> new URI("http://adfdaf,asfddsaf,adfafd:44") $2 ==> http://adfdaf,asfddsaf,adfafd:44 jshell> $2.getHost() $3 ==> null jshell> $2.getAuthority() $4 ==> "adfdaf,asfddsaf,adfafd:44" ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: users@infra.apache.org With regards, Apache Git Services