atg.distributor
Class DistributorSender

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.distributor.DistributorSender
All Implemented Interfaces:
DistributorConstants, atg.naming.AbsoluteNameable, NameContextBindingListener, NameContextElement, atg.naming.NameContextParentable, NameResolver, AdminableService, atg.nucleus.Configured, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, java.util.EventListener

public class DistributorSender
extends GenericService
implements DistributorConstants

Client agent that pushes files to DistributorReceivers (servers). This class maintains a connection to one or more servers and processes requests to push files. The DistributorSender is tolerant of broken network connections with servers. Upon startup it connects to all the specified servers that answer and ignores those that do not answer. Every time a putFile request is processed the DistributorSender transmits the file to each server, trying to reestablish connections to any that are not alive. This way the server can go up an down independently of the client without introducing a single point of failure.


Field Summary
static java.lang.String CLASS_VERSION
          Class version string
 
Fields inherited from class atg.nucleus.GenericService
SERVICE_INFO_KEY
 
Fields inherited from interface atg.distributor.DistributorConstants
DEBUG_PREFIX, DEFAULT_FILE_BUFFER_SIZE, ERROR_PREFIX, FAILURE_FLAG, FILECHECK_CMD, INFO_PREFIX, MAX_RETRIES_FOR_FILE_ACCESS, MY_RESOURCE_NAME, PUT_CMD, SUCCESS_FLAG, WARNING_PREFIX
 
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging
DEFAULT_LOG_TRACE_STATUS
 
Fields inherited from interface atg.nucleus.logging.ApplicationLogging
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
 
Constructor Summary
DistributorSender()
          Constructs an instanceof DistributorSender
DistributorSender(java.lang.String[] pServerList)
          Constructs an instanceof DistributorSender
DistributorSender(java.lang.String[] pServerList, int pInterval)
          Constructs an instanceof DistributorSender
 
Method Summary
protected  void cacheLocally(java.lang.String pCacheDirectory, java.lang.String pCacheFileName, ContentRepositoryItem pItem, java.lang.String pContentKey)
          Cache the ContentRepositoryItem to a local directory
protected  void cacheLocally(java.lang.String pCacheDirectory, java.lang.String pCacheFileName, java.io.File pFile)
          Cache the file to a local directory
protected  void cacheLocally(java.lang.String pCacheDirectory, java.lang.String pCacheFileName, java.lang.String pFileName, byte[] pData)
          Cache the file to a local directory
 void closeConnections()
          Close all open connections.
 void doStartService()
          Attempt to open a connection to each of the configured servers
 void doStopService()
          Attempt to close all the connections to each of the servers
protected  java.lang.String flattenPath(java.lang.String pPath)
          Flatten up the generated file name to make sure it is suitable to be used as a real File and for use in a URL.
protected  java.lang.String generateCacheDirectoryPath(ContentRepositoryItem pItem, java.lang.String pContentKey)
          Return the name of the directory which should be used to cache the supplied file in the remote server.
protected  java.lang.String generateCacheDirectoryPath(java.io.File pFile)
          Return the name of the directory which should be used to cache the supplied file in the remote server.
protected  java.lang.String generateCacheDirectoryPath(java.lang.String pFileName)
          Return the name of the directory which should be used to cache the supplied file in the remote server.
protected  java.lang.String generateFileName(ContentRepositoryItem pItem, java.lang.String pContentKey)
          Constructs a file name which can be used through distribution.
protected  java.lang.String generateFileName(java.io.File pFile)
          Constructs a file name which can be used through distribution.
protected  java.lang.String generateFileName(java.lang.String pFileName)
          Constructs a file name which can be used through distribution.
protected  java.lang.String generateURI(java.lang.String pDirectory, java.lang.String pFileName)
          For the given platform specific directory and filename generate a URI which describes the relative path of where the file should exist once it has been distributed
 java.lang.String getAbsoluteName()
          Returns the absolute name of this service, using Nucleus to get the absolute name.
 long getConnectionTimeout()
          Returns the length of time in milliseconds that this connection will wait for a connection to its remote target.
 java.lang.String getContentItemNameProperty()
          Returns property ContentItemNameProperty
 java.io.File getDocumentRoot()
          Returns property DocumentRoot
 java.lang.String getDocumentRootCachePath()
          Returns property DocumentRootCachePath
 java.lang.String getDocumentRootContextPath()
          Get the context path to prepend to generated URI's that refer to files in the document root.
