Example usage for java.util.concurrent.atomic AtomicReferenceArray AtomicReferenceArray

List of usage examples for java.util.concurrent.atomic AtomicReferenceArray AtomicReferenceArray

Introduction

In this page you can find the example usage for java.util.concurrent.atomic AtomicReferenceArray AtomicReferenceArray.

Prototype

public AtomicReferenceArray(E[] array) 

Source Link

Document

Creates a new AtomicReferenceArray with the same length as, and all elements copied from, the given array.

Usage

From source file:com.couchbase.client.dcp.state.SessionState.java

/**
 * Initializes with an empty partition state for 1024 partitions.
 *//* w  ww .  j a  va  2s.c om*/
public SessionState() {
    this.partitionStates = new AtomicReferenceArray<PartitionState>(MAX_PARTITIONS);
}

From source file:com.flowpowered.commons.StringToUniqueIntegerMap.java

/**
 * @param parent the parent of this map/*from  ww  w.  ja  v  a  2s  .c o  m*/
 * @param store the store to store ids
 * @param minId the lowest valid id for dynamic allocation (ids below this are assumed to be reserved)
 * @param maxId the highest valid id + 1
 * @param name The name of this StringToUniqueIntegerMap
 */
public StringToUniqueIntegerMap(StringToUniqueIntegerMap parent, SimpleStore<Integer> store, int minId,
        int maxId, String name) {
    super(store, name);
    this.parent = parent;
    if (this.parent != null) {
        thisToParentMap = new AtomicReferenceArray<>(maxId);
        parentToThisMap = new AtomicReferenceArray<>(maxId);
    } else {
        thisToParentMap = null;
        parentToThisMap = null;
    }
    this.minId = minId;
    this.maxId = maxId;
    nextId = new AtomicInteger(minId);
}

From source file:org.apache.bookkeeper.bookie.EntryLogManagerForEntryLogPerLedger.java

EntryLogManagerForEntryLogPerLedger(ServerConfiguration conf, LedgerDirsManager ledgerDirsManager,
        EntryLoggerAllocator entryLoggerAllocator, List<EntryLogger.EntryLogListener> listeners,
        EntryLogger.RecentEntryLogsStatus recentlyCreatedEntryLogsStatus, StatsLogger statsLogger)
        throws IOException {
    super(conf, ledgerDirsManager, entryLoggerAllocator, listeners);
    this.recentlyCreatedEntryLogsStatus = recentlyCreatedEntryLogsStatus;
    this.rotatedLogChannels = new CopyOnWriteArrayList<BufferedLogChannel>();
    this.replicaOfCurrentLogChannels = new ConcurrentLongHashMap<BufferedLogChannelWithDirInfo>();
    this.entrylogMapAccessExpiryTimeInSeconds = conf.getEntrylogMapAccessExpiryTimeInSeconds();
    this.maximumNumberOfActiveEntryLogs = conf.getMaximumNumberOfActiveEntryLogs();
    this.entryLogPerLedgerCounterLimitsMultFactor = conf.getEntryLogPerLedgerCounterLimitsMultFactor();

    ledgerDirsManager.addLedgerDirsListener(getLedgerDirsListener());
    this.lockArrayPool = new AtomicReferenceArray<Lock>(maximumNumberOfActiveEntryLogs * 2);
    this.entryLogAndLockTupleCacheLoader = new CacheLoader<Long, EntryLogAndLockTuple>() {
        @Override//w  w w .j a  v a2 s .  c  om
        public EntryLogAndLockTuple load(Long key) throws Exception {
            return new EntryLogAndLockTuple(key);
        }
    };
    /*
     * Currently we are relying on access time based eviction policy for
     * removal of EntryLogAndLockTuple, so if the EntryLogAndLockTuple of
     * the ledger is not accessed in
     * entrylogMapAccessExpiryTimeInSeconds period, it will be removed
     * from the cache.
     *
     * We are going to introduce explicit advisory writeClose call, with
     * that explicit call EntryLogAndLockTuple of the ledger will be
     * removed from the cache. But still timebased eviciton policy is
     * needed because it is not guaranteed that Bookie/EntryLogger would
     * receive successfully write close call in all the cases.
     */
    ledgerIdEntryLogMap = CacheBuilder.newBuilder()
            .expireAfterAccess(entrylogMapAccessExpiryTimeInSeconds, TimeUnit.SECONDS)
            .maximumSize(maximumNumberOfActiveEntryLogs)
            .removalListener(new RemovalListener<Long, EntryLogAndLockTuple>() {
                @Override
                public void onRemoval(
                        RemovalNotification<Long, EntryLogAndLockTuple> expiredLedgerEntryLogMapEntry) {
                    onCacheEntryRemoval(expiredLedgerEntryLogMapEntry);
                }
            }).build(entryLogAndLockTupleCacheLoader);

    this.statsLogger = statsLogger;
    this.entryLogsPerLedgerCounter = new EntryLogsPerLedgerCounter(this.statsLogger);
}

