oemware.core
Class NamedPipe

java.lang.Object
  extended by oemware.core.NamedPipe

public class NamedPipe
extends java.lang.Object

The named pipe class. Encapsulates all reads/writes to a named pipe. The read and write records will block while executing.

Version:
$Id: NamedPipe.java 13 2008-06-15 19:43:04Z oemware $

Field Summary
static int BIDIRECTIONAL
           
static byte END_TRANSMIT
           
protected  java.util.concurrent.atomic.AtomicLong mOperationStartTime
           
static int READ
           
static byte START_TRANSMIT
           
static int WRITE
           
 
Constructor Summary
NamedPipe(java.lang.String pPipeName)
          Create a new object.
NamedPipe(java.lang.String pPipeName, boolean pRead)
          Create a new object.
NamedPipe(java.lang.String pPipeName, boolean pRead, int pMaxOperationTime)
          Create a new object.
NamedPipe(java.lang.String pPipeName, int pType, long pMaxOperationTime, boolean pAppendInstanceId)
          Create a new object.
 
Method Summary
 java.lang.String getPipeName()
          Returns the pipe name.
 boolean isRead()
          Returns true if this class is set to read.
 int read(java.nio.ByteBuffer pBuffer)
          Handle reading from the np.
 int readAll(java.nio.ByteBuffer pBuffer)
          Fill the buffer.
 void shutdown()
          Stop the procss.
 void startup()
          Start the process.
 int write(java.nio.ByteBuffer pBuffer)
          Handle writing to the np.
 int writeAll(java.nio.ByteBuffer pBuffer)
          Write all the data to the buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mOperationStartTime

protected final java.util.concurrent.atomic.AtomicLong mOperationStartTime

BIDIRECTIONAL

public static final int BIDIRECTIONAL
See Also:
Constant Field Values

READ

public static final int READ
See Also:
Constant Field Values

WRITE

public static final int WRITE
See Also:
Constant Field Values

START_TRANSMIT

public static final byte START_TRANSMIT
See Also:
Constant Field Values

END_TRANSMIT

public static final byte END_TRANSMIT
See Also:
Constant Field Values
Constructor Detail

NamedPipe

public NamedPipe(java.lang.String pPipeName)
          throws ServiceException
Create a new object. This creates a bidirectional named pipe using a random access file. throws ServiceException

Throws:
ServiceException

NamedPipe

public NamedPipe(java.lang.String pPipeName,
                 boolean pRead)
          throws ServiceException
Create a new object. This creates a read or write named pipe based on which flag is set in the read boolean.

Parameters:
pRead - The read flag.
Throws:
ServiceException

NamedPipe

public NamedPipe(java.lang.String pPipeName,
                 boolean pRead,
                 int pMaxOperationTime)
          throws ServiceException
Create a new object. This creates a read or write named pipe based on which flag is set in the read boolean.

Parameters:
pRead - The read flag.
Throws:
ServiceException

NamedPipe

public NamedPipe(java.lang.String pPipeName,
                 int pType,
                 long pMaxOperationTime,
                 boolean pAppendInstanceId)
          throws ServiceException
Create a new object. This creates a read or write named pipe based on which flag is set in the read boolean. It also starts the operation time monitor with the frequency specified.

Parameters:
pPipeName - The pipe name.
pType - the named pipe type.
pMaxOperationTime - The max operation time. Set to zero for unlimited or use another constructor ;-)
pAppendInstanceId - The flag to set the instance id on the name.
Throws:
ServiceException
Method Detail

startup

public final void startup()
                   throws ServiceException
Start the process.

Throws:
ServiceException

shutdown

public final void shutdown()
                    throws ServiceException
Stop the procss. Must be called when done using the object.

Throws:
ServiceException

getPipeName

public final java.lang.String getPipeName()
Returns the pipe name.

Returns:
The pipe name.

isRead

public final boolean isRead()
Returns true if this class is set to read.

Returns:
True if readable.

write

public final int write(java.nio.ByteBuffer pBuffer)
                throws ServiceException
Handle writing to the np.

Parameters:
pBuffer - The buffer to write. This assumes the params are set on the byte buffer.
Returns:
The number of bytes written.
Throws:
ServiceExcpetion
ServiceException

writeAll

public final int writeAll(java.nio.ByteBuffer pBuffer)
                   throws ServiceException
Write all the data to the buffer. See the description of readAll(buffer) for more information on how this method works.

Parameters:
pBuffer - The buffer to write. This assumes the params are set on the byte buffer.
Returns:
The bytes written.
Throws:
ServiceExcpetion
ServiceException

read

public final int read(java.nio.ByteBuffer pBuffer)
               throws ServiceException
Handle reading from the np.

Parameters:
pBuffer - User configured byte buffer.
Returns:
The number of bytes read.
Throws:
ServiceException

readAll

public final int readAll(java.nio.ByteBuffer pBuffer)
                  throws ServiceException
Fill the buffer.

Parameters:
pBuffer - The buffer to write. This assumes the params are set on the byte buffer. The receiver needs to check and see the number of bytes actually written. Zero is possible if the named pipe is being restarted.
Throws:
ServiceExcpetion
ServiceException


Copyright © 2008 Deft Labs - Released under LGPL, Version 3.0