@Override public String toString(){ // Get a string to represent our internal property state. Multimap<String, String> entries = new CaseInsensitiveKeyMultimap<>(); entries.put("engine.mode", getMode()); entries.put("engine.regexcache.maxsize", String.valueOf(getRegexCacheMaxsize())); entries.put("engine.regexcache.expiryhours", String.valueOf(getRegexCacheExpiryHours())); entries.put("engine.environmentcache.maxage", String.valueOf(getEnvironmentCacheMaxage())); entries.put("engine.environmentcache.maxsize", String.valueOf(getEnvironmentCacheMaxsize())); entries.put("engine.environmentcache.expiryhours", String.valueOf(getEnvironmentCacheExpiryHours())); entries.put("engine.environmentcache.expiry", String.valueOf(getEnvironmentCacheExpiry())); entries.put("engine.environmentcache.verifyperiod", getEnvironmentCacheVerifyPeriod()); entries.put("engine.environmentcache.location", getEnvironmentCacheLocation()); entries.put("engine.environmentcache.mode", getEnvironmentCacheMode()); entries.put("engine.regextimeout", String.valueOf(getRegexTimeout())); return StringHelper.mapToHtml(entries); }
@Autowired public FilesystemInitializer(EngineProperties engineProperties, BooleanAgentServices booleanAgentServices){ this.booleanAgentServices = booleanAgentServices; environmentSnapshotCacheLocation = Paths.get(engineProperties.getEnvironmentCacheLocation()); environmentCacheExpiry = engineProperties.getEnvironmentCacheExpiry(); }
@Autowired public RegexMatcherFactoryImpl(EngineProperties engineProperties){ Integer maxPatternCacheSize = 100000; Integer patternCacheExpiryHours = 24; try { maxPatternCacheSize = engineProperties.getRegexCacheMaxsize(); patternCacheExpiryHours = engineProperties.getRegexCacheExpiryHours(); } catch (Exception e) { logger.warn("Problem loading pattern cache settings from config, using default.", e); } patternCache = CacheBuilder .newBuilder() .maximumSize(maxPatternCacheSize) .expireAfterAccess(patternCacheExpiryHours, TimeUnit.HOURS) .build( new CacheLoader<String, Pattern>() { public Pattern load(String regexString) throws Exception{ return Pattern.compile(regexString); } } ); }
@Autowired public EnvironmentSnapshotCacheImpl(ApplicationContext applicationContext, EngineProperties engineProperties) { Integer maxSequenceCacheSize = engineProperties.getEnvironmentCacheMaxsize(); Period period = new Period(engineProperties.getEnvironmentCacheVerifyPeriod()); environmentInitializer = applicationContext.getBean("Pipeline", EnvironmentInitializer.class); conditionEngineRepositoryCache = CacheBuilder.newBuilder() .maximumSize(maxSequenceCacheSize) .expireAfterWrite(period.toStandardDuration().getMillis(), TimeUnit.MILLISECONDS) .build( new CacheLoader<Long, EnvironmentSnapshot>() { public EnvironmentSnapshot load(Long sequenceId) throws Exception { try(CorePolicyLogger traceInfo = new CorePolicyLogger("EnvironmentSnapshot:load")) { EnvironmentSnapshotImpl environmentSnapshot = new EnvironmentSnapshotImpl(); environmentSnapshot.setCollectionSequenceId(sequenceId); environmentSnapshot = environmentInitializer.initialize(environmentSnapshot); return environmentSnapshot; } } } ); }
public PolicyWorkerFactory(Codec codec, DataStore dataStore, PolicyWorkerConfiguration config) { this.codec = codec; this.dataStore = dataStore; this.resultQueue = config.getResultQueue(); this.workerIdentifier = config.getWorkerIdentifier(); this.workerThreads = config.getWorkerThreads(); this.configuration = config; applicationContext = new CorePolicyApplicationContext(); createBeanDefinition(WorkerResponseHolder.class, "WorkerResponseHolder", "thread"); createBeanDefinition(WorkerRequestHolder.class, "WorkerRequestHolder", "thread"); applicationContext.refresh(); taskDataConverter = new TaskDataConverter(); apiProvider = new ApiProvider(applicationContext); EngineProperties engineProperties = applicationContext.getBean(EngineProperties.class); Period period = new Period(engineProperties.getEnvironmentCacheVerifyPeriod()); workflowCache = CacheBuilder.newBuilder().expireAfterWrite(period.toStandardDuration().getMillis(), TimeUnit.MILLISECONDS) .build(new CacheLoader<Long, SequenceWorkflow>() { @Override public SequenceWorkflow load(Long key) throws Exception { logger.warn("Loading workflow from database, id: {}", key); return getWorkflow(key, apiProvider.getWorkflowApi()); } }); if (config.getRegisterHandlers()) { new PolicyHandlerSetup(applicationContext).checkBasePolicies(); } }
@Override public EnvironmentSnapshotImpl initialize(EnvironmentSnapshotImpl environmentSnapshot) { try(CorePolicyLogger traceLogger = new CorePolicyLogger("FileSystemPersisence:initialize", Level.DEBUG)) { if (environmentSnapshot.getPersistedDate() != null) { traceLogger.log("snapshot has already been persisted - nothing to do."); return environmentSnapshot; } environmentSnapshot.setPersistedDate(DateTime.now(DateTimeZone.UTC)); String filename = String.valueOf(environmentSnapshot.getCollectionSequenceId()) + "-" + environmentSnapshot.getInstanceId() + ".json"; Path cacheFilePath = Paths.get(engineProperties.getEnvironmentCacheLocation(), filename); File file = cacheFilePath.toFile(); traceLogger.log("Persisting as: " + cacheFilePath); try { objectMapper.writeValue(file, environmentSnapshot); } catch (IOException e) { throw new RuntimeException(e); } return environmentSnapshot; } }
private void getMatches(Pattern pattern, Collection<MetadataValue> fieldValues, HashSet<String> matchedStrings) { for(MetadataValue fieldValue: fieldValues){ MatcherWithTimeout matcher = new MatcherWithTimeout(pattern.matcher(fieldValue.getStringValue()), engineProperties.getRegexTimeout()) ; while(matcher.find()){ matchedStrings.add(matcher.group()); } } }
public Period getEnvironmentCacheExpiry(){ String engineEnvironmentcacheExpiry = environment.getProperty("engine.environmentcache.expiry"); if (engineEnvironmentcacheExpiry == null) { engineEnvironmentcacheExpiry = "PT" + getEnvironmentCacheExpiryHours() + "H"; } return Period.parse(engineEnvironmentcacheExpiry); }
Session session = getSession(executionContext); EngineProperties engineProperties = applicationContext.getBean(EngineProperties.class); Integer maxBatchSize = engineProperties.getDefaultBatchSize(); int expressionCount = 0; StringBuilder stringBuilder = new StringBuilder();
Path cacheFilePath = Paths.get(engineProperties.getEnvironmentCacheLocation(), filename); File file = cacheFilePath.toFile();