Skip to content

Package: SocketBinder

SocketBinder

Coverage

1: /*
2: * Copyright (c) 2009, 2020 Oracle and/or its affiliates. All rights reserved.
3: * Copyright (c) 2018 Payara Services Ltd.
4: *
5: * This program and the accompanying materials are made available under the
6: * terms of the Eclipse Public License v. 2.0, which is available at
7: * http://www.eclipse.org/legal/epl-2.0.
8: *
9: * This Source Code may also be made available under the following Secondary
10: * Licenses when the conditions for such availability set forth in the
11: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
12: * version 2 with the GNU Classpath Exception, which is available at
13: * https://www.gnu.org/software/classpath/license.html.
14: *
15: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16: */
17:
18: package org.glassfish.grizzly;
19:
20: import java.io.IOException;
21: import java.net.SocketAddress;
22:
23: /**
24: * Common API for {@link java.net.Socket} based {@link Transport}s, which are able to bind server
25: * {@link java.net.Socket} to specific address and listen for incoming data.
26: *
27: * @author Alexey Stashok
28: */
29: public interface SocketBinder {
30: /**
31: * Binds Transport to the specific port on localhost.
32: *
33: * @param port the port to bind to
34: * @return bound {@link Connection}
35: *
36: * @throws java.io.IOException if unable to bind i.e. if port already bound
37: */
38: Connection<?> bind(int port) throws IOException;
39:
40: /**
41: * Binds Transport to the specific host and port.
42: *
43: * @param host the local host the server will bind to
44: * @param port specific port to bind to
45: * @return bound {@link Connection}
46: *
47: * @throws java.io.IOException if unable to bind i.e. if port already bound
48: */
49: Connection<?> bind(String host, int port) throws IOException;
50:
51: /**
52: * Binds Transport to the specific host and port.
53: *
54: * @param host the local host the server will bind to
55: * @param port the port to bind to
56: * @param backlog the maximum length of the queue
57: * @return bound {@link Connection}
58: *
59: * @throws java.io.IOException if unable to bind i.e. if port already bound
60: */
61: Connection<?> bind(String host, int port, int backlog) throws IOException;
62:
63: /**
64: * Binds Transport to the specific host, and port within a {@link PortRange}.
65: *
66: * @param host the local host the server will bind to
67: * @param portRange {@link PortRange}.
68: * @param backlog the maximum length of the queue
69: * @return bound {@link Connection}
70: *
71: * @throws java.io.IOException if unable to bind i.e. if port already bound
72: */
73: Connection<?> bind(String host, PortRange portRange, int backlog) throws IOException;
74:
75: /**
76: * Binds Transport to the specific host, and port within a {@link PortRange}.
77: *
78: * @param host the local host the server will bind to
79: * @param portRange {@link PortRange}.
80: * @param randomStartPort if true, a random port in the range will be used as the initial port.
81: * @param backlog the maximum length of the queue
82: * @return bound {@link Connection}
83: *
84: * @throws java.io.IOException if unable to bind i.e. if port already bound
85: */
86: Connection<?> bind(String host, PortRange portRange, boolean randomStartPort, int backlog) throws IOException;
87:
88: /**
89: * Binds Transport to the specific SocketAddress.
90: *
91: * @param socketAddress the local address the server will bind to
92: * @return bound {@link Connection}
93: *
94: * @throws java.io.IOException if unable to bind i.e. if port already bound
95: */
96: Connection<?> bind(SocketAddress socketAddress) throws IOException;
97:
98: /**
99: * Binds Transport to the specific SocketAddress.
100: *
101: * @param socketAddress the local address the server will bind to
102: * @param backlog the maximum length of the queue
103: * @return bound {@link Connection}
104: *
105: * @throws java.io.IOException if unable to bind i.e. if port already bound
106: */
107: Connection<?> bind(SocketAddress socketAddress, int backlog) throws IOException;
108:
109: /**
110: * Binds the Transport to the channel inherited from the entity that created this Java virtual machine.
111: *
112: * @return bound {@link Connection}
113: *
114: * @throws IOException if unable to bind i.e. if port already bound
115: */
116: Connection<?> bindToInherited() throws IOException;
117:
118: /**
119: * Unbinds bound {@link Transport} connection.
120: *
121: * @param connection {@link Connection}
122: */
123: void unbind(Connection<?> connection);
124:
125: /**
126: * Unbinds all bound {@link Transport} connections.
127: *
128: */
129: void unbindAll();
130:
131: }