org.apache.commons.collections.map.LRUMap Java Examples

The following examples show how to use org.apache.commons.collections.map.LRUMap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: tajo   Author: apache   File: QueryMaster.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void serviceInit(Configuration conf) throws Exception {

  this.systemConf = TUtil.checkTypeAndGet(conf, TajoConf.class);
  this.manager = RpcClientManager.getInstance();
  this.rpcClientParams = RpcParameterFactory.get(this.systemConf);

  querySessionTimeout = systemConf.getIntVar(TajoConf.ConfVars.QUERY_SESSION_TIMEOUT);
  queryMasterContext = new QueryMasterContext(systemConf);

  clock = new SystemClock();
  finishedQueryMasterTasksCache = new LRUMap(systemConf.getIntVar(TajoConf.ConfVars.HISTORY_QUERY_CACHE_SIZE));

  this.dispatcher = new AsyncDispatcher();
  addIfService(dispatcher);

  globalPlanner = new GlobalPlanner(systemConf, workerContext);

  dispatcher.register(QueryStartEvent.EventType.class, new QueryStartEventHandler());
  dispatcher.register(QueryStopEvent.EventType.class, new QueryStopEventHandler());
  super.serviceInit(conf);
  LOG.info("QueryMaster inited");
}
 
Example #2
Source Project: tajo   Author: apache   File: QueryManager.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void serviceInit(Configuration conf) throws Exception {
  try {
    this.dispatcher = new AsyncDispatcher();
    addService(this.dispatcher);

    this.dispatcher.register(QueryJobEvent.Type.class, new QueryJobManagerEventHandler());

    TajoConf tajoConf = TUtil.checkTypeAndGet(conf, TajoConf.class);
    this.historyCache = new LRUMap(tajoConf.getIntVar(TajoConf.ConfVars.HISTORY_QUERY_CACHE_SIZE));
  } catch (Exception e) {
    LOG.error("Failed to init service " + getName() + " by exception " + e, e);
  }

  super.serviceInit(conf);
}
 
Example #3
Source Project: pxf   Author: greenplum-db   File: AggBridge.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean beginIteration() throws Exception {
    /* Initialize LRU cache with 100 items*/
    outputCache = new LRUMap();
    boolean openForReadStatus = accessor.openForRead();
    ((StatsAccessor) accessor).retrieveStats();
    return openForReadStatus;
}
 
Example #4
Source Project: zap-extensions   Author: zaproxy   File: WebSocketMessagesViewModel.java    License: Apache License 2.0 5 votes vote down vote up
/** Useful Ctor for subclasses. */
protected WebSocketMessagesViewModel(TableWebSocket webSocketTable) {
    super();

    table = webSocketTable;
    fullMessagesCache = new LRUMap(10);
}
 
Example #5
Source Project: zap-extensions   Author: zaproxy   File: GitIndexEntryCache.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * puts the Git Index and Git Index Entry in a map
 *
 * @param gitIndexUri
 * @param gitIndexEntryUri
 */
@SuppressWarnings("unchecked")
public synchronized void putIndexEntry(URI gitIndexUri, URI gitIndexEntryUri, String gitSHA1) {
    Map<URI, String> indexEntryMap;
    if (gitIndexMap.containsKey(gitIndexUri)) {
        indexEntryMap = gitIndexMap.get(gitIndexUri);
    } else {
        indexEntryMap =
                Collections.synchronizedMap(
                        new LRUMap(1000)); // max: 1000 Git index entries (LRU)
    }
    indexEntryMap.put(gitIndexEntryUri, gitSHA1);
    gitIndexMap.put(gitIndexUri, indexEntryMap);
}
 
Example #6
Source Project: zap-extensions   Author: zaproxy   File: EventStreamViewModel.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Useful Ctor for subclasses.
 *
 * @param databaseTable
 */
