Search in sources :

Example 1 with WebSocketServiceResponse

use of org.kie.server.controller.websocket.common.handlers.WebSocketServiceResponse in project droolsjbpm-integration by kiegroup.

the class WebSocketKieServerControllerClient method sendCommand.

private <T> T sendCommand(final String service, final String method, final Object... arguments) {
    final KieServerControllerDescriptorCommand command = new KieServerControllerDescriptorCommand(service, method, arguments);
    LOGGER.debug("About to send descriptor command to kie server controller: {}", command);
    final String content = WebSocketUtils.marshal(command);
    LOGGER.debug("Content to be sent over Web Socket '{}'", content);
    try {
        final WebSocketServiceResponse response = getMessageHandler();
        client.sendTextWithInternalHandler(content, response);
        LOGGER.debug("Message successfully sent to kie server controller");
        if (response.getType() == ResponseType.FAILURE) {
            throw new KieServerControllerClientException(response.getMsg());
        } else {
            return (T) response.getResult();
        }
    } catch (KieServerControllerClientException e) {
        LOGGER.warn("Received Web Socket service error with message: {}", e.getMessage());
        throw e;
    } catch (Exception e) {
        LOGGER.error("Error trying to send message to kie server controller", e);
        throw new KieServerControllerClientException(e);
    }
}
Also used : WebSocketServiceResponse(org.kie.server.controller.websocket.common.handlers.WebSocketServiceResponse) KieServerControllerDescriptorCommand(org.kie.server.controller.api.commands.KieServerControllerDescriptorCommand) KieServerControllerClientException(org.kie.server.controller.client.exception.KieServerControllerClientException) KieServerControllerClientException(org.kie.server.controller.client.exception.KieServerControllerClientException) IOException(java.io.IOException)

Example 2 with WebSocketServiceResponse

use of org.kie.server.controller.websocket.common.handlers.WebSocketServiceResponse in project droolsjbpm-integration by kiegroup.

the class WebSocketKieServerClient method getContainerInfo.

@Override
public ServiceResponse<KieContainerResource> getContainerInfo(String id) {
    CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new GetContainerInfoCommand(id)));
    ServiceResponse<KieContainerResource> response = (ServiceResponse<KieContainerResource>) 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) KieServerCommand(org.kie.server.api.model.KieServerCommand) WebSocketServiceResponse(org.kie.server.controller.websocket.common.handlers.WebSocketServiceResponse) CommandScript(org.kie.server.api.commands.CommandScript) GetContainerInfoCommand(org.kie.server.api.commands.GetContainerInfoCommand) KieContainerResource(org.kie.server.api.model.KieContainerResource)

Example 3 with WebSocketServiceResponse

use of org.kie.server.controller.websocket.common.handlers.WebSocketServiceResponse in project droolsjbpm-integration by kiegroup.

the class WebSocketKieServerClient method deactivateContainer.

@Override
public ServiceResponse<KieContainerResource> deactivateContainer(String id) {
    CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DeactivateContainerCommand(id)));
    ServiceResponse<KieContainerResource> response = (ServiceResponse<KieContainerResource>) 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 : ServiceResponsesList(org.kie.server.api.model.ServiceResponsesList) 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) DeactivateContainerCommand(org.kie.server.api.commands.DeactivateContainerCommand) KieContainerResource(org.kie.server.api.model.KieContainerResource)

Example 4 with WebSocketServiceResponse

use of org.kie.server.controller.websocket.common.handlers.WebSocketServiceResponse 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 5 with WebSocketServiceResponse

use of org.kie.server.controller.websocket.common.handlers.WebSocketServiceResponse 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)

Aggregations

WebSocketServiceResponse (org.kie.server.controller.websocket.common.handlers.WebSocketServiceResponse)14 ServiceResponse (org.kie.server.api.model.ServiceResponse)13 ServiceResponsesList (org.kie.server.api.model.ServiceResponsesList)13 CommandScript (org.kie.server.api.commands.CommandScript)12 KieServerCommand (org.kie.server.api.model.KieServerCommand)10 KieContainerResource (org.kie.server.api.model.KieContainerResource)4 IOException (java.io.IOException)2 KieScannerResource (org.kie.server.api.model.KieScannerResource)2 ReleaseId (org.kie.server.api.model.ReleaseId)2 ArrayList (java.util.ArrayList)1 Session (javax.websocket.Session)1 ActivateContainerCommand (org.kie.server.api.commands.ActivateContainerCommand)1 CreateContainerCommand (org.kie.server.api.commands.CreateContainerCommand)1 DeactivateContainerCommand (org.kie.server.api.commands.DeactivateContainerCommand)1 DisposeContainerCommand (org.kie.server.api.commands.DisposeContainerCommand)1 GetContainerInfoCommand (org.kie.server.api.commands.GetContainerInfoCommand)1 GetReleaseIdCommand (org.kie.server.api.commands.GetReleaseIdCommand)1 GetScannerInfoCommand (org.kie.server.api.commands.GetScannerInfoCommand)1 GetServerInfoCommand (org.kie.server.api.commands.GetServerInfoCommand)1 GetServerStateCommand (org.kie.server.api.commands.GetServerStateCommand)1