public class RestRepoTransport extends AbstractRepoTransport implements CredentialsProvider
| 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 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. |
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, unprefixPathpublic RestRepoTransport()
protected DynamicX509TrustManagerCallback getDynamicX509TrustManagerCallback()
public UUID getRepositoryId()
RepoTransportgetRepositoryId in interface RepoTransportpublic byte[] getPublicKey()
RepoTransportgetPublicKey in interface RepoTransportnull.public RepositoryDto getRepositoryDto()
RepoTransportThis operation does not require authentication! It can (and is regularly) invoked anonymously.
getRepositoryDto in interface RepoTransportnull.public RepositoryDto getClientRepositoryDto()
getClientRepositoryDto in interface RepoTransportpublic void requestRepoConnection(byte[] publicKey)
RepoTransportrequestRepoConnection in interface RepoTransportpublicKey - the public key of the client repository which requests the connection. Must not be
null.public void close()
close in interface RepoTransportclose in interface AutoCloseableclose in class AbstractRepoTransportpublic 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 RepoTransportlocalSync - 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)
RepoTransportprepareForChangeSetDto in interface RepoTransportchangeSetDto - the change-set from the other RepoTransport (the source of the sync). Never null.public void makeDirectory(String path, Date lastModified)
RepoTransportIf 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 RepoTransportpath - 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 RepoTransportpublic void copy(String fromPath, String toPath)
copy in interface RepoTransportpublic void move(String fromPath, String toPath)
move in interface RepoTransportpublic void delete(String path)
RepoTransportpath.
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 RepoTransportpath - 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)
RepoTransportgetRepoFileDto in interface RepoTransportpath - the path to the file.path. Never null.public byte[] getFileData(String path, long offset, int length)
RepoTransportoffset 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 RepoTransportpath - 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)
RepoTransportRepoTransport (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 RepoTransportpath - 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 RepoTransportoffset - 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)
RepoTransportRepoTransport (more precisely the remote repository behind it).endPutFile in interface RepoTransportpath - 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()
RepoTransportRepoTransport.
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 RepoTransportpublic void endSyncToRepository(long fromLocalRevision)
RepoTransportRepoTransport.
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 RepoTransportfromLocalRevision - the localRevision of the source-repository to which the destination
repository is now synchronous.public void putParentConfigPropSetDto(ConfigPropSetDto parentConfigPropSetDto)
putParentConfigPropSetDto in interface RepoTransportpublic String getUserName()
getUserName in interface CredentialsProviderpublic String getPassword()
getPassword in interface CredentialsProviderprotected CloudStoreRestClient getClient()
protected URL determineRemoteRootWithoutPathPrefix()
determineRemoteRootWithoutPathPrefix in class AbstractRepoTransportpublic String getRepositoryName()
protected String getPathAfterBaseURL()
public VersionInfoDto getVersionInfoDto()
getVersionInfoDto in interface RepoTransportCopyright © 2013–2017. All rights reserved.