Search in sources :

Example 11 with ServiceResponsesList

use of org.kie.server.api.model.ServiceResponsesList in project droolsjbpm-integration by kiegroup.

the class WebSocketKieServerClient method sendCommandToAllSessions.

protected ServiceResponsesList sendCommandToAllSessions(CommandScript script, WebSocketServiceResponse response) {
    logger.debug("About to send command {} to kie server located at {}", script, url);
    List<Session> sessions = manager.getByUrl(url);
    List<ServiceResponse<?>> responses = new ArrayList<>();
    ServiceResponsesList result = new ServiceResponsesList(responses);
    for (Session session : sessions) {
        logger.debug("Web Socket session ({}) is open {}", session.getId(), session.isOpen());
        String content = WebSocketUtils.marshal(script);
        logger.debug("Content to be sent over Web Socket '{}'", content);
        try {
            manager.getHandler(session.getId()).addHandler(response);
            session.getBasicRemote().sendText(content);
            logger.debug("Message successfully sent to kie server");
            responses.add(response);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    return result;
}
Also used : ServiceResponsesList(org.kie.server.api.model.ServiceResponsesList) WebSocketServiceResponse(org.kie.server.controller.websocket.common.handlers.WebSocketServiceResponse) ServiceResponse(org.kie.server.api.model.ServiceResponse) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Session(javax.websocket.Session)

Example 12 with ServiceResponsesList

use of org.kie.server.api.model.ServiceResponsesList in project droolsjbpm-integration by kiegroup.

the class WebSocketKieServerClient method getServerState.

@Override
public ServiceResponse<KieServerStateInfo> getServerState() {
    CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new GetServerStateCommand()));
    ServiceResponse<KieServerStateInfo> response = (ServiceResponse<KieServerStateInfo>) sendCommand(script, new WebSocketServiceResponse(true, (message) -> {
        ServiceResponsesList list = WebSocketUtils.unmarshal(message, ServiceResponsesList.class);
        return list.getResponses().get(0);
    })).getResponses().get(0);
    return response;
}
Also used : ServiceResponsesList(org.kie.server.api.model.ServiceResponsesList) GetServerStateCommand(org.kie.server.api.commands.GetServerStateCommand) WebSocketServiceResponse(org.kie.server.controller.websocket.common.handlers.WebSocketServiceResponse) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) WebSocketServiceResponse(org.kie.server.controller.websocket.common.handlers.WebSocketServiceResponse) CommandScript(org.kie.server.api.commands.CommandScript) KieServerStateInfo(org.kie.server.api.model.KieServerStateInfo)

Example 13 with ServiceResponsesList

use of org.kie.server.api.model.ServiceResponsesList in project droolsjbpm-integration by kiegroup.

the class WebSocketKieServerClient method getReleaseId.

@Override
public ServiceResponse<ReleaseId> getReleaseId(String containerId) {
    CommandScript script = new CommandScript(Collections.singletonList(new GetReleaseIdCommand(containerId)));
    ServiceResponse<ReleaseId> response = (ServiceResponse<ReleaseId>) sendCommand(script, new WebSocketServiceResponse(true, (message) -> {
        ServiceResponsesList list = WebSocketUtils.unmarshal(message, ServiceResponsesList.class);
        return list.getResponses().get(0);
    })).getResponses().get(0);
    return response;
}
Also used : ServiceResponsesList(org.kie.server.api.model.ServiceResponsesList) WebSocketServiceResponse(org.kie.server.controller.websocket.common.handlers.WebSocketServiceResponse) ServiceResponse(org.kie.server.api.model.ServiceResponse) WebSocketServiceResponse(org.kie.server.controller.websocket.common.handlers.WebSocketServiceResponse) CommandScript(org.kie.server.api.commands.CommandScript) ReleaseId(org.kie.server.api.model.ReleaseId) GetReleaseIdCommand(org.kie.server.api.commands.GetReleaseIdCommand)

Example 14 with ServiceResponsesList

use of org.kie.server.api.model.ServiceResponsesList in project droolsjbpm-integration by kiegroup.

the class WebSocketKieServerClient method updateReleaseId.

@Override
public ServiceResponse<ReleaseId> updateReleaseId(String id, ReleaseId releaseId, boolean resetBeforeUpdate) {
    CommandScript script = new CommandScript(Collections.singletonList(new UpdateReleaseIdCommand(id, releaseId, resetBeforeUpdate)));
    ServiceResponse<ReleaseId> response = (ServiceResponse<ReleaseId>) sendCommandToAllSessions(script, new WebSocketServiceResponse(true, (message) -> {
        ServiceResponsesList list = WebSocketUtils.unmarshal(message, ServiceResponsesList.class);
        return list.getResponses().get(0);
    })).getResponses().get(0);
    return response;
}
Also used : UpdateReleaseIdCommand(org.kie.server.api.commands.UpdateReleaseIdCommand) ServiceResponsesList(org.kie.server.api.model.ServiceResponsesList) WebSocketServiceResponse(org.kie.server.controller.websocket.common.handlers.WebSocketServiceResponse) ServiceResponse(org.kie.server.api.model.ServiceResponse) WebSocketServiceResponse(org.kie.server.controller.websocket.common.handlers.WebSocketServiceResponse) CommandScript(org.kie.server.api.commands.CommandScript) ReleaseId(org.kie.server.api.model.ReleaseId)

Example 15 with ServiceResponsesList

use of org.kie.server.api.model.ServiceResponsesList in project droolsjbpm-integration by kiegroup.

the class WebSocketKieServerClient method sendCommand.

protected ServiceResponsesList sendCommand(CommandScript script, WebSocketServiceResponse response) {
    logger.debug("About to send command {} to kie server located at {}", script, url);
    List<Session> sessions = manager.getByUrl(url);
    Session session = sessions.get(0);
    logger.debug("Web Socket session ({}) is open {}", session.getId(), session.isOpen());
    String content = WebSocketUtils.marshal(script);
    logger.debug("Content to be sent over Web Socket '{}'", content);
    try {
        manager.getHandler(session.getId()).addHandler(response);
        session.getBasicRemote().sendText(content);
        logger.debug("Message successfully sent to kie server");
        return new ServiceResponsesList(Arrays.asList(response));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ServiceResponsesList(org.kie.server.api.model.ServiceResponsesList) IOException(java.io.IOException) Session(javax.websocket.Session)

Aggregations

ServiceResponsesList (org.kie.server.api.model.ServiceResponsesList)30 ServiceResponse (org.kie.server.api.model.ServiceResponse)23 KieServerCommand (org.kie.server.api.model.KieServerCommand)18 CommandScript (org.kie.server.api.commands.CommandScript)17 WebSocketServiceResponse (org.kie.server.controller.websocket.common.handlers.WebSocketServiceResponse)13 ArrayList (java.util.ArrayList)9 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)5 KieContainerResource (org.kie.server.api.model.KieContainerResource)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 JMSException (javax.jms.JMSException)4 CreateContainerCommand (org.kie.server.api.commands.CreateContainerCommand)4 DisposeContainerCommand (org.kie.server.api.commands.DisposeContainerCommand)4 Wrapped (org.kie.server.api.model.Wrapped)4 TextMessage (javax.jms.TextMessage)3 Test (org.junit.Test)3 UpdateReleaseIdCommand (org.kie.server.api.commands.UpdateReleaseIdCommand)3 UpdateScannerCommand (org.kie.server.api.commands.UpdateScannerCommand)3 KieServicesException (org.kie.server.api.exception.KieServicesException)3 ReleaseId (org.kie.server.api.model.ReleaseId)3 IOException (java.io.IOException)2