|
43 | 43 | */
|
44 | 44 | public class SocketBinding {
|
45 | 45 |
|
46 |
| - public static final ServiceName JBOSS_BINDING_NAME = ServiceName.JBOSS.append("binding"); |
47 |
| - |
48 |
| - private final String name; |
49 |
| - private int port; |
50 |
| - private boolean isFixedPort; |
51 |
| - private InetAddress multicastAddress; |
52 |
| - private int multicastPort; |
53 |
| - private final NetworkInterfaceBinding networkInterface; |
54 |
| - private final SocketBindingManager socketBindings; |
55 |
| - |
56 |
| - SocketBinding(final String name, int port, boolean isFixedPort, |
57 |
| - InetAddress multicastAddress, int multicastPort, |
58 |
| - final NetworkInterfaceBinding networkInterface, SocketBindingManager socketBindings) { |
59 |
| - this.name = name; |
60 |
| - this.port = port; |
61 |
| - this.isFixedPort = isFixedPort; |
62 |
| - this.multicastAddress = multicastAddress; |
63 |
| - this.multicastPort = multicastPort; |
64 |
| - this.socketBindings = socketBindings; |
65 |
| - this.networkInterface = networkInterface; |
66 |
| - } |
| 46 | + public static final ServiceName JBOSS_BINDING_NAME = ServiceName.JBOSS.append("binding"); |
| 47 | + |
| 48 | + private final String name; |
| 49 | + private int port; |
| 50 | + private boolean isFixedPort; |
| 51 | + private InetAddress multicastAddress; |
| 52 | + private int multicastPort; |
| 53 | + private final NetworkInterfaceBinding networkInterface; |
| 54 | + private final SocketBindingManager socketBindings; |
| 55 | + |
| 56 | + SocketBinding(final String name, int port, boolean isFixedPort, |
| 57 | + InetAddress multicastAddress, int multicastPort, |
| 58 | + final NetworkInterfaceBinding networkInterface, SocketBindingManager socketBindings) { |
| 59 | + this.name = name; |
| 60 | + this.port = port; |
| 61 | + this.isFixedPort = isFixedPort; |
| 62 | + this.multicastAddress = multicastAddress; |
| 63 | + this.multicastPort = multicastPort; |
| 64 | + this.socketBindings = socketBindings; |
| 65 | + this.networkInterface = networkInterface; |
| 66 | + } |
67 | 67 |
|
68 | 68 | /**
|
69 | 69 | * Return the name of the SocketBinding used in the configuration
|
70 |
| - * |
71 | 70 | * @return the SocketBinding configuration name
|
72 | 71 | */
|
73 | 72 | public String getName() {
|
74 | 73 | return name;
|
75 | 74 | }
|
76 | 75 |
|
77 |
| - /** |
78 |
| - * Get the socket binding manager. |
79 |
| - * |
80 |
| - * @return the socket binding manger |
81 |
| - */ |
82 |
| - public SocketBindingManager getSocketBindings() { |
83 |
| - return socketBindings; |
84 |
| - } |
85 |
| - |
86 |
| - /** |
87 |
| - * Get the socket address. |
88 |
| - * |
89 |
| - * @return the socket address |
90 |
| - */ |
91 |
| - public InetSocketAddress getSocketAddress() { |
92 |
| - int port = this.port; |
93 |
| - if (port > 0 && isFixedPort == false) { |
94 |
| - port += socketBindings.getPortOffset(); |
95 |
| - } |
96 |
| - return new InetSocketAddress(networkInterface.getAddress(), port); |
97 |
| - } |
98 |
| - |
99 |
| - /** |
100 |
| - * Get the multicast socket address. |
101 |
| - * |
102 |
| - * @return |
103 |
| - */ |
104 |
| - public InetSocketAddress getMulticastSocketAddress() { |
105 |
| - if (multicastAddress == null) { |
106 |
| - throw new IllegalStateException("no multicast binding: " + name); |
107 |
| - } |
108 |
| - return new InetSocketAddress(multicastAddress, multicastPort); |
109 |
| - } |
110 |
| - |
111 |
| - /** |
112 |
| - * Create and bind a socket. |
113 |
| - * |
114 |
| - * @return the socket |
115 |
| - * @throws IOException |
116 |
| - */ |
117 |
| - public Socket createSocket() throws IOException { |
118 |
| - final Socket socket = getSocketFactory().createSocket(); |
119 |
| - socket.bind(getSocketAddress()); |
120 |
| - return socket; |
121 |
| - } |
122 |
| - |
123 |
| - /** |
124 |
| - * Create and bind a server socket |
125 |
| - * |
126 |
| - * @return the server socket |
127 |
| - * @throws IOException |
128 |
| - */ |
129 |
| - public ServerSocket createServerSocket() throws IOException { |
130 |
| - final ServerSocket socket = getServerSocketFactory().createServerSocket(); |
131 |
| - socket.bind(getSocketAddress()); |
132 |
| - return socket; |
133 |
| - } |
134 |
| - |
135 |
| - /** |
136 |
| - * Create and bind a server socket. |
137 |
| - * |
138 |
| - * @param backlog the backlog |
139 |
| - * @return the server socket |
140 |
| - * @throws IOException |
141 |
| - */ |
142 |
| - public ServerSocket createServerSocket(int backlog) throws IOException { |
143 |
| - final ServerSocket socket = getServerSocketFactory().createServerSocket(); |
144 |
| - socket.bind(getSocketAddress(), backlog); |
145 |
| - return socket; |
146 |
| - } |
147 |
| - |
148 |
| - /** |
149 |
| - * Create and bind a datagrap socket. |
150 |
| - * |
151 |
| - * @return the datagram socket |
152 |
| - * @throws SocketException |
153 |
| - */ |
154 |
| - public DatagramSocket createDatagramSocket() throws SocketException { |
155 |
| - return new ManagedDatagramSocketBinding(socketBindings, getSocketAddress()); |
156 |
| - } |
157 |
| - |
158 |
| - /** |
159 |
| - * Create and bind a multicast socket. This will also join the given multicast address. |
160 |
| - * |
161 |
| - * @return the multicast socket |
162 |
| - * @throws IOException |
163 |
| - */ |
164 |
| - public MulticastSocket createMulticastSocket() throws IOException { |
165 |
| - final MulticastSocket socket = new ManagedMulticastSocketBinding(socketBindings, getSocketAddress()); |
166 |
| - socket.joinGroup(getMulticastSocketAddress(), networkInterface.getNetworkInterface()); |
167 |
| - return socket; |
168 |
| - } |
169 |
| - |
170 |
| - SocketFactory getSocketFactory() { |
171 |
| - return socketBindings.getSocketFactory(); |
172 |
| - } |
173 |
| - |
174 |
| - ServerSocketFactory getServerSocketFactory() { |
175 |
| - return socketBindings.getServerSocketFactory(); |
176 |
| - } |
| 76 | + /** |
| 77 | + * Get the socket binding manager. |
| 78 | + * |
| 79 | + * @return the socket binding manger |
| 80 | + */ |
| 81 | + public SocketBindingManager getSocketBindings() { |
| 82 | + return socketBindings; |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * Get the socket address. |
| 87 | + * |
| 88 | + * @return the socket address |
| 89 | + */ |
| 90 | + public InetSocketAddress getSocketAddress() { |
| 91 | + int port = this.port; |
| 92 | + if(port > 0 && isFixedPort == false) { |
| 93 | + port += socketBindings.getPortOffset(); |
| 94 | + } |
| 95 | + return new InetSocketAddress(networkInterface.getAddress(), port); |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * Get the multicast socket address. |
| 100 | + * |
| 101 | + * @return |
| 102 | + */ |
| 103 | + public InetSocketAddress getMulticastSocketAddress() { |
| 104 | + if(multicastAddress == null) { |
| 105 | + throw new IllegalStateException("no multicast binding: " + name); |
| 106 | + } |
| 107 | + return new InetSocketAddress(multicastAddress, multicastPort); |
| 108 | + } |
| 109 | + |
| 110 | + /** |
| 111 | + * Create and bind a socket. |
| 112 | + * |
| 113 | + * @return the socket |
| 114 | + * @throws IOException |
| 115 | + */ |
| 116 | + public Socket createSocket() throws IOException { |
| 117 | + final Socket socket = getSocketFactory().createSocket(); |
| 118 | + socket.bind(getSocketAddress()); |
| 119 | + return socket; |
| 120 | + } |
| 121 | + |
| 122 | + /** |
| 123 | + * Create and bind a server socket |
| 124 | + * |
| 125 | + * @return the server socket |
| 126 | + * @throws IOException |
| 127 | + */ |
| 128 | + public ServerSocket createServerSocket() throws IOException { |
| 129 | + final ServerSocket socket = getServerSocketFactory().createServerSocket(); |
| 130 | + socket.bind(getSocketAddress()); |
| 131 | + return socket; |
| 132 | + } |
| 133 | + |
| 134 | + /** |
| 135 | + * Create and bind a server socket. |
| 136 | + * |
| 137 | + * @param backlog the backlog |
| 138 | + * @return the server socket |
| 139 | + * @throws IOException |
| 140 | + */ |
| 141 | + public ServerSocket createServerSocket(int backlog) throws IOException { |
| 142 | + final ServerSocket socket = getServerSocketFactory().createServerSocket(); |
| 143 | + socket.bind(getSocketAddress(), backlog); |
| 144 | + return socket; |
| 145 | + } |
| 146 | + |
| 147 | + /** |
| 148 | + * Create and bind a datagrap socket. |
| 149 | + * |
| 150 | + * @return the datagram socket |
| 151 | + * @throws SocketException |
| 152 | + */ |
| 153 | + public DatagramSocket createDatagramSocket() throws SocketException { |
| 154 | + return new ManagedDatagramSocketBinding(socketBindings, getSocketAddress()); |
| 155 | + } |
| 156 | + |
| 157 | + /** |
| 158 | + * Create and bind a multicast socket. This will also join the given |
| 159 | + * multicast address. |
| 160 | + * |
| 161 | + * @return the multicast socket |
| 162 | + * @throws IOException |
| 163 | + */ |
| 164 | + public MulticastSocket createMulticastSocket() throws IOException { |
| 165 | + final MulticastSocket socket = new ManagedMulticastSocketBinding(socketBindings, getSocketAddress()); |
| 166 | + socket.joinGroup(getMulticastSocketAddress(), networkInterface.getNetworkInterface()); |
| 167 | + return socket; |
| 168 | + } |
| 169 | + |
| 170 | + SocketFactory getSocketFactory() { |
| 171 | + return socketBindings.getSocketFactory(); |
| 172 | + } |
| 173 | + |
| 174 | + ServerSocketFactory getServerSocketFactory() { |
| 175 | + return socketBindings.getServerSocketFactory(); |
| 176 | + } |
177 | 177 |
|
178 | 178 | }
|
0 commit comments