protected  java.io.File getLocalCacheDirectory(java.lang.String pCacheDirectory, ContentRepositoryItem pItem, java.lang.String pContentKey)
          Return the directory which should be used to cache the supplied ContentRepositoryItem.
protected  java.io.File getLocalCacheDirectory(java.lang.String pCacheDirectory, java.io.File pFile)
          Return the directory which should be used to cache the supplied file.
protected  java.io.File getLocalCacheDirectory(java.lang.String pCacheDirectory, java.lang.String pFileName)
          Return the directory which should be used to cache the supplied file.
 java.lang.String getLoggingIdentifier()
          Returns property LoggingIdentifier
 int getMinReconnectInterval()
          Returns property MinReconnectInterval, the minimum interval between connect retries in msec (default 120000 msec)
 int getReadTimeout()
          Returns property ReadTimeout (default 30000 msec)
 atg.distributor.RemoteServerCache getRemoteServerCache()
          Returns property RemoteServerCache
 java.lang.String[] getServerList()
          Returns property ServerList, the list of host:port combinations that this client should connect to.
 int getWriteTimeout()
          Returns property WriteTimeout (default 30000 msec)
 void initializeConnections()
          Attempts to establish connections to each server defined by serverList.
 boolean isCacheLocally()
          Returns property CacheLocally.
 boolean isCreateCacheDirectories()
          Returns property CreateCacheDirectories
 boolean isEscapeURI()
          Returns property EscapeURI
 boolean isFlatten()
          Returns property Flatten
 boolean isPre61()
          Returns property Pre61
protected  boolean locallyCached(java.io.File pCacheFile, long pDataLastModified, long pDataSize)
          Returns true if the supplied cache file already exists, and if the size and last modified fields match.
static void main(java.lang.String[] pArgs)
          The command line allows one to perform a unit test, send and delete files on the remote system.
protected  void markAsLocallyCached(java.io.File pKey, long pLastModified, long pFileSize)
          Indicate to the connection that the specified "key" of content has been distributed remotely.
protected  void markAsRemotelyDistributed(atg.distributor.RemoteConnection pConnection, java.lang.String pKey, ContentRepositoryItem pItem, java.lang.String pContentKey)
          Indicate to the connection that the specified "key" of content has been distributed remotely.
protected  void markAsRemotelyDistributed(atg.distributor.RemoteConnection pConnection, java.lang.String pKey, java.io.File pFile)
          Indicate to the connection that the specified "key" of content has been distributed remotely.
protected  void markAsRemotelyDistributed(atg.distributor.RemoteConnection pConnection, java.lang.String pKey, long pLastModified, long pFileSize)
          Indicate to the connection that the specified "key" of content has been distributed remotely.
 void openConnections()
          If no connections are open, they are initialized and established.
 java.lang.String putFile(ContentRepositoryItem pItem)
          Send the content of the default rendition of the given ContentRepositoryItem to the remote servers.
 java.lang.String putFile(ContentRepositoryItem pItem, java.lang.String pContentKey)
          Send the content of the specified rendition of the given ContentRepositoryItem to the remote servers.
 java.lang.String putFile(java.io.File pFile)
          Send the specified file to all of the servers.
 java.lang.String putFile(java.lang.String pFileName, byte[] pData)
          Send the specified file to all of the servers.
protected  boolean receiveAcknowledgement(atg.distributor.RemoteConnection pConnection)
          Using the remote connection, attempt to read the message from the remote server that acknowledges that the data was received and successfully written to the remote file system.
protected  boolean remotelyDistributed(atg.distributor.RemoteConnection pConnection, java.lang.String pRemoteDirectory, java.lang.String pRemoteFileName, java.lang.String pCacheKey, ContentRepositoryItem pItem, java.lang.String pContentKey)
          Return true if the file has been distributed to the remote servers
protected  boolean remotelyDistributed(atg.distributor.RemoteConnection pConnection, java.lang.String pRemoteDirectory, java.lang.String pRemoteFileName, java.lang.String pCacheKey, java.io.File pFile)
          Return true if the file has been distributed to the remote servers
protected  boolean remotelyDistributed(atg.distributor.RemoteConnection pConnection, java.lang.String pRemoteDirectory, java.lang.String pRemoteFileName, java.lang.String pCacheKey, long pLastModified, long pFileSize)
          Return true if the file has been distributed to the remote servers
 void sendLogEvent(LogEvent pLogEvent)
          Sends a LogEvent to all of the listeners
protected  boolean sendPutCommand(atg.distributor.RemoteConnection pConnection, java.lang.String pRemoteDirectory, java.lang.String pRemoteFileName, byte[] pData)
          Using the remote connection, attempt to send the supplied byte array to the server.
protected  boolean sendPutCommand(atg.distributor.RemoteConnection pConnection, java.lang.String pRemoteDirectory, java.lang.String pRemoteFileName, ContentRepositoryItem pItem, java.lang.String pContentKey)
           
protected  boolean sendPutCommand(atg.distributor.RemoteConnection pConnection, java.lang.String pRemoteDirectory, java.lang.String pRemoteFileName, java.io.File pFile)
          Using the remote connection, attempt to send the contents of the local file to the remote server.
 void setCacheLocally(boolean pCacheLocally)
          Sets property CacheLocally
 void setConnectionTimeout(long pConnectionTimeout)
          Set the time in milliseconds to wait for a socket when attempting to connect to its remote target.
 void setContentItemNameProperty(java.lang.String pContentItemNameProperty)
          Sets property ContentItemNameProperty
 void setCreateCacheDirectories(boolean pCreateCacheDirectories)
          Sets property CreateCacheDirectories
 void setDocumentRoot(java.io.File pDocumentRoot)
          Sets property DocumentRoot
 void setDocumentRootCachePath(java.lang.String pDocumentRootCachePath)
          Sets property DocumentRootCachePath
 void setDocumentRootContextPath(java.lang.String pDocumentRootContextPath)
          Set the context path to prepend to generated URI's that refer to files in the document root specified by documentRoot.
 void setEscapeURI(boolean pEscapeURI)
          Sets property EscapeURI
 void setFlatten(boolean pFlatten)
          Sets property Flatten
 void setLoggingIdentifier(java.lang.String pLoggingIdentifier)
          Sets property LoggingIdentifier
 void setMinReconnectInterval(int pMinReconnectInterval)
          Sets property MinReconnectInterval, the minimum interval between connect retries in msec
 void setPre61(boolean pPre61)
          Sets property mPre61
 void setReadTimeout(int pReadTimeout)
          Sets property ReadTimeout
 void setRemoteServerCache(atg.distributor.RemoteServerCache pRemoteServerCache)
          Sets property RemoteServerCache
 void setServerList(java.lang.String[] pServerList)
          Sets property ServerList, the list of host:port combinations that this client should connect to.
 void setWriteTimeout(int pWriteTimeout)
          Sets property WriteTimeout
protected  java.lang.String unLocalizeDirectoryPath(java.lang.String pDirectoryPath)
           
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, getAdminServlet, getAdminServletOutputStreamEncoding, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isAdminServletUseServletOutputStream, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, reResolveThis, resolveName, resolveName, resolveName, resolveName, setAdminServletOutputStreamEncoding, setAdminServletUseServletOutputStream, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogDebugTrace, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string

Constructor Detail

DistributorSender

public DistributorSender()
Constructs an instanceof DistributorSender


DistributorSender

public DistributorSender(java.lang.String[] pServerList)
Constructs an instanceof DistributorSender

Parameters:
pServerList - the list of host:port combinations that this client should connect to.

DistributorSender

public DistributorSender(java.lang.String[] pServerList,
                         int pInterval)
Constructs an instanceof DistributorSender

Parameters:
pInterval - minimum reconnect interval to use (in millis)
pServerList - the list of host:port combinations that this client should connect to.
Method Detail

setRemoteServerCache

public void setRemoteServerCache(atg.distributor.RemoteServerCache pRemoteServerCache)
Sets property RemoteServerCache


getRemoteServerCache

public atg.distributor.RemoteServerCache getRemoteServerCache()
Returns property RemoteServerCache


setLoggingIdentifier

public void setLoggingIdentifier(java.lang.String pLoggingIdentifier)
Sets property LoggingIdentifier


getLoggingIdentifier

public java.lang.String getLoggingIdentifier()
Returns property LoggingIdentifier


setMinReconnectInterval

public void setMinReconnectInterval(int pMinReconnectInterval)
Sets property MinReconnectInterval, the minimum interval between connect retries in msec


getMinReconnectInterval

