use of org.glassfish.api.admin.progress.ProgressStatusEvent in project Payara by payara.
the class ProgressStatusPrinter method onAdminCommandEvent.
@Override
public synchronized void onAdminCommandEvent(String name, GfSseInboundEvent event) {
try {
if (CommandProgress.EVENT_PROGRESSSTATUS_STATE.equals(name)) {
ProgressStatusDTO dto = event.getData(ProgressStatusDTO.class, CONTENT_TYPE);
client.mirror(dto);
commandProgress = (CommandProgress) client.getProgressStatus();
if (StringUtils.ok(commandProgress.getName()) && !StringUtils.ok(commandProgress.getLastMessage())) {
commandProgress.progress(strings.getString("progressstatus.message.starting", "Starting"));
}
printCommandProgress();
} else if (CommandProgress.EVENT_PROGRESSSTATUS_CHANGE.equals(name)) {
if (commandProgress == null) {
logger.log(Level.WARNING, strings.get("progressstatus.event.applyerror", "Inapplicable progress status event"));
return;
}
ProgressStatusEvent pse = event.getData(ProgressStatusEvent.class, CONTENT_TYPE);
client.mirror(pse);
printCommandProgress();
} else if (AdminCommandEventBroker.EventBrokerUtils.USER_MESSAGE_NAME.equals(name)) {
String msg = event.getData();
printUserMessage(msg);
}
} catch (IOException ex) {
logger.log(Level.SEVERE, strings.get("progressstatus.event.parseerror", "Can not parse progress status event"), ex);
}
}
use of org.glassfish.api.admin.progress.ProgressStatusEvent in project Payara by payara.
the class ProgressStatusEventTest method testEventSet.
@Test
public void testEventSet() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
writer.writeTo(EVENT_SET, null, null, null, MediaType.APPLICATION_JSON_TYPE, null, baos);
baos.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ProgressStatusEvent event = reader.readFrom(bais, MediaType.APPLICATION_JSON);
assertEquals(event, EVENT_SET);
}
use of org.glassfish.api.admin.progress.ProgressStatusEvent in project Payara by payara.
the class CommandRunnerProgressHelper method connectWithClientProgressStatus.
private void connectWithClientProgressStatus(Job commandInstance, ProgressStatus clientProgressStatus) {
if (clientProgressStatus == null) {
return;
}
final ProgressStatusClient psc = new ProgressStatusClient(clientProgressStatus);
commandInstance.getEventBroker().registerListener(CommandProgress.EVENT_PROGRESSSTATUS_STATE, new AdminCommandEventBroker.AdminCommandListener<ProgressStatusBase>() {
@Override
public void onAdminCommandEvent(String name, ProgressStatusBase event) {
psc.mirror(event);
}
});
commandInstance.getEventBroker().registerListener(CommandProgress.EVENT_PROGRESSSTATUS_CHANGE, new AdminCommandEventBroker.AdminCommandListener<ProgressStatusEvent>() {
@Override
public void onAdminCommandEvent(String name, ProgressStatusEvent event) {
psc.mirror(event);
}
});
}
use of org.glassfish.api.admin.progress.ProgressStatusEvent in project Payara by payara.
the class ProgressStatusEventJsonProprietaryReader method readProgressStatusEvent.
public static ProgressStatusEvent readProgressStatusEvent(JsonParser jp) throws IOException {
String id = null;
JsonToken token = null;
ProgressStatusEvent result = null;
while ((token = jp.nextToken()) != JsonToken.END_OBJECT) {
if (token == JsonToken.START_OBJECT) {
String nm = jp.getCurrentName();
if ("set".equals(nm)) {
result = new ProgressStatusEventSet(id);
readToPSEventSet((ProgressStatusEventSet) result, jp);
} else if ("progres".equals(nm)) {
result = new ProgressStatusEventProgress(id);
readToPSEventProgress((ProgressStatusEventProgress) result, jp);
} else if ("complete".equals(nm)) {
result = new ProgressStatusEventComplete(id);
readToPSEventComplete((ProgressStatusEventComplete) result, jp);
} else if ("create-child".equals(nm)) {
result = new ProgressStatusEventCreateChild(id);
readToPSEventCreateChild((ProgressStatusEventCreateChild) result, jp);
}
} else {
String fieldname = jp.getCurrentName();
if ("id".equals(fieldname)) {
// move to value
jp.nextToken();
id = jp.getText();
}
}
}
return result;
}
use of org.glassfish.api.admin.progress.ProgressStatusEvent in project Payara by payara.
the class ProgressStatusEventTest method testEventComplete.
@Test
public void testEventComplete() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
writer.writeTo(EVENT_COMPLETE, null, null, null, MediaType.APPLICATION_JSON_TYPE, null, baos);
baos.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ProgressStatusEvent event = reader.readFrom(bais, MediaType.APPLICATION_JSON);
assertEquals(event, EVENT_COMPLETE);
}
Aggregations