Search in sources :

Example 1 with ResponseHandler

use of org.kie.server.client.jms.ResponseHandler in project droolsjbpm-integration by kiegroup.

the class DroolsJmsResponseHandlerIntegrationTest method testExecuteSimpleRuleFlowProcessWithAsyncResponseHandler.

@Test
public void testExecuteSimpleRuleFlowProcessWithAsyncResponseHandler() {
    Marshaller marshaller = MarshallerFactory.getMarshaller(new HashSet<Class<?>>(extraClasses.values()), configuration.getMarshallingFormat(), client.getClassLoader());
    ResponseCallback responseCallback = new BlockingResponseCallback(marshaller);
    ResponseHandler asyncResponseHandler = new AsyncResponseHandler(responseCallback);
    ruleClient.setResponseHandler(asyncResponseHandler);
    List<Command<?>> commands = new ArrayList<Command<?>>();
    commands.add(commandsFactory.newSetGlobal(LIST_NAME, new ArrayList<String>(), LIST_OUTPUT_NAME));
    commands.add(commandsFactory.newStartProcess(PROCESS_ID));
    commands.add(commandsFactory.newGetGlobal(LIST_NAME, LIST_OUTPUT_NAME));
    BatchExecutionCommand batchExecution = commandsFactory.newBatchExecution(commands, KIE_SESSION);
    ServiceResponse<?> response = ruleClient.executeCommandsWithResults(CONTAINER_ID, batchExecution);
    assertThat(response).isNull();
    ExecutionResults result = responseCallback.get(ExecutionResultImpl.class);
    List<String> outcome = (List<String>) result.getValue(LIST_OUTPUT_NAME);
    assertThat(outcome).isNotNull();
    assertThat(outcome).containsExactly("Rule from first ruleflow group executed", "Rule from second ruleflow group executed");
}
Also used : Marshaller(org.kie.server.api.marshalling.Marshaller) ResponseHandler(org.kie.server.client.jms.ResponseHandler) AsyncResponseHandler(org.kie.server.client.jms.AsyncResponseHandler) RequestReplyResponseHandler(org.kie.server.client.jms.RequestReplyResponseHandler) FireAndForgetResponseHandler(org.kie.server.client.jms.FireAndForgetResponseHandler) AsyncResponseHandler(org.kie.server.client.jms.AsyncResponseHandler) ExecutionResults(org.kie.api.runtime.ExecutionResults) ArrayList(java.util.ArrayList) Command(org.kie.api.command.Command) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) BlockingResponseCallback(org.kie.server.client.jms.BlockingResponseCallback) ResponseCallback(org.kie.server.client.jms.ResponseCallback) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) BlockingResponseCallback(org.kie.server.client.jms.BlockingResponseCallback) BeforeClass(org.junit.BeforeClass) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) DroolsKieServerBaseIntegrationTest(org.kie.server.integrationtests.drools.DroolsKieServerBaseIntegrationTest)

Example 2 with ResponseHandler

use of org.kie.server.client.jms.ResponseHandler in project droolsjbpm-integration by kiegroup.

the class OptaPlannerJmsResponseHandlerIntegrationTest method testSolverWithAsyncResponseHandler.