public int getMinReconnectInterval()
Returns property MinReconnectInterval, the minimum interval between connect retries in msec (default 120000 msec)


setReadTimeout

public void setReadTimeout(int pReadTimeout)
Sets property ReadTimeout


getReadTimeout

public int getReadTimeout()
Returns property ReadTimeout (default 30000 msec)


setWriteTimeout

public void setWriteTimeout(int pWriteTimeout)
Sets property WriteTimeout


getWriteTimeout

public int getWriteTimeout()
Returns property WriteTimeout (default 30000 msec)


setServerList

public void setServerList(java.lang.String[] pServerList)
Sets property ServerList, the list of host:port combinations that this client should connect to.


getServerList

public java.lang.String[] getServerList()
Returns property ServerList, the list of host:port combinations that this client should connect to.


setContentItemNameProperty

public void setContentItemNameProperty(java.lang.String pContentItemNameProperty)
Sets property ContentItemNameProperty


getContentItemNameProperty

public java.lang.String getContentItemNameProperty()
Returns property ContentItemNameProperty


setDocumentRoot

public void setDocumentRoot(java.io.File pDocumentRoot)
Sets property DocumentRoot


getDocumentRoot

public java.io.File getDocumentRoot()
Returns property DocumentRoot


setDocumentRootCachePath

public void setDocumentRootCachePath(java.lang.String pDocumentRootCachePath)
Sets property DocumentRootCachePath


getDocumentRootCachePath

public java.lang.String getDocumentRootCachePath()
Returns property DocumentRootCachePath


setDocumentRootContextPath

public void setDocumentRootContextPath(java.lang.String pDocumentRootContextPath)
Set the context path to prepend to generated URI's that refer to files in the document root specified by documentRoot.

This will typically be null for applications running on the Dynamo Application Server and in the deployment configuration of applications running on DAF but writing files directly into an external HTTP server's document root, where no special handling is necessary to access files in the document root.

It will typically be "/dyn/dyn" in the development and staging configurations of applications running on DAF, where cached documents are stored in the Dynamo document root and served from the third party application server rather than an external HTTP server. In these environments using /dyn/dyn as the context path is required to access files that live in the Dynamo document root.


getDocumentRootContextPath

public java.lang.String getDocumentRootContextPath()
Get the context path to prepend to generated URI's that refer to files in the document root.


setCreateCacheDirectories

public void setCreateCacheDirectories(boolean pCreateCacheDirectories)
Sets property CreateCacheDirectories


isCreateCacheDirectories

public boolean isCreateCacheDirectories()
Returns property CreateCacheDirectories


setCacheLocally

public void setCacheLocally(boolean pCacheLocally)
Sets property CacheLocally


isCacheLocally

public boolean isCacheLocally()
Returns property CacheLocally. If documentRoot is null, then this always returns false


setConnectionTimeout

public void setConnectionTimeout(long pConnectionTimeout)
Set the time in milliseconds to wait for a socket when attempting to connect to its remote target.

Parameters:
long - the timeout (milliseconds)

getConnectionTimeout

public long getConnectionTimeout()
Returns the length of time in milliseconds that this connection will wait for a connection to its remote target.


setFlatten

public void setFlatten(boolean pFlatten)
Sets property Flatten


isFlatten

public boolean isFlatten()
Returns property Flatten


setPre61

public void setPre61(boolean pPre61)
Sets property mPre61


isPre61

public boolean isPre61()
Returns property Pre61


setEscapeURI

public void setEscapeURI(boolean pEscapeURI)
Sets property EscapeURI


isEscapeURI

public boolean isEscapeURI()
Returns property EscapeURI


doStartService

public void doStartService()
                    throws ServiceException
Attempt to open a connection to each of the configured servers

Overrides:
doStartService in class GenericService
Throws:
ServiceException - if the Service had a problem starting up

doStopService

public void doStopService()
                   throws ServiceException
Attempt to close all the connections to each of the servers

Overrides:
doStopService in class GenericService
Throws:
ServiceException - if the Service had a problem shutting down

sendLogEvent

public void sendLogEvent(LogEvent pLogEvent)
Description copied from class: GenericService
Sends a LogEvent to all of the listeners

Overrides:
sendLogEvent in class GenericService

getAbsoluteName

public java.lang.String getAbsoluteName()
Returns the absolute name of this service, using Nucleus to get the absolute name.

