|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object atg.nucleus.logging.VariableArgumentApplicationLoggingImpl atg.nucleus.GenericService atg.distributor.DistributorSender
public class DistributorSender
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.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 |
---|
public static java.lang.String CLASS_VERSION
Constructor Detail |
---|
public DistributorSender()
public DistributorSender(java.lang.String[] pServerList)
pServerList
- the list of host:port
combinations
that this client should connect to.public DistributorSender(java.lang.String[] pServerList, int pInterval)
pInterval
- minimum reconnect interval to use (in millis)pServerList
- the list of host:port
combinations
that this client should connect to.Method Detail |
---|
public void setRemoteServerCache(atg.distributor.RemoteServerCache pRemoteServerCache)
public atg.distributor.RemoteServerCache getRemoteServerCache()
public void setLoggingIdentifier(java.lang.String pLoggingIdentifier)
public java.lang.String getLoggingIdentifier()
public void setMinReconnectInterval(int pMinReconnectInterval)
public int getMinReconnectInterval()
public void setReadTimeout(int pReadTimeout)
public int getReadTimeout()
public void setWriteTimeout(int pWriteTimeout)
public int getWriteTimeout()
public void setServerList(java.lang.String[] pServerList)
host:port
combinations
that this client should connect to.
public java.lang.String[] getServerList()
host:port
combinations
that this client should connect to.
public void setContentItemNameProperty(java.lang.String pContentItemNameProperty)
public java.lang.String getContentItemNameProperty()
public void setDocumentRoot(java.io.File pDocumentRoot)
public java.io.File getDocumentRoot()
public void setDocumentRootCachePath(java.lang.String pDocumentRootCachePath)
public java.lang.String getDocumentRootCachePath()
public void setDocumentRootContextPath(java.lang.String pDocumentRootContextPath)
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.
public java.lang.String getDocumentRootContextPath()
public void setCreateCacheDirectories(boolean pCreateCacheDirectories)
public boolean isCreateCacheDirectories()
public void setCacheLocally(boolean pCacheLocally)
public boolean isCacheLocally()
documentRoot
is null, then
this always returns false
public void setConnectionTimeout(long pConnectionTimeout)
long
- the timeout (milliseconds)public long getConnectionTimeout()
public void setFlatten(boolean pFlatten)
public boolean isFlatten()
public void setPre61(boolean pPre61)
public boolean isPre61()
public void setEscapeURI(boolean pEscapeURI)
public boolean isEscapeURI()
public void doStartService() throws ServiceException
doStartService
in class GenericService
ServiceException
- if the Service had a problem starting uppublic void doStopService() throws ServiceException
doStopService
in class GenericService
ServiceException
- if the Service had a problem shutting downpublic void sendLogEvent(LogEvent pLogEvent)
GenericService
sendLogEvent
in class GenericService
public java.lang.String getAbsoluteName()
getAbsoluteName
in interface atg.naming.AbsoluteNameable
getAbsoluteName
in class GenericService
public void openConnections() throws ServerConnectionException
ServerConnectionException
- if there were any problems attempting to
connect to to each remote serverpublic void initializeConnections() throws ServerConnectionException
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
.
ServerConnectionException
- if there were any problems attempting to
initialize the connection to to each remote serverpublic void closeConnections() throws ServerConnectionException
ServerConnectionException
- if there were any problems attempting to
close the connection to to each remote serverprotected boolean sendPutCommand(atg.distributor.RemoteConnection pConnection, java.lang.String pRemoteDirectory, java.lang.String pRemoteFileName, byte[] pData) throws java.io.IOException
pConnection
- a single remote connection to a Distributor Receiver serverpFileName
- the file name to use on the remote server for the datapData
- a byte array which represents the data for the filetrue
- 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.
java.io.IOException
- if an error occurs while sending the dataprotected boolean sendPutCommand(atg.distributor.RemoteConnection pConnection, java.lang.String pRemoteDirectory, java.lang.String pRemoteFileName, java.io.File pFile) throws java.io.IOException
pConnection
- a single remote connection to a Distributor Receiver serverpFile
- the local file to send to the remote servertrue
- 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.
java.io.IOException
- if an error occurs while sending the dataprotected boolean sendPutCommand(atg.distributor.RemoteConnection pConnection, java.lang.String pRemoteDirectory, java.lang.String pRemoteFileName, ContentRepositoryItem pItem, java.lang.String pContentKey) throws java.io.IOException
java.io.IOException
protected java.lang.String flattenPath(java.lang.String pPath)
pPath
- path to flatten, null ok
protected java.lang.String unLocalizeDirectoryPath(java.lang.String pDirectoryPath)
protected java.lang.String generateFileName(java.lang.String pFileName)
cleanFileNamemethod.
protected java.lang.String generateFileName(java.io.File pFile)
cleanFileNamemethod and passes the
name of the File.
protected java.lang.String generateFileName(ContentRepositoryItem pItem, java.lang.String pContentKey)
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).
protected java.lang.String generateCacheDirectoryPath(java.lang.String pFileName)
protected java.lang.String generateCacheDirectoryPath(java.io.File pFile)
protected java.lang.String generateCacheDirectoryPath(ContentRepositoryItem pItem, java.lang.String pContentKey)
protected java.lang.String generateURI(java.lang.String pDirectory, java.lang.String pFileName)
public java.lang.String putFile(java.lang.String pFileName, byte[] pData) throws ServerConnectionException
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.
pFileName
- Name of file to create which will contain the supplied datapData
- the raw byte array of the contents of file to send
ServerConnectionException
- if there were any problems attempting to communicate to to any of the remote serverspublic java.lang.String putFile(java.io.File pFile) throws ServerConnectionException
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.
pFile
- the local file to send to the remote server
ServerConnectionException
- if there were any problems attempting to communicate to to any of the remote serverspublic java.lang.String putFile(ContentRepositoryItem pItem) throws ServerConnectionException
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.
pItem
- the content to send to the remote servers
ServerConnectionException
- if there were any problems attempting to communicate to to any of the remote serverspublic java.lang.String putFile(ContentRepositoryItem pItem, java.lang.String pContentKey) throws ServerConnectionException
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.
pItem
- the content to send to the remote serverspContentKey
- the rendition of the content item to send
ServerConnectionException
- if there were any problems attempting to communicate to to any of the remote serversprotected 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
java.io.IOException
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
java.io.IOException
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
java.io.IOException
protected void markAsRemotelyDistributed(atg.distributor.RemoteConnection pConnection, java.lang.String pKey, long pLastModified, long pFileSize)
protected void markAsRemotelyDistributed(atg.distributor.RemoteConnection pConnection, java.lang.String pKey, java.io.File pFile)
protected void markAsRemotelyDistributed(atg.distributor.RemoteConnection pConnection, java.lang.String pKey, ContentRepositoryItem pItem, java.lang.String pContentKey)
protected void markAsLocallyCached(java.io.File pKey, long pLastModified, long pFileSize)
protected java.io.File getLocalCacheDirectory(java.lang.String pCacheDirectory, java.lang.String pFileName) throws java.io.IOException
createCacheDirectories
property is true.
java.io.IOException
- if there was an error creating the cache directoryprotected java.io.File getLocalCacheDirectory(java.lang.String pCacheDirectory, java.io.File pFile) throws java.io.IOException
createCacheDirectories
property is true.
java.io.IOException
- if there was an error creating the cache directoryprotected java.io.File getLocalCacheDirectory(java.lang.String pCacheDirectory, ContentRepositoryItem pItem, java.lang.String pContentKey) throws java.io.IOException
createCacheDirectories
property is true.
java.io.IOException
- if there was an error creating the cache directoryprotected boolean locallyCached(java.io.File pCacheFile, long pDataLastModified, long pDataSize)
protected void cacheLocally(java.lang.String pCacheDirectory, java.lang.String pCacheFileName, java.lang.String pFileName, byte[] pData) throws java.io.IOException
pFileName
- Name of file to create which will contain the supplied datapData
- the raw byte array of the contents of file to send
java.io.IOException
- if there was an error caching the fileprotected void cacheLocally(java.lang.String pCacheDirectory, java.lang.String pCacheFileName, java.io.File pFile) throws java.io.IOException
pFileName
- Name of file to create which will contain the supplied datapData
- the raw byte array of the contents of file to send
java.io.IOException
- if there was an error caching the fileprotected void cacheLocally(java.lang.String pCacheDirectory, java.lang.String pCacheFileName, ContentRepositoryItem pItem, java.lang.String pContentKey) throws java.io.IOException
pFileName
- Name of file to create which will contain the supplied datapData
- the raw byte array of the contents of file to send
java.io.IOException
- if there was an error caching the fileprotected boolean receiveAcknowledgement(atg.distributor.RemoteConnection pConnection) throws java.io.IOException
pConnection
- a single remote connection to a Distributor Receiver servertrue
- if the remote connection sends us a successful acknowledgement, false
if the message received does not match out success criteria.
java.io.IOException
- if an error occurs while reading the acknowledgementpublic static void main(java.lang.String[] pArgs)
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.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |