Class SVNRepositoryReplicator
- java.lang.Object
-
- org.tmatesoft.svn.core.replicator.SVNRepositoryReplicator
-
- All Implemented Interfaces:
ISVNCanceller
,ISVNEventHandler
public class SVNRepositoryReplicator extends java.lang.Object implements ISVNEventHandler
The SVNRepositoryReplicator class provides an ability to make a copy of an existing repository. The replicator does not create a repository for itself, so, both repositories, source and target, must already exist. There's two general strategies for a replicator:- Copying a range of revisions.
- Incremental copying (like the first one, but copies a special range of revisions).
[start, end]
, then the target repository's last revision must bestart - 1
. For example, when copying from the very beginning of a source repository, you passstart = 1
, what means that the target repository's latest revision must be 0. An incremental copying means copying from a source repository a revisions range starting at the revision equal to the target repository's latest revision + 1 (including) and up to the source repository's latest revision (also including). This allows to fill up missing revisions from the source repository in the target one, when you, say, once replicated the source repository and got some extra new revisions in it since then. On condition that a user has got read permissions on the entire source repository and write permissions on the destination one, replicating guarantees that for each N th revision copied from the source repository the user'll have in the N th revision of the destination repository the same changes in both versioned and unversioned (revision properties) data except locks as in the source repository. With modern Subersion servers you may alternatively useSVNRepository.replay(long, long, boolean, ISVNEditor)
for repository replication purposes.- Since:
- 1.2
- Version:
- 1.3
-
-
Field Summary
Fields Modifier and Type Field Description private ISVNReplicationHandler
myHandler
-
Fields inherited from interface org.tmatesoft.svn.core.ISVNCanceller
NULL
-
Fields inherited from interface org.tmatesoft.svn.core.wc.ISVNEventHandler
UNKNOWN
-
-
Constructor Summary
Constructors Modifier Constructor Description private
SVNRepositoryReplicator()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
checkCancelled()
Redirects a call to the registered handler'scheckCancelled()
method.protected void
fireReplicatedEvent(SVNCommitInfo commitInfo)
Fires a replicating iteration finished event to the registered handler.protected void
fireReplicatingEvent(SVNLogEntry revision)
Fires a replicating iteration started event to the registered handler.void
handleEvent(SVNEvent event, double progress)
Does nothing.static SVNRepositoryReplicator
newInstance()
Creates a new repository replicator.long
replicateRepository(SVNRepository src, SVNRepository dst, boolean incremental)
Replicates a repository either incrementally or totally.long
replicateRepository(SVNRepository src, SVNRepository dst, long fromRevision, long toRevision)
Replicates a range of repository revisions.void
setReplicationHandler(ISVNReplicationHandler handler)
Registers a replication handler to this replicator.private void
updateRevisionProperties(SVNRepository repository, long revision, SVNProperties properties)
-
-
-
Field Detail
-
myHandler
private ISVNReplicationHandler myHandler
-
-
Method Detail
-
newInstance
public static SVNRepositoryReplicator newInstance()
Creates a new repository replicator.- Returns:
- a new replicator
-
replicateRepository
public long replicateRepository(SVNRepository src, SVNRepository dst, boolean incremental) throws SVNException
Replicates a repository either incrementally or totally. Ifincremental
is true then copies a range of revisions from the source repository starting at the revision equal todst.getLatestRevision() + 1
(including) and expandig tosrc.getLatestRevision()
. Ifincremental
is false then the revision range to copy is[1, src.getLatestRevision()]
. Bothsrc
anddst
must be created for the root locations of the repositories.- Parameters:
src
- a source repository to copy fromdst
- a destination repository to copy intoincremental
- controls the way of copying- Returns:
- the number of copied revisions
- Throws:
SVNException
- See Also:
replicateRepository(SVNRepository,SVNRepository,long,long)
-
replicateRepository
public long replicateRepository(SVNRepository src, SVNRepository dst, long fromRevision, long toRevision) throws SVNException
Replicates a range of repository revisions. Starts copying fromfromRevision
(including) and expands totoRevision
. IffromRevision <= 0
then it defaults to revision 1. IftoRevision
doesn't lie in(0, src.getLatestRevision()]
, it defaults tosrc.getLatestRevision()
. The latest revision of the destination repository must be equal tofromRevision - 1
, wherefromRevision
is already a valid revision. The replicator uses a log operation to investigate the changed paths in every revision to be copied. So, for each revision being replicated an appropriate event with log information for that revision is fired (fireReplicatingEvent(SVNLogEntry)
) to the registeredhandler
(if any). Also during each copy iteration the replicator tests the handler'scheckCancelled()
method to check if the replication operation is cancelled. At the end of the copy operation the replicator (fireReplicatedEvent(SVNCommitInfo)
) yet one event with commit information about the replicated revision. Bothsrc
anddst
must be created for the root locations of the repositories.- Parameters:
src
- a source repository to copy fromdst
- a destination repository to copy intofromRevision
- a start revisiontoRevision
- a final revision- Returns:
- the number of revisions copied from the source repository
- Throws:
SVNException
- See Also:
replicateRepository(SVNRepository,SVNRepository,boolean)
-
updateRevisionProperties
private void updateRevisionProperties(SVNRepository repository, long revision, SVNProperties properties) throws SVNException
- Throws:
SVNException
-
setReplicationHandler
public void setReplicationHandler(ISVNReplicationHandler handler)
Registers a replication handler to this replicator. This handler will be notified of every revision to be copied and provided with corresponding log information (taken from the source repository) concerning that revision. Also the handler is notified as a next source repository revision is already replicated, this time the handler is dispatched commit information on the revision. In addition, during each replicating iteration the handler is used to check whether the operation is cancelled.- Parameters:
handler
- a replication handler
-
fireReplicatingEvent
protected void fireReplicatingEvent(SVNLogEntry revision) throws SVNException
Fires a replicating iteration started event to the registered handler.- Parameters:
revision
- log information about the revision to be copied- Throws:
SVNException
-
fireReplicatedEvent
protected void fireReplicatedEvent(SVNCommitInfo commitInfo) throws SVNException
Fires a replicating iteration finished event to the registered handler.- Parameters:
commitInfo
- commit info about the copied revision (includes revision number, date, author)- Throws:
SVNException
-
handleEvent
public void handleEvent(SVNEvent event, double progress) throws SVNException
Does nothing.- Specified by:
handleEvent
in interfaceISVNEventHandler
- Parameters:
event
-progress
-- Throws:
SVNException
-
checkCancelled
public void checkCancelled() throws SVNCancelException
Redirects a call to the registered handler'scheckCancelled()
method.- Specified by:
checkCancelled
in interfaceISVNCanceller
- Throws:
SVNCancelException
-
-