Class IOJobImpl
java.lang.Object
io.deephaven.enterprise.comm.sched.Job
io.deephaven.enterprise.niowrapper.sched.IOJobImpl
- All Implemented Interfaces:
com.fishlib.base.log.LogOutputAppendable,IOJob
Created by IntelliJ IDEA. User: jrauser Date: Sep 26, 2006 Time: 7:47:30 PM To change this template use File |
Settings | File Templates.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.deephaven.enterprise.niowrapper.sched.IOJob
IOJob.Null -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final com.fishlib.base.log.LogOutput.ObjFormatter<ByteBuffer>object formatter for byte buffer state -
Constructor Summary
ConstructorsConstructorDescriptionIOJobImpl(Scheduler sched, SelectableChannel channel, IOParameters parameters, IOStats stats, 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.IOJobImpl(Scheduler sched, SelectableChannel channel, IOParameters parameters, IOStats stats, 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.IOJobImpl(Scheduler sched, SelectableChannel channel, IOParameters parameters, IOStats stats, 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.IOJobImpl(Scheduler sched, SelectableChannel channel, IOParameters parameters, IOStats stats, 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 TypeMethodDescriptionvoidaddHandler(IOHandler handler) Add a new handler to the job.voidaddPrimaryHandler(IOHandler handler) Add a new handler to the job, making it the primary handler.voidadviseReadSpace(int n) Advise the job of the amount of space required to read the next message.com.fishlib.base.log.LogOutputappend(com.fishlib.base.log.LogOutput logOutput) voidCalled by the scheduler when the job is cancelled before it is invoked.voidNotifies 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.intReturn the number of datagrams currently in the input buffer.intReturns the length of the next datagram in the buffer.Return the job's read buffer.longReturns the number of bytes in the job's write queue.intinvoke(SelectableChannel channel, int readyOps, com.fishlib.base.Procedure.Nullary handoff) Called by the scheduler when the ready set overlaps our interest set.booleanvoidremoveHandler(IOHandler handler) Remove the given handler from the job.voidshutdown()Shuts down the job.booleansuspend(boolean flag) Temporarily suspend the job, or re-enable it after a suspension.voidtimedOut()Called by the scheduler when the job times out.toString()Return an informative string description of this job.longAdd a buffer to the write queue.longwriteBuffers(ByteBuffer[] ba, int pos, int n) Add an array of buffers to the write queue atomically.longAdd a datagram buffer to the write queue.longAdd a message to the write queue.longwriteMessage(Message m, boolean allowFlush) Add a message to the write queue.longwriteMessages(Message[] ma, int pos, int n, boolean allowFlush) Add an array of messages to the write queue atomically.protected booleanwriteOk()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 io.deephaven.enterprise.comm.sched.Job
getStateFor, makeStateForMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface io.deephaven.enterprise.niowrapper.sched.IOJob
writeMessage, writeMessages
-
Field Details
-
BUFFER_FMT
object formatter for byte buffer state
-
-
Constructor Details
-
IOJobImpl
public IOJobImpl(Scheduler sched, SelectableChannel channel, IOParameters parameters, IOStats stats, 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
-
IOJobImpl
public IOJobImpl(Scheduler sched, SelectableChannel channel, IOParameters parameters, IOStats stats, 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
-
IOJobImpl
public IOJobImpl(Scheduler sched, SelectableChannel channel, IOParameters parameters, IOStats stats, 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
-
IOJobImpl
public IOJobImpl(Scheduler sched, SelectableChannel channel, IOParameters parameters, IOStats stats, 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) -
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 -
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 -
timedOut
public void timedOut()Called by the scheduler when the job times out. NOTE: not synchronized, called only from the scheduler -
getDatagramCount
public int getDatagramCount()Return the number of datagrams currently in the input buffer.- Specified by:
getDatagramCountin interfaceIOJob
-
getDatagramAddr
Returns the source address of the next datagram in the buffer.- Specified by:
getDatagramAddrin interfaceIOJob
-
getDatagramLength
public int getDatagramLength()Returns the length of the next datagram in the buffer.- Specified by:
getDatagramLengthin interfaceIOJob
-
consumeDatagram
public void consumeDatagram()Notifies the job that a datagram has been consumed.- Specified by:
consumeDatagramin interfaceIOJob
-
getReadBuffer
Return the job's read buffer.- Specified by:
getReadBufferin interfaceIOJob
-
adviseReadSpace
public void adviseReadSpace(int n) Advise the job of the amount of space required to read the next message.- Specified by:
adviseReadSpacein interfaceIOJob
-
writeBuffer
Add a buffer to the write queue.- Specified by:
writeBufferin interfaceIOJob- Parameters:
b- the buffer, containing data to be written between its position() and limit()- Returns:
- the change in the size of the job's write queue; this may be positive, negative or zero, depending on whether and how much data was immediately flushable.
- Throws:
IOException
-
writeMessage
Add a message to the write queue.- Specified by:
writeMessagein interfaceIOJob- Parameters:
m- the message, containing data to be written between its position() and limit()allowFlush- whether to allow an immediate flush (on this thread)- Returns:
- the change in the size of the job's write queue; this may be positive, negative or zero, depending on whether and how much data was immediately flushable.
- Throws:
IOException
-
writeDatagramBuffer
Add a datagram buffer to the write queue.- Specified by:
writeDatagramBufferin interfaceIOJob- Parameters:
b- the buffer, containing data to be written between its position() and limit()a- the destination address for the datagram; should be null if the channel is connected- Returns:
- the change in the size of the job's write queue; this may be positive, negative or zero, depending on whether and how much data was immediately flushable.
- Throws:
IOException
-
writeDatagramMessage
Add a message to the write queue.- Specified by:
writeDatagramMessagein interfaceIOJob- Parameters:
m- the message, containing data to be written between its position() and limit()a- the destination address for the datagram; should be null if the channel is connected- Returns:
- the change in the size of the job's write queue; this may be positive, negative or zero, depending on whether and how much data was immediately flushable.
- Throws:
IOException
-
writeMessages
Add an array of messages to the write queue atomically.- Specified by:
writeMessagesin interfaceIOJob- Parameters:
ma- the message arraypos- the position of the first buffer to be writtenn- the number of buffers to be writtenallowFlush- whether to allow an immediate flush (on this thread)- Returns:
- the change in the size of the job's write queue; this may be positive, negative or zero, depending on whether and how much data was immediately flushable.
- Throws:
IOException
-
writeBuffers
Add an array of buffers to the write queue atomically.- Specified by:
writeBuffersin interfaceIOJob- Parameters:
ba- the buffer arraypos- the position of the first buffer to be writtenn- the number of buffers to be written- Returns:
- the change in the size of the job's write queue; this may be positive, negative or zero, depending on whether and how much data was immediately flushable.
- Throws:
IOException
-
getWriteQueueSize
public long getWriteQueueSize()Returns the number of bytes in the job's write queue.- Specified by:
getWriteQueueSizein interfaceIOJob- Returns:
- the number of bytes in the job's write queue.
-
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(). -
isShutdown
public boolean isShutdown()- Specified by:
isShutdownin interfaceIOJob- Returns:
- Whether the job has been shutdown.
-
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. -
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:
getChannelin interfaceIOJob- Returns:
- the channel
-
addHandler
Add a new handler to the job. If the handler is already present in the job, do nothing.- Specified by:
addHandlerin interfaceIOJob
-
addPrimaryHandler
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:
addPrimaryHandlerin interfaceIOJob
-
removeHandler
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:
removeHandlerin interfaceIOJob
-