Top Description Inners Fields Constructors Methods
org.jboss.logmanager.handlers

public Class SocketHandler

extends ExtHandler
Class Inheritance
Annotations
@SuppressWarnings:unused, WeakerAccess
Imports
java.io.Closeable, .Flushable, .IOException, .OutputStream, .OutputStreamWriter, .UnsupportedEncodingException, .Writer, java.net.InetAddress, .UnknownHostException, java.util.logging.ErrorManager, .Formatter, javax.net.SocketFactory, javax.net.ssl.SSLSocketFactory, org.jboss.logmanager.ExtHandler, .ExtLogRecord

A handler used to communicate over a socket.
Author
James R. Perkins

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
SocketHandler.Protocol

The type of socket

Field Summary

Modifier and TypeField and Description
private InetAddress
private boolean
private ClientSocketFactory
public static final int
private boolean
private int
private SocketHandler.Protocol
private SocketFactory
private Writer
Inherited from org.jboss.logmanager.ExtHandler:
handlershandlersUpdaterlock

Constructor Summary

AccessConstructor and Description
public
SocketHandler()

Creates a socket handler with an address of localhost and port of 4560.

public
SocketHandler(final String
the hostname to connect to
hostname
,
final int
the port to connect to
port
)

Creates a socket handler.

public
SocketHandler(final InetAddress
the address to connect to
address
,
final int
the port to connect to
port
)

Creates a socket handler.

public
SocketHandler(final SocketHandler.Protocol
the protocol to connect with
protocol
,
final String
the hostname to connect to
hostname
,
final int
the port to connect to
port
)

Creates a socket handler.

public
SocketHandler(final SocketHandler.Protocol
the protocol to connect with
protocol
,
final InetAddress
the address to connect to
address
,
final int
the port to connect to
port
)

Creates a socket handler.

public
SocketHandler(final SocketFactory
the socket factory to use for creating TCP or SSL TCP connections, if null a default factory will be used
socketFactory
,
final SocketHandler.Protocol
the protocol to connect with
protocol
,
final String
the hostname to connect to
hostname
,
final int
the port to connect to
port
)

Creates a socket handler.

public
SocketHandler(final SocketFactory
the socket factory to use for creating TCP or SSL TCP connections, if null a default factory will be used
socketFactory
,
final SocketHandler.Protocol
the protocol to connect with
protocol
,
final InetAddress
the address to connect to
address
,
final int
the port to connect to
port
)

Creates a socket handler.

public
SocketHandler(final ClientSocketFactory
the client socket factory used to create sockets
clientSocketFactory
,
final SocketHandler.Protocol
the protocol to connect with
protocol
)

Creates a socket handler.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides org.jboss.logmanager.ExtHandler.close.

Implements java.lang.AutoCloseable.close.

Close all child handlers.

private OutputStream
protected void
doPublish(final ExtLogRecord
the log record to publish
record
)

Overrides org.jboss.logmanager.ExtHandler.doPublish.

Do the actual work of publication; the record will have been filtered already.

public void
flush()

Overrides org.jboss.logmanager.ExtHandler.flush.

Implements java.io.Flushable.flush.

Flush all child handlers.

public InetAddress

Returns:

the address
getAddress
()

Returns the address being used.

private ClientSocketFactory
public int

Returns:

the port
getPort
()

Returns the port being used.

public SocketHandler.Protocol

Returns:

the protocol
getProtocol
()

Returns the protocol being used.

private void
public boolean

Returns:

true if blocking is enabled, otherwise false
isBlockOnReconnect
()

Indicates whether or not the output stream is set to block when attempting to reconnect a TCP connection.

private void
private void
public void
setAddress(final InetAddress
the address
address
)

Sets the address to connect to.

public void
setBlockOnReconnect(final boolean
true to block when reconnecting or false to reconnect asynchronously discarding any new messages coming in
blockOnReconnect
)

Enables or disables blocking when attempting to reconnect the socket when using a TCP or SSL TCP connections.

public void
setClientSocketFactory(final ClientSocketFactory
the client socket factory to use
clientSocketFactory
)

Sets the client socket factory used to create sockets.

public void
setHostname(final String
the host name used to resolve the address
hostname
)

Sets the address to connect to by doing a lookup on the hostname.

