On Mon, Feb 1, 2021 at 4:06 PM <[email protected]> wrote:

> This is an automated email from the ASF dual-hosted git repository.
>
> remm pushed a commit to branch master
> in repository https://gitbox.apache.org/repos/asf/tomcat.git
>
>
> The following commit(s) were added to refs/heads/master by this push:
>      new 48c9b87  Remove ugly reflection using a generic id
> 48c9b87 is described below
>
> commit 48c9b873ab0eef18d5a4d76cf80033ee2afca7eb
> Author: remm <[email protected]>
> AuthorDate: Mon Feb 1 15:04:32 2021 +0100
>
>     Remove ugly reflection using a generic id
>
>     The id if available then replaces address-port to name threads and
>     mbeans.
> ---
>  java/org/apache/catalina/connector/Connector.java     | 14 +++++++-------
>  java/org/apache/coyote/AbstractProtocol.java          | 12 +++++++++---
>  java/org/apache/coyote/ProtocolHandler.java           | 11 +++++++++++
>  java/org/apache/tomcat/util/net/AbstractEndpoint.java | 11 +++++++++++
>  java/org/apache/tomcat/util/net/AprEndpoint.java      | 10 ++++++++++
>  java/org/apache/tomcat/util/net/NioEndpoint.java      | 12 ++++++++++++
>  6 files changed, 60 insertions(+), 10 deletions(-)
>
> diff --git a/java/org/apache/catalina/connector/Connector.java
> b/java/org/apache/catalina/connector/Connector.java
> index 4f4be1c..8eb235d 100644
> --- a/java/org/apache/catalina/connector/Connector.java
> +++ b/java/org/apache/catalina/connector/Connector.java
> @@ -950,11 +950,11 @@ public class Connector extends LifecycleMBeanBase  {
>
>          StringBuilder sb = new StringBuilder("type=");
>          sb.append(type);
> -        Object path = getProperty("unixDomainSocketPath");
> -        if (path != null) {
> +        String id = protocolHandler.getId();
> +        if (id != null) {
>              // Maintain MBean name compatibility, even if not accurate
>              sb.append(",port=0,address=");
> -            sb.append(ObjectName.quote(path.toString()));
> +            sb.append(ObjectName.quote(id));
>          } else {
>              sb.append(",port=");
>              int port = getPortWithOffset();
> @@ -1066,7 +1066,7 @@ public class Connector extends LifecycleMBeanBase  {
>      protected void startInternal() throws LifecycleException {
>
>          // Validate settings before starting
> -        if (getProperty("unixDomainSocketPath") == null &&
> getPortWithOffset() < 0) {
> +        if (protocolHandler.getId() == null && getPortWithOffset() < 0) {
>              throw new LifecycleException(sm.getString(
>                      "coyoteConnector.invalidPort",
> Integer.valueOf(getPortWithOffset())));
>          }
> @@ -1132,9 +1132,9 @@ public class Connector extends LifecycleMBeanBase  {
>          StringBuilder sb = new StringBuilder("Connector[");
>          sb.append(getProtocol());
>          sb.append('-');
> -        Object path = getProperty("unixDomainSocketPath");
> -        if (path != null) {
> -            sb.append(path.toString());
> +        Object id = protocolHandler.getId();
>

Why Object + toString() ? It is a String


> +        if (id != null) {
> +            sb.append(id.toString());
>          } else {
>              int port = getPortWithOffset();
>              if (port > 0) {
> diff --git a/java/org/apache/coyote/AbstractProtocol.java
> b/java/org/apache/coyote/AbstractProtocol.java
> index 09b60dd..7b8756d 100644
> --- a/java/org/apache/coyote/AbstractProtocol.java
> +++ b/java/org/apache/coyote/AbstractProtocol.java
> @@ -207,6 +207,12 @@ public abstract class AbstractProtocol<S> implements
> ProtocolHandler,
>      }
>
>
> +    @Override
> +    public String getId() {
> +        return endpoint.getId();
> +    }
> +
> +
>      // ---------------------- Properties that are passed through to the
> EndPoint
>
>      @Override
> @@ -347,9 +353,9 @@ public abstract class AbstractProtocol<S> implements
> ProtocolHandler,
>      private String getNameInternal() {
>          StringBuilder name = new StringBuilder(getNamePrefix());
>          name.append('-');
> -        String path = getProperty("unixDomainSocketPath");
> -        if (path != null) {
> -            name.append(path);
> +        String id = getId();
> +        if (id != null) {
> +            name.append(id);
>          } else {
>              if (getAddress() != null) {
>                  name.append(getAddress().getHostAddress());
> diff --git a/java/org/apache/coyote/ProtocolHandler.java
> b/java/org/apache/coyote/ProtocolHandler.java
> index dfa5a25..cf25010 100644
> --- a/java/org/apache/coyote/ProtocolHandler.java
> +++ b/java/org/apache/coyote/ProtocolHandler.java
> @@ -207,6 +207,17 @@ public interface ProtocolHandler {
>
>
>      /**
> +     * The default behavior is to identify connectors uniquely with
> address
> +     * and port. However, certain connectors are not using that and need
> +     * some other identifier, which then can be used as a replacement.
> +     * @return the id
> +     */
> +    public default String getId() {
> +        return null;
> +    }
> +
> +
> +    /**
>       * Create a new ProtocolHandler for the given protocol.
>       * @param protocol the protocol
>       * @return the newly instantiated protocol handler
> diff --git a/java/org/apache/tomcat/util/net/AbstractEndpoint.java
> b/java/org/apache/tomcat/util/net/AbstractEndpoint.java
> index 62f8045..ae5c798 100644
> --- a/java/org/apache/tomcat/util/net/AbstractEndpoint.java
> +++ b/java/org/apache/tomcat/util/net/AbstractEndpoint.java
> @@ -807,6 +807,17 @@ public abstract class AbstractEndpoint<S,U> {
>      }
>
>
> +    /**
> +     * The default behavior is to identify connectors uniquely with
> address
> +     * and port. However, certain connectors are not using that and need
> +     * some other identifier, which then can be used as a replacement.
> +     * @return the id
> +     */
> +    public String getId() {
> +        return null;
> +    }
> +
> +
>      protected final List<String> negotiableProtocols = new ArrayList<>();
>      public void addNegotiatedProtocol(String negotiableProtocol) {
>          negotiableProtocols.add(negotiableProtocol);
> diff --git a/java/org/apache/tomcat/util/net/AprEndpoint.java
> b/java/org/apache/tomcat/util/net/AprEndpoint.java
> index 9d212a1..cf62eab 100644
> --- a/java/org/apache/tomcat/util/net/AprEndpoint.java
> +++ b/java/org/apache/tomcat/util/net/AprEndpoint.java
> @@ -304,6 +304,16 @@ public class AprEndpoint extends
> AbstractEndpoint<Long,Long> implements SNICallB
>      }
>
>
> +    @Override
> +    public String getId() {
> +        if (getUnixDomainSocketPath() != null) {
> +            return getUnixDomainSocketPath();
> +        } else {
> +            return null;
> +        }
> +    }
> +
> +
>      // ----------------------------------------------- Public Lifecycle
> Methods
>
>
> diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java
> b/java/org/apache/tomcat/util/net/NioEndpoint.java
> index 5d16bbf..3c9515a 100644
> --- a/java/org/apache/tomcat/util/net/NioEndpoint.java
> +++ b/java/org/apache/tomcat/util/net/NioEndpoint.java
> @@ -176,6 +176,18 @@ public class NioEndpoint extends
> AbstractJsseEndpoint<NioChannel,SocketChannel>
>      }
>
>
> +    @Override
> +    public String getId() {
> +        if (getUseInheritedChannel()) {
> +            return "JVMInheritedChannel";
> +        } else if (getUnixDomainSocketPath() != null) {
> +            return getUnixDomainSocketPath();
> +        } else {
> +            return null;
> +        }
> +    }
> +
> +
>      // ----------------------------------------------- Public Lifecycle
> Methods
>
>      /**
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

Reply via email to