use of org.glassfish.api.admin.ProgressStatus in project Payara by payara.
the class ProgressPayloadCommand method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
ProgressStatus ps = context.getProgressStatus();
for (int i = 0; i < 4; i++) {
doSomeLogic();
ps.progress(1);
}
// Prepare payload
Outbound out = context.getOutboundPayload();
StringBuilder msg = new StringBuilder();
if (down == null || down.isEmpty()) {
msg.append("No file requested.");
} else {
msg.append("You are requesting for ").append(down).append('.').append(StringUtils.EOL);
File f = new File(down);
if (!f.exists()) {
msg.append("But it does not exist!");
} else {
try {
String canonicalPath = f.getCanonicalPath();
canonicalPath = canonicalPath.replace('\\', '/');
if (canonicalPath.charAt(1) == ':') {
canonicalPath = canonicalPath.substring(2);
}
if (f.isDirectory()) {
msg.append("It is directory - recursive download");
out.attachFile("application/octet-stream", URI.create(canonicalPath), f.getName(), f, true);
} else {
out.attachFile("application/octet-stream", URI.create(canonicalPath), f.getName(), f);
}
} catch (IOException ex) {
report.failure(logger, "Can not append " + f.getAbsolutePath());
}
}
}
if (report.getActionExitCode() == ActionReport.ExitCode.SUCCESS) {
report.setMessage(msg.toString());
}
// Return
ps.progress(1);
ps.complete("Finished");
}
use of org.glassfish.api.admin.ProgressStatus in project Payara by payara.
the class ProgressCustomCommand method execute.
@Override
public void execute(AdminCommandContext context) {
ProgressStatus ps = context.getProgressStatus();
parsedIntervals = new ArrayList<Interval>(intervals != null ? intervals.length : 0);
ActionReport report = context.getActionReport();
for (String interval : intervals) {
parsedIntervals.add(new Interval(interval));
}
// Count
if (parsedIntervals.isEmpty()) {
report.setMessage("Done command process without waiting interval.");
return;
}
ps.setTotalStepCount(getStepCount());
int blockId = 0;
for (Interval interval : parsedIntervals) {
blockId++;
if (interval.isValid()) {
int multip = interval.getMultiplicator();
if (interval.getMaxSec() == 0) {
ps.progress(multip, "Finished block without sleeping: [" + blockId + "] " + interval);
} else {
for (int i = 0; i < multip; i++) {
if (i == 0) {
ps.progress(0, "Starting block[" + blockId + "] " + interval, interval.isSpin());
}
try {
Thread.sleep(interval.getMilis());
} catch (Exception ex) {
}
if (i == (multip - 1)) {
ps.progress(1, "Finished block [" + blockId + "] " + interval);
} else {
ps.progress(1, "Block [" + blockId + "] " + interval + ", step: " + (i + 1));
}
}
}
} else {
ps.progress(1, "Finished unparsable block [" + blockId + "] " + interval);
}
}
report.setMessage("Finished command process in " + parsedIntervals.size() + " block(s).");
}
use of org.glassfish.api.admin.ProgressStatus in project Payara by payara.
the class ProgressExecOtherCommand method execute.
@Override
public void execute(AdminCommandContext context) {
ProgressStatus ps = context.getProgressStatus();
// Do some before logic
ps.progress("Preparing");
for (int i = 0; i < 10; i++) {
doSomeLogic();
ps.progress(1);
}
// Execute other command
final CommandRunner.CommandInvocation commandInvocation = commandRunner.getCommandInvocation("progress-simple", context.getActionReport().addSubActionsReport(), context.getSubject());
commandInvocation.progressStatusChild(// Number 20 is little bit tricky. Please see javadoc of ProgressStatus
ps.createChild("subcommand", 20)).execute();
// Do some after logic
ps.progress("Finishing outer command");
for (int i = 0; i < 10; i++) {
doSomeLogic();
ps.progress(1);
}
ps.complete("Finished outer command");
}
use of org.glassfish.api.admin.ProgressStatus in project Payara by payara.
the class ProgressWithSupplementCommand method execute.
@Override
public void execute(AdminCommandContext context) {
ProgressStatus ps = context.getProgressStatus();
ps.setTotalStepCount(4);
ps.progress("Parsing");
doSomeLogic();
ps.progress(1, "Working on main part");
for (int i = 0; i < 3; i++) {
doSomeLogic();
ps.progress(1);
}
ps.complete("Finished");
}
use of org.glassfish.api.admin.ProgressStatus in project Payara by payara.
the class SupplementBefore method execute.
@Override
public void execute(AdminCommandContext context) {
ProgressStatus ps = context.getProgressStatus();
ps.progress("2 seconds supplemental command");
for (int i = 0; i < 4; i++) {
try {
Thread.sleep(500L);
} catch (InterruptedException ex) {
}
ps.progress(1);
}
context.getActionReport().setActionExitCode(ActionReport.ExitCode.SUCCESS);
ps.complete();
}
Aggregations