openlsd.network.server.legacy
Class LSDLegacy

java.lang.Object
  extended by openlsd.network.server.legacy.LSDLegacy

public class LSDLegacy
extends java.lang.Object

LSDDbLegacy is the class that defines one particular set of Storages with equals properties on each (crypted or not, same key for crypto, same size, ...).

Author:
Frederic Bregier LGPL

Field Summary
 boolean is_stopped
          Is this Legacy running or not ?
protected  boolean isCrypted
          This storage is in Crypted mode
 
Constructor Summary
LSDLegacy(java.lang.String sNameLID, long lid, boolean iscrypted, byte[] key, java.lang.String basepath, java.lang.String outbase, long size)
          New LSDDbLegacy from parameters.
 
Method Summary
 boolean createDir()
          Force the creation of the basepath
 boolean createDir(long sid)
          Force the creation of the basepath down to the storage with the given sid.
 boolean createDirOut()
          Create the base Out Path
 boolean deleteDir(boolean recursive)
          Delete the basepath (if not empty)
 boolean deleteDir(long sid, boolean recursive)
          Delete the basepath down to the storage with the given sid (if not empty)
 boolean deleteDirOut()
          Delete the base Out Path if not empty
 byte[] get(long sid, long did)
          Get the full file in one array of byte (limited to 2^32 bytes).
 java.lang.String getBasePath()
          Return the base path of this Legacy
 byte[] getBlock(LSDDocument document, int sizeblock)
          Get a block of the file associated with the LSDDocument argument from the same Legacy.
 LSDDocument getDocument(long sid, long did)
          Returns the LSDDocument object associated with the current Legacy lid, Storage sid, Document did
 LSDCrypto getFileCrypto()
          Get the fileCrypto
 java.lang.String getInPath(long sid, long did)
          Get the the full path to access to a copy of the file in the base out path defined for this Legacy.
 long getLID()
          Get the LID
 java.lang.String getName()
          Get the name of the Legacy
 java.lang.String getOutPath()
          Return the base Out path of this Legacy
protected  byte[] getSecretkey()
          Get the sercretkey
 long getSize()
          Get the max size of one Storage from this Legacy.
 boolean isDirEmpty(boolean recursive)
          Returns True if the basepath is empty.
 boolean isDirEmpty(long sid, boolean recursive)
          Returns True if the basepath down to the storage with the given sid is empty.
 boolean isDirOutEmpty()
          Returns True if the base out path is empty.
 boolean move(long sid, long did, long sidnew, long didnew)
          Move one document in the same Legacy from one couple sid/did to another couple sidnew/didnew
 boolean move(long sid, long did, LSDDocument newdoc)
          Move one document from this Legacy (sid/did) to another document (newdoc) that can be outside the current Legacy.
 LSDDocument moveToDocument(long sid, long did, long sidnew, long didnew)
          Same as move(sid,did,sidnew,didnew) but returning the new LSDDocument associated to the new place of the document or null in case of error.
 long put(java.nio.channels.FileChannel fileChannelIn, long sid, long did)
          Put a file from the fileChannelIn in the Storage (sid) and Document (did).
 long put(java.lang.String fileName, LSDDocument doc)
          Put a file from the filename in the Document.
 boolean putBlock(byte[] bytes, LSDDocument document, boolean lastblock)
          Put a block of file from the array of byte to the document associated with the LSDDocument argument from the same Legacy.
 int remove(long sid, long did, java.lang.String shash)
          Remove the physical file associated with this Storade sid and Document did if the hash String is the correct one.
 void setOutPath(java.lang.String outPath)
          Set a new base out Path
 boolean start()
          Start this Legacy (put and delete allowed).
 boolean stop()
          Stop this Legacy (put and delete not allowed).
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

isCrypted

protected boolean isCrypted
This storage is in Crypted mode


is_stopped

