비동기적으로 규칙 세트 호출

비동기 규칙 세트 실행을 설정하려면 코드로 Stateless 세션과 실행 요청을 작성하고, 정규 규칙 세트 경로를 지정하며, 입력 매개변수를 전달하고, 관찰자를 작성해야 합니다.

이 태스크 정보

Stateless 세션을 설정하여 실행 이벤트에 따라 규칙 세트를 비동기로 실행할 수 있습니다. 실행을 비동기로 설정하면 코드의 나머지는 실행 결과를 대기할 필요가 없습니다. 이것은 예를 들어, GUI(Graphical User Interface)에서 작업할 때 실행되는 동안 GUI에서 조치를 실행할 수 있기를 원하는 경우 유용합니다. 이를 달성하기 위해 수동으로 멀티스레딩을 코딩할 필요가 없습니다. 실행을 비동기로 설정하면 API가 사용자 대신 실행을 처리합니다.

API에 대한 세부사항은 ilog.rules.res.session.async 패키지를 참조하십시오.

참고: WebSphere MQ를 사용하여 비동기 실행을 지원할 수 있습니다. 이 지원을 통합하는 방법은 Operational Decision Manager 문서의 이전 버전에 설명되어 있습니다(WebSphere® Application Server 비동기 실행을 지원하도록 WebSphere Application Server에서 WebSphere MQ 통합 참조).

프로시저

비동기 실행을 설정하려면 다음을 수행하십시오.

  1. 팩토리를 사용하여 Stateless 세션을 작성하십시오.
    IlrStatelessSession statelessSession = getSessionFactory().createStatelessSession();
  2. 팩토리를 사용하여 실행 요청을 작성하십시오.
    IlrSessionRequest request = sessionFactory.createRequest();
  3. 규칙 세트 경로를 지정하십시오.
    request.setRulesetPath(IlrPath.parsePath("/bigsequential/1.0/bigsequentialruleset/1.0"));
  4. 입력 매개변수를 전달하십시오.
    request.setInputParameter("param1", "ruoa")
  5. 관찰자를 작성하십시오.

    관찰자는 실행이 실패하거나 종료할 때 호출됩니다.

    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);                    
          }
       }
    };
  6. 관찰자와 함께 실행을 비동기로 시작하십시오.
    statelessSession.executeAsynchronous(request, myObserver, -1);

결과

규칙 세트 실행은 코드를 차단하지 않습니다.