public class AisTcpReader extends AisReader
Connection handling is fail tolerant. Connection error is handled by waiting a specified amount of time before doing a re-connect (default 5 sec).
Handlers for the parsed AIS messages must be registered with registerHanlder() method.
Example of use:
IAisHandler handler = new SomeHandler();
AisTcpReader aisReader = new AisTcpReader("localhost", 4001); aisReader.registerHandler(handler); aisReader.addProprietaryFactory(new GatehouseFactory()); aisReader.start(); aisReader.join();
AisReader.StatusThread.State, Thread.UncaughtExceptionHandler| Modifier and Type | Field and Description |
|---|---|
protected AtomicReference<Socket> |
clientSocket
The Client socket.
|
protected OutputStream |
outputStream
The Output stream.
|
protected long |
reconnectInterval
The Reconnect interval.
|
protected int |
timeout
The Timeout.
|
handlers, packetHandlers, sendThreadPoolMAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY| Constructor and Description |
|---|
AisTcpReader() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
connect()
Connect.
|
protected void |
disconnect()
Disconnect.
|
int |
getHostCount()
Get the number of hosts
|
String |
getHostname()
Returns the current hostname
|
int |
getPort()
Get port
|
long |
getReconnectInterval()
Get the interval in milliseconds between re-connect attempts
|
AisReader.Status |
getStatus()
Get the status of the connection, either connected or disconnected
|
int |
getTimeout()
Get socket read timeout
|
void |
run()
Main read loop
|
void |
send(SendRequest sendRequest,
Consumer<Abk> resultListener)
Send sendRequest to the socket output stream and get result sent to resultListener.
|
void |
setReconnectInterval(long reconnectInterval)
Set the interval in milliseconds between re-connect attempts
|
void |
setTimeout(int timeout)
Set socket read timeout
|
void |
stopReader()
Stop the reader
|
String |
toString() |
distribute, doSend, getNumberOfBytesRead, getNumberOfBytesWritten, getNumberOfLinesRead, getSourceId, isShutdown, readLoop, registerHandler, registerPacketHandler, registerQueue, registerQueueHandler, send, send, setSourceId, streamactiveCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, yieldprotected volatile long reconnectInterval
protected OutputStream outputStream
protected final AtomicReference<Socket> clientSocket
protected volatile int timeout
public void run()
public void stopReader()
AisReaderstopReader in class AisReaderprotected void connect()
throws IOException
IOException - the io exceptionprotected void disconnect()
public void send(SendRequest sendRequest, Consumer<Abk> resultListener) throws SendException
send in class AisReadersendRequest - sendRequestresultListener - Consumer resultListenerSendException - a SendExceptionpublic AisReader.Status getStatus()
AisReaderpublic long getReconnectInterval()
public void setReconnectInterval(long reconnectInterval)
reconnectInterval - the reconnect intervalpublic int getHostCount()
public int getTimeout()
public void setTimeout(int timeout)
timeout - the timeoutpublic String getHostname()
public int getPort()
Copyright © 2011–2019 Danish Maritime Authority. All rights reserved.