Package com.linecorp.centraldogma.client
Class AbstractCentralDogma
java.lang.Object
com.linecorp.centraldogma.client.AbstractCentralDogma
- All Implemented Interfaces:
CentralDogma
,AutoCloseable
A skeletal
CentralDogma
implementation.-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractCentralDogma
(ScheduledExecutorService blockingTaskExecutor) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected final ScheduledExecutorService
executor()
Returns theScheduledExecutorService
which is used for scheduling the tasks related with automatic retries and invoking the callbacks for watched changes.<T,
U> Watcher <U> fileWatcher
(String projectName, String repositoryName, Query<T> query, Function<? super T, ? extends U> function) <T,
U> Watcher <U> fileWatcher
(String projectName, String repositoryName, Query<T> query, Function<? super T, ? extends U> function, Executor executor) Returns a newCentralDogmaRepository
that is used to send a request to the specifiedprojectName
andrepositoryName
.final CompletableFuture
<Change<?>> Returns the diff of a file between twoRevision
s.final CompletableFuture
<Entry<?>> Retrieves the file at the specified revision and path.final CompletableFuture
<List<Commit>> getHistory
(String projectName, String repositoryName, Revision from, Revision to) Retrieves the history of the repository between twoRevision
s.final CompletableFuture
<List<Change<?>>> getPreviewDiffs
(String projectName, String repositoryName, Revision baseRevision, Change<?>... changes) Retrieves the preview diffs, which are hypothetical diffs generated if the specifiedChange
s were successfully pushed to the specified repository.protected final CompletableFuture
<Revision> maybeNormalizeRevision
(String projectName, String repositoryName, Revision revision) Normalizes the specifiedRevision
only if it is a relative revision.final CompletableFuture
<MergedEntry<?>> mergeFiles
(String projectName, String repositoryName, Revision revision, MergeSource... mergeSources) Retrieves the merged entry of the specifiedMergeSource
s at the specified revision.final CompletableFuture
<MergedEntry<?>> mergeFiles
(String projectName, String repositoryName, Revision revision, Iterable<MergeSource> mergeSources) Retrieves the merged entry of the specifiedMergeSource
s at the specified revision.final CompletableFuture
<PushResult> push
(String projectName, String repositoryName, Revision baseRevision, Author author, String summary, Change<?>... changes) Pushes the specifiedChange
s to the repository.final CompletableFuture
<PushResult> push
(String projectName, String repositoryName, Revision baseRevision, Author author, String summary, Iterable<? extends Change<?>> changes) Pushes the specifiedChange
s to the repository.final CompletableFuture
<PushResult> push
(String projectName, String repositoryName, Revision baseRevision, Author author, String summary, String detail, Markup markup, Change<?>... changes) Pushes the specifiedChange
s to the repository.final CompletableFuture
<PushResult> push
(String projectName, String repositoryName, Revision baseRevision, String summary, Change<?>... changes) Pushes the specifiedChange
s to the repository.final CompletableFuture
<PushResult> push
(String projectName, String repositoryName, Revision baseRevision, String summary, Iterable<? extends Change<?>> changes) Pushes the specifiedChange
s to the repository.final CompletableFuture
<PushResult> push
(String projectName, String repositoryName, Revision baseRevision, String summary, String detail, Markup markup, Change<?>... changes) Pushes the specifiedChange
s to the repository.<T> Watcher
<T> repositoryWatcher
(String projectName, String repositoryName, String pathPattern, Function<Revision, ? extends T> function) Returns aWatcher
which notifies its listeners when the specified repository has a new commit that contains the changes for the files matched by the givenpathPattern
. e.g:<T> Watcher
<T> repositoryWatcher
(String projectName, String repositoryName, String pathPattern, Function<Revision, ? extends T> function, Executor executor) Returns aWatcher
which notifies its listeners when the specified repository has a new commit that contains the changes for the files matched by the givenpathPattern
. e.g:Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.linecorp.centraldogma.client.CentralDogma
close, createProject, createRepository, fileWatcher, getDiff, getDiff, getDiffs, getFile, getFiles, getFiles, getHistory, getHistory, getHistory, getPreviewDiffs, listFiles, listFiles, listProjects, listRemovedProjects, listRemovedRepositories, listRepositories, mergeFiles, normalizeRevision, purgeProject, purgeRepository, push, push, removeProject, removeRepository, repositoryWatcher, unremoveProject, unremoveRepository, watchFile, watchFile, watchFile, watchRepository, watchRepository, watchRepository, whenEndpointReady
-
Constructor Details
-
AbstractCentralDogma
Creates a new instance.- Parameters:
blockingTaskExecutor
- theScheduledExecutorService
which will be used for scheduling the tasks related with automatic retries and invoking the callbacks for watched changes.
-
-
Method Details
-
executor
Returns theScheduledExecutorService
which is used for scheduling the tasks related with automatic retries and invoking the callbacks for watched changes. -
forRepo
Description copied from interface:CentralDogma
Returns a newCentralDogmaRepository
that is used to send a request to the specifiedprojectName
andrepositoryName
.- Specified by:
forRepo
in interfaceCentralDogma
-
getFile
public final CompletableFuture<Entry<?>> getFile(String projectName, String repositoryName, Revision revision, String path) Description copied from interface:CentralDogma
Retrieves the file at the specified revision and path. This method is a shortcut ofgetFile(projectName, repositoryName, revision, Query.identity(path)
. Consider usingCentralDogma.getFile(String, String, Revision, Query)
withQuery.ofText(String)
orQuery.ofJson(String)
if you already know the file type.- Specified by:
getFile
in interfaceCentralDogma
- Returns:
- the
Entry
at the givenpath
-
mergeFiles
public final CompletableFuture<MergedEntry<?>> mergeFiles(String projectName, String repositoryName, Revision revision, MergeSource... mergeSources) Description copied from interface:CentralDogma
Retrieves the merged entry of the specifiedMergeSource
s at the specified revision. Only JSON entry merge is currently supported. The JSON files are merged sequentially as specified in themergeSources
.Note that only
ObjectNode
is recursively merged traversing the children. Other node types are simply replaced.- Specified by:
mergeFiles
in interfaceCentralDogma
- Returns:
- the
MergedEntry
which contains the result of the merge
-
mergeFiles
public final CompletableFuture<MergedEntry<?>> mergeFiles(String projectName, String repositoryName, Revision revision, Iterable<MergeSource> mergeSources) Description copied from interface:CentralDogma
Retrieves the merged entry of the specifiedMergeSource
s at the specified revision. Only JSON entry merge is currently supported. The JSON files are merged sequentially as specified in themergeSources
.Note that only
ObjectNode
is recursively merged traversing the children. Other node types are simply replaced.- Specified by:
mergeFiles
in interfaceCentralDogma
- Returns:
- the
MergedEntry
which contains the result of the merge
-
getHistory
public final CompletableFuture<List<Commit>> getHistory(String projectName, String repositoryName, Revision from, Revision to) Description copied from interface:CentralDogma
Retrieves the history of the repository between twoRevision
s. This method is a shortcut ofgetHistory(projectName, repositoryName, from, to, "/**")
. Note that this method does not retrieve the diffs but only metadata about the changes. UseCentralDogma.getDiff(String, String, Revision, Revision, Query)
orCentralDogma.getDiff(String, String, Revision, Revision, PathPattern)
to retrieve the diffs.- Specified by:
getHistory
in interfaceCentralDogma
- Returns:
- a
List
that contains theCommit
s of the specified repository
-
getDiff
public final CompletableFuture<Change<?>> getDiff(String projectName, String repositoryName, Revision from, Revision to, String path) Description copied from interface:CentralDogma
Returns the diff of a file between twoRevision
s. This method is a shortcut ofgetDiff(projectName, repositoryName, from, to, Query.identity(path))
. Consider usingCentralDogma.getDiff(String, String, Revision, Revision, Query)
withQuery.ofText(String)
orQuery.ofJson(String)
if you already know the file type.- Specified by:
getDiff
in interfaceCentralDogma
- Returns:
- the
Change
that contains the diff of the givenpath
between the specified two revisions
-
getPreviewDiffs
public final CompletableFuture<List<Change<?>>> getPreviewDiffs(String projectName, String repositoryName, Revision baseRevision, Change<?>... changes) Description copied from interface:CentralDogma
Retrieves the preview diffs, which are hypothetical diffs generated if the specifiedChange
s were successfully pushed to the specified repository. This operation is useful for pre-checking if the specifiedChange
s will be applied as expected without any conflicts.- Specified by:
getPreviewDiffs
in interfaceCentralDogma
- Returns:
- the diffs which would be committed if the specified
Change
s were pushed successfully
-
push
public final CompletableFuture<PushResult> push(String projectName, String repositoryName, Revision baseRevision, String summary, Change<?>... changes) Description copied from interface:CentralDogma
Pushes the specifiedChange
s to the repository.- Specified by:
push
in interfaceCentralDogma
- Returns:
- the
PushResult
which tells theRevision
and timestamp of the newCommit
-
push
public final CompletableFuture<PushResult> push(String projectName, String repositoryName, Revision baseRevision, String summary, Iterable<? extends Change<?>> changes) Description copied from interface:CentralDogma
Pushes the specifiedChange
s to the repository.- Specified by:
push
in interfaceCentralDogma
- Returns:
- the
PushResult
which tells theRevision
and timestamp of the newCommit
-
push
public final CompletableFuture<PushResult> push(String projectName, String repositoryName, Revision baseRevision, String summary, String detail, Markup markup, Change<?>... changes) Description copied from interface:CentralDogma
Pushes the specifiedChange
s to the repository.- Specified by:
push
in interfaceCentralDogma
- Returns:
- the
PushResult
which tells theRevision
and timestamp of the newCommit
-
push
public final CompletableFuture<PushResult> push(String projectName, String repositoryName, Revision baseRevision, Author author, String summary, Change<?>... changes) Description copied from interface:CentralDogma
Pushes the specifiedChange
s to the repository.- Specified by:
push
in interfaceCentralDogma
- Returns:
- the
PushResult
which tells theRevision
and timestamp of the newCommit
-
push
public final CompletableFuture<PushResult> push(String projectName, String repositoryName, Revision baseRevision, Author author, String summary, Iterable<? extends Change<?>> changes) Description copied from interface:CentralDogma
Pushes the specifiedChange
s to the repository.- Specified by:
push
in interfaceCentralDogma
- Returns:
- the
PushResult
which tells theRevision
and timestamp of the newCommit
-
push
public final CompletableFuture<PushResult> push(String projectName, String repositoryName, Revision baseRevision, Author author, String summary, String detail, Markup markup, Change<?>... changes) Description copied from interface:CentralDogma
Pushes the specifiedChange
s to the repository.- Specified by:
push
in interfaceCentralDogma
- Returns:
- the
PushResult
which tells theRevision
and timestamp of the newCommit
-
fileWatcher
public <T,U> Watcher<U> fileWatcher(String projectName, String repositoryName, Query<T> query, Function<? super T, ? extends U> function) Description copied from interface:CentralDogma
Returns aWatcher
which notifies its listeners after applying the specifiedFunction
when the result of the givenQuery
becomes available or changes. e.g:Watcher<MyType> watcher = client.fileWatcher( "foo", "bar", Query.ofJson("/baz.json"), content -> new ObjectMapper().treeToValue(content, MyType.class)); watcher.watch((revision, myValue) -> { assert myValue instanceof MyType; ... });
Note that
Function
by default is executed by a blocking task executor so that you can safely call a blocking operation.- Specified by:
fileWatcher
in interfaceCentralDogma
-
fileWatcher
public <T,U> Watcher<U> fileWatcher(String projectName, String repositoryName, Query<T> query, Function<? super T, ? extends U> function, Executor executor) Description copied from interface:CentralDogma
Returns aWatcher
which notifies its listeners after applying the specifiedFunction
when the result of the givenQuery
becomes available or changes. e.g:Watcher<MyType> watcher = client.fileWatcher( "foo", "bar", Query.ofJson("/baz.json"), content -> new ObjectMapper().treeToValue(content, MyType.class), executor); watcher.watch((revision, myValue) -> { assert myValue instanceof MyType; ... });
- Specified by:
fileWatcher
in interfaceCentralDogma
-
repositoryWatcher
public <T> Watcher<T> repositoryWatcher(String projectName, String repositoryName, String pathPattern, Function<Revision, ? extends T> function) Description copied from interface:CentralDogma
Returns aWatcher
which notifies its listeners when the specified repository has a new commit that contains the changes for the files matched by the givenpathPattern
. e.g:Watcher<Map<String, Entry<?>> watcher = client.repositoryWatcher( "foo", "bar", "/*.json", revision -> client.getFiles("foo", "bar", revision, "/*.json").join()); watcher.watch((revision, contents) -> { ... });
Function
by default is executed by a blocking task executor so that you can safely call a blocking operation.Note that you may get
RevisionNotFoundException
during thegetFiles()
call and may have to retry in the above example due to a known issue.- Specified by:
repositoryWatcher
in interfaceCentralDogma
-
repositoryWatcher
public <T> Watcher<T> repositoryWatcher(String projectName, String repositoryName, String pathPattern, Function<Revision, ? extends T> function, Executor executor) Description copied from interface:CentralDogma
Returns aWatcher
which notifies its listeners when the specified repository has a new commit that contains the changes for the files matched by the givenpathPattern
. e.g:
Note that you may getWatcher<Map<String, Entry<?>> watcher = client.repositoryWatcher( "foo", "bar", "/*.json", revision -> client.getFiles("foo", "bar", revision, "/*.json").join(), executor); watcher.watch((revision, contents) -> { ... });
RevisionNotFoundException
during thegetFiles()
call and may have to retry in the above example due to a known issue.- Specified by:
repositoryWatcher
in interfaceCentralDogma
- Parameters:
executor
- theExecutor
that executes theFunction
-
maybeNormalizeRevision
protected final CompletableFuture<Revision> maybeNormalizeRevision(String projectName, String repositoryName, Revision revision) Normalizes the specifiedRevision
only if it is a relative revision.- Returns:
- the absolute
Revision
-