public class RestRepoTransport extends AbstractRepoTransport implements CredentialsProvider, ContextWithLocalRepoManager
Modifier and Type | Field and Description |
---|---|
static String |
CHANGE_SET_DTO_CACHE_FILE_NAME_PREFIX |
static String |
CHANGE_SET_DTO_CACHE_FILE_NAME_SUFFIX |
static long |
CONFIG_DEFAULT_GET_CHANGE_SET_DTO_TIMEOUT |
static long |
CONFIG_DEFAULT_GET_REPO_FILE_DTO_WITH_FILE_CHUNK_DTOS_TIMEOUT |
static String |
CONFIG_KEY_GET_CHANGE_SET_DTO_TIMEOUT |
static String |
CONFIG_KEY_GET_REPO_FILE_DTO_WITH_FILE_CHUNK_DTOS_TIMEOUT |
static String |
TMP_FILE_NAME_SUFFIX |
Constructor and Description |
---|
RestRepoTransport() |
Modifier and Type | Method and Description |
---|---|
void |
beginPutFile(String path)
Begins a file transfer to this
RepoTransport (more precisely the remote repository behind it). |
void |
close() |
void |
copy(String fromPath,
String toPath) |
void |
delete(String path)
Deletes the file (or directory) specified by
path . |
protected URL |
determineRemoteRootWithoutPathPrefix() |
void |
endPutFile(String path,
Date lastModified,
long length,
String sha1)
Ends a file transfer to this
RepoTransport (more precisely the remote repository behind it). |
void |
endSyncFromRepository()
Marks the end of a synchronisation from the remote repository behind this
RepoTransport . |
void |
endSyncToRepository(long fromLocalRevision)
Marks the end of a synchronisation to the remote repository behind this
RepoTransport . |
ChangeSetDto |
getChangeSetDto(boolean localSync,
Long lastSyncToRemoteRepoLocalRepositoryRevisionSynced)
Gets the change-set from the remote repository.
|
protected File |
getChangeSetDtoCacheFile(Long lastSyncToRemoteRepoLocalRepositoryRevisionSynced) |
protected List<File> |
getChangeSetDtoCacheFiles(boolean includeTmpFiles) |
protected CloudStoreRestClient |
getClient() |
RepositoryDto |
getClientRepositoryDto() |
protected DynamicX509TrustManagerCallback |
getDynamicX509TrustManagerCallback() |
byte[] |
getFileData(String path,
long offset,
int length)
Get the binary file data at the given
offset and with the given length . |
LocalRepoManager |
getLocalRepoManager() |
protected File |
getLocalRepoMetaDir() |
protected File |
getLocalRepoTmpDir() |
String |
getPassword() |
protected String |
getPathAfterBaseURL() |
byte[] |
getPublicKey()
Gets the remote repository's public key.
|
RepoFileDto |
getRepoFileDto(String path)
|
RepositoryDto |
getRepositoryDto()
Gets the remote repository's repository-descriptor.
|
UUID |
getRepositoryId()
Get the remote repository's unique identifier.
|
String |
getRepositoryName() |
String |
getUserName() |
VersionInfoDto |
getVersionInfoDto() |
void |
makeDirectory(String path,
Date lastModified)
Creates the specified directory (including all parent-directories as needed).
|
void |
makeSymlink(String path,
String target,
Date lastModified) |
void |
move(String fromPath,
String toPath) |
void |
prepareForChangeSetDto(ChangeSetDto changeSetDto)
Notifies the destination repository that this change-set is about to be synced into it.
|
void |
putFileData(String path,
long offset,
byte[] fileData)
Write a block of binary data into the file.
|
void |
putParentConfigPropSetDto(ConfigPropSetDto parentConfigPropSetDto) |
void |
requestRepoConnection(byte[] publicKey)
Request to connect the client repository with
the remote repository.
|
determinePathPrefix, finalize, getClientRepositoryId, getClientRepositoryIdOrFail, getPathPrefix, getRemoteRoot, getRemoteRootWithoutPathPrefix, getRepoTransportFactory, isPathUnderPathPrefix, prefixPath, setClientRepositoryId, setRemoteRoot, setRepoTransportFactory, unprefixPath
public static final String CONFIG_KEY_GET_CHANGE_SET_DTO_TIMEOUT
public static final long CONFIG_DEFAULT_GET_CHANGE_SET_DTO_TIMEOUT
public static final String CONFIG_KEY_GET_REPO_FILE_DTO_WITH_FILE_CHUNK_DTOS_TIMEOUT
public static final long CONFIG_DEFAULT_GET_REPO_FILE_DTO_WITH_FILE_CHUNK_DTOS_TIMEOUT
public static final String CHANGE_SET_DTO_CACHE_FILE_NAME_PREFIX
public static final String CHANGE_SET_DTO_CACHE_FILE_NAME_SUFFIX
public static final String TMP_FILE_NAME_SUFFIX
public RestRepoTransport()
protected DynamicX509TrustManagerCallback getDynamicX509TrustManagerCallback()
public UUID getRepositoryId()
RepoTransport
getRepositoryId
in interface RepoTransport
public byte[] getPublicKey()
RepoTransport
getPublicKey
in interface RepoTransport
null
.public RepositoryDto getRepositoryDto()
RepoTransport
This operation does not require authentication! It can (and is regularly) invoked anonymously.
getRepositoryDto
in interface RepoTransport
null
.public RepositoryDto getClientRepositoryDto()
getClientRepositoryDto
in interface RepoTransport
public void requestRepoConnection(byte[] publicKey)
RepoTransport
requestRepoConnection
in interface RepoTransport
publicKey
- the public key of the client repository which requests the connection. Must not be
null
.public void close()
close
in interface RepoTransport
close
in interface AutoCloseable
close
in class AbstractRepoTransport
public ChangeSetDto getChangeSetDto(boolean localSync, Long lastSyncToRemoteRepoLocalRepositoryRevisionSynced)
RepoTransport
The invocation of this method marks the beginning of a synchronisation. After the synchronisation is
complete, the RepoTransport.endSyncFromRepository()
method must be invoked to notify the remote repository
that all changes contained in the change set have been successfully and completely written to the
client repository.
The change-set is dependent on the client repository: Every client repository gets its own individual
change-set. The remote repository tracks which changes need to be sent to the client. In normal
operation, the same change is transferred only once. Under certain circumstances, however, the same
change might be transferred multiple times and the client must cope with this! Such duplicate
transfers happen, if the transfer is interrupted - i.e. the RepoTransport.endSyncFromRepository()
was not
invoked.
Please note that the DTOs in this ChangeSetDto
do not need to be completely resolved. They
might be incomplete in order to reduce the size of the ChangeSetDto
. For example,
NormalFileDto.fileChunkDtos
is not populated. These details
are separately requested, later - e.g. by RepoTransport.getRepoFileDto(String)
.
getChangeSetDto
in interface RepoTransport
localSync
- true
indicates that the remote repository should perform a local sync
before calculating the change set. false
indicates that the remote repository should
abstain from a local sync. This flag is a hint and the remote repository does not need to adhere it.lastSyncToRemoteRepoLocalRepositoryRevisionSynced
- the last revision that was synced.
May be null
. If it is not null
, the property
co.codewizards.cloudstore.local.persistence.LastSyncToRemoteRepo.localRepositoryRevisionSynced
is overwritten by this value, before querying the changes. This causes all data modified in greater
(not equal) revisions to be included.null
.public void prepareForChangeSetDto(ChangeSetDto changeSetDto)
RepoTransport
prepareForChangeSetDto
in interface RepoTransport
changeSetDto
- the change-set from the other RepoTransport (the source of the sync). Never null
.public void makeDirectory(String path, Date lastModified)
RepoTransport
If the directory already exists, this is a noop.
If there is any obstruction in the way of this path (e.g. a normal file), it is moved away (renamed or simply deleted depending on the conflict resolution strategy).
makeDirectory
in interface RepoTransport
path
- the path of the directory. Must not be null
. No matter which operating system is used,
the separation-character is always '/'. This path may start with a "/", but there is no difference, if it does:
It is always relative to the repository's root directory.lastModified
- the last-modified-timestamp the newly created
directory will be set to.
May be null
(in which case the lastModified
property is not touched). This applies only to the
actual directory and not to the parent-directories! The parent-directories' lastModified
properties are never
touched - even if the parent-directories are newly created.public void makeSymlink(String path, String target, Date lastModified)
makeSymlink
in interface RepoTransport
public void copy(String fromPath, String toPath)
copy
in interface RepoTransport
public void move(String fromPath, String toPath)
move
in interface RepoTransport
public void delete(String path)
RepoTransport
path
.
If there is no such file (or directory), this method is a noop.
If path
denotes a directory, all its children (if there are) are deleted recursively.
delete
in interface RepoTransport
path
- the path of the file (or directory) to be deleted. Must not be null
. No matter which
operating system is used, the separation-character is always '/'. This path may start with a "/", but there is no
difference, if it does: It is always relative to the repository's root directory.public RepoFileDto getRepoFileDto(String path)
RepoTransport
getRepoFileDto
in interface RepoTransport
path
- the path to the file.path
. Never null
.public byte[] getFileData(String path, long offset, int length)
RepoTransport
offset
and with the given length
.
If the file was modified/deleted, this method should not fail, but simply return null
or a result being shorter than the length
specified.
getFileData
in interface RepoTransport
path
- the path of the file. Must not be null
. No matter which operating system is used,
the separation-character is always '/'. This path may start with a "/", but there is no difference, if it does:
It is always relative to the repository's root directory.offset
- the offset of the first byte to be read (0-based).length
- the length of the data to be read. -1 to read from offset
to the end of the file.public void beginPutFile(String path)
RepoTransport
RepoTransport
(more precisely the remote repository behind it).
Usually, this method creates the specified file in the file system (if necessary with parent-directories)
and in the database. But this operation may be deferred until RepoTransport.endPutFile(String, Date, long, String)
.
If the file is immediately created, it should not be synchronised to any other repository, yet! It should
be ignored, until RepoTransport.endPutFile(String, Date, long, String)
was called for it.
In normal operation, zero or more invocations of RepoTransport.putFileData(String, long, byte[])
and
finally one invocation of RepoTransport.endPutFile(String, Date, long, String)
follow this method. However, this is not
guaranteed and the file transfer may be interrupted. If it is resumed, later this method is called again,
without RepoTransport.endPutFile(String, Date, long, String)
ever having been called in between.
beginPutFile
in interface RepoTransport
path
- the path of the file. Must not be null
. No matter which operating system is used,
the separation-character is always '/'. This path may start with a "/", but there is no difference, if it does:
It is always relative to the repository's root directory.RepoTransport.putFileData(String, long, byte[])
,
RepoTransport.endPutFile(String, Date, long, String)
public void putFileData(String path, long offset, byte[] fileData)
RepoTransport
This method may only be called after RepoTransport.beginPutFile(String)
and before RepoTransport.endPutFile(String, Date, long, String)
.
putFileData
in interface RepoTransport
offset
- the 0-based position in the file at which the block should be written.RepoTransport.beginPutFile(String)
,
RepoTransport.endPutFile(String, Date, long, String)
public void endPutFile(String path, Date lastModified, long length, String sha1)
RepoTransport
RepoTransport
(more precisely the remote repository behind it).endPutFile
in interface RepoTransport
path
- the path of the file. Must not be null
. No matter which operating system is used,
the separation-character is always '/'. This path may start with a "/", but there is no difference, if it does:
It is always relative to the repository's root directory.lastModified
- when was the file's last modification. Must not be null
.length
- the length of the file in bytes. If the file already existed and was longer, it is
truncated to this length.sha1
- the SHA1 hash of the file. May be null
. If it is given, the repository may
log a warning, if the current file is different. It should not throw an exception, because it
is a valid state that a file is modified (by another process) while it is transferred.public void endSyncFromRepository()
RepoTransport
RepoTransport
.
This method should be invoked after all changes indicated by #getChangeSetDto(boolean, long)
have
been completely written into the client repository.
After this method was invoked, #getChangeSetDto(boolean, long)
will return the new changes only.
New changes means all those changes that were accumulated after its last invocation - not after the
invocation of this method! This method might be called some time after getChangeSetDto(...)
and it must be guaranteed that changes done between getChangeSetDto(...)
and
endSyncFromRepository()
are contained in the next invocation of getChangeSetDto(...)
.
This method must not be invoked, if an error was encountered during the synchronisation! It must thus
not be used in a finally block! More invocations of getChangeSetDto(...)
than of
endSyncFromRepository()
are totally fine.
endSyncFromRepository
in interface RepoTransport
public void endSyncToRepository(long fromLocalRevision)
RepoTransport
RepoTransport
.
This method should be invoked after all changes in the client repository have been completely written
into the remote repository behind this RepoTransport
.
endSyncToRepository
in interface RepoTransport
fromLocalRevision
- the localRevision
of the source-repository to which the destination
repository is now synchronous.public void putParentConfigPropSetDto(ConfigPropSetDto parentConfigPropSetDto)
putParentConfigPropSetDto
in interface RepoTransport
public String getUserName()
getUserName
in interface CredentialsProvider
public String getPassword()
getPassword
in interface CredentialsProvider
protected CloudStoreRestClient getClient()
protected URL determineRemoteRootWithoutPathPrefix()
determineRemoteRootWithoutPathPrefix
in class AbstractRepoTransport
public String getRepositoryName()
protected String getPathAfterBaseURL()
public VersionInfoDto getVersionInfoDto()
getVersionInfoDto
in interface RepoTransport
protected File getChangeSetDtoCacheFile(Long lastSyncToRemoteRepoLocalRepositoryRevisionSynced)
protected List<File> getChangeSetDtoCacheFiles(boolean includeTmpFiles)
protected File getLocalRepoTmpDir()
protected File getLocalRepoMetaDir()
public LocalRepoManager getLocalRepoManager()
getLocalRepoManager
in interface ContextWithLocalRepoManager
Copyright © 2013–2019. All rights reserved.