public void
setPort(final int
the port
port
)

Sets the port to connect to.

public void
setProtocol(final SocketHandler.Protocol
the protocol to use
protocol
)

Sets the protocol to use.

public void
setSocketFactory(final SocketFactory
the socket factory
socketFactory
)

Sets the socket factory to use for creating TCP or SSL connections.

private void
writeHead(final Writer writer)

private void
writeTail(final Writer writer)

Inherited from org.jboss.logmanager.ExtHandler:
addHandlercheckAccesscheckAccessclearHandlersgetCharsetgetEncodinggetErrorManagergetFiltergetFormattergetHandlersgetLevelisAutoFlushisCallerCalculationRequiredisCloseChildrenisEnabledpublishpublishpublishToNestedHandlersremoveHandlerreportErrorreportErrorsetAutoFlushsetCharsetsetCharsetPrivatesetCloseChildrensetEnabledsetEncodingsetErrorManagersetFiltersetFormattersetHandlerssetLevel

Field Detail

addressback to summary
private InetAddress address
blockOnReconnectback to summary
private boolean blockOnReconnect
clientSocketFactoryback to summary
private ClientSocketFactory clientSocketFactory
DEFAULT_PORTback to summary
public static final int DEFAULT_PORT
Annotations
@SuppressWarnings:WeakerAccess
initializeback to summary
private boolean initialize
portback to summary
private int port
protocolback to summary
private SocketHandler.Protocol protocol
socketFactoryback to summary
private SocketFactory socketFactory
writerback to summary
private Writer writer

Constructor Detail

SocketHandlerback to summary
public SocketHandler() throws UnknownHostException

Creates a socket handler with an address of localhost and port of 4560.

Exceptions
UnknownHostException:
if an error occurs attempting to retrieve the localhost
SocketHandlerback to summary
public SocketHandler(final String hostname, final int port) throws UnknownHostException

Creates a socket handler.

Parameters
hostname:String

the hostname to connect to

port:int

the port to connect to

Exceptions
UnknownHostException:
if an error occurs resolving the address
SocketHandlerback to summary
public SocketHandler(final InetAddress address, final int port)

Creates a socket handler.

Parameters
address:InetAddress

the address to connect to

port:int

the port to connect to

SocketHandlerback to summary
public SocketHandler(final SocketHandler.Protocol protocol, final String hostname, final int port) throws UnknownHostException

Creates a socket handler.

Parameters
protocol:SocketHandler.Protocol

the protocol to connect with

hostname:String

the hostname to connect to

port:int

the port to connect to

Exceptions
UnknownHostException:
if an error occurs resolving the hostname
SocketHandlerback to summary
public SocketHandler(final SocketHandler.Protocol protocol, final InetAddress address, final int port)

Creates a socket handler.

Parameters
protocol:SocketHandler.Protocol

the protocol to connect with

address:InetAddress

the address to connect to

port:int

the port to connect to

SocketHandlerback to summary
public SocketHandler(final SocketFactory socketFactory, final SocketHandler.Protocol protocol, final String hostname, final int port) throws UnknownHostException

Creates a socket handler.

Parameters
socketFactory:SocketFactory

the socket factory to use for creating TCP or SSL TCP connections, if null a default factory will be used

protocol:SocketHandler.Protocol

the protocol to connect with

hostname:String

the hostname to connect to

port:int

the port to connect to

Exceptions
UnknownHostException:
if an error occurs resolving the hostname
See Also
SocketHandler(ClientSocketFactory, Protocol)
SocketHandlerback to summary
public SocketHandler(final SocketFactory socketFactory, final SocketHandler.Protocol protocol, final InetAddress address, final int port)

Creates a socket handler.

Parameters
socketFactory:SocketFactory

the socket factory to use for creating TCP or SSL TCP connections, if null a default factory will be used

protocol:SocketHandler.Protocol

the protocol to connect with

address:InetAddress

the address to connect to

port:int

the port to connect to

See Also
SocketHandler(ClientSocketFactory, Protocol)
SocketHandlerback to summary
public SocketHandler(final ClientSocketFactory clientSocketFactory, final SocketHandler.Protocol protocol)

Creates a socket handler.

Parameters
clientSocketFactory:ClientSocketFactory

the client socket factory used to create sockets

