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);
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations