org.apache.commons.collections4.keyvalue.MultiKey Java Examples

The following examples show how to use org.apache.commons.collections4.keyvalue.MultiKey. 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 File: DefaultRestClientRequest.java    From vertx-rest-client with Apache License 2.0 5 votes vote down vote up
private MultiKey createCacheKey(String uri, MultiMap headers, ByteBuf body) {
    return new MultiKey(
            uri,
            headers.entries().stream().map(e -> e.getKey() + ": " + e.getValue()).sorted().collect(Collectors.toList()),
            body.hashCode()
    );
}
 
Example #2
Source File: DefaultRestClientRequest.java    From vertx-rest-client with Apache License 2.0 5 votes vote down vote up
private void evictBefore(MultiKey key) {
    if (requestCacheOptions != null && requestCacheOptions.getEvictBefore()) {
        log.debug("EVICTING entry from cache for key {}", key);
        cancelOutstandingEvictionTimer(key);
        restClient.getRequestCache().remove(key);
    }
}
 
Example #3
Source File: DefaultRestClientRequest.java    From vertx-rest-client with Apache License 2.0 5 votes vote down vote up
private void cancelOutstandingEvictionTimer(MultiKey multiKey) {
    final Long outstandingTimer = restClient.getEvictionTimersCache().get(multiKey);
    if (outstandingTimer != null) {
        vertx.cancelTimer(outstandingTimer);
        restClient.getEvictionTimersCache().remove(multiKey);
    }
}
 
Example #4
Source File: DefaultRestClientRequest.java    From vertx-rest-client with Apache License 2.0 5 votes vote down vote up
private void createEvictionTimer(MultiKey key, long ttl) {
    final long timerId = vertx.setTimer(ttl, timerIdRef -> {
        if (restClient.getEvictionTimersCache().containsValue(timerIdRef)) {
            log.debug("EVICTING entry from cache for key {}", key);
            restClient.getRequestCache().remove(key);
            restClient.getEvictionTimersCache().remove(key);
        }
    });
    restClient.getEvictionTimersCache().put(key, timerId);
}
 
Example #5
Source File: DefaultRestClientRequest.java    From vertx-rest-client with Apache License 2.0 5 votes vote down vote up
private void finishRequest(Optional<MultiKey> key) {
    if (timeoutInMillis > 0) {
        httpClientRequest.setTimeout(timeoutInMillis);
    }
    httpClientRequest.end(Buffer.buffer(bufferedHttpOutputMessage.getBody()));
    key.ifPresent(e -> restClient.getRunningRequests().put(e, this));
    logRequest();
}
 
Example #6
Source File: MultiKeysTest.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@Test
public void test(){
	MultiKey key1 = new MultiKey(32, "test");
	MultiKey key2 = new MultiKey("test", 32);
	Assert.assertEquals(key1.hashCode(), key2.hashCode());
	Assert.assertNotEquals(key1, key2);
	
	MultiKeyMap map = new MultiKeyMap();
	map.put(key1, "test");
	String value = (String)map.get(key1);
	String value2 = (String)map.get(key1);
	Assert.assertEquals(value, value2);
	
}
 
Example #7
Source File: DefaultRestClient.java    From vertx-rest-client with Apache License 2.0 4 votes vote down vote up
Map<MultiKey, RestClientResponse> getRequestCache() {
    return requestCache;
}
 
Example #8
Source File: DefaultRestClient.java    From vertx-rest-client with Apache License 2.0 4 votes vote down vote up
Map<MultiKey, Long> getEvictionTimersCache() {
    return evictionTimersCache;
}
 
Example #9
Source File: DefaultRestClient.java    From vertx-rest-client with Apache License 2.0 4 votes vote down vote up
LinkedListMultimap<MultiKey, DefaultRestClientRequest> getRunningRequests() {
    return runningRequests;
}
 
Example #10
Source File: DefaultRestClientRequest.java    From vertx-rest-client with Apache License 2.0 4 votes vote down vote up
private void resetExpires(MultiKey key) {
    if (requestCacheOptions.getExpiresAfterAccessMillis() > 0) {
        cancelOutstandingEvictionTimer(key);
        createEvictionTimer(key, requestCacheOptions.getExpiresAfterAccessMillis());
    }
}
 
Example #11
Source File: CommonCollections.java    From j360-dubbo-app-all with Apache License 2.0 2 votes vote down vote up
/**
 * 联合多个Key来定位Value的HashMap.
 * 
 * 普通HashMap,需要将多个Key拼装成一个字符串作为主键,因此MultiKeyMap尤其适合于这几个Key的类型不是String时.
 * 
 * @param map 被包裹的底层HashMap,可先定义HashMap的初始大小和加载因子,可使用类型为LinkedMap
 */
public static <K, V> MultiKeyMap<K, V> multiKeyMap(final AbstractHashedMap<MultiKey<? extends K>, V> map) {
	return MultiKeyMap.multiKeyMap(map);
}