public boolean is_stopped
Is this Legacy running or not ? When not, only Get/Info/Move are allowed. Move is allowed since if someone wants to implements a defrag operation, it needs the legacy to be not locked but locked for others (Put/Del).

Constructor Detail

LSDLegacy

public LSDLegacy(java.lang.String sNameLID,
                 long lid,
                 boolean iscrypted,
                 byte[] key,
                 java.lang.String basepath,
                 java.lang.String outbase,
                 long size)
          throws java.lang.Exception
New LSDDbLegacy from parameters. By default, the Legacy is not ready after its creation. You must call start() explicitely.

Parameters:
sNameLID - : logical name of this Legacy
lid - : unique id of the Legacy
iscrypted - : status crypto for this Legacy
key - : the key if crypted or null
basepath - : the basepath for this Legacy
outbase - : the basepath for the export/extraction for this Legacy
size - : the max size of each Storage in the Set of this Legacy
Throws:
java.lang.Exception - if one value is incorrect
Method Detail

getBasePath

public java.lang.String getBasePath()
Return the base path of this Legacy

Returns:
the sPath.

getOutPath

public java.lang.String getOutPath()
Return the base Out path of this Legacy

Returns:
the base out path

setOutPath

public void setOutPath(java.lang.String outPath)
Set a new base out Path

Parameters:
outPath -

createDir

public boolean createDir()
Force the creation of the basepath

Returns:
True if OK, False else

createDir

public boolean createDir(long sid)
Force the creation of the basepath down to the storage with the given sid.

Parameters:
sid -
Returns:
True if OK, False else

deleteDir

public boolean deleteDir(boolean recursive)
Delete the basepath (if not empty)

Parameters:
recursive - if the operation must be done recursively
Returns:
True if OK, False else

deleteDir

public boolean deleteDir(long sid,
                         boolean recursive)
Delete the basepath down to the storage with the given sid (if not empty)

Parameters:
sid -
recursive - if the operation must be done recursively
Returns:
True if OK, False else

isDirEmpty

public boolean isDirEmpty(boolean recursive)
Returns True if the basepath is empty. Returns False if not or if is does not exist or is not a directory.

Parameters:
recursive - if the operation must be done recursively
Returns:
True if empty directory, False else

isDirEmpty

public boolean isDirEmpty(long sid,
                          boolean recursive)
Returns True if the basepath down to the storage with the given sid is empty. Returns False if not or if is does not exist or is not a directory.

Parameters:
sid -
recursive - if the operation must be done recursively
Returns:
True if empty directory, False else

createDirOut

public boolean createDirOut()
Create the base Out Path

Returns:
True if OK, False else

deleteDirOut

public boolean deleteDirOut()
Delete the base Out Path if not empty

Returns:
True if OK, False else

isDirOutEmpty

public boolean isDirOutEmpty()
Returns True if the base out path is empty. Returns False if not or if is does not exist or is not a directory.

Returns:
True if empty directory, False else

stop

public boolean stop()
Stop this Legacy (put and delete not allowed). When stopped, only Get/Info/Move are allowed. Move is allowed since if someone wants to implements a defrag operation, it needs the legacy to be not locked but locked for others (Put/Del).

Returns:
True if stopped

start

public boolean start()
Start this Legacy (put and delete allowed). When stopped, only Get/Info/Move are allowed. Move is allowed since if someone wants to implements a defrag operation, it needs the legacy to be not locked but locked for others (Put/Del).

Returns:
False if started

put

public long put(java.lang.String fileName,
                LSDDocument doc)
Put a file from the filename in the Document. Storage (sid) and Document (did). Returns True if OK, False if not inserted. The original file is not deleted. The filename can be either a true file accessed from the filesystem of the server, or either a file accessed from a net service (http, ftp, ...).

Parameters:
fileName -
doc -
Returns:
The size of insertion if is OK, else (-1)

put

public long put(java.nio.channels.FileChannel fileChannelIn,
                long sid,
                long did)
