public class SocketHandler extends ExtHandler
Modifier and Type | Class and Description |
---|---|
static class |
SocketHandler.Protocol
The type of socket
|
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_PORT |
handlers, handlersUpdater
Constructor and Description |
---|
SocketHandler()
|
SocketHandler(ClientSocketFactory clientSocketFactory,
SocketHandler.Protocol protocol)
Creates a socket handler.
|
SocketHandler(InetAddress address,
int port)
Creates a socket handler.
|
SocketHandler(SocketFactory socketFactory,
SocketHandler.Protocol protocol,
InetAddress address,
int port)
Creates a socket handler.
|
SocketHandler(SocketFactory socketFactory,
SocketHandler.Protocol protocol,
String hostname,
int port)
Creates a socket handler.
|
SocketHandler(SocketHandler.Protocol protocol,
InetAddress address,
int port)
Creates a socket handler.
|
SocketHandler(SocketHandler.Protocol protocol,
String hostname,
int port)
Creates a socket handler.
|
SocketHandler(String hostname,
int port)
Creates a socket handler.
|
Modifier and Type | Method and 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.
|
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(InetAddress address)
Sets the address to connect to.
|
void |
setBlockOnReconnect(boolean blockOnReconnect)
|
void |
setClientSocketFactory(ClientSocketFactory clientSocketFactory)
Sets the client socket factory used to create sockets.
|
void |
setHostname(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(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
getEncoding, getErrorManager, getFilter, getFormatter, getLevel, isLoggable, reportError
public static final int DEFAULT_PORT
public SocketHandler() throws UnknownHostException
UnknownHostException
- if an error occurs attempting to retrieve the localhostpublic SocketHandler(String hostname, int port) throws UnknownHostException
hostname
- the hostname to connect toport
- the port to connect toUnknownHostException
- if an error occurs resolving the addresspublic SocketHandler(InetAddress address, int port)
address
- the address to connect toport
- the port to connect topublic SocketHandler(SocketHandler.Protocol protocol, String hostname, int port) throws UnknownHostException
protocol
- the protocol to connect withhostname
- the hostname to connect toport
- the port to connect toUnknownHostException
- if an error occurs resolving the hostnamepublic SocketHandler(SocketHandler.Protocol protocol, InetAddress address, int port)
protocol
- the protocol to connect withaddress
- the address to connect toport
- the port to connect topublic SocketHandler(SocketFactory socketFactory, SocketHandler.Protocol protocol, String hostname, int port) throws 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 toUnknownHostException
- if an error occurs resolving the hostnameSocketHandler(ClientSocketFactory, Protocol)
public SocketHandler(SocketFactory socketFactory, SocketHandler.Protocol protocol, InetAddress address, int port)
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 withaddress
- the address to connect toport
- the port to connect toSocketHandler(ClientSocketFactory, Protocol)
public SocketHandler(ClientSocketFactory clientSocketFactory, SocketHandler.Protocol protocol)
clientSocketFactory
- the client socket factory used to create socketsprotocol
- the protocol to connect withprotected 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 Flushable
flush
in class ExtHandler
public void close() throws SecurityException
ExtHandler
close
in interface Closeable
close
in interface AutoCloseable
close
in class ExtHandler
SecurityException
public InetAddress getAddress()
public void setAddress(InetAddress address)
Note that is resets the client socket factory.
address
- the addresspublic void setHostname(String hostname) throws UnknownHostException
Note that is resets the client socket factory.
hostname
- the host name used to resolve the addressUnknownHostException
- 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 if it was previously set.
protocol
- the protocol to usepublic int getPort()
public void setPort(int port)
Note that is resets the client socket factory.
port
- the portpublic void setSocketFactory(SocketFactory socketFactory)
Note that if the protocol is set the socket factory will be set to
null
and reset. Setting a value here also resets the
client socket factory.
socketFactory
- the socket factorysetClientSocketFactory(ClientSocketFactory)
public void setClientSocketFactory(ClientSocketFactory clientSocketFactory)
null
the
address and port are required to be set.clientSocketFactory
- the client socket factory to useCopyright © 2021 JBoss by Red Hat. All rights reserved.