Package org.jboss.logmanager.handlers

# Class SocketHandler

java.lang.Object
java.util.logging.Handler
org.jboss.logmanager.ExtHandler
org.jboss.logmanager.handlers.SocketHandler

All Implemented Interfaces:
  `Closeable`, `Flushable`, `AutoCloseable`, `FlushableCloseable`, `Protectable`

public class SocketHandler extends ExtHandler
A handler used to communicate over a socket.

Author:
  James R. Perkins

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static enum`
`SocketHandler.Protocol`
The type of socket

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`DEFAULT_PORT`

### Fields inherited from class org.jboss.logmanager.ExtHandler

`handlers, handlersUpdater`

## Constructor Summary

Constructors
Constructor
Description
`SocketHandler()`
Creates a socket handler with an address of localhost and port of 4560.
`SocketHandler(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 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.
`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)`
Enables or disables blocking when attempting to reconnect the socket when using a TCP or SSL TCP connections.
`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)`
Sets the socket factory to use for creating TCP or SSL connections.

### Methods inherited from class org.jboss.logmanager.ExtHandler

`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`

### Methods inherited from class java.util.logging.Handler

`getEncoding, getErrorManager, getFilter, getFormatter, getLevel, isLoggable, reportError`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### DEFAULT_PORT

public static final int DEFAULT_PORT

See Also:
  - Constant Field Values

## Constructor Details

### SocketHandler

public SocketHandler() throws UnknownHostException
Creates a socket handler with an address of localhost and port of 4560.

Throws:
  `UnknownHostException` - if an error occurs attempting to retrieve the localhost

### SocketHandler

public SocketHandler(String hostname, int port) throws UnknownHostException
Creates a socket handler.

Parameters:
  `hostname` - the hostname to connect to
  `port` - the port to connect to
Throws:
  `UnknownHostException` - if an error occurs resolving the address

### SocketHandler

public SocketHandler(InetAddress address, int port)
Creates a socket handler.

Parameters:
  `address` - the address to connect to
  `port` - 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 with
  `hostname` - the hostname to connect to
  `port` - the port to connect to
Throws:
  `UnknownHostException` - if an error occurs resolving the hostname

### SocketHandler

public SocketHandler(SocketHandler.Protocol protocol, InetAddress address, int port)
Creates a socket handler.

Parameters:
  `protocol` - the protocol to connect with
  `address` - the address to connect to
  `port` - 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, if `null` a default factory will be used
  `protocol` - the protocol to connect with
  `hostname` - the hostname to connect to
  `port` - the port to connect to
Throws:
  `UnknownHostException` - if an error occurs resolving the hostname
See Also:
  - `SocketHandler(ClientSocketFactory, Protocol)`

### SocketHandler

public SocketHandler(SocketFactory socketFactory, SocketHandler.Protocol protocol, InetAddress address, int port)
Creates a socket handler.

Parameters:
  `socketFactory` - the socket factory to use for creating TCP or SSL TCP connections, if `null` a default factory will be used
  `protocol` - the protocol to connect with
  `address` - the address to connect to
  `port` - the port to connect to
See Also:
  - `SocketHandler(ClientSocketFactory, Protocol)`

### SocketHandler

public SocketHandler(ClientSocketFactory clientSocketFactory, SocketHandler.Protocol protocol)
Creates a socket handler.

Parameters:
  `clientSocketFactory` - the client socket factory used to create sockets
  `protocol` - the protocol to connect with

## Method Details

### doPublish

protected void doPublish(ExtLogRecord record)
Description copied from class: `ExtHandler`
Do the actual work of publication; the record will have been filtered already. The default implementation does nothing except to flush if the `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.

Overrides:
  `doPublish` in class `ExtHandler`
Parameters:
  `record` - the log record to publish

### flush

public void flush()
Description copied from class: `ExtHandler`
Flush all child handlers.

Specified by:
  `flush` in interface `Flushable`
Overrides:
  `flush` in class `ExtHandler`

### close

public void close() throws SecurityException
Description copied from class: `ExtHandler`
Close all child handlers.

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Closeable`
Overrides:
  `close` in class `ExtHandler`
Throws:
  `SecurityException`

### getAddress

public InetAddress getAddress()
Returns the address being used.

Returns:
  the address

### setAddress

public void setAddress(InetAddress address)
Sets the address to connect to.

Note that is resets the client socket factory.

Parameters:
  `address` - the address

### setHostname

public void setHostname(String hostname) throws UnknownHostException
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:
  `true` if blocking is enabled, otherwise `false`

### 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 to `true` the `write` methods will block when attempting to reconnect. This is only advisable to be set to `true` if using an asynchronous handler.

Parameters:
  `blockOnReconnect` - `true` to block when reconnecting or `false` to reconnect asynchronously discarding any new messages coming in

### getProtocol

public SocketHandler.Protocol getProtocol()
Returns the protocol being used.

Returns:
  the protocol

### setProtocol

public void setProtocol(SocketHandler.Protocol protocol)
Sets the protocol to use. If the value is `null` the 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

public void setSocketFactory(SocketFactory socketFactory)
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 `null` and reset. Setting a value here also resets the client socket factory.

Parameters:
  `socketFactory` - the socket factory
See Also:
  - `setClientSocketFactory(ClientSocketFactory)`

### setClientSocketFactory

public void setClientSocketFactory(ClientSocketFactory clientSocketFactory)
Sets the client socket factory used to create sockets. If `null` the address and port are required to be set.

Parameters:
  `clientSocketFactory` - the client socket factory to use