Put a file from the fileChannelIn in the Storage (sid) and Document (did). Returns True if OK, False if not inserted. This call closes the fileChannelIn with fileChannelIn.close() if the operation is in success.

Parameters:
fileChannelIn -
sid -
did -
Returns:
True if inserted, False else.

putBlock

public boolean putBlock(byte[] bytes,
                        LSDDocument document,
                        boolean lastblock)
Put a block of file from the array of byte to the document associated with the LSDDocument argument from the same Legacy. Returns True if OK, False if not inserted.

Parameters:
bytes - array of byte added to the corresponding document
document - LSDDocument from the same Legacy
lastblock - Says if this is the last block
Returns:
True if inserted, False else.

getBlock

public byte[] getBlock(LSDDocument document,
                       int sizeblock)
Get a block of the file associated with the LSDDocument argument from the same Legacy. The size of the block is at most sizeblock. If the block size is less than sizeblock, this is the last block to read from the document.

Parameters:
document - LSDDocument from the same Legacy
sizeblock - Size of block to read
Returns:
the byte array for the block, or null if no more block are to be read.

get

public byte[] get(long sid,
                  long did)
Get the full file in one array of byte (limited to 2^32 bytes).

Parameters:
sid - Storage id
did - Document id
Returns:
the array of byte

getInPath

public java.lang.String getInPath(long sid,
                                  long did)
Get the the full path to access to a copy of the file in the base out path defined for this Legacy. The copy of the file is created during this call.

Parameters:
sid - Storage id
did - Document id
Returns:
the full path (using base out path) to a copy of the file or null if an error occurs

remove

public int remove(long sid,
                  long did,
                  java.lang.String shash)
Remove the physical file associated with this Storade sid and Document did if the hash String is the correct one.

Parameters:
sid - Storage id
did - Document id
shash -
Returns:
1 if deleted (already or newly deleted), else 0 if MD5 or Ids are bad, else -1 if stopped, else -2 if not deleted

getDocument

public LSDDocument getDocument(long sid,
                               long did)
Returns the LSDDocument object associated with the current Legacy lid, Storage sid, Document did

Parameters:
sid - Storage id
did - Document id
Returns:
the LSDDocument associated

move

public boolean move(long sid,
                    long did,
                    long sidnew,
                    long didnew)
Move one document in the same Legacy from one couple sid/did to another couple sidnew/didnew

Parameters:
sid - Storage id source
did - Document id source
sidnew - Storage id destination
didnew - Document id destination
Returns:
True if the move is ok, else False

move

public boolean move(long sid,
                    long did,
                    LSDDocument newdoc)
Move one document from this Legacy (sid/did) to another document (newdoc) that can be outside the current Legacy.

Parameters:
sid - Storage id source
did - Document id source
newdoc - LSDDocument as destination
Returns:
True if the move is ok, else False

moveToDocument

public LSDDocument moveToDocument(long sid,
                                  long did,
                                  long sidnew,
                                  long didnew)
Same as move(sid,did,sidnew,didnew) but returning the new LSDDocument associated to the new place of the document or null in case of error.

Parameters:
sid - Storage id source
did - Document id source
sidnew - Storage id destination
didnew - Document id destination
Returns:
the new LSDDocument if the move is OK, False else

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

getFileCrypto

public LSDCrypto getFileCrypto()
Get the fileCrypto

Returns:
Returns the fileCrypto.

getSecretkey

protected byte[] getSecretkey()
Get the sercretkey

Returns:
Returns the secretkey.

getLID

public long getLID()
Get the LID

Returns:
the LID for this Legacy

getSize

public long getSize()
Get the max size of one Storage from this Legacy.
Warning: this size must be less than real size since encryption should add some bytes. In general, depending on files size and crypto, 5 percent less than the real size should be enough.

Returns:
the max size for this Legacy

getName

public java.lang.String getName()
Get the name of the Legacy

Returns:
the name of this Legacy