Class RemoteReceiverStreamClient
- All Implemented Interfaces:
Client
,RemoteReceiverClient
,ContextAware
,Closeable
,AutoCloseable
,Runnable
RemoteReceiverClient
that writes serialized logging events to an
OutputStream
.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final String
private final OutputStream
private BlockingQueue
<Serializable> private final Socket
Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context
-
Constructor Summary
ConstructorsConstructorDescriptionRemoteReceiverStreamClient
(String id, OutputStream outputStream) Constructs a new client.RemoteReceiverStreamClient
(String id, Socket socket) Constructs a new client. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes any resources that are held by the client.private ObjectOutputStream
boolean
offer
(Serializable event) Offers an event to the client.void
run()
void
setQueue
(BlockingQueue<Serializable> queue) Sets the client's event queue.Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContext
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface ch.qos.logback.core.spi.ContextAware
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContext
-
Field Details
-
clientId
-
socket
-
outputStream
-
queue
-
-
Constructor Details
-
RemoteReceiverStreamClient
Constructs a new client.- Parameters:
id
- identifier string for the clientsocket
- socket to which logging events will be written
-
RemoteReceiverStreamClient
RemoteReceiverStreamClient(String id, OutputStream outputStream) Constructs a new client.This constructor exists primarily to support unit tests where it is inconvenient to have to create a socket for the test.
- Parameters:
id
- identifier string for the clientoutputStream
- output stream to which logging Events will be written
-
-
Method Details
-
setQueue
Sets the client's event queue.This method must be invoked before the
Runnable.run()
method is invoked.- Specified by:
setQueue
in interfaceRemoteReceiverClient
- Parameters:
queue
- the queue to set
-
offer
Offers an event to the client.- Specified by:
offer
in interfaceRemoteReceiverClient
- Parameters:
event
- the subject event- Returns:
true
if the client's queue accepted the event,false
if the client's queue is full
-
close
public void close()Closes any resources that are held by the client.Note that (as described in Doug Lea's discussion about interrupting I/O operations in "Concurrent Programming in Java" (Addison-Wesley Professional, 2nd edition, 1999) this method is used to interrupt any blocked I/O operation in the client when the server is shutting down. The client implementation must anticipate this potential, and gracefully exit when the blocked I/O operation throws the relevant
IOException
subclass.Note also, that unlike
Closeable.close()
this method is not permitted to propagate anyIOException
that occurs when closing the underlying resource(s). -
run
public void run() -
createObjectOutputStream
- Throws:
IOException
-