|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectuk.ac.rdg.resc.jstyx.server.StyxFile
public class StyxFile
Class representing a file (or directory) on a Styx server. There may be different types of file; a file might map directly to a file on disk, or it may be a synthetic file representing a program interface. This class creates a StyxFile that does nothing useful, returning errors when reading from or writing to it. Subclasses should override the read(), write() and getLength() methods to implement the desired behaviour. Currently each StyxFile has exactly one parent. Therefore symbolic links on the host filesystem cannot currently be handled.
| Field Summary | |
|---|---|
protected boolean |
auth
|
protected boolean |
directory
|
protected long |
lastModifiedTime
|
protected java.lang.String |
name
|
protected StyxDirectory |
parent
|
| Constructor Summary | |
|---|---|
StyxFile(java.lang.String name)
Creates a StyxFile with the default permissions (0666, rw-rw-rw-) |
|
StyxFile(java.lang.String name,
int permissions)
|
|
StyxFile(java.lang.String name,
int permissions,
boolean isAppendOnly,
boolean isExclusive)
Creates a StyxFile with the default username and group |
|
StyxFile(java.lang.String name,
java.lang.String owner,
java.lang.String group,
int permissions,
boolean isAppendOnly,
boolean isExclusive)
|
|
| Method Summary | |
|---|---|
void |
addChangeListener(StyxFileChangeListener listener)
Registers a StyxFileChangeListener. |
void |
addClient(StyxFileClient client)
Adds the given client to the file's list of connected clients. |
void |
checkSetLastModifiedTime(long lastModifiedTime)
|
void |
checkSetLength(ULong newLength)
Check to see if the length of this file can be changed to the given value. |
void |
checkSetMode(long newMode)
Checks to see if this file allows the mode (permissions plus flags) of the file to be changed. |
void |
checkSetName(java.lang.String newName)
|
protected void |
clientConnected(StyxFileClient client)
Called after a client connects to this file (i.e. |
protected void |
clientDisconnected(StyxFileClient client)
Called after a client disconnects from this file (i.e. |
void |
contentsChanged()
Call this to indicate that the file's data have changed. |
protected void |
delete()
Called when the file is removed from the server. |
protected void |
fireContentsChanged()
This method is called when the contents of the file change. |
StyxFileClient |
getClient(org.apache.mina.protocol.ProtocolSession session,
long fid)
Gets the StyxFileClient associated with the given Session and fid, or null if client does not exist |
DirEntry |
getDirEntry()
|
java.lang.String |
getFullPath()
Gets the full path relative to the root of this file system. |
java.lang.String |
getGroup()
|
ULong |
getLength()
|
java.lang.String |
getName()
|
int |
getNumClients()
|
java.lang.String |
getOwner()
|
StyxDirectory |
getParent()
Returns the parent of this file. |
int |
getPermissions()
|
Qid |
getQid()
|
long |
getVersion()
|
protected void |
incrementVersion()
Increments the file's version number and ensures that the version number never exceeds the maximum value of an unsigned 4-byte integer (it wraps back to zero if the version number gets this large) |
boolean |
isAppendOnly()
|
boolean |
isAuth()
|
boolean |
isDirectory()
|
boolean |
isExclusive()
|
void |
processAndReplyRead(byte[] fileContents,
StyxFileClient client,
long offset,
int count,
int tag)
Method for processing a read request and replying appropriately to the client, based on the contents of the file. |
void |
processAndReplyRead(org.apache.mina.common.ByteBuffer fileContents,
StyxFileClient client,
long offset,
int count,
int tag)
Method for processing a read request and replying appropriately to the client, based on the contents of the file. |
void |
processAndReplyRead(java.lang.String fileContents,
StyxFileClient client,
long offset,
int count,
int tag)
Method for processing a read request and replying appropriately to the client, based on the contents of the file. |
void |
read(StyxFileClient client,
long offset,
int count,
int tag)
Reads data from this file. |
void |
refresh()
Refreshes this file (if it represents another entity, such as a file on disk, this method is used to make sure that the file metadata (length, access time etc) are up to date. |
void |
remove()
Removes this file from the Styx server |
void |
removeChangeListener(StyxFileChangeListener listener)
Removes a change listener. |
void |
removeClient(StyxFileClient client)
Removes the client that is connected on the given session. |
void |
rename(java.lang.String newName)
Renames this file to the given name. |
protected void |
replyRead(StyxFileClient client,
byte[] bytes,
int tag)
Method to reply to a Read message. |
protected void |
replyRead(StyxFileClient client,
byte[] bytes,
int pos,
int count,
int tag)
Method to reply to a Read message. |
protected void |
replyRead(StyxFileClient client,
java.nio.ByteBuffer buf,
int tag)
Method to reply to a Read message. |
protected void |
replyRead(StyxFileClient client,
org.apache.mina.common.ByteBuffer buf,
int tag)
Method to reply to a Read message. |
protected void |
replyRead(StyxFileClient client,
RreadMessage rReadMsg)
Method to reply to a Read message. |
protected void |
replyWrite(StyxFileClient client,
int count,
int tag)
Method to reply to a Write message. |
void |
setLastAccessTime(long lastAccessTime)
|
void |
setLastModified(long lastModifiedTime,
User user)
Sets the last modified time of the file. |
void |
setLength(ULong newLength)
Sets the length of the file. |
void |
setMode(long newMode)
Sets the mode of the file (permissions plus other flags). |
void |
setName(java.lang.String name)
Changes the name of the file. |
void |
setPermissions(int permissions)
Sets the permissions of the file |
void |
setReadOnly()
Makes the file read-only (e.g. |
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 java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected java.lang.String name
protected StyxDirectory parent
protected boolean directory
protected boolean auth
protected long lastModifiedTime
| Constructor Detail |
|---|
public StyxFile(java.lang.String name,
java.lang.String owner,
java.lang.String group,
int permissions,
boolean isAppendOnly,
boolean isExclusive)
throws StyxException
StyxException - if an attempt is made to create a file with the name
"", "." or ".."
public StyxFile(java.lang.String name,
int permissions,
boolean isAppendOnly,
boolean isExclusive)
throws StyxException
StyxException
public StyxFile(java.lang.String name,
int permissions)
throws StyxException
StyxException
public StyxFile(java.lang.String name)
throws StyxException
StyxException| Method Detail |
|---|
public java.lang.String getName()
public void checkSetName(java.lang.String newName)
throws StyxException
StyxException - if the name of this file cannot be changedpublic void setName(java.lang.String name)
public boolean isDirectory()
public boolean isAppendOnly()
public boolean isExclusive()
public boolean isAuth()
public java.lang.String getFullPath()
public ULong getLength()
public StyxDirectory getParent()
public java.lang.String getOwner()
public java.lang.String getGroup()
public DirEntry getDirEntry()
public Qid getQid()
public int getPermissions()
public void setPermissions(int permissions)
permissions - the permissions of the file as an integer (e.g. 0755).public void setReadOnly()
public void checkSetMode(long newMode)
throws StyxException
newMode - the new mode of the file (permissions plus any other flags
such as DMDIR, DMAPPEND, DMEXCL, DMAUTH)
StyxException - if the mode of this file cannot be changedpublic void setMode(long newMode)
public void checkSetLength(ULong newLength)
throws StyxException
StyxExceptionpublic void setLength(ULong newLength)
public void checkSetLastModifiedTime(long lastModifiedTime)
throws StyxException
StyxException - if the last modified time cannot be changed directly
(i.e. with a Twstat message)
public void setLastModified(long lastModifiedTime,
User user)
lastModifiedTime - time as represented in a stat entry (e.g. in a
TwstatMessage), i.e. the number of seconds (not milliseconds) since the
epoch (Jan 1 00:00 1970 GMT)user - The user who is modifying the filepublic void setLastAccessTime(long lastAccessTime)
public void rename(java.lang.String newName)
throws StyxException
StyxException
public void read(StyxFileClient client,
long offset,
int count,
int tag)
throws StyxException
client - The client that is performing the readoffset - The point in the file at which to start readingcount - The maximum number of bytes to readtag - The tag of the incoming Tread message (this is needed when
calling readReply())
StyxException
public void write(StyxFileClient client,
long offset,
int count,
org.apache.mina.common.ByteBuffer data,
boolean truncate,
int tag)
throws StyxException
client - The client that is performing the write operationoffset - The place in the file where the new data will be addedcount - The number of bytes to writedata - 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 datatag - The tag of the incoming Twrite message (this is needed when
calling writeReply())
StyxExceptionpublic void refresh()
public void remove()
throws StyxException
StyxExceptionprotected void delete()
public void addClient(StyxFileClient client)
protected void clientConnected(StyxFileClient client)
public StyxFileClient getClient(org.apache.mina.protocol.ProtocolSession session,
long fid)
public int getNumClients()
public void removeClient(StyxFileClient client)
protected void clientDisconnected(StyxFileClient client)
client - The client that has just disconnected from the file. This
will not be null.
public void processAndReplyRead(java.lang.String fileContents,
StyxFileClient client,
long offset,
int count,
int tag)
fileContents - String representing the entire contents of
the file.client - the StyxFileClient making the requestoffset - the index of the first byte in the file to return to the clientcount - the maximum number of bytes to return to the clienttag - the tag of the incoming read message
public void processAndReplyRead(byte[] fileContents,
StyxFileClient client,
long offset,
int count,
int tag)
fileContents - Byte array representing the entire contents of
the file.client - the StyxFileClient making the requestoffset - the index of the first byte in the file to return to the clientcount - the maximum number of bytes to return to the clienttag - the tag of the incoming read message
public void processAndReplyRead(org.apache.mina.common.ByteBuffer fileContents,
StyxFileClient client,
long offset,
int count,
int tag)
fileContents - ByteBuffer representing the entire contents of
the file. The position and limit of this buffer will be unchanged by this
method. This can be null: in this case all read requests will return zero bytes.client - the StyxFileClient making the requestoffset - the index of the first byte in the file to return to the clientcount - the maximum number of bytes to return to the clienttag - the tag of the incoming read message
protected void replyRead(StyxFileClient client,
byte[] bytes,
int tag)
client - The connection on which the reply will be sentbytes - The data to include in the message. All the data in this
array will be writtentag - The tag to be attached to the message
protected void replyRead(StyxFileClient client,
java.nio.ByteBuffer buf,
int tag)
client - The connection on which the reply will be sentbuf - a java.nio.ByteBuffer containing the data to write to the file.
All the remaining data in the buffer will be sent back to the client.tag - The tag to be attached to the message
protected void replyRead(StyxFileClient client,
org.apache.mina.common.ByteBuffer buf,
int tag)
client - The connection on which the reply will be sentbuf - a org.apache.mina.common.ByteBuffer containing the data to
write to the file. All the remaining data in the buffer will be sent
back to the client.tag - The tag to be attached to the message
protected void replyRead(StyxFileClient client,
byte[] bytes,
int pos,
int count,
int tag)
client - The connection on which the reply will be sentbytes - The data to include in the message.pos - The index of the first byte in the array to be writtencount - The number of bytes in the array to writetag - The tag to be attached to the message
protected void replyRead(StyxFileClient client,
RreadMessage rReadMsg)
client - The connection on which the reply will be sentrReadMsg - The RreadMessage to send back to the client. The tag of
this message must be set correctly.
protected void replyWrite(StyxFileClient client,
int count,
int tag)
client - The connection on which the reply will be sentcount - The number of bytes actually written to the file in question.tag - The tag to be attached to the messagepublic long getVersion()
public void contentsChanged()
protected final void incrementVersion()
public void addChangeListener(StyxFileChangeListener listener)
public void removeChangeListener(StyxFileChangeListener listener)
protected void fireContentsChanged()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||