protected EventStreamViewModel(TableEventStream databaseTable) {
    super();

    table = databaseTable;
    fullMessagesCache = new LRUMap(10);
}
 
Example #7
Source Project: jmeter-cassandra   Author: slowenthal   File: AbstractCassandaTestElement.java    License: Apache License 2.0 5 votes vote down vote up
private BoundStatement getPreparedStatement(Session conn, boolean callable) {
    Map<String, PreparedStatement> preparedStatementMap = perConnCache.get(conn);
    if (null == preparedStatementMap ) {
        @SuppressWarnings("unchecked") // LRUMap is not generic
                Map<String, PreparedStatement> lruMap = new LRUMap(MAX_OPEN_PREPARED_STATEMENTS) {
            private static final long serialVersionUID = 1L;
            @Override
            protected boolean removeLRU(LinkEntry entry) {
                PreparedStatement preparedStatement = (PreparedStatement)entry.getValue();
                return true;
            }
        };

        // TODO - This is wrong, but is synchronized
        preparedStatementMap = Collections.<String, PreparedStatement>synchronizedMap(lruMap);
        // As a connection is held by only one thread, we cannot already have a 
        // preparedStatementMap put by another thread
        perConnCache.put(conn, preparedStatementMap);
    }
    PreparedStatement pstmt = preparedStatementMap.get(getQuery());
    if (null == pstmt) {
        pstmt = conn.prepare(getQuery());

        // PreparedStatementMap is associated to one connection so
        //  2 threads cannot use the same PreparedStatement map at the same time
        preparedStatementMap.put(getQuery(), pstmt);
    }

    return pstmt.bind();
}
 
Example #8
Source Project: iaf   Author: ibissource   File: XsltSender.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * The <code>configure()</code> method instantiates a transformer for the specified
 * XSL. If the stylesheetName cannot be accessed, a ConfigurationException is thrown.
 */
@Override
public void configure() throws ConfigurationException {
	super.configure();
	
	streamingXslt = AppConstants.getInstance(getConfigurationClassLoader()).getBoolean("xslt.streaming.default", false);
	dynamicTransformerPoolMap = Collections.synchronizedMap(new LRUMap(transformerPoolMapSize));
	
	if(StringUtils.isNotEmpty(getXpathExpression()) && getOutputType()==null) {
		setOutputType("text");
	}
	if(StringUtils.isNotEmpty(getStyleSheetName()) || StringUtils.isNotEmpty(getXpathExpression())) {
		Boolean omitXmlDeclaration = getOmitXmlDeclaration();
		if (omitXmlDeclaration==null) {
			omitXmlDeclaration=true;
		}
		transformerPool = TransformerPool.configureTransformer0(getLogPrefix(), getConfigurationClassLoader(), getNamespaceDefs(), getXpathExpression(), getStyleSheetName(), getOutputType(), !omitXmlDeclaration, getParameterList(), getXsltVersion());
	}
	else if(StringUtils.isEmpty(getStyleSheetNameSessionKey())) {
		throw new ConfigurationException(getLogPrefix()+" one of xpathExpression, styleSheetName or styleSheetNameSessionKey must be specified");
	}

	if (getXsltVersion()>=2) {
		ParameterList parameterList = getParameterList();
		if (parameterList!=null) {
			for (int i=0; i<parameterList.size(); i++) {
				Parameter parameter = parameterList.getParameter(i);
				if (StringUtils.isNotEmpty(parameter.getType()) && "node".equalsIgnoreCase(parameter.getType())) {
					throw new ConfigurationException(getLogPrefix() + "type \"node\" is not permitted in combination with XSLT 2.0, use type \"domdoc\"");
				}
			}
		}
	}
}
 
Example #9
Source Project: windup   Author: windup   File: ClassificationServiceCache.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Keep a cache of items files associated with classification in order to improve performance.
 */
