org.iids.aos.kernel.ac
Class SegmentInfo

java.lang.Object
  extended by org.iids.aos.kernel.ac.SegmentInfo

public class SegmentInfo
extends java.lang.Object

A SegmentInfo (a) contains the in-memory representation of a TOC entry and (b) mediates access to the entry's segment. The special TOC entries / segments are also represented by a TOCEntry. Most attributes of a TOCEntry are documented in the XDR specification of TOC entries. TOCEntry is thread-unsafe.

Author:
Patrick Verkaik, Arno Bakker

Field Summary
 java.io.File contentFileName
          The file that stores this segment's content.
protected  TOCEntry entry
          The in-memory representation
 
Constructor Summary
SegmentInfo(int segmentID, java.io.File agentContainerDir, TOCSerialiser tocSerialiser)
          Constructs a special TOCEntry.
SegmentInfo(int segmentID, int segmentType, byte[] subtype, byte[] description, java.io.File agentContainerDir)
          Constructs a SegmentInfo with the given fields.
 
Method Summary
 TOC_ENTRY createTOC_ENTRY()
          Creates a TOC_ENTRY based on this TOCEntry.
 void deleteSegment()
          Deletes this TOC entry's segment content as part of an API.deleteSegment().
 void deleteSpecialSegment()
          Deletes this special TOC entry's segment content.
 void finalizeNonSpecial(java.util.zip.ZipOutputStream zip, TOCSerialiser tocSerialiser)
          Performs this TOC entry's part in the finalization of the containing agent container.
 void finalizeSpecial(java.util.zip.ZipOutputStream zip, byte[] content, int length)
          Performs this TOC entry's part in the finalization of the containing agent container.
 byte[] getDigest()
          Returns a copy of the last computed digest, or null if never computed.
 TOCEntry getTOCEntry()
           
 boolean makePersistent()
          Marks the segment of this entry as persistent.
 byte[] readSegment(int offset, int length)
          The semantics follow AOSapi.readSegment().
 int writeSegment(int offset, byte[] buf, int buflen, boolean sync)
          The semantics follow APIv4.writeSegment().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

entry

protected TOCEntry entry
The in-memory representation


contentFileName

public final java.io.File contentFileName
The file that stores this segment's content.

Constructor Detail

SegmentInfo

public SegmentInfo(int segmentID,
                   int segmentType,
                   byte[] subtype,
                   byte[] description,
                   java.io.File agentContainerDir)
Constructs a SegmentInfo with the given fields. The segment is marked transient.

Parameters:
agentContainerDir - the directory that stores the agent container's state.

SegmentInfo

public SegmentInfo(int segmentID,
                   java.io.File agentContainerDir,
                   TOCSerialiser tocSerialiser)
Constructs a special TOCEntry. The entry type is determined from the given segment ID. Fields are filled in as appropriate for the particular entry type.

Parameters:
segmentID - one of the special segment IDs
agentContainerDir - the directory that stores the agent container's state.
Method Detail

getTOCEntry

public TOCEntry getTOCEntry()

deleteSegment

public void deleteSegment()
                   throws PersistentSegmentException,
                          InputOutputException,
                          AccessDeniedException
Deletes this TOC entry's segment content as part of an API.deleteSegment(). The TOC entry object cannot be used following this call.

Throws:
PersistentSegmentException
InputOutputException
AccessDeniedException

deleteSpecialSegment

public void deleteSpecialSegment()
                          throws InputOutputException
Deletes this special TOC entry's segment content. The TOC entry object cannot be used following this call.

Throws:
InputOutputException

readSegment

public byte[] readSegment(int offset,
                          int length)
                   throws KernelException
The semantics follow AOSapi.readSegment().

Throws:
KernelException

writeSegment

public int writeSegment(int offset,
                        byte[] buf,
                        int buflen,
                        boolean sync)
                 throws KernelException
The semantics follow APIv4.writeSegment().

Throws:
KernelException

makePersistent

public boolean makePersistent()
                       throws AccessDeniedException
Marks the segment of this entry as persistent.

Returns:
true iff the segment was transient
Throws:
AccessDeniedException

finalizeNonSpecial

public void finalizeNonSpecial(java.util.zip.ZipOutputStream zip,
                               TOCSerialiser tocSerialiser)
                        throws KernelException
Performs this TOC entry's part in the finalization of the containing agent container. This call is only used for non-special segments. Writes the current segment content to the given zipfile, updates the TOC entry's digest for the segment content, and serialises the TOC entry to the TOC.

Parameters:
zip - zipfile to write the segment content to
tocSerialiser - where to serialise this TOC entry to
Throws:
KernelException
See Also:
AgentContainer.finalizeAgentContainer(boolean, java.security.PrivateKey, byte[])

finalizeSpecial

public void finalizeSpecial(java.util.zip.ZipOutputStream zip,
                            byte[] content,
                            int length)
                     throws KernelException
Performs this TOC entry's part in the finalization of the containing agent container. This call is only used for finalization segments. The passed segment content becomes the new segment content for this entry and is written to the given zipfile.

Parameters:
zip - zipfile to write this entry's segment to
content - buffer holding the new content of this entry's segment. The content starts at offset 0.
length - the number of bytes of content held by contentBuffer or -1 for the entire contentBuffer
Throws:
KernelException
See Also:
AgentContainer.finalizeAgentContainer(boolean, java.security.PrivateKey, byte[])

createTOC_ENTRY

public TOC_ENTRY createTOC_ENTRY()
Creates a TOC_ENTRY based on this TOCEntry. This is a stable copy of the TOC entry, i.e. a copy that is not affected by subsequent or concurrent modifications to this TOC entry.


getDigest

public byte[] getDigest()
Returns a copy of the last computed digest, or null if never computed.



Copyright ? 2003, 2004 IIDS Group. All Rights Reserved.