@Test
public void testSolverWithAsyncResponseHandler() throws Exception {
    Marshaller marshaller = MarshallerFactory.getMarshaller(new HashSet<>(extraClasses.values()), configuration.getMarshallingFormat(), client.getClassLoader());
    ResponseCallback responseCallback = new BlockingResponseCallback(marshaller);
    ResponseHandler asyncResponseHandler = new AsyncResponseHandler(responseCallback);
    solverClient.setResponseHandler(asyncResponseHandler);
    SolverInstance response = solverClient.createSolver(CONTAINER_1_ID, SOLVER_1_ID, SOLVER_1_CONFIG);
    assertThat(response).isNull();
    SolverInstance solver = responseCallback.get(SolverInstance.class);
    assertThat(solver).isNotNull();
    assertThat(solver.getContainerId()).isEqualTo(CONTAINER_1_ID);
    assertThat(solver.getSolverId()).isEqualTo(SOLVER_1_ID);
    List<SolverInstance> solverInstanceList = solverClient.getSolvers(CONTAINER_1_ID);
    assertThat(solverInstanceList).isNull();
    SolverInstanceList solverList = responseCallback.get(SolverInstanceList.class);
    assertThat(solverList).isNotNull();
    assertThat(solverList.getContainers()).isNotNull().isNotEmpty().hasSize(1);
    solver = solverList.getContainers().get(0);
    assertThat(solver.getSolverId()).isEqualTo(SOLVER_1_ID);
    assertThat(solver.getStatus()).isEqualTo(SolverInstance.SolverStatus.NOT_SOLVING);
    solverClient.solvePlanningProblem(CONTAINER_1_ID, SOLVER_1_ID, loadPlanningProblem(5, 15));
    // Make sure the service call result is consumed
    responseCallback.get(Void.class);
    response = solverClient.getSolver(CONTAINER_1_ID, SOLVER_1_ID);
    assertThat(response).isNull();
    solver = responseCallback.get(SolverInstance.class);
    assertThat(solver.getSolverId()).isEqualTo(SOLVER_1_ID);
    assertThat(solver.getStatus()).isEqualTo(SolverInstance.SolverStatus.SOLVING);
    solverClient.terminateSolverEarly(CONTAINER_1_ID, SOLVER_1_ID);
    // Make sure the service call result is consumed
    responseCallback.get(Void.class);
    response = solverClient.getSolver(CONTAINER_1_ID, SOLVER_1_ID);
    assertThat(response).isNull();
    solver = responseCallback.get(SolverInstance.class);
    assertThat(solver.getSolverId()).isEqualTo(SOLVER_1_ID);
    assertThat(solver.getStatus()).isIn(SolverInstance.SolverStatus.TERMINATING_EARLY, SolverInstance.SolverStatus.NOT_SOLVING);
    solverClient.disposeSolver(CONTAINER_1_ID, SOLVER_1_ID);
    // Make sure the service call result is consumed
    responseCallback.get(Void.class);
    solverClient.getSolvers(CONTAINER_1_ID);
    assertThat(response).isNull();
    solverList = responseCallback.get(SolverInstanceList.class);
    assertThat(solverList).isNotNull();
    assertThat(solverList.getContainers()).isNullOrEmpty();
}
Also used : SolverInstance(org.kie.server.api.model.instance.SolverInstance) Marshaller(org.kie.server.api.marshalling.Marshaller) ResponseHandler(org.kie.server.client.jms.ResponseHandler) AsyncResponseHandler(org.kie.server.client.jms.AsyncResponseHandler) RequestReplyResponseHandler(org.kie.server.client.jms.RequestReplyResponseHandler) FireAndForgetResponseHandler(org.kie.server.client.jms.FireAndForgetResponseHandler) AsyncResponseHandler(org.kie.server.client.jms.AsyncResponseHandler) BlockingResponseCallback(org.kie.server.client.jms.BlockingResponseCallback) ResponseCallback(org.kie.server.client.jms.ResponseCallback) BlockingResponseCallback(org.kie.server.client.jms.BlockingResponseCallback) SolverInstanceList(org.kie.server.api.model.instance.SolverInstanceList) OptaplannerKieServerBaseIntegrationTest(org.kie.server.integrationtests.optaplanner.OptaplannerKieServerBaseIntegrationTest) Test(org.junit.Test)

Example 3 with ResponseHandler

use of org.kie.server.client.jms.ResponseHandler in project droolsjbpm-integration by kiegroup.

the class KieServicesClientImpl method getCapabilitiesFromServer.

private List<String> getCapabilitiesFromServer() {
    ResponseHandler responseHandler = getResponseHandler();
    if (config.isJms() && !(responseHandler instanceof RequestReplyResponseHandler)) {
        setResponseHandler(new RequestReplyResponseHandler());
        kieServerInfo = getServerInfo().getResult();
        setResponseHandler(responseHandler);
    } else {
        kieServerInfo = getServerInfo().getResult();
    }
    logger.debug("KieServicesClient connected to: {} version {}", kieServerInfo.getServerId(), kieServerInfo.getVersion());
    List<String> capabilities = kieServerInfo.getCapabilities();
    logger.debug("Supported capabilities by the server: {}", capabilities);
    return capabilities;
}
Also used : RequestReplyResponseHandler(org.kie.server.client.jms.RequestReplyResponseHandler) ResponseHandler(org.kie.server.client.jms.ResponseHandler) RequestReplyResponseHandler(org.kie.server.client.jms.RequestReplyResponseHandler)

Aggregations

RequestReplyResponseHandler (org.kie.server.client.jms.RequestReplyResponseHandler)3 ResponseHandler (org.kie.server.client.jms.ResponseHandler)3 Test (org.junit.Test)2 Marshaller (org.kie.server.api.marshalling.Marshaller)2 AsyncResponseHandler (org.kie.server.client.jms.AsyncResponseHandler)2 BlockingResponseCallback (org.kie.server.client.jms.BlockingResponseCallback)2 FireAndForgetResponseHandler (org.kie.server.client.jms.FireAndForgetResponseHandler)2 ResponseCallback (org.kie.server.client.jms.ResponseCallback)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 BeforeClass (org.junit.BeforeClass)1 BatchExecutionCommand (org.kie.api.command.BatchExecutionCommand)1 Command (org.kie.api.command.Command)1 ExecutionResults (org.kie.api.runtime.ExecutionResults)1 SolverInstance (org.kie.server.api.model.instance.SolverInstance)1 SolverInstanceList (org.kie.server.api.model.instance.SolverInstanceList)1 DroolsKieServerBaseIntegrationTest (org.kie.server.integrationtests.drools.DroolsKieServerBaseIntegrationTest)1 OptaplannerKieServerBaseIntegrationTest (org.kie.server.integrationtests.optaplanner.OptaplannerKieServerBaseIntegrationTest)1