protocol:SocketHandler.Protocol

the protocol to connect with

Method Detail

closeback to summary
public void close() throws SecurityException

Overrides org.jboss.logmanager.ExtHandler.close.

Implements java.lang.AutoCloseable.close.

Doc from org.jboss.logmanager.ExtHandler.close.

Close all child handlers.

Annotations
@Override
Exceptions
SecurityException:

Doc from java.util.logging.Handler.close.

if a security manager exists and if the caller does not have LoggingPermission("control").

createOutputStreamback to summary
private OutputStream createOutputStream()
doPublishback to summary
protected void doPublish(final ExtLogRecord record)

Overrides org.jboss.logmanager.ExtHandler.doPublish.

Doc from org.jboss.logmanager.ExtHandler.doPublish.

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.

Parameters
record:ExtLogRecord

the log record to publish

Annotations
@Override
flushback to summary
public void flush()

Overrides org.jboss.logmanager.ExtHandler.flush.

Implements java.io.Flushable.flush.

Doc from org.jboss.logmanager.ExtHandler.flush.

Flush all child handlers.

Annotations
@Override
getAddressback to summary
public InetAddress getAddress()

Returns the address being used.

Returns:InetAddress

the address

getClientSocketFactoryback to summary
private ClientSocketFactory getClientSocketFactory()
getPortback to summary
public int getPort()

Returns the port being used.

Returns:int

the port

getProtocolback to summary
public SocketHandler.Protocol getProtocol()

Returns the protocol being used.

Returns:SocketHandler.Protocol

the protocol

initializeback to summary
private void initialize()
isBlockOnReconnectback to summary
public boolean isBlockOnReconnect()

Indicates whether or not the output stream is set to block when attempting to reconnect a TCP connection.

Returns:boolean

true if blocking is enabled, otherwise false

safeCloseback to summary
private void safeClose(Closeable c)
safeFlushback to summary
private void safeFlush(Flushable f)
setAddressback to summary
public void setAddress(final InetAddress address)

Sets the address to connect to.

Note that is resets the client socket factory.

Parameters
address:InetAddress

the address

setBlockOnReconnectback to summary
public void setBlockOnReconnect(final 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:boolean

true to block when reconnecting or false to reconnect asynchronously discarding any new messages coming in

setClientSocketFactoryback to summary
public void setClientSocketFactory(final ClientSocketFactory clientSocketFactory)

Sets the client socket factory used to create sockets. If null the address and port are required to be set.

Parameters
clientSocketFactory:ClientSocketFactory

the client socket factory to use

setHostnameback to summary
public void setHostname(final 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:String

the host name used to resolve the address

Exceptions
UnknownHostException:
if an error occurs resolving the address
setPortback to summary
public void setPort(final int port)

Sets the port to connect to.

Note that is resets the client socket factory.

Parameters
port:int

the port

setProtocolback to summary
public void setProtocol(final 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:SocketHandler.Protocol

the protocol to use

setSocketFactoryback to summary
public void setSocketFactory(final 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:SocketFactory

the socket factory

See Also
setClientSocketFactory(ClientSocketFactory)
writeHeadback to summary
private void writeHead(final Writer writer)
writeTailback to summary
private void writeTail(final Writer writer)
org.jboss.logmanager.handlers back to summary

public final Enum SocketHandler.Protocol

extends Enum<SocketHandler.Protocol>
Class Inheritance

The type of socket

Field Summary

Modifier and TypeField and Description
public static final SocketHandler.Protocol
SSL_TCP

Transport Layer Security over TCP

public static final SocketHandler.Protocol
TCP

Transmission Control Protocol

public static final SocketHandler.Protocol
UDP

User Datagram Protocol

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static SocketHandler.Protocol
public static SocketHandler.Protocol[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

SSL_TCPback to summary
public static final SocketHandler.Protocol SSL_TCP

Transport Layer Security over TCP

TCPback to summary
public static final SocketHandler.Protocol TCP

Transmission Control Protocol

UDPback to summary
public static final SocketHandler.Protocol UDP

User Datagram Protocol

Constructor Detail

Protocolback to summary
private Protocol()

Method Detail

valueOfback to summary
public static SocketHandler.Protocol valueOf(String name)
valuesback to summary
public static SocketHandler.Protocol[] values()