uk.ac.rdg.resc.jstyx.server
Class InMemoryFile

java.lang.Object
  extended by uk.ac.rdg.resc.jstyx.server.StyxFile
      extended by uk.ac.rdg.resc.jstyx.server.InMemoryFile
Direct Known Subclasses:
AuthFile

public class InMemoryFile
extends StyxFile

File whose underlying data are stored as a ByteBuffer in memory. This buffer can grow to arbitrary size.

Author:
Jon Blower $Revision: 601 $ $Date: 2006-03-20 17:51:50 +0000 (Mon, 20 Mar 2006) $ $Log$ Revision 1.20 2006/03/20 17:51:50 jonblower Adding authentication to base JStyx system Revision 1.19 2005/09/08 07:08:59 jonblower Removed "String user" from list of parameters to StyxFile.write() Revision 1.18 2005/09/02 16:51:20 jonblower Fixed bug with ByteBuffers being released prematurely and changed to use autoExpanding ByteBuffers Revision 1.17 2005/09/01 07:50:22 jonblower Trying to fix bug with ByteBuffers being released (can't read from InMemoryFile) Revision 1.16 2005/08/30 16:29:00 jonblower Added processAndReplyRead() helper functions to StyxFile Revision 1.13 2005/06/10 07:53:12 jonblower Changed SGS namespace: removed "inurl" and subsumed functionality into "stdin" Revision 1.12 2005/04/28 08:11:15 jonblower Modified permissions handling in documentation directory of SGS Revision 1.10 2005/04/27 16:11:43 jonblower Added capability to add documentation files to SGS namespace Revision 1.9 2005/04/26 07:46:11 jonblower Continuing to improve setting of parameters in Styx Grid Services Revision 1.8 2005/03/24 15:11:07 jonblower Changed so that underlying ByteBuffer is allocated on the first write to the file Revision 1.7 2005/03/24 13:07:09 jonblower Added code to prevent the file growing to larger than a specified size Revision 1.6 2005/03/24 12:55:14 jonblower Changed to use ByteBuffer as backing store Revision 1.5 2005/03/24 09:48:31 jonblower Changed 'count' from long to int throughout for reading and writing Revision 1.4 2005/03/16 17:56:23 jonblower Replaced use of java.nio.ByteBuffer with MINA's ByteBuffer to minimise copying of buffers Revision 1.3 2005/03/11 14:02:16 jonblower Merged MINA-Test_20059309 into main line of development Revision 1.2.2.1 2005/03/10 20:55:38 jonblower Removed references to Netty Revision 1.2 2005/03/01 13:47:43 jonblower Changed default user and group to 'user' and 'group' Revision 1.1.1.1 2005/02/16 18:58:31 jonblower Initial import

Field Summary
protected  org.apache.mina.common.ByteBuffer buf
          The org.apache.mina.common.ByteBuffer that holds the data exposed by this file.
 
Fields inherited from class uk.ac.rdg.resc.jstyx.server.StyxFile
auth, directory, lastModifiedTime, name, parent
 
Constructor Summary
InMemoryFile(java.lang.String name)
          Creates an InMemoryFile with default permissions (0666, rw-rw-rw-)
InMemoryFile(java.lang.String name, int permissions)
           
InMemoryFile(java.lang.String name, int permissions, boolean isAppendOnly, boolean isExclusive)
           
InMemoryFile(java.lang.String name, java.lang.String userID, java.lang.String groupID, int permissions, boolean isAppendOnly, boolean isExclusive)
          Creates a new instance of InMemoryFile
 
Method Summary
 void delete()
          Frees the resources associated with the file (releases the underlying ByteBuffer back to the pool).
 java.lang.String getContents()
          Gets the data in this file as a String
 ULong getLength()
           
static void main(java.lang.String[] args)
           
 void read(StyxFileClient client, long offset, int count, int tag)
          Reads data from this file.
 void setContents(java.lang.String newContents)
          Set the contents of this file to the given String.
 void write(StyxFileClient client, long offset, int count, org.apache.mina.common.ByteBuffer data, boolean truncate, int tag)
          Writes data to this file.
 
Methods inherited from class uk.ac.rdg.resc.jstyx.server.StyxFile
addChangeListener, addClient, checkSetLastModifiedTime, checkSetLength, checkSetMode, checkSetName, clientConnected, clientDisconnected, contentsChanged, fireContentsChanged, getClient, getDirEntry, getFullPath, getGroup, getName, getNumClients, getOwner, getParent, getPermissions, getQid, getVersion, incrementVersion, isAppendOnly, isAuth, isDirectory, isExclusive, processAndReplyRead, processAndReplyRead, processAndReplyRead, refresh, remove, removeChangeListener, removeClient, rename, replyRead, replyRead, replyRead, replyRead, replyRead, replyWrite, setLastAccessTime, setLastModified, setLength, setMode, setName, setPermissions, setReadOnly
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buf

protected org.apache.mina.common.ByteBuffer buf
The org.apache.mina.common.ByteBuffer that holds the data exposed by this file. The first byte of readable data is always at position zero and the number of valid bytes in the buffer is its limit

Constructor Detail

InMemoryFile

public InMemoryFile(java.lang.String name,
                    java.lang.String userID,
                    java.lang.String groupID,
                    int permissions,
                    boolean isAppendOnly,
                    boolean isExclusive)
             throws StyxException
Creates a new instance of InMemoryFile

Throws:
StyxException

InMemoryFile

public InMemoryFile(java.lang.String name,
                    int permissions,
                    boolean isAppendOnly,
                    boolean isExclusive)
             throws StyxException
Throws:
StyxException

InMemoryFile

public InMemoryFile(java.lang.String name,
                    int permissions)
             throws StyxException
Throws:
StyxException

InMemoryFile

public InMemoryFile(java.lang.String name)
             throws StyxException
Creates an InMemoryFile with default permissions (0666, rw-rw-rw-)

Throws:
StyxException
Method Detail

read

public void read(StyxFileClient client,
                 long offset,
                 int count,
                 int tag)
          throws StyxException
Description copied from class: StyxFile
Reads data from this file. This method could be synchronized in subclasses, but watch out for blocks if the read is expected to take some time to complete. Subclasses must make sure they reply to the read request by creating a java.nio.ByteBuffer or byte array of data, then calling the appropriate readReply() (this can be done at any time; it does not have to be done within the read() method). This default implementation simply throws a StyxException, which will result in an Rerror message being sent back to the client. Subclasses should override this to provide the desired behaviour when the file is read.

Overrides:
read in class StyxFile
Parameters:
client - The client that is performing the read
offset - The point in the file at which to start reading
count - The maximum number of bytes to read
tag - The tag of the incoming Tread message (this is needed when calling readReply())
Throws:
StyxException

write

public void write(StyxFileClient client,
                  long offset,
                  int count,
                  org.apache.mina.common.ByteBuffer data,
                  boolean truncate,
                  int tag)
           throws StyxException
Description copied from class: StyxFile
Writes data to this file. Must check that the file is open for writing before this. We have already dealt with the possibility that this is an append-only file before calling this method so subclasses do not need to check this. Subclasses must make sure they reply to the write request by calling writeReply() (although this can be done at any time; it does not have to be done within the write() method). After this method is called, ByteBuffer containing the data will be returned to the pool. If subclasses wish to keep the ByteBuffer after this method is complete, they should call data.acquire() to increase the reference count to the buffer. This default implementation simply throws a StyxException, which will result in an Rerror message being sent back to the client. Subclasses should override this to provide the desired behaviour when the file is written to.

Overrides:
write in class StyxFile
Parameters:
client - The client that is performing the write operation
offset - The place in the file where the new data will be added
count - The number of bytes to write
data - The data to write. The position and limit of this ByteBuffer will be set correctly, but subclasses should note that the position might not be zero.
truncate - If this is true the file will be truncated at the end of the new data
tag - The tag of the incoming Twrite message (this is needed when calling writeReply())
Throws:
StyxException

setContents

public void setContents(java.lang.String newContents)
Set the contents of this file to the given String.


getLength

public ULong getLength()
Overrides:
getLength in class StyxFile
Returns:
the length of the file. This default implementation returns zero; subclasses should override this method

delete

public void delete()
Frees the resources associated with the file (releases the underlying ByteBuffer back to the pool). After this is called, the file can no longer be used.

Overrides:
delete in class StyxFile

getContents

public java.lang.String getContents()
Gets the data in this file as a String


main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception


Copyright © 2004-2006 Reading e-Science Centre. All Rights Reserved.