edu.ucsb.nceas.metacat.replication
Class ReplicationService

java.lang.Object
  extended by edu.ucsb.nceas.metacat.shared.BaseService
      extended by edu.ucsb.nceas.metacat.replication.ReplicationService

public class ReplicationService
extends BaseService


Field Summary
static java.lang.String FORCEREPLICATEDELETE
           
static java.lang.String METACAT_REPL_ERROR_MSG
           
static java.lang.String REPLICATION_LOG_FILE_NAME
           
static java.lang.String REPLICATIONUSER
           
 
Fields inherited from class edu.ucsb.nceas.metacat.shared.BaseService
_serviceName
 
Method Summary
protected  void doRefresh()
           
static java.lang.String getCatalogXML()
          Returns the xml_catalog table encoded in xml
static int getHomeServerCodeForDocId(java.lang.String accNum)
          Returns a home server location given a accnum
static java.util.Hashtable<java.lang.String,java.lang.String> getHomeServerInfoForDocId(java.lang.String docId)
          Method to get a host server information for given docid
static ReplicationService getInstance()
          Get the single instance of SessionService.
static int getServerCodeForServerName(java.lang.String server)
          Returns a server code given a server name
static java.lang.String getServerNameForServerCode(int serverCode)
          Returns the name of a server given a serverCode
static java.lang.String getURLContent(java.net.URL u)
          This method returns the content of a url
protected static void handleForceReplicateDataFileRequest(java.util.Hashtable<java.lang.String,java.lang.String[]> params, javax.servlet.http.HttpServletRequest request)
          when a forcereplication data file request comes in, local host sends a readdata request to the requesting server (remote server) for the specified docid.
protected static void handleForceReplicateDeleteRequest(java.io.PrintWriter out, java.util.Hashtable<java.lang.String,java.lang.String[]> params, javax.servlet.http.HttpServletResponse response, javax.servlet.http.HttpServletRequest request)
           
protected static void handleForceReplicateRequest(java.io.PrintWriter out, java.util.Hashtable<java.lang.String,java.lang.String[]> params, javax.servlet.http.HttpServletResponse response, javax.servlet.http.HttpServletRequest request)
          when a forcereplication request comes in, local host sends a read request to the requesting server (remote server) for the specified docid.
protected static java.lang.String handleGetCatalogRequest(java.io.PrintWriter out, java.util.Hashtable<java.lang.String,java.lang.String[]> params, javax.servlet.http.HttpServletResponse response, boolean printFlag)
          Sends the contents of the xml_catalog table encoded in xml The xml format is: All of the sub elements of row are #PCDATA If printFlag == false then do not print to out.
protected static void handleGetDataFileRequest(java.io.OutputStream outPut, java.util.Hashtable<java.lang.String,java.lang.String[]> params, javax.servlet.http.HttpServletResponse response)
          Sends a datafile to a remote host
protected static void handleGetDocumentInfoRequest(java.io.PrintWriter out, java.util.Hashtable<java.lang.String,java.lang.String[]> params, javax.servlet.http.HttpServletResponse response)
          Sends all of the xml_documents information encoded in xml to a requestor the format is: all of the subelements of document info are #PCDATA
protected static void handleGetDocumentRequest(java.io.PrintWriter out, java.util.Hashtable<java.lang.String,java.lang.String[]> params, javax.servlet.http.HttpServletResponse response)
          Sends a document to a remote host
protected static void handleGetLockRequest(java.io.PrintWriter out, java.util.Hashtable<java.lang.String,java.lang.String[]> params, javax.servlet.http.HttpServletResponse response)
          Grants or denies a lock to a requesting host.
protected static void handleGetTimeRequest(java.io.PrintWriter out, java.util.Hashtable<java.lang.String,java.lang.String[]> params, javax.servlet.http.HttpServletResponse response)
          Sends the current system date to the remote server.
protected static void handleServerControlRequest(java.io.PrintWriter out, java.util.Hashtable<java.lang.String,java.lang.String[]> params, javax.servlet.http.HttpServletResponse response)
          This method can add, delete and list the servers currently included in xml_replication.
