java.io.Closeable
, java.io.Flushable
, java.lang.AutoCloseable
, FlushableCloseable
, Protectable
public class SocketHandler extends ExtHandler
Modifier and Type | Class | Description |
---|---|---|
static class |
SocketHandler.Protocol |
The type of socket
|
Modifier and Type | Field | Description |
---|---|---|
static int |
DEFAULT_PORT |
handlers, handlersUpdater
Constructor | Description |
---|---|
SocketHandler() |
Creates a socket handler with an address of localhost and port
of 4560.
|
SocketHandler(java.lang.String hostname,
int port) |
Creates a socket handler.
|
SocketHandler(java.net.InetAddress address,
int port) |
Creates a socket handler.
|
SocketHandler(javax.net.SocketFactory socketFactory,
SocketHandler.Protocol protocol,
java.lang.String hostname,
int port) |
Creates a socket handler.
|
SocketHandler(javax.net.SocketFactory socketFactory,
SocketHandler.Protocol protocol,
java.net.InetAddress address,
int port) |
Creates a socket handler.
|
SocketHandler(SocketHandler.Protocol protocol,
java.lang.String hostname,
int port) |
Creates a socket handler.
|
SocketHandler(SocketHandler.Protocol protocol,
java.net.InetAddress address,
int port) |
Creates a socket handler.
|
Modifier and Type | Method | Description |
---|---|---|
void |
close() |
Close all child handlers.
|
protected void |
doPublish(ExtLogRecord record) |
Do the actual work of publication; the record will have been filtered already.
|
void |
flush() |
Flush all child handlers.
|
java.net.InetAddress |
getAddress() |
Returns the address being used.
|
int |
getPort() |
Returns the port being used.
|
SocketHandler.Protocol |
getProtocol() |
Returns the protocol being used.
|
boolean |
isBlockOnReconnect() |
Indicates whether or not the output stream is set to block when attempting to reconnect a TCP connection.
|
void |
setAddress(java.net.InetAddress address) |
Sets the address to connect to.
|
void |
setBlockOnReconnect(boolean blockOnReconnect) |
|
void |
setHostname(java.lang.String hostname) |
Sets the address to connect to by doing a lookup on the hostname.
|
void |
setPort(int port) |
Sets the port to connect to.
|
void |
setProtocol(SocketHandler.Protocol protocol) |
Sets the protocol to use.
|
void |
setSocketFactory(javax.net.SocketFactory socketFactory) |
addHandler, checkAccess, checkAccess, clearHandlers, disableAccess, enableAccess, getHandlers, isAutoFlush, isCallerCalculationRequired, isCloseChildren, isEnabled, protect, publish, publish, removeHandler, setAutoFlush, setCloseChildren, setEnabled, setEncoding, setErrorManager, setFilter, setFormatter, setHandlers, setLevel, unprotect
public static final int DEFAULT_PORT
public SocketHandler() throws java.net.UnknownHostException
java.net.UnknownHostException
- if an error occurs attempting to retrieve the localhostpublic SocketHandler(java.lang.String hostname, int port) throws java.net.UnknownHostException
hostname
- the hostname to connect toport
- the port to connect tojava.net.UnknownHostException
- if an error occurs resolving the addresspublic SocketHandler(java.net.InetAddress address, int port)
address
- the address to connect toport
- the port to connect topublic SocketHandler(SocketHandler.Protocol protocol, java.lang.String hostname, int port) throws java.net.UnknownHostException
protocol
- the protocol to connect withhostname
- the hostname to connect toport
- the port to connect tojava.net.UnknownHostException
- if an error occurs resolving the hostnamepublic SocketHandler(SocketHandler.Protocol protocol, java.net.InetAddress address, int port)
protocol
- the protocol to connect withaddress
- the address to connect toport
- the port to connect topublic SocketHandler(javax.net.SocketFactory socketFactory, SocketHandler.Protocol protocol, java.lang.String hostname, int port) throws java.net.UnknownHostException
socketFactory
- the socket factory to use for creating TCP or
SSL TCP connections, if null
a default factory will
be usedprotocol
- the protocol to connect withhostname
- the hostname to connect toport
- the port to connect tojava.net.UnknownHostException
- if an error occurs resolving the hostnamepublic SocketHandler(javax.net.SocketFactory socketFactory, SocketHandler.Protocol protocol, java.net.InetAddress address, int port)
protected void doPublish(ExtLogRecord record)
ExtHandler
autoFlush
property is set to true
; if this behavior is to be
preserved in a subclass then this method should be called after the record is physically written.doPublish
in class ExtHandler
record
- the log record to publishpublic void flush()
ExtHandler
flush
in interface java.io.Flushable
flush
in class ExtHandler
public void close() throws java.lang.SecurityException
ExtHandler
close
in interface java.lang.AutoCloseable
close
in interface java.io.Closeable
close
in class ExtHandler
java.lang.SecurityException
public java.net.InetAddress getAddress()
public void setAddress(java.net.InetAddress address)
address
- the addresspublic void setHostname(java.lang.String hostname) throws java.net.UnknownHostException
hostname
- the host name used to resolve the addressjava.net.UnknownHostException
- if an error occurs resolving the addresspublic boolean isBlockOnReconnect()
true
if blocking is enabled, otherwise false
public void setBlockOnReconnect(boolean blockOnReconnect)
true
the write
methods will block when attempting to reconnect. This is only advisable
to be set to true
if using an asynchronous handler.blockOnReconnect
- true
to block when reconnecting or false
to reconnect asynchronously
discarding any new messages coming inpublic SocketHandler.Protocol getProtocol()
public void setProtocol(SocketHandler.Protocol protocol)
null
the protocol will be set to
TCP.
Note that is resets the socket factory.
protocol
- the protocol to usepublic int getPort()
public void setPort(int port)
port
- the portCopyright © 2018. All rights reserved.