View Javadoc
1   /*
2    * junixsocket
3    *
4    * Copyright 2009-2024 Christian Kohlschütter
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.newsclub.net.unix;
19  
20  import java.net.SocketException;
21  import java.net.URI;
22  import java.util.Set;
23  
24  import org.newsclub.net.unix.AFSocketAddress.AFSocketAddressConstructor;
25  
26  /**
27   * The implementation-specifics for a given {@link AFSocketAddress} subclass implementation.
28   *
29   * @param <A> The supported address type.
30   * @author Christian Kohlschütter
31   * @see AFAddressFamilyConfig
32   */
33  public abstract class AFSocketAddressConfig<A extends AFSocketAddress> {
34  
35    /**
36     * Constructor.
37     */
38    protected AFSocketAddressConfig() {
39    }
40  
41    /**
42     * Tries to parse the given address-specific URI.
43     *
44     * @param u The URI.
45     * @param port The port to use, or {@code -1} for "unspecified".
46     * @return The address.
47     * @throws SocketException on error.
48     */
49    protected abstract A parseURI(URI u, int port) throws SocketException;
50  
51    /**
52     * Returns the implementation's address constructor.
53     *
54     * @return The implementation's address constructor.
55     */
56    protected abstract AFSocketAddressConstructor<A> addressConstructor();
57  
58    /**
59     * Returns the name of the implementation's selector provider class.
60     *
61     * @return The name of the implementation's selector provider class.
62     */
63    protected abstract String selectorProviderClassname();
64  
65    /**
66     * Returns the set of supported URI schemes that can be parsed via {@link #parseURI(URI,int)}.
67     *
68     * These schemes must be unique to this {@link AFSocketAddress} type.
69     *
70     * @return The set of supported URI schemes.
71     */
72    protected abstract Set<String> uriSchemes();
73  }