org.tranche.routing
Class RoutingTrancheServer

java.lang.Object
  extended by org.tranche.commons.Debuggable
      extended by org.tranche.TrancheServer
          extended by org.tranche.routing.RoutingTrancheServer

public class RoutingTrancheServer
extends TrancheServer

Used to connect to one or more Tranche Servers ("data servers"). Redirects requests to appropriate servers.

Author:
Bryan Smith - bryanesmith@gmail.com

Field Summary
 
Fields inherited from class org.tranche.TrancheServer
BAD_NONCE, BAD_SIG
 
Constructor Summary
RoutingTrancheServer()
           
RoutingTrancheServer(java.security.cert.X509Certificate cert, java.security.PrivateKey key)
           
 
Method Summary
 boolean addListener(RoutingTrancheServerListener l)
           
 void clearListeners()
           
 void close()
          Closes the server and shuts down any associated resources.
 PropagationReturnWrapper deleteData(BigHash hash, Signature[] sigs, byte[][] nonces, java.lang.String[] hosts)
          Delete data chunk from selected servers.
 PropagationReturnWrapper deleteMetaData(BigHash hash, java.lang.String uploaderName, java.lang.Long uploadTimestamp, java.lang.String relativePathInDataSet, Signature[] sigs, byte[][] nonces, java.lang.String[] hosts)
          p>Delete meta data chunk from selected servers.
 void fireDataServersAdded(java.lang.String[] hosts)
           
 void fireDataServersRemoved(java.lang.String[] hosts)
          Fired when a RoutingTrancheServer instance removes one or more data server.
 Activity[] getActivityLogEntries(long startTimestamp, long finishTimestamp, int limit, byte mask)
          Get all activity log entries from within a time period.
 int getActivityLogEntriesCount(long startTimestamp, long stopTimestamp, byte mask)
          Returns a count of all activity log entries from within a time period.
 java.security.cert.X509Certificate getAuthCert()
          By setting a certificate and private key to the routing Tranche server that can perform deletes, will be able to delete from managed data servers.
 java.security.PrivateKey getAuthPrivateKey()
          By setting a certificate and private key to the routing Tranche server that can perform deletes, will be able to delete from managed data servers.
 Configuration getConfiguration()
           
 Configuration getConfiguration(Signature sig, byte[] nonce)
           
 PropagationReturnWrapper getData(BigHash[] hashes, boolean propagateRequest)
           
 BigHash[] getDataHashes(java.math.BigInteger offset, java.math.BigInteger length)
           
 java.lang.String getHost()
          Returns the host name of the server.
 java.util.Set<java.lang.String> getManagedServers()
          Just returns a deep copy of servers to use.
 PropagationReturnWrapper getMetaData(BigHash[] hashes, boolean propagateRequest)
           
 BigHash[] getMetaDataHashes(java.math.BigInteger offset, java.math.BigInteger length)
           
 StatusTable getNetworkStatusPortion(java.lang.String startHost, java.lang.String endHost)
          Returns the rows in the local network status that have host names that are between the startHost (inclusive) and the endHost (exclusive.)
 PropagationReturnWrapper getNonces(java.lang.String[] hosts, int count)
          Get batch of nonces from selected server hosts.
 BigHash[] getProjectHashes(java.math.BigInteger offset, java.math.BigInteger length)
          Returns a list of all projects that this server has.
 boolean[] hasData(BigHash[] hashes)
           
 boolean[] hasMetaData(BigHash[] hashes)
           
 boolean isClosed()
          Returns true if and only if the server has been closed.
 boolean isManagedServer(java.lang.String host)
          Returns true if server host is among managed host list; false otherwise.
 void ping()
          Ping the server.
 void registerServer(java.lang.String url)
          Registers the given URL as a known server.
 boolean removeListener(RoutingTrancheServerListener l)
           
 void requestShutdown(Signature sig, byte[] nonce)
          Request that a server shut down.
 void saveConfiguration()
          Serialize the Configurtation data and save to disk.
 void setAuthCert(java.security.cert.X509Certificate authCert)
          By setting a certificate and private key to the routing Tranche server that can perform deletes, will be able to delete from managed data servers.
 void setAuthPrivateKey(java.security.PrivateKey authPrivateKey)
          By setting a certificate and private key to the routing Tranche server that can perform deletes, will be able to delete from managed data servers.
 void setConfiguration(byte[] data, Signature sig, byte[] nonce)
          Sets a new configuration for the server.
 void setConfiguration(Configuration newConfig)
           
 PropagationReturnWrapper setData(BigHash hash, byte[] data, Signature sig, java.lang.String[] hosts)
          Set data and replicate to specified hosts.
 PropagationReturnWrapper setMetaData(boolean merge, BigHash hash, byte[] data, Signature sig, java.lang.String[] hosts)
          Set meta data and replicate to specified hosts.
 
