|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | ENUM CONSTANTS | FIELD | METHOD | DETAIL: ENUM CONSTANTS | FIELD | METHOD | ||||||||
java.lang.Objectjava.lang.Enum<FileMode>
org.jnetstream.capture.FileMode
public enum FileMode
Defines a file mode for either open or new files created. The file mode is only usable with file captures and no other type. There are a number of file modes available with some default behaviours defined under each mode constant. Typical usage is as follows:
FileCapture capture;
capture = Captures.openFile(new File("temp.pcap"), FileMode.ReadOnly);
capture.close();
or
FileCapture capture; capture = Captures.newFile(new File(FormatType.Pcap, "temp.pcap", FileMode.ReadWrite); capture.close();For convenience both of these modes are available with no FileMode version of each of the above 2 methods
Captures.openFile(java.io.File) and
org.jnetstream.capture.Captures#newFile(FormatType, java.io.File) and
other variations. You can of course specify any of the constants defined
below in order to open the file in another mode.
Another important feature of the FileMode selection is the associated memory model with the file mode. The critical aspect is the usage of memory mapped files. All modern operating systems provide a very efficient means of accessing contents of a file by mapping its contents directly to memory. This is typically done in hardware by a memory controller, which provides the contents of a file as if they were normal RAM memory. This is a very low level function that is typically much more efficient then tranditional read data into a user provided buffer. Some of the constants below provide different options of when to use the map function of the kernel.
There is a known caviat with using any of the modes that map file contents
directly to memory using an OS call "map". Sun Microsystems has an
outstanding bug (Sun Bug ID# 4724038)
which prevents files from being truncated, renamed or deleted after a map
function has been used on a file. The bug more specifically, does not allow a
previously mapped file to be unmapped which keeps the file handle open in the
OS and file contents locked, even after a close call in java.
It may take some time for the file contents to become unmapped and until
then, the above mentioned file operations will fail. Therefore the default
readonly mode, assumes that since the file is being opened in readonly mode
by the user, that no immediate file modifications will take place upon the
file. Eventually though, the file will be cleared of any mappings and the
file operations will succeed. The amount of time needed for this to happen is
undefined, even when all references to any mapped file buffers are released
by the user, i.e. references through packets or records, directly to buffers
as returned by {org.jnetstream.packet.Packet#getBuffer()} call. Therefore the
user is advised to choose a different readonly mode that explicitely does not
use file mapping function if some kind of file manipulation will be required
relatively soon after the FileCapture is to be closed. No file manipulation
is possible when file capture is open wheather mapped or not.
| Enum Constant Summary | |
|---|---|
Append
File is opened for general read and write operations, which have portions of the file memory mapped and with the limitation that only structural change peration that is permitted is append or add at the
end of the file. |
|
AppendNoMap
File is opened for general read and no write operations and only structural change peration that is permitted is append or add at the
end of the file. |
|
ReadOnly
File and file editor is opened in read only mode. |
|
ReadOnlyNoMap
File and file editor is opened in read only mode without using memory map OS function. |
|
ReadWrite
The file is opened in read-write mode and no memory map functions are utilized. |
|
ReadWriteWithMap
File is opened for read and write operations while utilizing the very efficient file memory mapping feature, but no operations which result in structural changes such as add, remove, swap, retain, etc. |
|
| Method Summary | |
|---|---|
boolean |
isAppend()
Checks if append structural operation is permitted. |
boolean |
isContent()
Checks if the file content is allowed to be modified, non structuraly. |
boolean |
isMap()
Checks if capture file is memory mapped for efficiency purposes. |
boolean |
isStructure()
Determines if record structure can be modified. |
static FileMode |
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. |
static FileMode[] |
values()
Returns an array containing the constants of this enum type, in the order they're declared. |
| Methods inherited from class java.lang.Enum |
|---|
clone, compareTo, equals, getDeclaringClass, hashCode, name, ordinal, toString, valueOf |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Enum Constant Detail |
|---|
public static final FileMode ReadOnly
File and file editor is opened in read only mode. All mutable operations are disabled and the buffer operated on and returned to the user is read only as well.
In readonly mode, file contents are fetched using 3 different algorithms:
There is a known caviat with this mode. Sun Microsystems has an outstanding
bug (Sun Bug ID# 4724038)
which prevents files from being truncated, renamed or deleted after a map
function has been used on a file. The bug more specifically, does not allow
a previously mapped file to be unmapped which keeps the file handle open in
the OS and file contents locked, even after a close call in
java. It may take some time for the file contents to become unmapped and
until then, the above mentioned file operations will fail. Therefore the
default readonly mode, assumes that since the file is being opened in
readonly mode by the user, that no immediate file modifications will take
place upon the file. Eventually though, the file will be cleared of any
mappings and the file operations will succeed. The amount of time needed
for this to happen is undefined, even when all references to any mapped
file buffers are released by the user, i.e. references through packets or
records, directly to buffers as returned by
{org.jnetstream.packet.Packet#getBuffer()} call. Therefore the user is advised
to choose another mode that explicitely does not use file mapping function
if some kind of file manipulation will be required relatively soon after
the FileCapture is to be closed. No file manipulation is possible when file
capture is open wheather mapped or not.
public static final FileMode ReadOnlyNoMap
File and file editor is opened in read only mode without using memory map OS function. All mutable operations are disabled and the buffer operated on and returned to the user is read only as well. In this mode the file mapping to memory OS function is not used and this mode does not suffer any of the file locking or manipulation issues described in the main description.
In readonly mode, file contents are fetched using 2 different algorithms:
public static final FileMode ReadWrite
The file is opened in read-write mode and no memory map functions are
utilized. All mutable operations are allowed in this mode. All changes have
to be flushed by a call to flush(), close()
or flushed automatically by the autoflush mechanism. No memory map
functions are used to map file contents to memory for direct manipulation
in this default mode. Therefore this mode does not suffer any of the file
manipulation issues as described in the description.
In read-write mode, file contents are fetched using 2 different algorithms:
getBuffer on any of the returned packets
or records the buffer returned there, are readonly. The first call to any
of the mutable methods in the API with autoedit enabled will convert the
buffer to read-write and mark the buffer as dirty so that it may eventually
be sunchronized with the physical file using a flush or a
close call. You may also use the
org.jnetstream.packet.Packet#edit() or
jnetstrea.capture.file.Record#edit() calls to manually put the
buffer in read-write mode.
Note that in this mode, any changes that have been made to any of the
records or file structure (i.e. removed records or packets, insert packets,
etc..) can be undone if they have not been flushed yet. Since with
autoflush enabled it may not be possible to determine or prevent edits from
being flushed unexpectidely, you may need to set the autoflush mode with
org.jnetstream.capture.FileCapture#setAutoflush method to false. This
will require the user to manually call flush every so often, since all the
changes are kept in memory and eventually the system may run out of memory.
public static final FileMode ReadWriteWithMap
public static final FileMode Append
File is opened for general read and write operations, which have portions
of the file memory mapped and with the limitation that only structural
change peration that is permitted is append or add at the
end of the file. Operations such as remove, retain, swap or replace are not
allowed. The buffers returned are read write and allow to be modified. Any
modifications to buffer is synchronized with the file immediately and no
flush is required. A flush is required when data has been appended to the
file. Initialy those changes are kept in memory but will be synched with
the physical file by a flush or close
operation.
Since portions of the file are memory mapped, it may not be possible to do certain operations on the main file, even after the FileCapture has been closed. Please read the section in the main description about the map limitation.
public static final FileMode AppendNoMap
append or add at the
end of the file. Operations such as remove, retain, swap or replace are not
allowed. The buffers returned are readonly and are not allowed to be
modified. A flush is required when data has been appended to the file.
Initialy those changes are kept in memory but will be synched with the
physical file by a flush, close operation or
autoflush if enabled.
| Method Detail |
|---|
public static final FileMode[] values()
for(FileMode c : FileMode.values())
System.out.println(c);
public static FileMode valueOf(java.lang.String name)
name - the name of the enum constant to be returned.
java.lang.IllegalArgumentException - if this enum type has no constant
with the specified namepublic final boolean isAppend()
public final boolean isContent()
public final boolean isMap()
isContent() determines if the memory
map will be READ_ONLY or READ_WRITE. If content is not modifiable the
memory map will be READ_ONLY resulting in READ_ONLY ByteBuffers.
public final boolean isStructure()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | ENUM CONSTANTS | FIELD | METHOD | DETAIL: ENUM CONSTANTS | FIELD | METHOD | ||||||||