Specified by:
getAbsoluteName in interface atg.naming.AbsoluteNameable
Overrides:
getAbsoluteName in class GenericService

openConnections

public void openConnections()
                     throws ServerConnectionException
If no connections are open, they are initialized and established. If connections to distributors have been initialized, then this method will attempt to reopen the same set of connections.

Throws:
ServerConnectionException - if there were any problems attempting to connect to to each remote server

initializeConnections

public void initializeConnections()
                           throws ServerConnectionException
Attempts to establish connections to each server defined by serverList. If a connection cannot be established with valid host and port information, we will keep track of the server host information and attempt to reconnect when data must be sent. All existing open connections will first be closed and discarded. This method can be used to rebuild a set of connections based on live changes to serverList.

Throws:
ServerConnectionException - if there were any problems attempting to initialize the connection to to each remote server

closeConnections

public void closeConnections()
                      throws ServerConnectionException
Close all open connections.

Throws:
ServerConnectionException - if there were any problems attempting to close the connection to to each remote server

sendPutCommand

protected boolean sendPutCommand(atg.distributor.RemoteConnection pConnection,
                                 java.lang.String pRemoteDirectory,
                                 java.lang.String pRemoteFileName,
                                 byte[] pData)
                          throws java.io.IOException
Using the remote connection, attempt to send the supplied byte array to the server.

Parameters:
pConnection - a single remote connection to a Distributor Receiver server
pFileName - the file name to use on the remote server for the data
pData - a byte array which represents the data for the file
true - if the entire buffer was sent through the remote connection. Returns false if there are conditions by which an IOException is not generated, but the data could not be sent.
Throws:
java.io.IOException - if an error occurs while sending the data

sendPutCommand

protected boolean sendPutCommand(atg.distributor.RemoteConnection pConnection,
                                 java.lang.String pRemoteDirectory,
                                 java.lang.String pRemoteFileName,
                                 java.io.File pFile)
                          throws java.io.IOException
Using the remote connection, attempt to send the contents of the local file to the remote server.

Parameters:
pConnection - a single remote connection to a Distributor Receiver server
pFile - the local file to send to the remote server
true - if the entire file was sent through the remote connection. Returns false if there are conditions by which an IOException is not generated, but the data could not be sent.
Throws:
java.io.IOException - if an error occurs while sending the data

sendPutCommand

protected boolean sendPutCommand(atg.distributor.RemoteConnection pConnection,
                                 java.lang.String pRemoteDirectory,
                                 java.lang.String pRemoteFileName,
                                 ContentRepositoryItem pItem,
                                 java.lang.String pContentKey)
                          throws java.io.IOException
Throws:
java.io.IOException

flattenPath

protected java.lang.String flattenPath(java.lang.String pPath)
Flatten up the generated file name to make sure it is suitable to be used as a real File and for use in a URL. Each whitespace char, file separator char, forward slash ('/') char, and colon (':') char is replaced with an underscore char ('_').

Parameters:
pPath - path to flatten, null ok
Returns:
the flattened path, or null if pPath is null

unLocalizeDirectoryPath

protected java.lang.String unLocalizeDirectoryPath(java.lang.String pDirectoryPath)

generateFileName

protected java.lang.String generateFileName(java.lang.String pFileName)
Constructs a file name which can be used through distribution. This method just calls through to the cleanFileNamemethod.


generateFileName

protected java.lang.String generateFileName(java.io.File pFile)
Constructs a file name which can be used through distribution. This method just calls through to the cleanFileNamemethod and passes the name of the File.


generateFileName

protected java.lang.String generateFileName(ContentRepositoryItem pItem,
                                            java.lang.String pContentKey)
Constructs a file name which can be used through distribution. This method constructs a name starting with the item's repository id. If the contentItemNameProperty is defined, then the value of this property (if non-null) is appended after the repository id. Finally the resulting file name is passed through the cleanFileName method (using a StringBuffer as the input parameter).


generateCacheDirectoryPath

protected java.lang.String generateCacheDirectoryPath(java.lang.String pFileName)
Return the name of the directory which should be used to cache the supplied file in the remote server.

Returns:
null if no subdirectory should be used in the caching of remote files

generateCacheDirectoryPath

protected java.lang.String generateCacheDirectoryPath(java.io.File pFile)
Return the name of the directory which should be used to cache the supplied file in the remote server.

