Package org.kiwiproject.net
Class SocketChecker
- java.lang.Object
-
- org.kiwiproject.net.SocketChecker
-
public class SocketChecker extends Object
Utilities for checking sockets.
-
-
Field Summary
Fields Modifier and Type Field Description static DurationDEFAULT_TIMEOUT
-
Constructor Summary
Constructors Constructor Description SocketChecker()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanConnectViaSocket(String host, int port)Check whether aSocketcan be opened on the specified host and port.booleancanConnectViaSocket(String host, int port, Duration timeout)Check whether aSocketcan be opened on the specified host and port, with the specified timeout.booleancanConnectViaSocket(org.apache.commons.lang3.tuple.Pair<String,Integer> hostAndPort)Check whether aSocketcan be opened on the specified host and port.booleancanConnectViaSocket(org.apache.commons.lang3.tuple.Pair<String,Integer> hostAndPort, Duration timeout)Check whether aSocketcan be opened on the specified host and port, with the specified timeout.
-
-
-
Field Detail
-
DEFAULT_TIMEOUT
public static final Duration DEFAULT_TIMEOUT
-
-
Method Detail
-
canConnectViaSocket
public boolean canConnectViaSocket(String host, int port)
Check whether aSocketcan be opened on the specified host and port.- Parameters:
host- the host to checkport- the port to check- Returns:
trueif the port is open;falseotherwise
-
canConnectViaSocket
public boolean canConnectViaSocket(String host, int port, Duration timeout)
Check whether aSocketcan be opened on the specified host and port, with the specified timeout.- Parameters:
host- the host to checkport- the port to checktimeout- how long to wait for the socket connection before timing out- Returns:
trueif the socket connection succeeded;falseotherwise
-
canConnectViaSocket
public boolean canConnectViaSocket(org.apache.commons.lang3.tuple.Pair<String,Integer> hostAndPort)
Check whether aSocketcan be opened on the specified host and port. Uses the default timeout ofDEFAULT_TIMEOUT.- Parameters:
hostAndPort- a Pair containing the host and port to check- Returns:
trueif the socket connection succeeded;falseotherwise
-
canConnectViaSocket
public boolean canConnectViaSocket(org.apache.commons.lang3.tuple.Pair<String,Integer> hostAndPort, Duration timeout)
Check whether aSocketcan be opened on the specified host and port, with the specified timeout.- Parameters:
hostAndPort- a Pair containing the host and port to checktimeout- how long to wait for the socket connection before timing out- Returns:
trueif the socket connection succeeded;falseotherwise
-
-