@SuppressWarnings("unchecked")
private static synchronized Map<String, Boolean> getCache(GraphRewrite event)
{
    Map<String, Boolean> result = (Map<String, Boolean>)event.getRewriteContext().get(ClassificationServiceCache.class);
    if (result == null)
    {
        result = Collections.synchronizedMap(new LRUMap(30000));
        event.getRewriteContext().put(ClassificationServiceCache.class, result);
    }
    return result;
}
 
Example #10
Source Project: emissary   Author: NationalSecurityAgency   File: MetadataDictionary.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Setup from configuration file or stream Items used here are
 * <ul>
 * <li>RENAME_* - read into a map for exact match renaming</li>
 * <li>REGEX - regex patterns that can drive renaming</li>
 * <li>CACHE_SIZE - size for LRU regex cache</li>
 * </ul>
 * 
 * @param confArg the config stream to use or null for default
 */
@SuppressWarnings("unchecked")
protected void reconfigure(final Configurator confArg) {
    try {
        final Configurator conf;
        if (confArg == null) {
            conf = ConfigUtil.getConfigInfo(MetadataDictionary.class);
        } else {
            conf = confArg;
        }

        this.nameMap = conf.findStringMatchMap("RENAME_", Configurator.PRESERVE_CASE);

        final int cacheSize = conf.findIntEntry("CACHE_SIZE", 500);
        this.regexCache = new ConcurrentHashMap<String, String>(new LRUMap(cacheSize));
        this.logger.debug("LRU cache configured with size {}", cacheSize);

        final Map<String, String> list = conf.findStringMatchMap("REGEX_", Configurator.PRESERVE_CASE);

        this.regexMap = new HashMap<Pattern, String>();

        for (final Map.Entry<String, String> entry : list.entrySet()) {
            try {
                this.regexMap.put(Pattern.compile(entry.getKey()), entry.getValue());
            } catch (Exception pex) {
                this.logger.warn("Pattern '{}' could not compile", entry.getKey(), pex);
            }
        }
    } catch (IOException ex) {
        this.logger.warn("Cannot read config file", ex);
    } finally {
        if (this.nameMap == null) {
            this.nameMap = Collections.emptyMap();
        }

        if (this.regexMap == null) {
            this.regexMap = Collections.emptyMap();
        }

        if (this.regexCache == null) {
            this.regexCache = new LRUMap(500);
        }
    }
}
 
Example #11
Source Project: hadoop   Author: naver   File: TimelineACLsManager.java    License: Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public TimelineACLsManager(Configuration conf) {
  this.adminAclsManager = new AdminACLsManager(conf);
  aclExts = Collections.synchronizedMap(
      new LRUMap(DOMAIN_ACCESS_ENTRY_CACHE_SIZE));
}
 