Returns:
null if no subdirectory should be used in the caching of remote files

generateCacheDirectoryPath

protected java.lang.String generateCacheDirectoryPath(ContentRepositoryItem pItem,
                                                      java.lang.String pContentKey)
Return the name of the directory which should be used to cache the supplied file in the remote server.

Returns:
null if no subdirectory should be used in the caching of remote files

generateURI

protected java.lang.String generateURI(java.lang.String pDirectory,
                                       java.lang.String pFileName)
For the given platform specific directory and filename generate a URI which describes the relative path of where the file should exist once it has been distributed


putFile

public java.lang.String putFile(java.lang.String pFileName,
                                byte[] pData)
                         throws ServerConnectionException
Send the specified file to all of the servers. If a server has trouble, press ahead and continue with other servers. If we get exceptions talking to a server, we save them up and throw when done.

putFile has two phases: 1) sending all the requests; and 2) reading all the status codes back from the servers. It works hard to get the request through to all the servers.

Parameters:
pFileName - Name of file to create which will contain the supplied data
pData - the raw byte array of the contents of file to send
Throws:
ServerConnectionException - if there were any problems attempting to communicate to to any of the remote servers

putFile

public java.lang.String putFile(java.io.File pFile)
                         throws ServerConnectionException
Send the specified file to all of the servers. If a server has trouble, press ahead and continue with other servers. If we get exceptions talking to a server, we save them up and throw when done.

putFile has two phases: 1) sending all the requests; and 2) reading all the status codes back from the servers. It works hard to get the request through to all the servers.

Parameters:
pFile - the local file to send to the remote server
Throws:
ServerConnectionException - if there were any problems attempting to communicate to to any of the remote servers

putFile

public java.lang.String putFile(ContentRepositoryItem pItem)
                         throws ServerConnectionException
Send the content of the default rendition of the given ContentRepositoryItem to the remote servers.

putFile has two phases: 1) sending all the requests; and 2) reading all the status codes back from the servers. It works hard to get the request through to all the servers.

Parameters:
pItem - the content to send to the remote servers
Throws:
ServerConnectionException - if there were any problems attempting to communicate to to any of the remote servers

putFile

public java.lang.String putFile(ContentRepositoryItem pItem,
                                java.lang.String pContentKey)
                         throws ServerConnectionException
Send the content of the specified rendition of the given ContentRepositoryItem to the remote servers.

putFile has two phases: 1) sending all the requests; and 2) reading all the status codes back from the servers. It works hard to get the request through to all the servers.

Parameters:
pItem - the content to send to the remote servers
pContentKey - the rendition of the content item to send
Throws:
ServerConnectionException - if there were any problems attempting to communicate to to any of the remote servers

remotelyDistributed

protected boolean remotelyDistributed(atg.distributor.RemoteConnection pConnection,
                                      java.lang.String pRemoteDirectory,
                                      java.lang.String pRemoteFileName,
                                      java.lang.String pCacheKey,
                                      java.io.File pFile)
                               throws java.io.IOException
Return true if the file has been distributed to the remote servers

Throws:
java.io.IOException

remotelyDistributed

protected boolean remotelyDistributed(atg.distributor.RemoteConnection pConnection,
                                      java.lang.String pRemoteDirectory,
                                      java.lang.String pRemoteFileName,
                                      java.lang.String pCacheKey,
                                      ContentRepositoryItem pItem,
                                      java.lang.String pContentKey)
                               throws java.io.IOException
Return true if the file has been distributed to the remote servers

Throws:
java.io.IOException

remotelyDistributed

protected boolean remotelyDistributed(atg.distributor.RemoteConnection pConnection,
                                      java.lang.String pRemoteDirectory,
                                      java.lang.String pRemoteFileName,
                                      java.lang.String pCacheKey,
                                      long pLastModified,
                                      long pFileSize)
                               throws java.io.IOException
Return true if the file has been distributed to the remote servers

Throws:
java.io.IOException

markAsRemotelyDistributed

protected void markAsRemotelyDistributed(atg.distributor.RemoteConnection pConnection,
                                         java.lang.String pKey,
                                         long pLastModified,
                                         long pFileSize)
Indicate to the connection that the specified "key" of content has been distributed remotely.


markAsRemotelyDistributed

protected void markAsRemotelyDistributed(atg.distributor.RemoteConnection pConnection,
                                         java.lang.String pKey,
                                         java.io.File pFile)
