Class IOJobImplLenient
java.lang.Object
com.fishlib.io.sched.Job
com.illumon.iris.db.v2.locations.remote.IOJobImplLenient
- All Implemented Interfaces:
com.fishlib.base.log.LogOutputAppendable
,com.fishlib.io.sched.IOJob
public class IOJobImplLenient
extends com.fishlib.io.sched.Job
implements com.fishlib.io.sched.IOJob
This is a clone of
IOJobImpl
, with optional added protection against write queue overflows.-
Nested Class Summary
Nested classes/interfaces inherited from interface com.fishlib.io.sched.IOJob
com.fishlib.io.sched.IOJob.Null
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final com.fishlib.base.log.LogOutput.ObjFormatter<ByteBuffer>
object formatter for byte buffer state -
Constructor Summary
ConstructorsConstructorDescriptionIOJobImplLenient
(com.fishlib.io.sched.Scheduler sched, SelectableChannel channel, com.fishlib.io.sched.IOParameters parameters, com.fishlib.io.sched.IOStats stats, com.fishlib.io.sched.IOHandler[] initialHandlers, com.fishlib.io.logger.Logger log) When an IOJobImpl is constructed, it notifies its handler of its birth via the startJob() method, and then registers itself with the scheduler.IOJobImplLenient
(com.fishlib.io.sched.Scheduler sched, SelectableChannel channel, com.fishlib.io.sched.IOParameters parameters, com.fishlib.io.sched.IOStats stats, com.fishlib.io.sched.IOHandler[] initialHandlers, com.fishlib.io.logger.Logger log, String logDetails) When an IOJobImpl is constructed, it notifies its handler of its birth via the startJob() method, and then registers itself with the scheduler.IOJobImplLenient
(com.fishlib.io.sched.Scheduler sched, SelectableChannel channel, com.fishlib.io.sched.IOParameters parameters, com.fishlib.io.sched.IOStats stats, com.fishlib.io.sched.IOHandler initialHandler, com.fishlib.io.logger.Logger log) When an IOJobImpl is constructed, it notifies its handler of its birth via the startJob() method, and then registers itself with the scheduler.IOJobImplLenient
(com.fishlib.io.sched.Scheduler sched, SelectableChannel channel, com.fishlib.io.sched.IOParameters parameters, com.fishlib.io.sched.IOStats stats, com.fishlib.io.sched.IOHandler initialHandler, com.fishlib.io.logger.Logger log, String logDetails) When an IOJobImpl is constructed, it notifies its handler of its birth via the startJob() method, and then registers itself with the scheduler. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addHandler
(com.fishlib.io.sched.IOHandler handler) Add a new handler to the job.void
addPrimaryHandler
(com.fishlib.io.sched.IOHandler handler) Add a new handler to the job, making it the primary handler.void
adviseReadSpace
(int n) Advise the job of the amount of space required to read the next message.com.fishlib.base.log.LogOutput
append
(com.fishlib.base.log.LogOutput logOutput) void
Called by the scheduler when the job is cancelled before it is invoked.void
Notifies the job that a datagram has been consumed.Returns the job's channel, for use in the scheduler.Returns the source address of the next datagram in the buffer.int
Return the number of datagrams currently in the input buffer.int
Returns the length of the next datagram in the buffer.Return the job's read buffer.long
Returns the number of bytes in the job's write queue.int
invoke
(SelectableChannel channel, int readyOps, com.fishlib.base.Procedure.Nullary handoff) Called by the scheduler when the ready set overlaps our interest set.boolean
void
removeHandler
(com.fishlib.io.sched.IOHandler handler) Remove the given handler from the job.void
shutdown()
Shuts down the job.boolean
suspend
(boolean flag) Temporarily suspend the job, or re-enable it after a suspension.void
timedOut()
Called by the scheduler when the job times out.toString()
Return an informative string description of this job.long
Add a buffer to the write queue.long
writeBuffers
(ByteBuffer[] ba, int pos, int n) Add an array of buffers to the write queue atomically.long
Add a datagram buffer to the write queue.long
writeDatagramMessage
(com.fishlib.io.sched.Message m, SocketAddress a) Add a message to the write queue.long
writeMessage
(com.fishlib.io.sched.Message m, boolean allowFlush) Add a message to the write queue.long
writeMessages
(com.fishlib.io.sched.Message[] ma, int pos, int n, boolean allowFlush) Add an array of messages to the write queue atomically.protected boolean
writeOk()
We always want to get write data onto the wire as quickly as possible, but we respect the blocked write size if it's set.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.fishlib.io.sched.IOJob
writeMessage, writeMessages
-
Field Details
-
BUFFER_FMT
object formatter for byte buffer state
-
-
Constructor Details
-
IOJobImplLenient
public IOJobImplLenient(com.fishlib.io.sched.Scheduler sched, SelectableChannel channel, com.fishlib.io.sched.IOParameters parameters, com.fishlib.io.sched.IOStats stats, com.fishlib.io.sched.IOHandler initialHandler, com.fishlib.io.logger.Logger log) throws IOException When an IOJobImpl is constructed, it notifies its handler of its birth via the startJob() method, and then registers itself with the scheduler.- Parameters:
channel
- the channel on which this job will communicateparameters
- the parameters for timeouts and buffer managementinitialHandler
- the initial handler for I/O events on this channel- Throws:
IOException
-
IOJobImplLenient
public IOJobImplLenient(com.fishlib.io.sched.Scheduler sched, SelectableChannel channel, com.fishlib.io.sched.IOParameters parameters, com.fishlib.io.sched.IOStats stats, com.fishlib.io.sched.IOHandler initialHandler, com.fishlib.io.logger.Logger log, String logDetails) throws IOException When an IOJobImpl is constructed, it notifies its handler of its birth via the startJob() method, and then registers itself with the scheduler.- Parameters:
channel
- the channel on which this job will communicateparameters
- the parameters for timeouts and buffer managementinitialHandler
- the initial handler for I/O events on this channellogDetails
- additional information added to the log prefix- Throws:
IOException
-
IOJobImplLenient
public IOJobImplLenient(com.fishlib.io.sched.Scheduler sched, SelectableChannel channel, com.fishlib.io.sched.IOParameters parameters, com.fishlib.io.sched.IOStats stats, com.fishlib.io.sched.IOHandler[] initialHandlers, com.fishlib.io.logger.Logger log) throws IOException When an IOJobImpl is constructed, it notifies its handler of its birth via the startJob() method, and then registers itself with the scheduler.- Parameters:
channel
- the channel on which this job will communicateparameters
- the parameters for timeouts and buffer managementinitialHandlers
- the initial handlers for I/O events on this channel- Throws:
IOException
-
IOJobImplLenient
public IOJobImplLenient(com.fishlib.io.sched.Scheduler sched, SelectableChannel channel, com.fishlib.io.sched.IOParameters parameters, com.fishlib.io.sched.IOStats stats, com.fishlib.io.sched.IOHandler[] initialHandlers, com.fishlib.io.logger.Logger log, String logDetails) throws IOException When an IOJobImpl is constructed, it notifies its handler of its birth via the startJob() method, and then registers itself with the scheduler.- Parameters:
channel
- the channel on which this job will communicateparameters
- the parameters for timeouts and buffer managementinitialHandlers
- the initial handlers for I/O events on this channellogDetails
- additional information added to the log prefix- Throws:
IOException
-
-
Method Details
-
toString
Return an informative string description of this job. -
append
public com.fishlib.base.log.LogOutput append(com.fishlib.base.log.LogOutput logOutput) - Specified by:
append
in interfacecom.fishlib.base.log.LogOutputAppendable
- Overrides:
append
in classcom.fishlib.io.sched.Job
-
invoke
public int invoke(SelectableChannel channel, int readyOps, com.fishlib.base.Procedure.Nullary handoff) Called by the scheduler when the ready set overlaps our interest set. NOTE: not synchronized; called only from the scheduler- Specified by:
invoke
in classcom.fishlib.io.sched.Job
-
cancelled
public void cancelled()Called by the scheduler when the job is cancelled before it is invoked. NOTE: not synchronized, called only from the scheduler- Specified by:
cancelled
in classcom.fishlib.io.sched.Job
-
timedOut
public void timedOut()Called by the scheduler when the job times out. NOTE: not synchronized, called only from the scheduler- Specified by:
timedOut
in classcom.fishlib.io.sched.Job
-
getDatagramCount
public int getDatagramCount()Return the number of datagrams currently in the input buffer.- Specified by:
getDatagramCount
in interfacecom.fishlib.io.sched.IOJob
-
getDatagramAddr
Returns the source address of the next datagram in the buffer.- Specified by:
getDatagramAddr
in interfacecom.fishlib.io.sched.IOJob
-
getDatagramLength
public int getDatagramLength()Returns the length of the next datagram in the buffer.- Specified by:
getDatagramLength
in interfacecom.fishlib.io.sched.IOJob
-
consumeDatagram
public void consumeDatagram()Notifies the job that a datagram has been consumed.- Specified by:
consumeDatagram
in interfacecom.fishlib.io.sched.IOJob
-
getReadBuffer
Return the job's read buffer.- Specified by:
getReadBuffer
in interfacecom.fishlib.io.sched.IOJob
-
adviseReadSpace
public void adviseReadSpace(int n) Advise the job of the amount of space required to read the next message.- Specified by:
adviseReadSpace
in interfacecom.fishlib.io.sched.IOJob
-
writeBuffer
Add a buffer to the write queue.- Specified by:
writeBuffer
in interfacecom.fishlib.io.sched.IOJob
- Throws:
IOException
-
writeMessage
Add a message to the write queue.- Specified by:
writeMessage
in interfacecom.fishlib.io.sched.IOJob
- Throws:
IOException
-
writeDatagramBuffer
Add a datagram buffer to the write queue.- Specified by:
writeDatagramBuffer
in interfacecom.fishlib.io.sched.IOJob
- Throws:
IOException
-
writeDatagramMessage
public long writeDatagramMessage(com.fishlib.io.sched.Message m, SocketAddress a) throws IOException Add a message to the write queue.- Specified by:
writeDatagramMessage
in interfacecom.fishlib.io.sched.IOJob
- Throws:
IOException
-
writeMessages
public long writeMessages(com.fishlib.io.sched.Message[] ma, int pos, int n, boolean allowFlush) throws IOException Add an array of messages to the write queue atomically.- Specified by:
writeMessages
in interfacecom.fishlib.io.sched.IOJob
- Throws:
IOException
-
writeBuffers
Add an array of buffers to the write queue atomically.- Specified by:
writeBuffers
in interfacecom.fishlib.io.sched.IOJob
- Throws:
IOException
-
getWriteQueueSize
public long getWriteQueueSize()Returns the number of bytes in the job's write queue.- Specified by:
getWriteQueueSize
in interfacecom.fishlib.io.sched.IOJob
-
shutdown
public void shutdown()Shuts down the job. After shutdown returns, no more data will be read. However, if the write queue still contains data, the job will remain alive and continue to interact with the scheduler until the queue has been emptied. The channel will be closed as soon as the queue is empty. NOTE: this will *not* call the handlers' endJob methods directly; it will cancel the job and wait for the scheduler to invoke cancelled().- Specified by:
shutdown
in interfacecom.fishlib.io.sched.IOJob
-
isShutdown
public boolean isShutdown()- Specified by:
isShutdown
in interfacecom.fishlib.io.sched.IOJob
-
suspend
public boolean suspend(boolean flag) Temporarily suspend the job, or re-enable it after a suspension. When a job is suspended, it will not register itself for input events with the scheduler, but will continue to flush its write queue. This suspension mechanism is intended to be used for flow control, for example to throttle an incoming connection in response to the rate at which a peer can accept the data.- Specified by:
suspend
in interfacecom.fishlib.io.sched.IOJob
-
writeOk
protected boolean writeOk()We always want to get write data onto the wire as quickly as possible, but we respect the blocked write size if it's set.- Returns:
- true, if the channel is interested in writing
-
getChannel
Returns the job's channel, for use in the scheduler.- Specified by:
getChannel
in interfacecom.fishlib.io.sched.IOJob
- Returns:
- the channel
-
addHandler
public void addHandler(com.fishlib.io.sched.IOHandler handler) Add a new handler to the job. If the handler is already present in the job, do nothing.- Specified by:
addHandler
in interfacecom.fishlib.io.sched.IOJob
-
addPrimaryHandler
public void addPrimaryHandler(com.fishlib.io.sched.IOHandler handler) Add a new handler to the job, making it the primary handler. If the handler is already present in the job but is not the primary handler, it will be made primary.- Specified by:
addPrimaryHandler
in interfacecom.fishlib.io.sched.IOJob
-
removeHandler
public void removeHandler(com.fishlib.io.sched.IOHandler handler) Remove the given handler from the job. If the handler is not present in the job nothing happens. If the handler was the primary handler, then the next one in the vector becomes the primary handler.- Specified by:
removeHandler
in interfacecom.fishlib.io.sched.IOJob
-