Example #12
Source Project: hadoop   Author: naver   File: LeveldbTimelineStore.java    License: Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected void serviceInit(Configuration conf) throws Exception {
  Preconditions.checkArgument(conf.getLong(
      YarnConfiguration.TIMELINE_SERVICE_TTL_MS,
      YarnConfiguration.DEFAULT_TIMELINE_SERVICE_TTL_MS) > 0,
      "%s property value should be greater than zero",
      YarnConfiguration.TIMELINE_SERVICE_TTL_MS);
  Preconditions.checkArgument(conf.getLong(
      YarnConfiguration.TIMELINE_SERVICE_LEVELDB_TTL_INTERVAL_MS,
      YarnConfiguration.DEFAULT_TIMELINE_SERVICE_LEVELDB_TTL_INTERVAL_MS) > 0,
      "%s property value should be greater than zero",
      YarnConfiguration.TIMELINE_SERVICE_LEVELDB_TTL_INTERVAL_MS);
  Preconditions.checkArgument(conf.getLong(
      YarnConfiguration.TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE,
      YarnConfiguration.DEFAULT_TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE) >= 0,
      "%s property value should be greater than or equal to zero",
      YarnConfiguration.TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE);
  Preconditions.checkArgument(conf.getLong(
      YarnConfiguration.TIMELINE_SERVICE_LEVELDB_START_TIME_READ_CACHE_SIZE,
      YarnConfiguration.DEFAULT_TIMELINE_SERVICE_LEVELDB_START_TIME_READ_CACHE_SIZE) > 0,
      " %s property value should be greater than zero",
      YarnConfiguration.TIMELINE_SERVICE_LEVELDB_START_TIME_READ_CACHE_SIZE);
  Preconditions.checkArgument(conf.getLong(
      YarnConfiguration.TIMELINE_SERVICE_LEVELDB_START_TIME_WRITE_CACHE_SIZE,
      YarnConfiguration.DEFAULT_TIMELINE_SERVICE_LEVELDB_START_TIME_WRITE_CACHE_SIZE) > 0,
      "%s property value should be greater than zero",
      YarnConfiguration.TIMELINE_SERVICE_LEVELDB_START_TIME_WRITE_CACHE_SIZE);

  Options options = new Options();
  options.createIfMissing(true);
  options.cacheSize(conf.getLong(
      YarnConfiguration.TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE,
      YarnConfiguration.DEFAULT_TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE));
  JniDBFactory factory = new JniDBFactory();
  Path dbPath = new Path(
      conf.get(YarnConfiguration.TIMELINE_SERVICE_LEVELDB_PATH), FILENAME);
  FileSystem localFS = null;
  try {
    localFS = FileSystem.getLocal(conf);
    if (!localFS.exists(dbPath)) {
      if (!localFS.mkdirs(dbPath)) {
        throw new IOException("Couldn't create directory for leveldb " +
            "timeline store " + dbPath);
      }
      localFS.setPermission(dbPath, LEVELDB_DIR_UMASK);
    }
  } finally {
    IOUtils.cleanup(LOG, localFS);
  }
  LOG.info("Using leveldb path " + dbPath);
  db = factory.open(new File(dbPath.toString()), options);
  checkVersion();
  startTimeWriteCache =
      Collections.synchronizedMap(new LRUMap(getStartTimeWriteCacheSize(
          conf)));
  startTimeReadCache =
      Collections.synchronizedMap(new LRUMap(getStartTimeReadCacheSize(
          conf)));

  if (conf.getBoolean(YarnConfiguration.TIMELINE_SERVICE_TTL_ENABLE, true)) {
    deletionThread = new EntityDeletionThread(conf);
    deletionThread.start();
  }

  super.serviceInit(conf);
}
 
Example #13
Source Project: timely   Author: NationalSecurityAgency   File: VisibilityFilter.java    License: Apache License 2.0 4 votes vote down vote up
public VisibilityFilter(Authorizations authorizations) {
    this.ve = new VisibilityEvaluator(authorizations);
    this.cache = new LRUMap(1000);
}
 
Example #14
Source Project: big-c   Author: yncxcw   File: TimelineACLsManager.java    License: Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public TimelineACLsManager(Configuration conf) {
  this.adminAclsManager = new AdminACLsManager(conf);
  aclExts = Collections.synchronizedMap(
      new LRUMap(DOMAIN_ACCESS_ENTRY_CACHE_SIZE));
}
 
