1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.newsclub.net.unix.vsock;
19
20 import java.io.IOException;
21 import java.net.Socket;
22 import java.net.SocketException;
23
24 import org.newsclub.net.unix.AFSocketFactory;
25 import org.newsclub.net.unix.AFVSOCKSocketAddress;
26
27 import com.kohlschutter.annotations.compiletime.SuppressFBWarnings;
28
29
30
31
32 public abstract class AFVSOCKSocketFactory extends AFSocketFactory<AFVSOCKSocketAddress> {
33
34
35
36 protected AFVSOCKSocketFactory() {
37 super(AFVSOCKSocketAddress.class);
38 }
39
40 @Override
41 public final Socket createSocket() throws SocketException {
42 return configure(AFVSOCKSocket.newInstance(this));
43 }
44
45 @Override
46 protected final AFVSOCKSocket connectTo(AFVSOCKSocketAddress addr) throws IOException {
47 return configure(AFVSOCKSocket.connectTo(addr));
48 }
49
50
51
52
53
54
55
56
57 protected AFVSOCKSocket configure(AFVSOCKSocket sock) throws SocketException {
58 return sock;
59 }
60
61
62
63
64
65
66 public static final class FixedAddress extends AFVSOCKSocketFactory {
67 private final AFVSOCKSocketAddress addr;
68
69
70
71
72
73
74
75
76 public FixedAddress(int port, int cid) throws SocketException {
77 this(AFVSOCKSocketAddress.ofPortAndCID(port, cid));
78 }
79
80
81
82
83
84
85 @SuppressFBWarnings("EI_EXPOSE_REP2")
86 public FixedAddress(AFVSOCKSocketAddress addr) {
87 super();
88 this.addr = addr;
89 }
90
91 @SuppressFBWarnings("EI_EXPOSE_REP")
92 @Override
93 public AFVSOCKSocketAddress addressFromHost(String host, int javaPort) throws SocketException {
94 return addr;
95 }
96 }
97 }