List of usage examples for org.apache.commons.collections4.map PassiveExpiringMap PassiveExpiringMap
public PassiveExpiringMap(final Map<K, V> map)
From source file:io.sip3.tapir.captain.handler.PacketDefragmentator.java
public PacketDefragmentator(int order, int total, int ttl) throws Exception { super(order, total); this.ttl = ttl; this.accumulator = new PassiveExpiringMap<>(ttl); }
From source file:org.apache.ambari.view.hive.resources.browser.HiveBrowserService.java
public static Map<String, Cursor> getResultsCache() { if (resultsCache == null) { PassiveExpiringMap<String, Cursor> resultsCacheExpiringMap = new PassiveExpiringMap<String, Cursor>( EXPIRING_TIME);/*from w w w . j a va2 s .c o m*/ resultsCache = Collections.synchronizedMap(resultsCacheExpiringMap); } return resultsCache; }
From source file:org.apache.ambari.view.hive.resources.jobs.ResultsPaginationController.java
private Map<String, Cursor> getResultsCache() { if (resultsCache == null) { PassiveExpiringMap<String, Cursor> resultsCacheExpiringMap = new PassiveExpiringMap<String, Cursor>( new CustomTimeToLiveExpirationPolicy(EXPIRING_TIME)); resultsCache = Collections.synchronizedMap(resultsCacheExpiringMap); }//from w w w .j a v a2 s . com return resultsCache; }
From source file:org.apache.ambari.view.utils.ambari.RemoteCluster.java
/** * Constructor for RemoteCluster/* w ww.jav a2 s. c o m*/ * @param ambariClusterUrl Ambari Server Cluster REST API URL (for example: http://ambari.server:8080/api/v1/clusters/c1) * @param urlStreamProvider stream provider with authorization support */ public RemoteCluster(String ambariClusterUrl, URLStreamProvider urlStreamProvider) { this.baseUrl = ambariClusterUrl; this.urlStreamProvider = urlStreamProvider; String[] parts = ambariClusterUrl.split("/"); this.name = parts[parts.length - 1]; PassiveExpiringMap<String, JSONObject> configurations = new PassiveExpiringMap<String, JSONObject>(10000L); // keep cache for 10 seconds configurationCache = Collections.synchronizedMap(configurations); }
From source file:org.apache.ambari.view.utils.ambari.RemoteClusterTest.java
@Test public void testGetConfigurationValue() throws Exception { URLStreamProvider urlStreamProvider = createNiceMock(URLStreamProvider.class); final String desiredConfigsString = "{\"Clusters\": {\"desired_configs\": {\"test-site\": {\"tag\": \"TAG\"}}}}"; final String configurationString = "{\"items\": [{\"properties\": {\"test.property.name\": \"test property value\"}}]}"; final int[] desiredConfigPolls = { 0 }; final int[] testConfigPolls = { 0 }; expect(urlStreamProvider.readFrom(//w ww . java 2 s .com eq(AMBARI_CLUSTER_REST_URL + "?fields=services/ServiceInfo,hosts,Clusters"), eq("GET"), (String) isNull(), (Map<String, String>) anyObject())).andAnswer(new IAnswer<InputStream>() { @Override public InputStream answer() throws Throwable { desiredConfigPolls[0] += 1; return new ByteArrayInputStream(desiredConfigsString.getBytes()); } }).anyTimes(); expect(urlStreamProvider.readFrom(eq(AMBARI_CLUSTER_REST_URL + "/configurations?(type=test-site&tag=TAG)"), eq("GET"), (String) isNull(), (Map<String, String>) anyObject())) .andAnswer(new IAnswer<InputStream>() { @Override public InputStream answer() throws Throwable { testConfigPolls[0] += 1; return new ByteArrayInputStream(configurationString.getBytes()); } }).anyTimes(); replay(urlStreamProvider); RemoteCluster cluster = new RemoteCluster(AMBARI_CLUSTER_REST_URL, urlStreamProvider); PassiveExpiringMap<String, JSONObject> cache = new PassiveExpiringMap<String, JSONObject>(10000L); cluster.configurationCache = cache; String value = cluster.getConfigurationValue("test-site", "test.property.name"); assertEquals(value, "test property value"); assertEquals(desiredConfigPolls[0], 1); assertEquals(testConfigPolls[0], 1); value = cluster.getConfigurationValue("test-site", "test.property.name"); assertEquals(value, "test property value"); assertEquals(desiredConfigPolls[0], 1); // cache hit assertEquals(testConfigPolls[0], 1); cache.clear(); value = cluster.getConfigurationValue("test-site", "test.property.name"); assertEquals(value, "test property value"); assertEquals(desiredConfigPolls[0], 2); assertEquals(testConfigPolls[0], 2); }
From source file:org.apache.james.jmap.memory.access.MemoryAccessTokenRepository.java
@Inject public MemoryAccessTokenRepository(@Named(TOKEN_EXPIRATION_IN_MS) long durationInMilliseconds) { tokensExpirationDates = new PassiveExpiringMap<>(durationInMilliseconds); }
From source file:org.mitre.ptmatchadapter.service.ServerAuthorizationService.java
public final void setSessionData(Map<String, Object> map) { if (map == null) { sessionData = new PassiveExpiringMap<String, Object>(ENTRY_EXPIRATION_TIME); } else {/*from w w w . j a va 2 s. c o m*/ sessionData = new PassiveExpiringMap<String, Object>(ENTRY_EXPIRATION_TIME, map); } }