edu.ucsb.nceas.metacat.replication

## Class ReplicationService

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

-     public class ReplicationService
      extends BaseService

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `FORCEREPLICATEDELETE`
    `static java.lang.String` | `FORCEREPLICATEDELETEALL`
    `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

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `doRefresh()`
    `static java.lang.String` | `getCatalogXML()` Returns the xml_catalog table encoded in xml
    `static java.lang.String` | `getDocumentInfo(java.lang.String docid)` Gets a docInfo XML snippet for the replication API
    `static java.util.Hashtable<java.lang.String,java.lang.String>` | `getDocumentInfoMap(java.lang.String docid)`
    `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.util.Map<java.lang.Integer,java.lang.String>` | `getServerCodes()` Returns a Map of serverCode=serverName
    `static java.lang.String` | `getServerNameForServerCode(int serverCode)` Returns the name of a server given a serverCode
    `static byte[]` | `getURLBytes(java.net.URL u)` This method returns a byte array after opening a url
    `static java.lang.String` | `getURLContent(java.net.URL u)` This method returns the content of a url
    `static java.io.InputStream` | `getURLStream(java.net.URL u)` This method returns the InputStream after opening 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.util.Hashtable<java.lang.String,java.lang.String[]> params, javax.servlet.http.HttpServletResponse response, javax.servlet.http.HttpServletRequest request, boolean removeAll)`
    `protected static void` | `handleForceReplicateRequest(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 void` | `handleForceReplicateSystemMetadataRequest(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.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.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.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.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` | `handleGetSystemMetadataRequest(java.util.Hashtable<java.lang.String,java.lang.String[]> params, javax.servlet.http.HttpServletResponse response)` Sends System Metadata as XML
    `protected static void` | `handleGetTimeRequest(java.util.Hashtable<java.lang.String,java.lang.String[]> params, javax.servlet.http.HttpServletResponse response)` Sends the current system date to the remote server.
    `static void` | `handleServerControlRequest(java.util.Hashtable<java.lang.String,java.lang.String[]> params, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)` This method can add, delete and list the servers currently included in xml_replication.
    `protected static void` | `handleUpdateRequest(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()`
    `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

    - #### FORCEREPLICATEDELETEALL

          public static final java.lang.String FORCEREPLICATEDELETEALL

      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

          public 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

          public static void handleServerControlRequest(java.util.Hashtable<java.lang.String,java.lang.String[]> params,
                                                        javax.servlet.http.HttpServletRequest request,
                                                        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.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.util.Hashtable<java.lang.String,java.lang.String[]> params,
                                                                  javax.servlet.http.HttpServletResponse response,
                                                                  javax.servlet.http.HttpServletRequest request,
                                                                  boolean removeAll)

    - #### 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.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.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

    - #### getDocumentInfoMap

          public static java.util.Hashtable<java.lang.String,java.lang.String> getDocumentInfoMap(java.lang.String docid)
                                                                                           throws HandlerException,
                                                                                                  AccessControlException,
                                                                                                  org.dataone.exceptions.MarshallingException,
                                                                                                  java.io.IOException,
                                                                                                  McdbException,
                                                                                                  org.xml.sax.SAXException

      Throws:
        `HandlerException`
        `AccessControlException`
        `org.dataone.exceptions.MarshallingException`
        `java.io.IOException`
        `McdbException`
        `org.xml.sax.SAXException`

    - #### getDocumentInfo

          public static java.lang.String getDocumentInfo(java.lang.String docid)
                                                  throws AccessControlException,
                                                         org.dataone.exceptions.MarshallingException,
                                                         java.io.IOException,
                                                         McdbException

      Gets a docInfo XML snippet for the replication API
      Parameters:
        `docid` -
      Returns:
      Throws:
        `AccessControlException`
        `JiBXException`
        `java.io.IOException`
        `McdbException`
        `org.dataone.exceptions.MarshallingException`

    - #### handleGetSystemMetadataRequest

          protected static void handleGetSystemMetadataRequest(java.util.Hashtable<java.lang.String,java.lang.String[]> params,
                                                               javax.servlet.http.HttpServletResponse response)

      Sends System Metadata as XML

    - #### handleForceReplicateSystemMetadataRequest

          protected static void handleForceReplicateSystemMetadataRequest(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.

    - #### 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.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.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.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.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`

    - #### getServerCodes

          public static java.util.Map<java.lang.Integer,java.lang.String> getServerCodes()
                                                                                  throws ServiceException

      Returns a Map of serverCode=serverName
      Returns:
        Map of server codes to names (URIs)
      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.lang.Exception

      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`
        `java.lang.Exception`

    - #### getURLStream

          public static java.io.InputStream getURLStream(java.net.URL u)
                                                  throws java.lang.Exception

      This method returns the InputStream after opening a url
      Parameters:
        `u` - the url to return the content from
      Returns:
        a InputStream representing the content of the url
      Throws:
        `java.io.IOException`
        `java.lang.Exception`

    - #### getURLBytes

          public static byte[] getURLBytes(java.net.URL u)
                                    throws java.lang.Exception

      This method returns a byte array after opening a url
      Parameters:
        `u` - the url to return the content from
      Returns:
        a InputStream representing the content of the url
      Throws:
        `java.io.IOException`
        `java.lang.Exception`

    - #### 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 © 2020 Regents of the University of California. All Rights Reserved.