Search in sources :

Example 1 with ProgressStatusEvent

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);
    }
}
Also used : ProgressStatusEvent(org.glassfish.api.admin.progress.ProgressStatusEvent) IOException(java.io.IOException) ProgressStatusDTO(org.glassfish.api.admin.progress.ProgressStatusDTO)

Example 2 with ProgressStatusEvent

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);
}
Also used : ProgressStatusEvent(org.glassfish.api.admin.progress.ProgressStatusEvent) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 3 with ProgressStatusEvent

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);
        }
    });
}
Also used : ProgressStatusEvent(org.glassfish.api.admin.progress.ProgressStatusEvent) ProgressStatusBase(org.glassfish.api.admin.progress.ProgressStatusBase) ProgressStatusClient(com.sun.enterprise.admin.progress.ProgressStatusClient)

Example 4 with ProgressStatusEvent

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;
}
Also used : ProgressStatusEventComplete(org.glassfish.api.admin.progress.ProgressStatusEventComplete) ProgressStatusEventCreateChild(org.glassfish.api.admin.progress.ProgressStatusEventCreateChild) ProgressStatusEvent(org.glassfish.api.admin.progress.ProgressStatusEvent) JsonToken(com.fasterxml.jackson.core.JsonToken) ProgressStatusEventProgress(org.glassfish.api.admin.progress.ProgressStatusEventProgress) ProgressStatusEventSet(org.glassfish.api.admin.progress.ProgressStatusEventSet)

Example 5 with ProgressStatusEvent

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);
}
Also used : ProgressStatusEvent(org.glassfish.api.admin.progress.ProgressStatusEvent) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

ProgressStatusEvent (org.glassfish.api.admin.progress.ProgressStatusEvent)7 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 Test (org.junit.Test)4 JsonToken (com.fasterxml.jackson.core.JsonToken)1 ProgressStatusClient (com.sun.enterprise.admin.progress.ProgressStatusClient)1 IOException (java.io.IOException)1 ProgressStatusBase (org.glassfish.api.admin.progress.ProgressStatusBase)1 ProgressStatusDTO (org.glassfish.api.admin.progress.ProgressStatusDTO)1 ProgressStatusEventComplete (org.glassfish.api.admin.progress.ProgressStatusEventComplete)1 ProgressStatusEventCreateChild (org.glassfish.api.admin.progress.ProgressStatusEventCreateChild)1 ProgressStatusEventProgress (org.glassfish.api.admin.progress.ProgressStatusEventProgress)1 ProgressStatusEventSet (org.glassfish.api.admin.progress.ProgressStatusEventSet)1