protected static void handleUpdateRequest(java.io.PrintWriter out, java.util.Hashtable<java.lang.String,java.lang.String[]> params, javax.servlet.http.HttpServletResponse response)
          Sends a list of all of the documents on this sever along with their revision numbers.
 boolean refreshable()
           
static boolean replToServer(java.lang.String server)
          Returns true if the replicate field for server in xml_replication is 1.
 void run()
          this method handles the timeout for a file lock.
 void runOnce()
           
protected  void startReplication(java.util.Hashtable<java.lang.String,java.lang.String[]> params)
           
 void stop()
           
 void stopReplication()
           
static void updateUserOwner(DBConnection dbConn, java.lang.String docid, java.lang.String owner, java.lang.String updater)
           
 
Methods inherited from class edu.ucsb.nceas.metacat.shared.BaseService
refresh
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FORCEREPLICATEDELETE

public static final java.lang.String FORCEREPLICATEDELETE
See Also:
Constant Field Values

REPLICATIONUSER

public static final java.lang.String REPLICATIONUSER
See Also:
Constant Field Values

REPLICATION_LOG_FILE_NAME

public static final java.lang.String REPLICATION_LOG_FILE_NAME
See Also:
Constant Field Values

METACAT_REPL_ERROR_MSG

public static java.lang.String METACAT_REPL_ERROR_MSG
Method Detail

getInstance

public static ReplicationService getInstance()
                                      throws ServiceException
Get the single instance of SessionService.

Returns:
the single instance of SessionService
Throws:
ServiceException

refreshable

public boolean refreshable()
Specified by:
refreshable in class BaseService

doRefresh

protected void doRefresh()
                  throws ServiceException
Specified by:
doRefresh in class BaseService
Throws:
ServiceException

stop

public void stop()
          throws ServiceException
Specified by:
stop in class BaseService
Throws:
ServiceException

stopReplication

public void stopReplication()
                     throws ServiceException
Throws:
ServiceException

startReplication

protected void startReplication(java.util.Hashtable<java.lang.String,java.lang.String[]> params)
                         throws ServiceException
Throws:
ServiceException

runOnce

public void runOnce()
             throws ServiceException
Throws:
ServiceException

handleServerControlRequest

protected static void handleServerControlRequest(java.io.PrintWriter out,
                                                 java.util.Hashtable<java.lang.String,java.lang.String[]> params,
                                                 javax.servlet.http.HttpServletResponse response)
This method can add, delete and list the servers currently included in xml_replication. action subaction other needed params --------------------------------------------------------- servercontrol add server servercontrol delete server servercontrol list


handleForceReplicateRequest

protected static void handleForceReplicateRequest(java.io.PrintWriter out,
                                                  java.util.Hashtable<java.lang.String,java.lang.String[]> params,
                                                  javax.servlet.http.HttpServletResponse response,
                                                  javax.servlet.http.HttpServletRequest request)
when a forcereplication request comes in, local host sends a read request to the requesting server (remote server) for the specified docid. Then store it in local database.


handleForceReplicateDeleteRequest

protected static void handleForceReplicateDeleteRequest(java.io.PrintWriter out,
                                                        java.util.Hashtable<java.lang.String,java.lang.String[]> params,
                                                        javax.servlet.http.HttpServletResponse response,
                                                        javax.servlet.http.HttpServletRequest request)

handleForceReplicateDataFileRequest

protected static void handleForceReplicateDataFileRequest(java.util.Hashtable<java.lang.String,java.lang.String[]> params,
                                                          javax.servlet.http.HttpServletRequest request)
when a forcereplication data file request comes in, local host sends a readdata request to the requesting server (remote server) for the specified docid. Then store it in local database and file system


handleGetLockRequest

protected static void handleGetLockRequest(java.io.PrintWriter out,
                                           java.util.Hashtable<java.lang.String,java.lang.String[]> params,
                                           javax.servlet.http.HttpServletResponse response)
Grants or denies a lock to a requesting host. The servlet parameters of interrest are: docid: the docid of the file the lock is being requested for currentdate: the timestamp of the document on the remote server


handleGetDocumentInfoRequest