Methods inherited from class org.tranche.commons.Debuggable
debugErr, debugErr, debugOut, isDebug, setDebug
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RoutingTrancheServer

public RoutingTrancheServer(java.security.cert.X509Certificate cert,
                            java.security.PrivateKey key)

RoutingTrancheServer

public RoutingTrancheServer()
Method Detail

setConfiguration

public void setConfiguration(byte[] data,
                             Signature sig,
                             byte[] nonce)
                      throws java.lang.Exception
Sets a new configuration for the server. Must have appropriate permission to do so.

Specified by:
setConfiguration in class TrancheServer
Parameters:
data - The configuration saved as an array of bytes. Use ConfigurationUtil to generate the appropriate bytes.
sig - A signature for the data.
nonce - The nonce used from the server.
Throws:
java.lang.Exception - If invalid configuration format exceptions or security exceptions occur.

setConfiguration

public void setConfiguration(Configuration newConfig)
                      throws java.lang.Exception
Throws:
java.lang.Exception

saveConfiguration

public void saveConfiguration()

Serialize the Configurtation data and save to disk.


getConfiguration

public Configuration getConfiguration(Signature sig,
                                      byte[] nonce)
                               throws java.lang.Exception
Specified by:
getConfiguration in class TrancheServer
Parameters:
sig - the signature
nonce - the nonce bytes
Returns:
the configuration
Throws:
java.lang.Exception - if any exception occurs

getConfiguration

public Configuration getConfiguration()
                               throws java.lang.Exception
Specified by:
getConfiguration in class TrancheServer
Returns:
Throws:
java.lang.Exception

ping

public void ping()
          throws java.lang.Exception

Ping the server. Handled by Server object which wraps this object.

Specified by:
ping in class TrancheServer
Throws:
java.lang.Exception

getNetworkStatusPortion

public StatusTable getNetworkStatusPortion(java.lang.String startHost,
                                           java.lang.String endHost)
                                    throws java.lang.Exception

Returns the rows in the local network status that have host names that are between the startHost (inclusive) and the endHost (exclusive.)

Specified by:
getNetworkStatusPortion in class TrancheServer
Parameters:
startHost -
endHost -
Returns:
Throws:
java.lang.Exception

getManagedServers

public java.util.Set<java.lang.String> getManagedServers()

Just returns a deep copy of servers to use. Synchronized.

Returns:

isManagedServer

public boolean isManagedServer(java.lang.String host)

Returns true if server host is among managed host list; false otherwise.

Parameters:
host -
Returns:

hasData

public boolean[] hasData(BigHash[] hashes)
                  throws java.lang.Exception
Specified by:
hasData in class TrancheServer
Parameters:
hashes - the BigHash array of data chunks
Returns:
boolean array
Throws:
java.lang.Exception - if any exception occurs

hasMetaData

public boolean[] hasMetaData(BigHash[] hashes)
                      throws java.lang.Exception
Specified by:
hasMetaData in class TrancheServer
Parameters:
hashes - the BigHash array of meta data chunks
Returns:
boolean array
Throws:
java.lang.Exception - if any exception occurs

getMetaData

public PropagationReturnWrapper getMetaData(BigHash[] hashes,
                                            boolean propagateRequest)
                                     throws java.lang.Exception
Specified by:
getMetaData in class TrancheServer
Parameters:
hashes -
propagateRequest -
Returns:
Throws:
java.lang.Exception

getData

public PropagationReturnWrapper getData(BigHash[] hashes,
                                        boolean propagateRequest)
                                 throws java.lang.Exception
