규칙 세트 캐시 사용자 정의

사용자의 구현 클래스를 쓰고 이에 따라 배치 디스크립터 실행 단위(XU)를 수정하여 규칙 세트 캐시를 사용자 정의할 수 있습니다.

시작하기 전에

사용 가능한 메모리 정보를 보려면 Rule Execution Server 메모리 프로파일러 Java™ Agent를 설치해야 합니다.

이 태스크 정보

실행 단위(XU)는 각 실행의 규칙 세트를 구문 분석할 필요가 없도록 규칙 세트 인스턴스의 캐시를 사용합니다. 규칙 세트를 참조하는 XU의 JCA 연결 풀에 최소 하나의 연결이 존재하는 경우 규칙 세트는 메모리에 상주합니다. JCA 연결은 사용 중이 아니더라도 애플리케이션 서버가 해당 연결을 삭제할 때까지 규칙 세트를 참조합니다. JCA 연결이 규칙 세트를 더 이상 참조하지 않으면 규칙 세트는 가비지 수집될 수 있습니다. 이 기본 동작으로 사용하지 않는 규칙 세트는 메모리에서 제거됩니다. 규칙 세트가 다른 규칙 세트에 비해 자주 사용되지 않으면 재구문 분석이 발생할 수 있습니다.

ruleset.cache.maintenance.period 특성은 기본적으로 300에 설정됩니다. 이 값은 유지보수 스레드가 5분마다 실행됨을 의미합니다.

ra.xml XU 구성 파일에서 다른 구현 클래스를 패키징하여 규칙 세트 캐시의 자체 구현을 작성할 수 있습니다.

프로시저

  1. IlrRulesetCache 인터페이스를 구현하는 클래스를 작성하십시오. 사용 중인 클래스는 사용자 정의 특성을 정의할 수 있습니다.
    package ilog.rules.res.xu.ruleset.cache.sample;
    
    import java.util.*;
    import java.util.logging.*;
    
    import ilog.rules.res.xu.ruleset.*;
    
    public class RulesetCacheImpl implements IlrRulesetCache {
    		public static final int DEFAULT_MAXIMUM_SIZE = 2;
    
    		protected IlrRulesetUsageInformationMonitor monitor;
    		protected Logger logger;
    		protected ArrayList<IlrXURuleset> rulesets = new ArrayList<IlrXURuleset>();
    
    		/** Maximum number of rulesets that can be stored in the cache */
    		protected int maxSize = DEFAULT_MAXIMUM_SIZE;
    
    		public synchronized void addRuleset(IlrXURuleset ruleset) {
    				if (rulesets.size() == maxSize) {
    						logger.info("Max size reached, removing less used ruleset");
    						removeLessUsedRuleset();
    		}
    				rulesets.add(ruleset);
    	}
    
    
    	/**
    	 	 * Removes the least executed ruleset.
    	 */
    		protected void removeLessUsedRuleset() {
    				long minExecCount = Long.MAX_VALUE;
    				IlrXURuleset minExecRuleset = null;
    
    				for(IlrXURuleset ruleset: rulesets) {
    			IlrRulesetUsageInformation info
    								= monitor.getRulesetUsageInformation(ruleset.getCanonicalRulesetPath());
    						long execCounter = info.getExecutionCount();
    
    						if (execCounter <= minExecCount) {
    								minExecRuleset = ruleset;
    								minExecCount = execCounter;
    			}
    		}
    
    				if (minExecRuleset != null) {
    						logger.info("Remove ruleset: "+minExecRuleset.getCanonicalRulesetPath());
    						rulesets.remove(minExecRuleset);
    		}
    	}
    
    		public synchronized void clear() {
    				rulesets.clear();
    	}
    
    		public synchronized IlrXURuleset getDeprecatedRuleset(String canonicalRulesetPath,
    						ClassLoader xomClassLoader) {
    		return null;
    	}
    
    		public synchronized IlrXURuleset getRuleset(String canonicalRulesetPath,
    						ClassLoader xomClassLoader) {
    				for(IlrXURuleset ruleset: rulesets) {
    						if (ruleset.getCanonicalRulesetPath().equals(canonicalRulesetPath) &&
    										ruleset.getXOMClassLoader() == xomClassLoader) {
    								return ruleset;
    			}
    		}
    
    		return null;
    	}
    
    		public void initialize(Logger logger, Map<String, String> properties,
    						IlrRulesetUsageInformationMonitor monitor)
    						throws IlrRulesetCacheException {
    				this.monitor = monitor;
    				this.logger = logger;
    	}
    
    		public synchronized void rulesetChanged(String canonicalRulesetPath) {
    				Iterator<IlrXURuleset> iterator = rulesets.iterator();
    				while(iterator.hasNext()) {
    						IlrXURuleset ruleset = iterator.next();
    						if (ruleset.getCanonicalRulesetPath().equals(canonicalRulesetPath)) {
    								iterator.remove();
    			}
    		}
    	}
    
    }
     
  2. ra.xml XU 배치 디스크립터에 구현 클래스를 추가하십시오.
    1. 사용자 정의 규칙 세트 캐시를 구현하십시오.
      <config-property>
         <config-property-name>rulesetCacheProperties</config-property-name> 
         <config-property-type>java.lang.String</config-property-type>
         <config-property-value>ruleset.cache.class=mypackage.MyRulesetCache</config-property-value> 
      </config-property>
    2. 사용자 정의 캐시 특성을 설정하십시오.
      <config-property>
         <config-property-name>rulesetCacheProperties</config-property-name> 
         <config-property-type>java.lang.String</config-property-type>
         <config-property-value>ruleset.cache.class=mypackage.MyRulesetCache,mycustomprop=mycustomvalue/config-property-value>
      </config-property>
    3. rulesetUsageMonitorEnabled 특성이 기본값인 true로 설정되어 있는지 확인하십시오.
      <config-property>
         <config-property-name>rulesetUsageMonitorEnabled</config-property-name>
         <config-property-type>java.lang.Boolean</config-property-type> 
         <config-property-value>true</config-property-value>
      </config-property>
  3. 클래스를 패키징하십시오.

    Java SE 배치의 경우 클래스를 XU 또는 이의 상위와 동일한 클래스 경로에 클래스를 추가해야 합니다. Java EE에서, XU .rar 파일로 클래스를 패키징해야 합니다.