protected static void handleGetDocumentInfoRequest(java.io.PrintWriter out,
                                                   java.util.Hashtable<java.lang.String,java.lang.String[]> params,
                                                   javax.servlet.http.HttpServletResponse response)
Sends all of the xml_documents information encoded in xml to a requestor the format is: all of the subelements of document info are #PCDATA


handleGetDataFileRequest

protected static void handleGetDataFileRequest(java.io.OutputStream outPut,
                                               java.util.Hashtable<java.lang.String,java.lang.String[]> params,
                                               javax.servlet.http.HttpServletResponse response)
Sends a datafile to a remote host


handleGetDocumentRequest

protected static void handleGetDocumentRequest(java.io.PrintWriter out,
                                               java.util.Hashtable<java.lang.String,java.lang.String[]> params,
                                               javax.servlet.http.HttpServletResponse response)
Sends a document to a remote host


handleUpdateRequest

protected static void handleUpdateRequest(java.io.PrintWriter out,
                                          java.util.Hashtable<java.lang.String,java.lang.String[]> params,
                                          javax.servlet.http.HttpServletResponse response)
Sends a list of all of the documents on this sever along with their revision numbers. The format is: note that the rev in deletedDocument is always empty. I just left it in there to make the parser implementation easier.


updateUserOwner

public static void updateUserOwner(DBConnection dbConn,
                                   java.lang.String docid,
                                   java.lang.String owner,
                                   java.lang.String updater)
                            throws java.sql.SQLException
Parameters:
dbConn - connection for doing the update
docid - the document id to update
owner - the user_owner
updater - the user_updated
Throws:
java.sql.SQLException

getCatalogXML

public static java.lang.String getCatalogXML()
Returns the xml_catalog table encoded in xml


handleGetCatalogRequest

protected static java.lang.String handleGetCatalogRequest(java.io.PrintWriter out,
                                                          java.util.Hashtable<java.lang.String,java.lang.String[]> params,
                                                          javax.servlet.http.HttpServletResponse response,
                                                          boolean printFlag)
Sends the contents of the xml_catalog table encoded in xml The xml format is: All of the sub elements of row are #PCDATA If printFlag == false then do not print to out.


handleGetTimeRequest

protected static void handleGetTimeRequest(java.io.PrintWriter out,
                                           java.util.Hashtable<java.lang.String,java.lang.String[]> params,
                                           javax.servlet.http.HttpServletResponse response)
Sends the current system date to the remote server. Using this action for replication gets rid of any problems with syncronizing clocks because a time specific to a document is always kept on its home server.


run

public void run()
this method handles the timeout for a file lock. when a lock is granted it is granted for 30 seconds. When this thread runs out it deletes the docid from the queue, thus eliminating the lock.


getServerNameForServerCode

public static java.lang.String getServerNameForServerCode(int serverCode)
Returns the name of a server given a serverCode

Parameters:
serverCode - the serverid of the server
Returns:
the servername or null if the specified serverCode does not exist.

getServerCodeForServerName

public static int getServerCodeForServerName(java.lang.String server)
                                      throws ServiceException
Returns a server code given a server name

Parameters:
server - the name of the server
Returns:
integer > 0 representing the code of the server, 0 if the server does not exist.
Throws:
ServiceException

getHomeServerInfoForDocId

public static java.util.Hashtable<java.lang.String,java.lang.String> getHomeServerInfoForDocId(java.lang.String docId)
Method to get a host server information for given docid

Parameters:
conn - a connection to the database

getHomeServerCodeForDocId

public static int getHomeServerCodeForDocId(java.lang.String accNum)
                                     throws ServiceException
Returns a home server location given a accnum

Parameters:
accNum - , given accNum for a document
Throws:
ServiceException

getURLContent

public static java.lang.String getURLContent(java.net.URL u)
                                      throws java.io.IOException
This method returns the content of a url

Parameters:
u - the url to return the content from
Returns:
a string representing the content of the url
Throws:
java.io.IOException

replToServer

public static boolean replToServer(java.lang.String server)
Returns true if the replicate field for server in xml_replication is 1. Returns false otherwise



Copyright © 2000 National Center for Ecological Analysis and Synthesis. All Rights Reserved.