|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectbr.com.objectos.concurrent.StageComputationTask<V>
br.com.objectos.git.StageGitCommand<V>
V - the type of this command's resultpublic abstract class StageGitCommand<V>
Base class for creating high-level stage-based (porcelain) Git commands. This class is useful for chaining many low-level (plumbing) asynchronous tasks and other high-level asynchronous commands. It does so offering a (mostly) imperative programming style.
This class is an instance of GitCommand and is intended to be
executed by a GitService instance.
This class extends StageComputationTask and, therefore, inherits all
of its drawbacks. Please understand all of the drawbacks by reading the
superclass' javadocs before using this class.
CopyTreeCommand:
final class CopyTreeCommand extends StageGitCommand<ObjectId> {
private final MutableSet<ObjectId> objectsToCopy = MutableSet.create();
private final Repository source;
private final ObjectId sourceId;
private final Repository target;
CopyTreeCommand(Repository source, ObjectId tree, Repository destination) {
this.source = Checks.checkNotNull(source, "source == null");
this.sourceId = Checks.checkNotNull(tree, "tree == null");
this.target = Checks.checkNotNull(destination, "destination == null");
}
protected final void executeStage(int stage) throws Exception {
switch (stage) {
case 0:
readTree(source, sourceId);
case 1:
if (isComputing()) {
return;
}
final ImmutableList<Tree> trees;
trees = getAll();
for (Tree tree : trees) {
visitTree(tree);
}
if (hasComputations()) {
goTo(1);
return;
}
final ImmutableSet<ObjectId> set;
set = objectsToCopy.toImmutableSet();
objectsToCopy.clear();
copyObjects(source, set, target);
case 2:
if (isComputing()) {
return;
}
setResult(sourceId);
return;
default:
throw new AssertionError("Unexpected step=" + stage);
}
}
private void visitTree(Tree tree) {
ObjectId treeId;
treeId = tree.getObjectId();
objectsToCopy.add(treeId);
ImmutableList<Entry> entries;
entries = tree.getEntries();
for (Entry entry : entries) {
ObjectId entryId;
entryId = entry.getObjectId();
if (entry.isBlob()) {
objectsToCopy.add(entryId);
} else {
readTree(source, entryId);
}
}
}
}
| Constructor Summary | |
|---|---|
protected |
StageGitCommand()
Sole constructor. |
| Method Summary | |
|---|---|
protected void |
copyObjects(Repository source,
ImmutableSet<ObjectId> objects,
Repository destination)
Adds a single asynchronous computation by invoking GitCommandExecutor.copyObjects(Repository, ImmutableSet, Repository). |
protected void |
copyTree(Repository source,
ObjectId tree,
Repository destination)
Adds a single asynchronous computation that copies from the source repository the specified tree object to the destination repository (as loose objects). |
protected void |
executeFinally()
|
void |
formatToString(StringBuilder toString,
int level)
|
protected void |
materializeEntry(Repository repository,
Entry entry,
Directory target)
Adds a single asynchronous computation by invoking GitCommandExecutor.materializeEntry(Repository, Entry, Directory). |
protected void |
openRepository(Directory directory)
Adds a single asynchronous computation by invoking GitCommandExecutor.openRepository(Directory). |
protected void |
readBlob(Repository repository,
ObjectId id)
Adds a single asynchronous computation by invoking GitCommandExecutor.readBlob(Repository, ObjectId). |
protected void |
readCommit(Repository repository,
ObjectId id)
Adds a single asynchronous computation by invoking GitCommandExecutor.readCommit(Repository, ObjectId). |
protected void |
readTree(Repository repository,
ObjectId id)
Adds a single asynchronous computation by invoking GitCommandExecutor.readTree(Repository, ObjectId). |
protected void |
resolve(Repository repository,
RefName ref)
Adds a single asynchronous computation by invoking GitCommandExecutor.resolve(Repository, RefName). |
protected void |
submit(GitCommand<?> command)
Adds a single asynchronous computation by invoking GitExecutor.submit(GitCommand). |
Computation<V> |
submitAsync(GitCommandExecutor executor,
CpuWorker cpuWorker)
Returns a possibly new and possibly asynchronous git computation representing the pending result of this command. |
String |
toString()
|
protected void |
updateRef(Repository repository,
RefName ref,
ObjectId newValue)
Adds a single asynchronous computation by invoking GitCommandExecutor.updateRef(Repository, RefName, ObjectId). |
protected void |
writeCommit(Repository repository,
MutableCommit commit)
Adds a single asynchronous computation by invoking GitCommandExecutor.writeCommit(Repository, MutableCommit). |
protected void |
writeTree(Repository repository,
MutableTree tree)
Adds a single asynchronous computation by invoking GitCommandExecutor.writeTree(GitCommand, Repository, MutableTree). |
| Methods inherited from class br.com.objectos.concurrent.StageComputationTask |
|---|
addComputation, executeOne, executeStage, get, getAll, getResult, goTo, hasComputations, isActive, isComputing, reset, setResult |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface br.com.objectos.concurrent.Computation |
|---|
getResult, isActive |
| Constructor Detail |
|---|
protected StageGitCommand()
| Method Detail |
|---|
public void formatToString(StringBuilder toString,
int level)
formatToString in interface br.com.objectos.core.object.ToStringObject
public final Computation<V> submitAsync(GitCommandExecutor executor,
CpuWorker cpuWorker)
Please
submitAsync in interface GitCommand<V>executor - the executor providing low-level git taskscpuWorker - the cpu worker to execute the command
public final String toString()
toString in class Object
protected final void copyObjects(Repository source,
ImmutableSet<ObjectId> objects,
Repository destination)
GitCommandExecutor.copyObjects(Repository, ImmutableSet, Repository).
source - the source repository containing the objects. Git objects will be
read from this repository.objects - the ids (hash values) of the objects to be copieddestination - the destination repository. Git objects will (possibly) be written
to this repositoryStageComputationTask.addComputation(br.com.objectos.concurrent.Computation),
openRepository(Directory)
protected final void copyTree(Repository source,
ObjectId tree,
Repository destination)
The computation, once completed, returns the hash value of the tree object created in the destination repository.
The computation will fail if the source repository does not contain the specified tree object or if an I/O error occurs.
source - the repository from where to read the tree objecttree - the hash value of the tree object to copydestination - the repository where the tree will be copied toStageComputationTask.addComputation(br.com.objectos.concurrent.Computation),
openRepository(Directory)protected void executeFinally()
executeFinally in class StageComputationTask<V>
protected final void materializeEntry(Repository repository,
Entry entry,
Directory target)
GitCommandExecutor.materializeEntry(Repository, Entry, Directory).
repository - repository to read blob contents from (if necessary)entry - the entry to be materializedtarget - the target directoryStageComputationTask.addComputation(br.com.objectos.concurrent.Computation),
openRepository(Directory),
readTree(Repository, ObjectId)protected final void openRepository(Directory directory)
GitCommandExecutor.openRepository(Directory).
directory - the directory where a Git repository is locatedStageComputationTask.addComputation(br.com.objectos.concurrent.Computation)
protected final void readBlob(Repository repository,
ObjectId id)
GitCommandExecutor.readBlob(Repository, ObjectId).
repository - the git repository from which to read the commitid - the unique hash value of the blob to readStageComputationTask.addComputation(br.com.objectos.concurrent.Computation),
openRepository(Directory)
protected final void readCommit(Repository repository,
ObjectId id)
GitCommandExecutor.readCommit(Repository, ObjectId).
repository - the git repository from which to read the commitid - the unique hash value of the commit to readStageComputationTask.addComputation(br.com.objectos.concurrent.Computation),
openRepository(Directory)
protected final void readTree(Repository repository,
ObjectId id)
GitCommandExecutor.readTree(Repository, ObjectId).
repository - the git repository from which to read the treeid - the unique hash value of the tree to readStageComputationTask.addComputation(br.com.objectos.concurrent.Computation),
openRepository(Directory)
protected final void resolve(Repository repository,
RefName ref)
GitCommandExecutor.resolve(Repository, RefName).
repository - the repository for which the reference will be resolvedref - the Git reference to be resolvedStageComputationTask.addComputation(br.com.objectos.concurrent.Computation),
openRepository(Directory)protected final void submit(GitCommand<?> command)
GitExecutor.submit(GitCommand).
command - the command to be submittedStageComputationTask.addComputation(br.com.objectos.concurrent.Computation)
protected final void updateRef(Repository repository,
RefName ref,
ObjectId newValue)
GitCommandExecutor.updateRef(Repository, RefName, ObjectId).
repository - the repository for which the reference will be updatedref - the Git reference to be updatednewValue - the new value for the referenceStageComputationTask.addComputation(br.com.objectos.concurrent.Computation),
openRepository(Directory)
protected final void writeCommit(Repository repository,
MutableCommit commit)
GitCommandExecutor.writeCommit(Repository, MutableCommit).
repository - the git repository where the commit is to be writtencommit - a MutableCommit instance containing all the information to
be recorded as a commit objectStageComputationTask.addComputation(br.com.objectos.concurrent.Computation),
openRepository(Directory)
protected final void writeTree(Repository repository,
MutableTree tree)
GitCommandExecutor.writeTree(GitCommand, Repository, MutableTree).
repository - the git repository where the tree is to be writtentree - a MutableTree to be writtenStageComputationTask.addComputation(br.com.objectos.concurrent.Computation),
openRepository(Directory)
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||