public interface ProgressStatus extends Serializable
AdminCommand
implementations.
Progress is represented by two attributes:
steps
totalStepCount
(if defined).
message
Because AdminCommand
can execute other AdminCommand
and
command execution on a cluster triggers the replication process the
ProgressStatus
can have child ProgressStatus objects. Any
ProgressStatus
can be used independently without knowledge
of the parent's ProgressStatus
.
Any child ProgressStatus objects can be named by its creator. The name
is mainly used in connection with the message
attribute to define its
context.
Usage:
First inject a ProgressStatus
into an AdminCommand
implementation.
Optionally pass the total step count or name to provide context of the progress (if the name is not provided it defaults to the command's name).@Progress private ProgressStatus ps;
@Progress(totalStepCount=10, name="deploy")
Total step count can also be set via this method. This overrides the count if it was previously set (possibly via the @Progress annotation).
setTotalStepCount(int totalStepCount);
The primary use of tatalStepCount
is as the denominator for computing
the completion percentage as reported in the commands progress report:
percent complete = current step count / total step count * 100
The total step count can be changed after being set but may result in the completion percentage jumping (forward or backwards).
If the total step count is not set then a completion percentage will not be available.
The progress()
methods are used to move progress forward (or backwards).
The current step count will be incremented by the number of
steps indicated.
progress(String message, int steps); progress(String message); progress(int steps);
The version of progress that only takes a message will cause a new message to be displayed but will not change the completion percentage.
It is possible to set the current step count to a specific value, for example when an error occurs and the command must repeat a set of operations.
setCurrentStepCount(int stepCount);
This will likely result in the overall completion percentage jumping when the next progress() message is generated.
Any ProgressStatus can be completed using methods
complete(String message); complete();
Indicates the command is complete and no further progress status will
be delivered. Subsequent invocations of progress() will be ignored. This
method also invokes complete()
on all child ProgressStatus objects.
It is also possible to create a child ProgressStatus with independent logic
used to determine progress. The parent ProgressStatus
is not visible to the
child ProgressStatus object and the child can progress somewhat independently
from the parent's progress. But generally the parent should not complete
its progress before the children have completed.
createChild(String name, int allocatedSteps); createChild(int allocatedSteps);
The name allocated to the child is used in the progress status output to
define context of the message
.
. 80%: [parent name:[child name:[...]] message
The allocatedSteps parameter represents the subset of steps from the parent's allocation that will be given to the child to complete.
org.glassfish.api.Progress
Modifier and Type | Method and Description |
---|---|
void |
complete()
Indicates the command is complete and no further progress status will
be delivered.
|
void |
complete(String message)
Indicates the command is complete and no further progress status will
be delivered.
|
ProgressStatus |
createChild(int allocatedSteps)
Create a child ProgressStatus object which can be used independently by
a command's subroutine or sub-commands.
|
ProgressStatus |
createChild(String name,
int allocatedSteps)
Create a child ProgressStatus object which can be used independently by
a command's subroutine or sub-commands.
|
String |
getId()
Id is unique for any ProgressStatuses.
|
int |
getRemainingStepCount()
Remaining count of steps to complete this progress.
totalStepCount - currentStepCount - allocated step count |
int |
getTotalStepCount()
Total step count.
|
boolean |
isComplete()
Returns true if the
ProgressStatus has been marked as complete
via the complete() method. |
void |
progress(int steps)
Indicate progress occurred.
|
void |
progress(int steps,
String message)
Indicates progress occurred.
|
void |
progress(int steps,
String message,
boolean spinner)
Indicates progress occurred.
|
void |
progress(String message)
Indicate progress occurred.
|
void |
setCurrentStepCount(int stepCount)
This allows the current step count to be changed to a specific value,
for example when an error occurs and the command must repeat a set
of operations.
This will likely result in the overall completion percentage jumping when the next progress() message is generated. |
void |
setTotalStepCount(int totalStepCount)
Number of steps necessary to complete the operation.
|
void setTotalStepCount(int totalStepCount)
org.glassfish.api.Progress
annotation.
The total step count is used as the denominator for computing the
completion percentage as reported in the command's progress output:
percent complete = current step count / total step count * 100
Note the above formula is a bit more complex when child ProgressStatus
objects are in use.
The total step count can be changed after being set but may result in the completion percentage jumping (forward or backwards).
If the total step count is not set then a completion percentage will not be available.
It can be also set during injection using totalStepCount
parameter in org.glassfish.api.Progress
annotation.
totalStepCount
- non-negative value defines denominator for
the percentage computationint getTotalStepCount()
int getRemainingStepCount()
totalStepCount - currentStepCount - allocated step count
void progress(int steps, String message, boolean spinner)
steps
- the number of steps taken. Negative steps will reduce
the completion percentage. Never to non-negative value.message
- to be displayed by the client.spinner
- true
starts showing the spinner. It will be
active until next progress.void progress(int steps, String message)
steps
- the number of steps taken. Negative steps will reduce
the completion percentage. Never to non-negative value.message
- to be displayed by the client.void progress(int steps)
steps
- the number of steps taken. Negative steps will reduce
the completion percentage. Never to non-negative value.void progress(String message)
message
- to be displayed by the client.void setCurrentStepCount(int stepCount)
stepCount
- new stepCount
value. Negative is normalized to 0
greater than the total step count is normalized to the total step
countvoid complete(String message)
complete()
on all child ProgressStatus objects.
If this method is not invoked prior to the command completing the CLI
framework will implicitly invoke complete()
for the ProgressStatus
associated with the command.message
- to be displayed to the user.void complete()
complete()
on all child ProgressStatus objects.
If this method is not invoked prior to the command completing the CLI
framework will implicitly invoke complete()
for the ProgressStatus
associated with the command.boolean isComplete()
ProgressStatus
has been marked as complete
via the complete()
method.ProgressStatus createChild(String name, int allocatedSteps)
80%: [parent name:[child name: message]]
The allocatedSteps parameter represents the subset of steps from the parent's allocation that will be given to the child to complete. When the child has completed all its steps it will have progressed the parent's allocated steps.
Example: Suppose the parent sets its TotalStepCount to 100 and
allocates 25 steps to a child.
The child sets its TotalStepCount to 100. Then for every 4 steps
the child progresses it will move the parent's progress 1 step given
the parent only allocated a total of 25 steps to the child but the child
has a total step count of 100: 100/25 = 4
child steps are
equivalent to 1 parent step.
Note: care must be taken when allocating steps to children. The number
of steps allocated to all children of the parent must not exceed the
parent's total step count. Doing so may results in erroneous
completion percentages.
name
- to be associated with the child ProgressStatus. This name
appears in the progress sent to the client. If the name is an
empty string a name for this child will not be included in the
message.allocatedSteps
- the number of progress steps the parent is
allocating to the child.ProgressStatus createChild(int allocatedSteps)
80%: [parent name: message]
allocatedSteps
- the number of progress steps the parent is
allocating to the child.String getId()
Copyright © 2018. All rights reserved.