java.lang.Object
java.util.logging.Handler
org.jboss.logmanager.ExtHandler
org.jboss.logmanager.handlers.SocketHandler
- All Implemented Interfaces:
Flushable,AutoCloseable
A handler used to communicate over a socket.
- Author:
- James R. Perkins
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsFields inherited from class org.jboss.logmanager.ExtHandler
handlers, handlersUpdater, lock -
Constructor Summary
ConstructorsConstructorDescriptionSocketHandler(String hostname, int port) Creates a socket handler.SocketHandler(InetAddress address, int port) Creates a socket handler.SocketHandler(SocketFactory socketFactory, SocketHandler.Protocol protocol, String hostname, int port) Creates a socket handler.SocketHandler(SocketFactory socketFactory, SocketHandler.Protocol protocol, InetAddress address, int port) Creates a socket handler.SocketHandler(ClientSocketFactory clientSocketFactory, SocketHandler.Protocol protocol) Creates a socket handler.SocketHandler(SocketHandler.Protocol protocol, String hostname, int port) Creates a socket handler.SocketHandler(SocketHandler.Protocol protocol, InetAddress address, int port) Creates a socket handler. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close all child handlers.protected voiddoPublish(ExtLogRecord record) Do the actual work of publication; the record will have been filtered already.voidflush()Flush all child handlers.Returns the address being used.intgetPort()Returns the port being used.Returns the protocol being used.booleanIndicates whether or not the output stream is set to block when attempting to reconnect a TCP connection.voidsetAddress(InetAddress address) Sets the address to connect to.voidsetBlockOnReconnect(boolean blockOnReconnect) voidsetClientSocketFactory(ClientSocketFactory clientSocketFactory) Sets the client socket factory used to create sockets.voidsetHostname(String hostname) Sets the address to connect to by doing a lookup on the hostname.voidsetPort(int port) Sets the port to connect to.voidsetProtocol(SocketHandler.Protocol protocol) Sets the protocol to use.voidsetSocketFactory(SocketFactory socketFactory) Methods inherited from class org.jboss.logmanager.ExtHandler
addHandler, checkAccess, checkAccess, clearHandlers, getCharset, getEncoding, getErrorManager, getFilter, getFormatter, getHandlers, getLevel, isAutoFlush, isCallerCalculationRequired, isCloseChildren, isEnabled, publish, publish, publishToNestedHandlers, removeHandler, reportError, reportError, setAutoFlush, setCharset, setCharsetPrivate, setCloseChildren, setEnabled, setEncoding, setErrorManager, setFilter, setFormatter, setHandlers, setLevelMethods inherited from class java.util.logging.Handler
isLoggable
-
Field Details
-
DEFAULT_PORT
public static final int DEFAULT_PORT- See Also:
-
-
Constructor Details
-
SocketHandler
- Throws:
UnknownHostException- if an error occurs attempting to retrieve the localhost
-
SocketHandler
Creates a socket handler.- Parameters:
hostname- the hostname to connect toport- the port to connect to- Throws:
UnknownHostException- if an error occurs resolving the address
-
SocketHandler
Creates a socket handler.- Parameters:
address- the address to connect toport- the port to connect to
-
SocketHandler
public SocketHandler(SocketHandler.Protocol protocol, String hostname, int port) throws UnknownHostException Creates a socket handler.- Parameters:
protocol- the protocol to connect withhostname- the hostname to connect toport- the port to connect to- Throws:
UnknownHostException- if an error occurs resolving the hostname
-
SocketHandler
Creates a socket handler.- Parameters:
protocol- the protocol to connect withaddress- the address to connect toport- the port to connect to
-
SocketHandler
public SocketHandler(SocketFactory socketFactory, SocketHandler.Protocol protocol, String hostname, int port) throws UnknownHostException Creates a socket handler.- Parameters:
socketFactory- the socket factory to use for creating TCP or SSL TCP connections, ifnulla default factory will be usedprotocol- the protocol to connect withhostname- the hostname to connect toport- the port to connect to- Throws:
UnknownHostException- if an error occurs resolving the hostname- See Also:
-
SocketHandler
public SocketHandler(SocketFactory socketFactory, SocketHandler.Protocol protocol, InetAddress address, int port) Creates a socket handler. -
SocketHandler
Creates a socket handler.- Parameters:
clientSocketFactory- the client socket factory used to create socketsprotocol- the protocol to connect with
-
-
Method Details
-
doPublish
Description copied from class:ExtHandlerDo the actual work of publication; the record will have been filtered already. The default implementation does nothing except to flush if theautoFlushproperty is set totrue; if this behavior is to be preserved in a subclass then this method should be called after the record is physically written.- Overrides:
doPublishin classExtHandler- Parameters:
record- the log record to publish
-
flush
public void flush()Description copied from class:ExtHandlerFlush all child handlers.- Specified by:
flushin interfaceFlushable- Overrides:
flushin classExtHandler
-
close
Description copied from class:ExtHandlerClose all child handlers.- Specified by:
closein interfaceAutoCloseable- Overrides:
closein classExtHandler- Throws:
SecurityException
-
getAddress
Returns the address being used.- Returns:
- the address
-
setAddress
Sets the address to connect to.Note that is resets the client socket factory.
- Parameters:
address- the address
-
setHostname
Sets the address to connect to by doing a lookup on the hostname.Note that is resets the client socket factory.
- Parameters:
hostname- the host name used to resolve the address- Throws:
UnknownHostException- if an error occurs resolving the address
-
isBlockOnReconnect
public boolean isBlockOnReconnect()Indicates whether or not the output stream is set to block when attempting to reconnect a TCP connection.- Returns:
trueif blocking is enabled, otherwisefalse
-
setBlockOnReconnect
public void setBlockOnReconnect(boolean blockOnReconnect) Enables or disables blocking when attempting to reconnect the socket when using a TCP or SSL TCP connections. If set totruethewritemethods will block when attempting to reconnect. This is only advisable to be set totrueif using an asynchronous handler.- Parameters:
blockOnReconnect-trueto block when reconnecting orfalseto reconnect asynchronously discarding any new messages coming in
-
getProtocol
Returns the protocol being used.- Returns:
- the protocol
-
setProtocol
Sets the protocol to use. If the value isnullthe protocol will be set to TCP.Note that is resets the socket factory if it was previously set.
- Parameters:
protocol- the protocol to use
-
getPort
public int getPort()Returns the port being used.- Returns:
- the port
-
setPort
public void setPort(int port) Sets the port to connect to.Note that is resets the client socket factory.
- Parameters:
port- the port
-
setSocketFactory
Sets the socket factory to use for creating TCP or SSL connections.Note that if the protocol is set the socket factory will be set to
nulland reset. Setting a value here also resets the client socket factory.- Parameters:
socketFactory- the socket factory- See Also:
-
setClientSocketFactory
Sets the client socket factory used to create sockets. Ifnullthe address and port are required to be set.- Parameters:
clientSocketFactory- the client socket factory to use
-