1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.newsclub.net.unix.tipc;
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.AFTIPCSocketAddress;
26 import org.newsclub.net.unix.AFTIPCSocketAddress.Scope;
27
28
29
30
31
32
33
34 public abstract class AFTIPCSocketFactory extends AFSocketFactory<AFTIPCSocketAddress> {
35
36
37
38 protected AFTIPCSocketFactory() {
39 super(AFTIPCSocketAddress.class);
40 }
41
42 @Override
43 public final Socket createSocket() throws SocketException {
44 return configure(AFTIPCSocket.newInstance(this));
45 }
46
47 @Override
48 protected final AFTIPCSocket connectTo(AFTIPCSocketAddress addr) throws IOException {
49 return configure(AFTIPCSocket.connectTo(addr));
50 }
51
52
53
54
55
56
57
58
59 protected AFTIPCSocket configure(AFTIPCSocket sock) throws SocketException {
60 return sock;
61 }
62
63
64
65
66
67
68 public static class ServiceAddress extends AFTIPCSocketFactory {
69 private final int type;
70 private final int instance;
71
72
73
74
75
76
77
78
79 public ServiceAddress(int type, int instance) {
80 super();
81 this.type = type;
82 this.instance = instance;
83 }
84
85 @Override
86 public final AFTIPCSocketAddress addressFromHost(String host, int port) throws SocketException {
87 return AFTIPCSocketAddress.ofService(port, Scope.SCOPE_CLUSTER, type, instance, 0);
88 }
89 }
90 }