org.apache.ignite.internal.util.ipc.shmem

## Class IpcSharedMemorySpace

- java.lang.Object
- - org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemorySpace

All Implemented Interfaces:
  Closeable, AutoCloseable

    public class IpcSharedMemorySpace
    extends Object
    implements Closeable

### Constructor Summary

Constructors
Constructor and Description
`IpcSharedMemorySpace(String tokFileName, int writerPid, int readerPid, int size, boolean reader, IgniteLogger parent)` This will allocate system resources for the space.
`IpcSharedMemorySpace(String tokFileName, int writerPid, int readerPid, int size, boolean reader, int shmemId, IgniteLogger parent)` This should be called in order to attach to already allocated system resources.

### Method Summary

Methods
`void` `close()`
`void` `forceClose()` Forcibly closes the space and frees all system resources.
`int` `otherPartyPid()`
`int` `read(byte[] buf, int off, int len, long timeout)` Blocks until at least 1 byte is read.
`int` `read(ByteBuffer buf, int off, int len, long timeout)` Blocks until at least 1 byte is read.
`int` `readerPid()`
`int` `semaphoreId()`
`int` `sharedMemoryId()`
`long` `sharedMemPointer()`
`int` `size()`
`String` `tokenFileName()`
`String` `toString()`
`int` `unreadCount()`
`void` `write(byte[] buf, int off, int len, long timeout)`
`void` `write(ByteBuffer buf, int off, int len, long timeout)`
`int` `writerPid()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### IpcSharedMemorySpace

    public IpcSharedMemorySpace(String tokFileName,
                        int writerPid,
                        int readerPid,
                        int size,
                        boolean reader,
                        IgniteLogger parent)
                         throws IgniteCheckedException

This will allocate system resources for the space.

Parameters:
  `tokFileName` - Token filename.
  `writerPid` - Writer PID.
  `readerPid` - Reader PID.
  `size` - Size in bytes.
  `reader` - `True` if reader.
  `parent` - Parent logger.
Throws:
  `IgniteCheckedException` - If failed.

#### IpcSharedMemorySpace

    public IpcSharedMemorySpace(String tokFileName,
                        int writerPid,
                        int readerPid,
                        int size,
                        boolean reader,
                        int shmemId,
                        IgniteLogger parent)
                         throws IgniteCheckedException

This should be called in order to attach to already allocated system resources.

Parameters:
  `tokFileName` - Token file name (for proper cleanup).
  `writerPid` - Writer PID.
  `readerPid` - Reader PID.
  `size` - Size.
  `reader` - Reader flag.
  `shmemId` - Shared memory ID.
  `parent` - Logger.
Throws:
  `IgniteCheckedException` - If failed.

### Method Detail

#### write

    public void write(byte[] buf,
             int off,
             int len,
             long timeout)
               throws IgniteCheckedException,
                      IpcSharedMemoryOperationTimedoutException

Parameters:
  `buf` - Buffer.
  `off` - Offset.
  `len` - Length.
  `timeout` - Operation timeout in milliseconds (`0` to wait forever).
Throws:
  `IgniteCheckedException` - If space has been closed.
  `IpcSharedMemoryOperationTimedoutException` - If operation times out.

#### write

    public void write(ByteBuffer buf,
             int off,
             int len,
             long timeout)
               throws IgniteCheckedException,
                      IpcSharedMemoryOperationTimedoutException

Parameters:
  `buf` - Buffer.
  `off` - Offset.
  `len` - Length.
  `timeout` - Operation timeout in milliseconds (`0` to wait forever).
Throws:
  `IgniteCheckedException` - If space has been closed.
  `IpcSharedMemoryOperationTimedoutException` - If operation times out.

#### read

    public int read(byte[] buf,
           int off,
           int len,
           long timeout)
             throws IgniteCheckedException,
                    IpcSharedMemoryOperationTimedoutException

Blocks until at least 1 byte is read.

Parameters:
  `buf` - Buffer.
  `off` - Offset.
  `len` - Length.
  `timeout` - Operation timeout in milliseconds (`0` to wait forever).
Returns:
  Read bytes count.
Throws:
  `IgniteCheckedException` - If space has been closed.
  `IpcSharedMemoryOperationTimedoutException` - If operation times out.

#### read

    public int read(ByteBuffer buf,
           int off,
           int len,
           long timeout)
             throws IgniteCheckedException,
                    IpcSharedMemoryOperationTimedoutException

Blocks until at least 1 byte is read.

Parameters:
  `buf` - Buffer.
  `off` - Offset.
  `len` - Length.
  `timeout` - Operation timeout in milliseconds (`0` to wait forever).
Returns:
  Read bytes count.
Throws:
  `IgniteCheckedException` - If space has been closed.
  `IpcSharedMemoryOperationTimedoutException` - If operation times out.

#### close

    public void close()

Specified by:
  `close` in interface `Closeable`
Specified by:
  `close` in interface `AutoCloseable`

#### forceClose

    public void forceClose()

Forcibly closes the space and frees all system resources.

This method should be called with caution as it may result to the other-party process crash. It is intended to call when there was an IO error during handshake and other party has not yet attached to the space.

#### sharedMemoryId

    public int sharedMemoryId()

Returns:
  Shared memory ID.

#### semaphoreId

    public int semaphoreId()

Returns:
  Semaphore set ID.

#### unreadCount

    public int unreadCount()
                    throws IgniteCheckedException

Returns:
  Bytes available for read.
Throws:
  `IgniteCheckedException` - If failed.

#### sharedMemPointer

    public long sharedMemPointer()

Returns:
  Shared memory pointer.

#### readerPid

    public int readerPid()

Returns:
  Reader PID.

#### writerPid

    public int writerPid()

Returns:
  Writer PID.

#### otherPartyPid

    public int otherPartyPid()

Returns:
  Vis-a-vis PID.

#### tokenFileName

    public String tokenFileName()

Returns:
  Token file name used to create shared memory space.

#### size

    public int size()

Returns:
  Space size.

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.4.0
Release Date | : September 24 2015