org.opcfoundation.ua.utils.asyncsocket
Class AsyncOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by org.opcfoundation.ua.utils.asyncsocket.AsyncOutputStream
All Implemented Interfaces:
Closeable, Flushable

public abstract class AsyncOutputStream
extends OutputStream

Asyncronous output stream of asynchronous socket. There are two positions properties: Bytes written and bytes flushed.

Flushing of data can be monitored asyncronously with Alarm object. e.g. byte[] data; long pos = os.getPosition(); os.write(data); Alarm a = os.createAlarm(pos + data.length, flushListener);

Author:
Toni Kalajainen (toni.kalajainen@vtt.fi)
See Also:
BufferMonitor, AsyncSocketImpl

Constructor Summary
AsyncOutputStream()
           
 
Method Summary
abstract  BufferMonitor createMonitor(long position, MonitorListener flushListener)
          Create an object that monitors for flush position of the output stream.
abstract  long getFlushPosition()
          Get the position of stream that has been flushed.
abstract  long getPosition()
          Get the position of the stream
abstract  long getUnflushedBytes()
          Get number of bytes remaining to be written
abstract  void offer(ByteBuffer buf)
          Offers byte buffer to the output stream for write.
abstract  void write(ByteBuffer src)
          Write to stream
abstract  void write(ByteBuffer src, int length)
          Write to stream
 
Methods inherited from class java.io.OutputStream
close, flush, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AsyncOutputStream

public AsyncOutputStream()
Method Detail

write

public abstract void write(ByteBuffer src)
Write to stream

Parameters:
src - a ByteBuffer object.

write

public abstract void write(ByteBuffer src,
                           int length)
Write to stream

Parameters:
src - a ByteBuffer object.
length - a int.

offer

public abstract void offer(ByteBuffer buf)
Offers byte buffer to the output stream for write. The ownership of the byte buffer and its back-end will be taken over by the stream.

Parameters:
buf - buffer to offer

getFlushPosition

public abstract long getFlushPosition()
Get the position of stream that has been flushed. This position lags behind getPosition() value

Returns:
bytes flushed from the stream

getPosition

public abstract long getPosition()
Get the position of the stream

Returns:
number of bytes written to the stream

getUnflushedBytes

public abstract long getUnflushedBytes()
Get number of bytes remaining to be written

Returns:
the number of unflushed bytes

createMonitor

public abstract BufferMonitor createMonitor(long position,
                                            MonitorListener flushListener)
Create an object that monitors for flush position of the output stream.

Parameters:
position - position to trigger
flushListener - alarm listener
Returns:
alarm


Copyright © 2018. All rights reserved.