Package org.simpleframework.transport
Class SocketFlusher
- java.lang.Object
-
- org.simpleframework.transport.SocketFlusher
-
class SocketFlusher extends java.lang.Object
TheSocketFlusher
flushes bytes to the underlying socket channel. This allows asynchronous writes to the socket to be managed in such a way that there is order to the way data is delivered over the socket. This uses a selector to dispatch flush invocations to the underlying socket when the socket is write ready. This allows the writing thread to continue without having to wait for all the data to be written to the socket.- See Also:
SocketBufferWriter
-
-
Field Summary
Fields Modifier and Type Field Description private SocketBuffer
buffer
This is the writer used to queue the buffers written.private boolean
closed
This is used to determine if the socket flusher is closed.private FlushScheduler
scheduler
This is the scheduler used to block and signal the writer.private FlushSignaller
signaller
This is the signaller used to determine when to flush.
-
Constructor Summary
Constructors Constructor Description SocketFlusher(SocketBuffer buffer, Socket socket, Reactor reactor)
Constructor for theSocketFlusher
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
abort()
This is used to abort the flushing process when the reactor has been stopped.void
close()
This is used to close the flusher ensuring that all of the data within the writer will be flushed regardless of the amount of data within the writer that needs to be written.void
execute()
This is executed when the flusher is to write all of the data to the underlying socket.void
flush()
Here in this method we schedule a flush when the underlying writer is write ready.
-
-
-
Field Detail
-
signaller
private FlushSignaller signaller
This is the signaller used to determine when to flush.
-
scheduler
private FlushScheduler scheduler
This is the scheduler used to block and signal the writer.
-
buffer
private SocketBuffer buffer
This is the writer used to queue the buffers written.
-
closed
private boolean closed
This is used to determine if the socket flusher is closed.
-
-
Constructor Detail
-
SocketFlusher
public SocketFlusher(SocketBuffer buffer, Socket socket, Reactor reactor) throws java.io.IOException
Constructor for theSocketFlusher
object. This is used to flush buffers to the underlying socket asynchronously. When finished flushing all of the buffered data this signals any threads that are blocking waiting for the write to finish.- Parameters:
buffer
- this is used to write the buffered buffersreactor
- this is used to perform asynchronous writessocket
- this is the socket used to select with- Throws:
java.io.IOException
-
-
Method Detail
-
flush
public void flush() throws java.io.IOException
Here in this method we schedule a flush when the underlying writer is write ready. This allows the writer thread to return without having to fully flush the content to the underlying transport. If there are references queued this will block.- Throws:
java.io.IOException
-
execute
public void execute() throws java.io.IOException
This is executed when the flusher is to write all of the data to the underlying socket. In this situation the writes are attempted in a non blocking way, if the task does not complete then this will simply enqueue the writing task for OP_WRITE and leave the method. This returns true if all the buffers are written.- Throws:
java.io.IOException
-
abort
public void abort() throws java.io.IOException
This is used to abort the flushing process when the reactor has been stopped. An abort to the flusher typically happens when the server has been shutdown. It prevents threads lingering waiting for a I/O operation which prevents the server from shutting down.- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
This is used to close the flusher ensuring that all of the data within the writer will be flushed regardless of the amount of data within the writer that needs to be written. If the writer does not block then this waits to be finished.- Throws:
java.io.IOException
-
-