com.lts.ipc.fifo
Class FIFOImpl

java.lang.Object
  extended by com.lts.ipc.fifo.FIFOImpl

public class FIFOImpl
extends java.lang.Object

An internal class that provides the underlying system calls needed to implement named pipes.

This class is implementation dependent and not intended for general use.

Author:
cnh

Nested Class Summary
static class FIFOImpl.PipeDirection
          The role a client is taking (reader/writer) when using a named pipe.
 
Field Summary
static int BLOCKING_MODE_BLOCKING
           
static int BLOCKING_MODE_NON_BLOCKING
           
static int DIRECTION_READER
           
static int DIRECTION_WRITER
           
static int SELECT_BOTH
           
static int SELECT_READING
           
static int SELECT_WRITING
           
 
Constructor Summary
FIFOImpl(java.lang.String virtualName)
           
 
Method Summary
 void connectNonBlocking(FIFOResult result)
          Connect to the underlying FIFO.
 FIFOResult create()
           
 void createNonBlocking(FIFOResult result, java.lang.String name)
           
protected  java.lang.String getActualName()
           
protected  int getBufferSize()
           
protected  FIFOImpl.PipeDirection getDirection()
           
protected  int getDirectionInt()
           
protected  long getHandle()
           
 java.lang.String getVirtualName()
           
protected  void initialize(java.lang.String virtualName)
           
protected  boolean isCreator()
           
 FIFOResult open(FIFOImpl.PipeDirection direction)
           
 int read(byte[] buffer, int offset, int length)
           
 int read(byte[] buffer, int offset, int length, int timeoutMsec)
           
 void readNonBlocking(FIFOResult result, byte[] buffer, int start, int length, int timeoutMsec)
           
 void select(FIFOResult result, int timeoutMsec)
          Determine if the FIFO is ready for reading, writing, or both.
protected  void setActualName(java.lang.String actualName)
           
protected  void setBufferSize(int bufferSize)
           
 void setCreator(boolean creator)
           
protected  void setDirection(FIFOImpl.PipeDirection direction)
           
protected  void setHandle(long handle)
           
 void setVirtualName(java.lang.String virtualName)
           
static java.lang.String toActualName(java.lang.String virtualName)
          Return a name that the underlying OS can use for a named pipe, given a string that is more or less unique.
 int write(byte[] buffer, int offset, int length, int timeoutMsec)
          Try to write a buffer of data within the specified time frame.
 void writeNonBlocking(FIFOResult result, byte[] buffer, int start, int length, int timeoutMsec)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DIRECTION_READER

public static final int DIRECTION_READER
See Also:
Constant Field Values

DIRECTION_WRITER

public static final int DIRECTION_WRITER
See Also:
Constant Field Values

BLOCKING_MODE_BLOCKING

public static final int BLOCKING_MODE_BLOCKING
See Also:
Constant Field Values

BLOCKING_MODE_NON_BLOCKING

public static final int BLOCKING_MODE_NON_BLOCKING
See Also:
Constant Field Values

SELECT_READING

public static final int SELECT_READING
See Also:
Constant Field Values

SELECT_WRITING

public static final int SELECT_WRITING
See Also:
Constant Field Values

SELECT_BOTH

public static final int SELECT_BOTH
See Also:
Constant Field Values
Constructor Detail

FIFOImpl

public FIFOImpl(java.lang.String virtualName)
Method Detail

initialize

protected void initialize(java.lang.String virtualName)

create

public FIFOResult create()
                  throws IPCException
Throws:
IPCException

write

public int write(byte[] buffer,
                 int offset,
                 int length,
                 int timeoutMsec)
          throws IPCException
Try to write a buffer of data within the specified time frame.

It is possible for a FIFO to have enough data written to it that it runs out of buffer space. When that happens the writer must wait until the reader reads enough of the data to free up some more buffer space.

The timeout specifies how long the caller is willing to wait for buffer space to free up. A value of less than 0 means that the caller will wait "forever." A value of 0 means that the caller will not wait at all --- if it is not possible to write immediately, then throw a timeout.

Any other value specifies the number of milliseconds that the caller will wait for the space to free up.

Note that a wait will only occur if the FIFO is full --- in all other situations, the write will complete without delay.

Parameters:
buffer - The buffer that contains the data to write.
offset - The offset within the buffer that the data starts.
length - The number of bytes to try and write.
timeoutMsec - See description. The number of milliseconds to wait for a write to become possible.
Returns:
The number of bytes actually written.
Throws:
IPCException - If the caller specified a wait time and this elapsed before anything could be written, then this exception is thrown.

read

public int read(byte[] buffer,
                int offset,
                int length)
         throws IPCException
Throws:
IPCException

read

public int read(byte[] buffer,
                int offset,
                int length,
                int timeoutMsec)
         throws IPCException
Throws:
IPCException

open

public FIFOResult open(FIFOImpl.PipeDirection direction)
                throws IPCException
Throws:
IPCException

getVirtualName

public java.lang.String getVirtualName()

setVirtualName

public void setVirtualName(java.lang.String virtualName)

getBufferSize

protected int getBufferSize()

setBufferSize

protected void setBufferSize(int bufferSize)

getActualName

protected java.lang.String getActualName()

getDirection

protected FIFOImpl.PipeDirection getDirection()

getDirectionInt

protected int getDirectionInt()

getHandle

protected long getHandle()

setActualName

protected void setActualName(java.lang.String actualName)

setCreator

public void setCreator(boolean creator)

setDirection

protected void setDirection(FIFOImpl.PipeDirection direction)

setHandle

protected void setHandle(long handle)

isCreator

protected boolean isCreator()

createNonBlocking

public void createNonBlocking(FIFOResult result,
                              java.lang.String name)

readNonBlocking

public void readNonBlocking(FIFOResult result,
                            byte[] buffer,
                            int start,
                            int length,
                            int timeoutMsec)

writeNonBlocking

public void writeNonBlocking(FIFOResult result,
                             byte[] buffer,
                             int start,
                             int length,
                             int timeoutMsec)

toActualName

public static java.lang.String toActualName(java.lang.String virtualName)
Return a name that the underlying OS can use for a named pipe, given a string that is more or less unique.

Currently, all platforms that support named pipes use a file name to identify the named pipe. This method does several things. First of all, it signals to CLIPC whether or not the OS uses special names for pipes.

Windows, for example, requires that all named pipes occur in the directory, "\\.\pipe" whereas linux has no such requirement.

If the underlying OS has a special naming requirement, then it should return a name that it can use, given a suffix string.

On windows, for example, if one were to supply "123456" as the suffix, the method should return "\\.\pipe\123456"

If the underlying OS does not have a special naming requirement, then it should return null. Therefore on linux, this method should return null.

Parameters:
suffix - A string that the actual name should be based on. See description for details.
Returns:
A suitable name if the platform requires that named pipes use a particular format, otherwise null.

connectNonBlocking

public void connectNonBlocking(FIFOResult result)
Connect to the underlying FIFO.


select

public void select(FIFOResult result,
                   int timeoutMsec)
Determine if the FIFO is ready for reading, writing, or both.

This method is similar to the old Unix select system call, which would look for file handles read to read/write.

The call takes the amount of time the caller wants to wait for I/O to be ready on the FIFO. A value of less than 0 means wait until ready. A value of 0 means poll the FIFO but do not wait. Any other value is the number of milliseconds to wait for the FIFO to be ready.

If the client is the reader, then the method will wait until data is ready. If the client is a writer, it will wait for writing to become non-blocking.

Parameters:
timeouitMsec -