Documentation |
InterProcessSharedMemory.class
This class creates a block
(segment) of memory that implements java's Memory Mapped
IOand can be shared between different processes with atomicisity in an asynchronous manner, and includes a listener interface with thread safe asynchronous notification & update. It also has a built in asynchronous update timer to force saving to the underlying device at a specified interval. These segments are stored in a list know as InterProcessMemory.memoryList; Which is a list of MemoryFieldLink.class objects. MemoryFieldLink objects define the same bits as HyperView's ClassFieldLInk.class which is part of the Externalizer.class optimized serialization code. The HyperView has a non blocking RS232 Serial port interface (SerialHandler.class) and this is one of the principal methods for driving external hardware. The MemoryFieldLink,class can be mapped directly into the memory type of the underlying hardware and adjusts the indexing bitwidth according to the requirements of the index. This if you have a list of >256 integers, it will use an 8 bit index. This all works as a java application or a signed Applet. Idea. Make a ramdrive and store the Memory Mapped File there. Use a CRON job to copy that file to a separate device. public void setDataAligned() In this mode the InterProcessMemory.class will force all data to be aligned on an boundary specific to the bitwidth of the underlying device. For example if the underlying device uses 16 bit addressing, then the InterProcessMemory.class will enforce a 16 bit boundary and throw an illegalaccess misalignment exception. The default memory mode is unaligned memory with integer indexing and byte buffers. public void setDataUnAligned() Set the memory as unaligned. This is the default. public void setBitWidth(byte bitwidth) throws IllegalMemoryAccessException This sets the bitwidth of the memory. Valid values are 8,16,32, and 64. Anything else throws an IllegalMemoryAccessException. public int getBitWidth() returns the bit width of this memory which will be 8,16,32,or 64 public static void loadMemoryList() This forces the underlying device to be read for every single InterProcessMemory segment on the system memory list from its respective file. public void load() loads this InterProcessSharedMemory segment into RAM from its file. static InterProcessMemory open(String tName) open a shared memory segment named tName. If it doesn't exist it will be created. static int close(String tName) Close this memory segment. See below int close() Close this segment . /* Returns codes 0 = closed OK. -1 = Already closed. -2 = No Memory list exists -3 = fileChannel close exception */ public int write(byte tByte[]) throws IllegalMemoryAccessException write byte array to this segment. public int write(byte tByte[],int tOffset,int tLength) write tBute to this segment. public byte read() read a byte tLength. read a byte from the current file position and increment the position by 1 public int read(byte tByte[],int tOffset,int tLength) read from this segment starting at tOffset for tLength. (default 32 bit Memory) public long read(long[] tLong,long tOffset,long tLength) Read from this segment starting at tOffset for tLength. (read 64 bit Memory) public FileLock lock() Get an exclusive inter process lock on this memory segment. Note: This will block until successful or timeout after 30 seconds public void setFieldList(HyperLinkedList tList) Set up a list of MemoryFieldLink.class objects public void appendFieldList(HyperLinkedList tList) public void addListener(SharedMemoryListener tSharedMemoryListener) public void removeListener(SharedMemoryListener tSharedMemoryListener) public void enableBackupTimer(int tMillies) This starts the asynchronous backup timer and the Memory Segment will be automatically saved to its respective device at this interval. public void disableBackupTimer(int tMillies) Stop all timed memory to device saving and also the asynchronous timer. public void saveToDevice() Copy this memory segment to its backing file public void purge() completely drain the memory change listener list. public void setResident() Set this InterProcessMemory to always retain its backing file between various process runs. Otherwise the backup file is deleted on exit. public boolean isResident() true if resident. public void unsetResident() Set the backing file to be deleted on exit public void listenerWait() Block until there is a change in this segment. public int readInt() throws IllegalMemoryAccessException Read from the current file position and increment it by 4. public int readInt(int tOffset) throws IllegalMemoryAccessException Read from the location tOffset and and set position to tOffset+4. public int readInt(int tOffset,tInt[]) throws IllegalMemoryAccessException Read tInt.length from the location tOffset into tInt public void writeInt(int tInt) throws IllegalMemoryAccessException Write an int value to the current file position and increment it by 4 public void writeInt(int tOffset,int tInt) throws IllegalMemoryAccessException Write tInt to the file tOffset position & set file position to tOffset+4 public void writeInt(int tOffset,int tInt[]) throws IllegalMemoryAccessException Write tInt array to the file tOffset position & set file position to tOffset+tInt.length public void saveToDevice() Copy this memory segment to its backing file public short readShort() throws IllegalMemoryAccessException CRead the short value at the current file position & increment position by +2 public short readShort(int tOffset) throws IllegalMemoryAccessException Read the short value at file position tOffset and set the file position to tOffset+2 public void writeShort(short tShort) throws IllegalMemoryAccessException Write tShort to the current file position and increment it the file position by +2 public void writeShort(int tOffset,short tShort) throws IllegalMemoryAccessException Write tShort to the tOffset file position and increment it the file position to tOffset public int seek(int tInt) throws IllegalMemoryAccessException Set the current file position to tInt Direct IO methods. These methods are the same as their non direct counter parts except they do not get a lock. Thus they allow multiple IO operations with the confines of a a single lock as opposed to getting and releasing a lock for each operation, Warning: Not thread/process safe unless you already have a lock. I assume you can figure out what these do by the name :) public int writeDirect(byte tByte) throws IllegalMemoryAccessException public int writeDirect(byte tByte[]) throws IllegalMemoryAccessException public int writeDirect(byte tByte[],int tOffset,int tLength) throws IllegalMemoryAccessException public int writeDirect(String tString) throws IllegalMemoryAccessException public int writeDirect(String tString,int tOffset,int tLength) throws IllegalMemoryAccessException public byte readDirect() throws IllegalMemoryAccessException int writeRegionDirect(byte tByte[],int tOffset,int tLength) throws IllegalMemoryAccessException public int readDirect(int tInt[],int tOffset) throws IllegalMemoryAccessException public int readDirect(byte tByte[],int tOffset,int tLength) throws IllegalMemoryAccessException Note: MemoryFieldList.class mirrors ClassFieldLink.class in the HyperView Externalizer.class MemoryFieldList.class This is an Object to encapsulate different Field types within the memory segment. It
implements InterProcessMemoryConstants.class
Memory alignment can be either open or enforced. In this version it is always open.
|