Example #15
Source Project: big-c   Author: yncxcw   File: LeveldbTimelineStore.java    License: Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected void serviceInit(Configuration conf) throws Exception {
  Preconditions.checkArgument(conf.getLong(
      YarnConfiguration.TIMELINE_SERVICE_TTL_MS,
      YarnConfiguration.DEFAULT_TIMELINE_SERVICE_TTL_MS) > 0,
      "%s property value should be greater than zero",
      YarnConfiguration.TIMELINE_SERVICE_TTL_MS);
  Preconditions.checkArgument(conf.getLong(
      YarnConfiguration.TIMELINE_SERVICE_LEVELDB_TTL_INTERVAL_MS,
      YarnConfiguration.DEFAULT_TIMELINE_SERVICE_LEVELDB_TTL_INTERVAL_MS) > 0,
      "%s property value should be greater than zero",
      YarnConfiguration.TIMELINE_SERVICE_LEVELDB_TTL_INTERVAL_MS);
  Preconditions.checkArgument(conf.getLong(
      YarnConfiguration.TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE,
      YarnConfiguration.DEFAULT_TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE) >= 0,
      "%s property value should be greater than or equal to zero",
      YarnConfiguration.TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE);
  Preconditions.checkArgument(conf.getLong(
      YarnConfiguration.TIMELINE_SERVICE_LEVELDB_START_TIME_READ_CACHE_SIZE,
      YarnConfiguration.DEFAULT_TIMELINE_SERVICE_LEVELDB_START_TIME_READ_CACHE_SIZE) > 0,
      " %s property value should be greater than zero",
      YarnConfiguration.TIMELINE_SERVICE_LEVELDB_START_TIME_READ_CACHE_SIZE);
  Preconditions.checkArgument(conf.getLong(
      YarnConfiguration.TIMELINE_SERVICE_LEVELDB_START_TIME_WRITE_CACHE_SIZE,
      YarnConfiguration.DEFAULT_TIMELINE_SERVICE_LEVELDB_START_TIME_WRITE_CACHE_SIZE) > 0,
      "%s property value should be greater than zero",
      YarnConfiguration.TIMELINE_SERVICE_LEVELDB_START_TIME_WRITE_CACHE_SIZE);

  Options options = new Options();
  options.createIfMissing(true);
  options.cacheSize(conf.getLong(
      YarnConfiguration.TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE,
      YarnConfiguration.DEFAULT_TIMELINE_SERVICE_LEVELDB_READ_CACHE_SIZE));
  JniDBFactory factory = new JniDBFactory();
  Path dbPath = new Path(
      conf.get(YarnConfiguration.TIMELINE_SERVICE_LEVELDB_PATH), FILENAME);
  FileSystem localFS = null;
  try {
    localFS = FileSystem.getLocal(conf);
    if (!localFS.exists(dbPath)) {
      if (!localFS.mkdirs(dbPath)) {
        throw new IOException("Couldn't create directory for leveldb " +
            "timeline store " + dbPath);
      }
      localFS.setPermission(dbPath, LEVELDB_DIR_UMASK);
    }
  } finally {
    IOUtils.cleanup(LOG, localFS);
  }
  LOG.info("Using leveldb path " + dbPath);
  db = factory.open(new File(dbPath.toString()), options);
  checkVersion();
  startTimeWriteCache =
      Collections.synchronizedMap(new LRUMap(getStartTimeWriteCacheSize(
          conf)));
  startTimeReadCache =
      Collections.synchronizedMap(new LRUMap(getStartTimeReadCacheSize(
          conf)));

  if (conf.getBoolean(YarnConfiguration.TIMELINE_SERVICE_TTL_ENABLE, true)) {
    deletionThread = new EntityDeletionThread(conf);
    deletionThread.start();
  }

  super.serviceInit(conf);
}
 
Example #16
Source Project: spring-boot-doma2-sample   Author: miyabayt   File: DoubleSubmitCheckToken.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * トークンを取得する。
 *
 * @param request
 * @param key
 * @return
 */
protected static String getToken(HttpServletRequest request, String key) {
    LRUMap map = getLRUMap(request);
    val token = (String) map.get(key);
    return token;
}
 
Example #17
Source Project: spring-boot-doma2-sample   Author: miyabayt   File: DoubleSubmitCheckToken.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * トークンを保存する。
 *
 * @param request
 * @param key
 * @param token
 */
protected static void setToken(HttpServletRequest request, String key, String token) {
    LRUMap map = getLRUMap(request);
    map.put(key, token);
    SessionUtils.setAttribute(request, DOUBLE_SUBMIT_CHECK_CONTEXT, map);
}