Specified by:
getData in class TrancheServer
Parameters:
hashes -
propagateRequest -
Returns:
Throws:
java.lang.Exception

getHost

public java.lang.String getHost()
Description copied from class: TrancheServer

Returns the host name of the server.

Specified by:
getHost in class TrancheServer
Returns:

getDataHashes

public BigHash[] getDataHashes(java.math.BigInteger offset,
                               java.math.BigInteger length)
                        throws java.lang.Exception
Specified by:
getDataHashes in class TrancheServer
Parameters:
offset - the offset
length - the length
Returns:
an array of data hashes
Throws:
java.lang.Exception - if any exception occurs

getMetaDataHashes

public BigHash[] getMetaDataHashes(java.math.BigInteger offset,
                                   java.math.BigInteger length)
                            throws java.lang.Exception
Specified by:
getMetaDataHashes in class TrancheServer
Parameters:
offset - the offset
length - the length
Returns:
an array of meta data hashes
Throws:
java.lang.Exception - if any exception occurs

registerServer

public void registerServer(java.lang.String url)
                    throws java.lang.Exception
Registers the given URL as a known server. The server chooses if or if not it will remember this URL.

Specified by:
registerServer in class TrancheServer
Parameters:
url - the URL to register (e.g. tranche://proteomecommons.org:443 )
Throws:
java.lang.Exception - if any exception occurs

getProjectHashes

public BigHash[] getProjectHashes(java.math.BigInteger offset,
                                  java.math.BigInteger length)
                           throws java.lang.Exception
Returns a list of all projects that this server has.

Specified by:
getProjectHashes in class TrancheServer
Parameters:
offset - the offset
length - the length
Returns:
an array of project hashes
Throws:
java.lang.Exception - if any exception occurs

close

public void close()
Closes the server and shuts down any associated resources.

Specified by:
close in class TrancheServer

requestShutdown

public void requestShutdown(Signature sig,
                            byte[] nonce)
                     throws java.lang.Exception

Request that a server shut down. Intended for remote administration of servers.

Specified by:
requestShutdown in class TrancheServer
Parameters:
sig -
nonce -
Throws:
java.lang.Exception

getActivityLogEntries

public Activity[] getActivityLogEntries(long startTimestamp,
                                        long finishTimestamp,
                                        int limit,
                                        byte mask)
                                 throws java.lang.Exception

Get all activity log entries from within a time period.

Specified by:
getActivityLogEntries in class TrancheServer
Parameters:
startTimestamp - Timestamp from which to include activities (inclusive)
finishTimestamp - Timestamp to which to include activities (inclusive)
limit - Limit number of activity entries to return
mask - Used to match activity bytes. If all the bits in the mask are included in the activity byte, then the activity will be included. For example, if the mask is Activity.ACTION_TYPE_SET, then all logs that have this bit set (set data and set meta data) will be included. However, if Activity.SET_DATA is the mask, then only set data actions will match (since there are two bits set in the mask, making it more restrictive). 0 is least restrictive (restricts nothing) and 0xFF is most restrictive (restricts everything but itself).
Returns:
Throws:
java.lang.Exception

getActivityLogEntriesCount

public int getActivityLogEntriesCount(long startTimestamp,
                                      long stopTimestamp,
                                      byte mask)
                               throws java.lang.Exception

Returns a count of all activity log entries from within a time period.

Specified by:
getActivityLogEntriesCount in class TrancheServer
Parameters:
startTimestamp - Timestamp from which to include activities (inclusive)
stopTimestamp - Timestamp to which to include activities (inclusive)
mask - Used to match activity bytes. If all the bits in the mask are included in the activity byte, then the activity will be included. For example, if the mask is Activity.ACTION_TYPE_SET, then all logs that have this bit set (set data and set meta data) will be included. However, if Activity.SET_DATA is the mask, then only set data actions will match (since there are two bits set in the mask, making it more restrictive). 0 is least restrictive (restricts nothing) and 0xFF is most restrictive (restricts everything but itself).
Returns:
Throws:
java.lang.Exception

addListener

public boolean addListener(RoutingTrancheServerListener l)
Parameters:
l -
Returns:

removeListener

public boolean removeListener(RoutingTrancheServerListener l)
Parameters:
l -
Returns:

clearListeners

public void clearListeners()

fireDataServersAdded

public void fireDataServersAdded(java.lang.String[] hosts)
Parameters:
hosts -

fireDataServersRemoved

public void fireDataServersRemoved(java.lang.String[] hosts)

Fired when a RoutingTrancheServer instance removes one or more data server.

Parameters:
hosts -

setData

public PropagationReturnWrapper setData(BigHash hash,
                                        byte[] data,
                                        Signature sig,
                                        java.lang.String[] hosts)
                                 throws java.lang.Exception

Set data and replicate to specified hosts.

Specified by:
setData in class TrancheServer
Parameters:
hash -
data -
sig -
hosts -
Returns:
Throws:
java.lang.Exception

setMetaData

public PropagationReturnWrapper setMetaData(boolean merge,
                                            BigHash hash,
                                            byte[] data,
                                            Signature sig,
                                            java.lang.String[] hosts)
                                     throws java.lang.Exception
Description copied from class: TrancheServer

Set meta data and replicate to specified hosts.

Specified by:
setMetaData in class TrancheServer
Parameters:
merge -
hash -
data -
sig -
hosts -
Returns:
Throws:
java.lang.Exception

getNonces

public PropagationReturnWrapper getNonces(java.lang.String[] hosts,
                                          int count)
                                   throws java.lang.Exception

Get batch of nonces from selected server hosts.

Specified by:
getNonces in class TrancheServer
Parameters:
hosts -
count -
Returns:
Throws:
java.lang.Exception

deleteData

public PropagationReturnWrapper deleteData(BigHash hash,
                                           Signature[] sigs,
                                           byte[][] nonces,
                                           java.lang.String[] hosts)
                                    throws java.lang.Exception

Delete data chunk from selected servers.

Specified by:
deleteData in class TrancheServer
Parameters:
hash -
sigs -
nonces -
hosts -
Throws:
java.lang.Exception

deleteMetaData

public PropagationReturnWrapper deleteMetaData(BigHash hash,
                                               java.lang.String uploaderName,
                                               java.lang.Long uploadTimestamp,
                                               java.lang.String relativePathInDataSet,
                                               Signature[] sigs,
                                               byte[][] nonces,
                                               java.lang.String[] hosts)
                                        throws java.lang.Exception
p>Delete meta data chunk from selected servers.

Specified by:
deleteMetaData in class TrancheServer
Parameters:
hash -
sigs -
nonces -
hosts -
Throws:
java.lang.Exception

getAuthCert

public java.security.cert.X509Certificate getAuthCert()

By setting a certificate and private key to the routing Tranche server that can perform deletes, will be able to delete from managed data servers.

It is the responsibility of the administrator starting the routing server to secure a signed key/certificate that can perform deletes. Please contact the Tranche network administrators for more information.

Returns:

setAuthCert

public void setAuthCert(java.security.cert.X509Certificate authCert)

By setting a certificate and private key to the routing Tranche server that can perform deletes, will be able to delete from managed data servers.

It is the responsibility of the administrator starting the routing server to secure a signed key/certificate that can perform deletes. Please contact the Tranche network administrators for more information.

Parameters:
authCert -

getAuthPrivateKey

public java.security.PrivateKey getAuthPrivateKey()

By setting a certificate and private key to the routing Tranche server that can perform deletes, will be able to delete from managed data servers.

It is the responsibility of the administrator starting the routing server to secure a signed key/certificate that can perform deletes. Please contact the Tranche network administrators for more information.

Returns:

setAuthPrivateKey

public void setAuthPrivateKey(java.security.PrivateKey authPrivateKey)

By setting a certificate and private key to the routing Tranche server that can perform deletes, will be able to delete from managed data servers.

It is the responsibility of the administrator starting the routing server to secure a signed key/certificate that can perform deletes. Please contact the Tranche network administrators for more information.

Parameters:
authPrivateKey -

isClosed

public boolean isClosed()

Returns true if and only if the server has been closed.

Returns:


This code is free for use both commercially and non-commercially as stated in the project's license