org.tranche.server
Class ServerStartupThread

java.lang.Object
  extended by java.lang.Thread
      extended by org.tranche.commons.DebuggableThread
          extended by org.tranche.server.ServerStartupThread
All Implemented Interfaces:
java.lang.Runnable

public class ServerStartupThread
extends org.tranche.commons.DebuggableThread

Start up tasks thread for server. Important for integrity of network: makes sure certain items which should be deleted are, and attempts to get copies of any newly added chunks.

Author:
Bryan Smith - bryanesmith@gmail.com

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ServerStartupThread(Server socketServer, TrancheServer wrappedServer)
          Start up tasks thread for server.
 
Method Summary
static boolean addMetaData(BigHash hash, byte[] downloadedChunk, FlatFileTrancheServer localServerToUpdate, User user)
           
static boolean checkServerForChunksToAdd(long fromTimestamp, long toTimestamp, java.lang.String host, FlatFileTrancheServer localServerToUpdate)
          Update a local server (FlatFileTrancheServer) by checking specific server at a specific url is there any new chunks to consider between two timestamps.
static boolean checkServerForChunksToDelete(long fromTimestamp, long toTimestamp, java.lang.String host, FlatFileTrancheServer localServerToUpdate)
          Update a local server (FlatFileTrancheServer) by checking specific server at a specific url is there any deletes to consider between two timestamps.
static boolean checkServerForMetaDataToReplace(long fromTimestamp, long toTimestamp, java.lang.String host, FlatFileTrancheServer localServerToUpdate)
           
static boolean checkServerForMetaDataToReplace(long fromTimestamp, long toTimestamp, java.lang.String host, FlatFileTrancheServer localServerToUpdate, int[] metaDataUpdateCount)
           
 void run()
           
 boolean waitForStartupToComplete(long maxTimeToWaitInMillis)
          Wait for ServerStartupThread to finish running.
 
Methods inherited from class org.tranche.commons.DebuggableThread
debugErr, debugErr, debugOut, isDebug, setDebug
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ServerStartupThread

public ServerStartupThread(Server socketServer,
                           TrancheServer wrappedServer)

Start up tasks thread for server. Important for integrity of network: makes sure certain items which should be deleted are, and attempts to get copies of any newly added chunks.

Parameters:
socketServer -
wrappedServer -
Method Detail

run

public void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

addMetaData

public static boolean addMetaData(BigHash hash,
                                  byte[] downloadedChunk,
                                  FlatFileTrancheServer localServerToUpdate,
                                  User user)
                           throws java.lang.Exception
Parameters:
hash -
downloadedChunk -
localServerToUpdate -
user -
Returns:
Throws:
java.lang.Exception

checkServerForMetaDataToReplace

public static boolean checkServerForMetaDataToReplace(long fromTimestamp,
                                                      long toTimestamp,
                                                      java.lang.String host,
                                                      FlatFileTrancheServer localServerToUpdate)
Parameters:
fromTimestamp -
toTimestamp -
host -
localServerToUpdate -
Returns:

checkServerForMetaDataToReplace

public static boolean checkServerForMetaDataToReplace(long fromTimestamp,
                                                      long toTimestamp,
                                                      java.lang.String host,
                                                      FlatFileTrancheServer localServerToUpdate,
                                                      int[] metaDataUpdateCount)
Parameters:
fromTimestamp -
toTimestamp -
host -
localServerToUpdate -
metaDataUpdateCount -
Returns:

checkServerForChunksToDelete

public static boolean checkServerForChunksToDelete(long fromTimestamp,
                                                   long toTimestamp,
                                                   java.lang.String host,
                                                   FlatFileTrancheServer localServerToUpdate)

Update a local server (FlatFileTrancheServer) by checking specific server at a specific url is there any deletes to consider between two timestamps. If so, will perform deletes only if user is trusted.

Parameters:
fromTimestamp - Starting of period to check (inclusive)
toTimestamp - End of period to check (inclusive)
host - Host name for server to check for deletions
localServerToUpdate - The FlatFileTrancheServer to check

checkServerForChunksToAdd

public static boolean checkServerForChunksToAdd(long fromTimestamp,
                                                long toTimestamp,
                                                java.lang.String host,
                                                FlatFileTrancheServer localServerToUpdate)

Update a local server (FlatFileTrancheServer) by checking specific server at a specific url is there any new chunks to consider between two timestamps. If so, will add chunks only if user is trusted and belong to hash span.

Also performs a check for scenario known as 'Startup Radiation' (pun on Hawking Radiation) where, for tiny window of time, a chunk that is about to be deleted might be "rescued" by this activity. The delete should help prevent the replication of the "rescued" chunk, but cannot fully prevent it.

The only way to prevent the replication of a deleted chunk is to make sure that deletions are complete by verify after a time period that the chunk didn't replicate. This is a problem for a deletion tool and cannot be handled here.

Parameters:
fromTimestamp - Starting of period to check (inclusive)
toTimestamp - End of period to check (inclusive)
host - Host name for server to check for deletions
localServerToUpdate - The FlatFileTrancheServer to check

waitForStartupToComplete

public boolean waitForStartupToComplete(long maxTimeToWaitInMillis)

Wait for ServerStartupThread to finish running. Note this will only block for a maximum number of milliseconds, as set by parameter.

Parameters:
maxTimeToWaitInMillis - Maximum number of milliseconds to wait for thread to finish
Returns:
True if finished; false if not finished (i.e., maximum time to wait elapsed and not complete)


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