Indicate to the connection that the specified "key" of content has been distributed remotely.


markAsRemotelyDistributed

protected void markAsRemotelyDistributed(atg.distributor.RemoteConnection pConnection,
                                         java.lang.String pKey,
                                         ContentRepositoryItem pItem,
                                         java.lang.String pContentKey)
Indicate to the connection that the specified "key" of content has been distributed remotely.


markAsLocallyCached

protected void markAsLocallyCached(java.io.File pKey,
                                   long pLastModified,
                                   long pFileSize)
Indicate to the connection that the specified "key" of content has been distributed remotely.


getLocalCacheDirectory

protected java.io.File getLocalCacheDirectory(java.lang.String pCacheDirectory,
                                              java.lang.String pFileName)
                                       throws java.io.IOException
Return the directory which should be used to cache the supplied file. This method will also create the cache directory if it does not exist if the createCacheDirectories property is true.

Throws:
java.io.IOException - if there was an error creating the cache directory

getLocalCacheDirectory

protected java.io.File getLocalCacheDirectory(java.lang.String pCacheDirectory,
                                              java.io.File pFile)
                                       throws java.io.IOException
Return the directory which should be used to cache the supplied file. This method will also create the cache directory if it does not exist if the createCacheDirectories property is true.

Throws:
java.io.IOException - if there was an error creating the cache directory

getLocalCacheDirectory

protected java.io.File getLocalCacheDirectory(java.lang.String pCacheDirectory,
                                              ContentRepositoryItem pItem,
                                              java.lang.String pContentKey)
                                       throws java.io.IOException
Return the directory which should be used to cache the supplied ContentRepositoryItem. This method will also create the cache directory if it does not exist if the createCacheDirectories property is true.

Throws:
java.io.IOException - if there was an error creating the cache directory

locallyCached

protected boolean locallyCached(java.io.File pCacheFile,
                                long pDataLastModified,
                                long pDataSize)
Returns true if the supplied cache file already exists, and if the size and last modified fields match. If the LastModified parameter is less than or equal to 0, then we do not perform a check using that attribute of the file.


cacheLocally

protected void cacheLocally(java.lang.String pCacheDirectory,
                            java.lang.String pCacheFileName,
                            java.lang.String pFileName,
                            byte[] pData)
                     throws java.io.IOException
Cache the file to a local directory

Parameters:
pFileName - Name of file to create which will contain the supplied data
pData - the raw byte array of the contents of file to send
Throws:
java.io.IOException - if there was an error caching the file

cacheLocally

protected void cacheLocally(java.lang.String pCacheDirectory,
                            java.lang.String pCacheFileName,
                            java.io.File pFile)
                     throws java.io.IOException
Cache the file to a local directory

Parameters:
pFileName - Name of file to create which will contain the supplied data
pData - the raw byte array of the contents of file to send
Throws:
java.io.IOException - if there was an error caching the file

cacheLocally

protected void cacheLocally(java.lang.String pCacheDirectory,
                            java.lang.String pCacheFileName,
                            ContentRepositoryItem pItem,
                            java.lang.String pContentKey)
                     throws java.io.IOException
Cache the ContentRepositoryItem to a local directory

Parameters:
pFileName - Name of file to create which will contain the supplied data
pData - the raw byte array of the contents of file to send
Throws:
java.io.IOException - if there was an error caching the file

receiveAcknowledgement

protected boolean receiveAcknowledgement(atg.distributor.RemoteConnection pConnection)
                                  throws java.io.IOException
Using the remote connection, attempt to read the message from the remote server that acknowledges that the data was received and successfully written to the remote file system.

Parameters:
pConnection - a single remote connection to a Distributor Receiver server
true - if the remote connection sends us a successful acknowledgement, false if the message received does not match out success criteria.
Throws:
java.io.IOException - if an error occurs while reading the acknowledgement

main

public static void main(java.lang.String[] pArgs)
The command line allows one to perform a unit test, send and delete files on the remote system. The usage is as follows:

java atg.distributor.DistributorSender [-test] [-put path,path] [-delete path,path] -hosts host:port,host:port

Note: italic items are optional, i.e. one can run the unit test and/or send files and/or delete files remotely. The host information in bold is required.

The unit test will send 5 files named distributortest_#.tst (where # is incremented) that are 890 bytes large.