From source file:org.apache.flume.channel.file.Log.java

private Log(long checkpointInterval, long maxFileSize, int queueCapacity, int logWriteTimeout,
        int checkpointWriteTimeout, boolean useDualCheckpoints, File checkpointDir, File backupCheckpointDir,
        String name, boolean useLogReplayV1, boolean useFastReplay, long minimumRequiredSpace,
        @Nullable KeyProvider encryptionKeyProvider, @Nullable String encryptionKeyAlias,
        @Nullable String encryptionCipherProvider, long usableSpaceRefreshInterval, File... logDirs)
        throws IOException {
    Preconditions.checkArgument(checkpointInterval > 0, "checkpointInterval <= 0");
    Preconditions.checkArgument(queueCapacity > 0, "queueCapacity <= 0");
    Preconditions.checkArgument(maxFileSize > 0, "maxFileSize <= 0");
    Preconditions.checkNotNull(checkpointDir, "checkpointDir");
    Preconditions.checkArgument(usableSpaceRefreshInterval > 0, "usableSpaceRefreshInterval <= 0");
    Preconditions.checkArgument(checkpointDir.isDirectory() || checkpointDir.mkdirs(),
            "CheckpointDir " + checkpointDir + " could not be created");
    if (useDualCheckpoints) {
        Preconditions.checkNotNull(backupCheckpointDir,
                "backupCheckpointDir is" + " null while dual checkpointing is enabled.");
        Preconditions.checkArgument(backupCheckpointDir.isDirectory() || backupCheckpointDir.mkdirs(),
                "Backup CheckpointDir " + backupCheckpointDir + " could not be created");
    }//www  . j  a v  a  2 s. com
    Preconditions.checkNotNull(logDirs, "logDirs");
    Preconditions.checkArgument(logDirs.length > 0, "logDirs empty");
    Preconditions.checkArgument(name != null && !name.trim().isEmpty(), "channel name should be specified");

    this.channelNameDescriptor = "[channel=" + name + "]";
    this.useLogReplayV1 = useLogReplayV1;
    this.useFastReplay = useFastReplay;
    this.minimumRequiredSpace = minimumRequiredSpace;
    this.usableSpaceRefreshInterval = usableSpaceRefreshInterval;
    for (File logDir : logDirs) {
        Preconditions.checkArgument(logDir.isDirectory() || logDir.mkdirs(),
                "LogDir " + logDir + " could not be created");
    }
    locks = Maps.newHashMap();
    try {
        lock(checkpointDir);
        if (useDualCheckpoints) {
            lock(backupCheckpointDir);
        }
        for (File logDir : logDirs) {
            lock(logDir);
        }
    } catch (IOException e) {
        unlock(checkpointDir);
        for (File logDir : logDirs) {
            unlock(logDir);
        }
        throw e;
    }
    if (encryptionKeyProvider != null && encryptionKeyAlias != null && encryptionCipherProvider != null) {
        LOGGER.info("Encryption is enabled with encryptionKeyProvider = " + encryptionKeyProvider
                + ", encryptionKeyAlias = " + encryptionKeyAlias + ", encryptionCipherProvider = "
                + encryptionCipherProvider);
        this.encryptionKeyProvider = encryptionKeyProvider;
        this.encryptionKeyAlias = encryptionKeyAlias;
        this.encryptionCipherProvider = encryptionCipherProvider;
        this.encryptionKey = encryptionKeyProvider.getKey(encryptionKeyAlias);
    } else if (encryptionKeyProvider == null && encryptionKeyAlias == null
            && encryptionCipherProvider == null) {
        LOGGER.info("Encryption is not enabled");
    } else {
        throw new IllegalArgumentException(
                "Encryption configuration must all " + "null or all not null: encryptionKeyProvider = "
                        + encryptionKeyProvider + ", encryptionKeyAlias = " + encryptionKeyAlias
                        + ", encryptionCipherProvider = " + encryptionCipherProvider);
    }
    open = false;
    this.checkpointInterval = Math.max(checkpointInterval, 1000);
    this.maxFileSize = maxFileSize;
    this.queueCapacity = queueCapacity;
    this.useDualCheckpoints = useDualCheckpoints;
    this.checkpointDir = checkpointDir;
    this.backupCheckpointDir = backupCheckpointDir;
    this.logDirs = logDirs;
    this.logWriteTimeout = logWriteTimeout;
    this.checkpointWriteTimeout = checkpointWriteTimeout;
    logFiles = new AtomicReferenceArray<LogFile.Writer>(this.logDirs.length);
    workerExecutor = Executors.newSingleThreadScheduledExecutor(
            new ThreadFactoryBuilder().setNameFormat("Log-BackgroundWorker-" + name).build());
    workerExecutor.scheduleWithFixedDelay(new BackgroundWorker(this), this.checkpointInterval,
            this.checkpointInterval, TimeUnit.MILLISECONDS);
}