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

public class IOJobImpl extends Job implements 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.
  • Field Details

    • BUFFER_FMT

      protected static final com.fishlib.base.log.LogOutput.ObjFormatter<ByteBuffer> 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 communicate
      parameters - the parameters for timeouts and buffer management
      initialHandler - 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 communicate
      parameters - the parameters for timeouts and buffer management
      initialHandler - the initial handler for I/O events on this channel
      logDetails - 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 communicate
      parameters - the parameters for timeouts and buffer management
      initialHandlers - 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 communicate
      parameters - the parameters for timeouts and buffer management
      initialHandlers - the initial handlers for I/O events on this channel
      logDetails - additional information added to the log prefix
      Throws:
      IOException
  • Method Details

    • toString

      public String toString()
      Return an informative string description of this job.
      Overrides:
      toString in class Object
    • append

      public com.fishlib.base.log.LogOutput append(com.fishlib.base.log.LogOutput logOutput)
      Specified by:
      append in interface com.fishlib.base.log.LogOutputAppendable
      Overrides:
      append in class 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 class Job
      Parameters:
      channel - the channel which has become ready
      readyOps - the operations which can be performed on this channel without blocking
      Returns:
      the modified readyOps after the invocation; if non-zero, the job will be invoked again with these
    • 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 class 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 class Job
    • getDatagramCount

      public int getDatagramCount()
      Return the number of datagrams currently in the input buffer.
      Specified by:
      getDatagramCount in interface IOJob
    • getDatagramAddr

      public SocketAddress getDatagramAddr()
      Returns the source address of the next datagram in the buffer.
      Specified by:
      getDatagramAddr in interface IOJob
    • getDatagramLength

      public int getDatagramLength()
      Returns the length of the next datagram in the buffer.
      Specified by:
      getDatagramLength in interface IOJob
    • consumeDatagram

      public void consumeDatagram()
      Notifies the job that a datagram has been consumed.
      Specified by:
      consumeDatagram in interface IOJob
    • getReadBuffer

      public ByteBuffer getReadBuffer()
      Return the job's read buffer.
      Specified by:
      getReadBuffer in interface 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 interface IOJob
    • writeBuffer

      public long writeBuffer(ByteBuffer b) throws IOException
      Add a buffer to the write queue.
      Specified by:
      writeBuffer in interface IOJob
      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

      public long writeMessage(Message m, boolean allowFlush) throws IOException
      Add a message to the write queue.
      Specified by:
      writeMessage in interface IOJob
      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

      public long writeDatagramBuffer(ByteBuffer b, SocketAddress a) throws IOException
      Add a datagram buffer to the write queue.
      Specified by:
      writeDatagramBuffer in interface IOJob
      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

      public long writeDatagramMessage(Message m, SocketAddress a) throws IOException
      Add a message to the write queue.
      Specified by:
      writeDatagramMessage in interface IOJob
      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

      public long writeMessages(Message[] ma, int pos, int n, boolean allowFlush) throws IOException
      Add an array of messages to the write queue atomically.
      Specified by:
      writeMessages in interface IOJob
      Parameters:
      ma - the message array
      pos - the position of the first buffer to be written
      n - the number of buffers to be written
      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
    • writeBuffers

      public long writeBuffers(ByteBuffer[] ba, int pos, int n) throws IOException
      Add an array of buffers to the write queue atomically.
      Specified by:
      writeBuffers in interface IOJob
      Parameters:
      ba - the buffer array
      pos - the position of the first buffer to be written
      n - 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:
      getWriteQueueSize in interface IOJob
      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().
      Specified by:
      shutdown in interface IOJob
    • isShutdown

      public boolean isShutdown()
      Specified by:
      isShutdown in interface IOJob
      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.
      Specified by:
      suspend in interface IOJob
      Returns:
      true, if the suspension state of the job was changed
    • 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

      public SelectableChannel getChannel()
      Returns the job's channel, for use in the scheduler.
      Specified by:
      getChannel in interface IOJob
      Returns:
      the channel
    • addHandler

      public void addHandler(IOHandler handler)
      Add a new handler to the job. If the handler is already present in the job, do nothing.
      Specified by:
      addHandler in interface IOJob
    • addPrimaryHandler

      public void addPrimaryHandler(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 interface IOJob
    • removeHandler

      public void removeHandler(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 interface IOJob