Package ilog.rules.res.session.async

Provides classes for asynchronous ruleset execution via the Rule Sessions API. Asynchronous execution is limited to stateless rule sessions.

Code example

  // The stateless session is created as usual
  IlrStatelessSession statelessSession = getSessionFactory().createStatelessSession();
  IlrSessionRequest request = sessionFactory.createRequest();
  request.setRulesetPath(IlrPath.parsePath("/bigsequential/1.0/bigsequentialruleset/1.0"));
  request.setInputParameter("param1", "ruoa");
        
        // The Observer is created and will be called when the execution failed or ended.
  IlrAsyncExecutionObserver myObserver = new IlrAsyncExecutionObserver() {
    public void update(IlrAsyncExecutionEvent event) {
      if (event instanceof IlrAsyncExecutionEndedEvent) {
        IlrAsyncExecutionEndedEvent endedEvent = (IlrAsyncExecutionEndedEvent)event;
        IlrSessionResponse response = endedEvent.getResponse();
        assertNotNull("ended exec event references null response", response);
        assertNotNull("expected param not found in response", response.getOutputParameters().get("param1"));
        hasExecuted = true;
      } else if (event instanceof IlrAsyncExecutionFailedEvent) {
        IlrAsyncExecutionFailedEvent failedEvent = (IlrAsyncExecutionFailedEvent)event;
        String msg = "observer got notified of an error, e=" + failedEvent.getException().getMessage();
        fail(msg);                    
      }
    }
  };
  // asynchronous execution with your observer. Your code is not blocked by the ruleset execution  
  statelessSession.executeAsynchronous(request, myObserver, -1);