Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.undertow.server.handlers.cache;
import static io.undertow.server.handlers.cache.LimitedBufferSlicePool.PooledByteBuffer;
import java.nio.ByteBuffer;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import java.util.concurrent.ConcurrentHashMap;
import io.undertow.UndertowLogger;
import io.undertow.util.ConcurrentDirectDeque;
import org.xnio.BufferAllocator;
/**
* A non-blocking buffer cache where entries are indexed by a path and are made up of a
* subsequence of blocks in a fixed large direct buffer. An ideal application is
* a file system cache, where the path corresponds to a file location.
*
*
To reduce contention, entry allocation and eviction execute in a sampling
* fashion (entry hits modulo N). Eviction follows an LRU approach (oldest sampled
* entries are removed first) when the cache is out of capacity
*
*
In order to expedite reclamation, cache entries are reference counted as
* opposed to garbage collected.
*
* @author Jason T. Greene
*/
public class DirectBufferCache {
private static final int SAMPLE_INTERVAL = 5;
/**
* Max age 0, indicating that entries expire upon creation and are not retained;
*/
public static final int MAX_AGE_NO_CACHING = 0;
/**
* Mage age -1, entries dont expire
*/
public static final int MAX_AGE_NO_EXPIRY = -1;
private final LimitedBufferSlicePool pool;
private final ConcurrentMap