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.io.IOException; 21 import java.net.SocketAddress; 22 import java.net.SocketException; 23 import java.net.URI; 24 import java.util.Set; 25 26 import org.newsclub.net.unix.AFSocketAddress.AFSocketAddressConstructor; 27 28 /** 29 * The implementation-specifics for a given {@link AFSocketAddress} subclass implementation. 30 * 31 * @param <A> The supported address type. 32 * @author Christian Kohlschütter 33 * @see AFAddressFamilyConfig 34 */ 35 public abstract class AFSocketAddressConfig<A extends AFSocketAddress> { 36 37 /** 38 * Constructor. 39 */ 40 protected AFSocketAddressConfig() { 41 } 42 43 /** 44 * Tries to parse the given address-specific URI. 45 * 46 * @param u The URI. 47 * @param port The port to use, or {@code -1} for "unspecified". 48 * @return The address. 49 * @throws SocketException on error. 50 */ 51 protected abstract A parseURI(URI u, int port) throws SocketException; 52 53 /** 54 * Returns the implementation's address constructor. 55 * 56 * @return The implementation's address constructor. 57 */ 58 protected abstract AFSocketAddressConstructor<A> addressConstructor(); 59 60 /** 61 * Returns the name of the implementation's selector provider class. 62 * 63 * @return The name of the implementation's selector provider class. 64 */ 65 protected abstract String selectorProviderClassname(); 66 67 /** 68 * Returns the set of supported URI schemes that can be parsed via {@link #parseURI(URI,int)}. 69 * 70 * These schemes must be unique to this {@link AFSocketAddress} type. 71 * 72 * @return The set of supported URI schemes. 73 */ 74 protected abstract Set<String> uriSchemes(); 75 76 /** 77 * Returns an appropriate SocketAddress to be used when calling bind with a null argument. 78 * 79 * @return The new socket address, or {@code null}. 80 * @throws IOException on error. 81 */ 82 protected SocketAddress nullBindAddress() throws IOException { 83 return null; 84 } 85 }