Example usage for com.google.common.collect MapMaker MapMaker

List of usage examples for com.google.common.collect MapMaker MapMaker

Introduction

In this page you can find the example usage for com.google.common.collect MapMaker MapMaker.

Prototype

public MapMaker() 

Source Link

Usage

From source file:com.voxelplugineering.voxelsniper.bukkit.world.BukkitWorld.java

/**
 * Creates a new {@link BukkitWorld}./*from  ww w. j av  a2 s. com*/
 * 
 * @param world the world
 * @param thread The world Thread
 */
@SuppressWarnings("unchecked")
public BukkitWorld(Context context, org.bukkit.World world, Thread thread) {
    super(context, world);
    this.materials = context.getRequired(MaterialRegistry.class);
    this.worldReg = context.getRequired(WorldRegistry.class);
    this.biomes = context.getRequired(BiomeRegistry.class);
    this.chunks = new MapMaker().weakKeys().makeMap();
    this.entitiesCache = new MapMaker().weakKeys().makeMap();
    this.worldThread = thread;
}

From source file:lombok.ast.grammar.Source.java

public void clear() {
    nodes = Lists.newArrayList();//from   ww w. j a v a  2  s .c  o m
    problems = Lists.newArrayList();
    comments = Lists.newArrayList();
    lineEndings = ImmutableList.of();
    parsed = false;
    parsingResult = null;
    positionDeltas = Maps.newTreeMap();
    registeredComments = new MapMaker().weakKeys().makeMap();
    registeredStructures = new MapMaker().weakKeys().makeMap();
    cachedSourceStructures = null;
}

From source file:com.alibaba.otter.manager.biz.common.arbitrate.ArbitrateConfigImpl.java

public void afterPropertiesSet() throws Exception {
    // ?nid??/*  w  w w  .j  a  v  a2s.co  m*/
    channelMapping = new MapMaker().makeComputingMap(new Function<Long, Long>() {

        public Long apply(Long pipelineId) {
            // ?pipline -> channel?
            Channel channel = channelService.findByPipelineId(pipelineId);
            if (channel == null) {
                throw new ConfigException("No Such Channel by pipelineId[" + pipelineId + "]");
            }

            updateMapping(channel, pipelineId);// 
            channelCache.put(channel.getId(), channel);// channelCache
            return channel.getId();

        }
    });

    channelCache = new RefreshMemoryMirror<Long, Channel>(timeout, new ComputeFunction<Long, Channel>() {

        public Channel apply(Long key, Channel oldValue) {
            Channel channel = channelService.findById(key);
            if (channel == null) {
                // 
                return oldValue;
            } else {
                updateMapping(channel, null);// 
                return channel;
            }
        }
    });

    nodeCache = new RefreshMemoryMirror<Long, Node>(timeout, new ComputeFunction<Long, Node>() {

        public Node apply(Long key, Node oldValue) {
            Node node = nodeService.findById(key);
            if (node == null) {
                return oldValue;
            } else {
                return node;
            }
        }
    });
}

From source file:io.warp10.standalone.StandaloneChunkedMemoryStore.java

public StandaloneChunkedMemoryStore(Properties properties, KeyStore keystore) {
    this.properties = properties;

    this.series = new MapMaker().concurrencyLevel(64).makeMap();

    this.chunkcount = Integer
            .parseInt(properties.getProperty(io.warp10.continuum.Configuration.IN_MEMORY_CHUNK_COUNT, "3"));
    this.chunkspan = Long.parseLong(properties.getProperty(
            io.warp10.continuum.Configuration.IN_MEMORY_CHUNK_LENGTH, Long.toString(Long.MAX_VALUE)));

    this.labelsKeyLongs = SipHashInline.getKey(keystore.getKey(KeyStore.SIPHASH_LABELS));
    this.classKeyLongs = SipHashInline.getKey(keystore.getKey(KeyStore.SIPHASH_CLASS));

    ////  w w  w  .jav  a2s . co  m
    // Add a shutdown hook to dump the memory store on exit
    //

    if (null != properties.getProperty(io.warp10.continuum.Configuration.STANDALONE_MEMORY_STORE_DUMP)) {

        final StandaloneChunkedMemoryStore self = this;
        final String path = properties
                .getProperty(io.warp10.continuum.Configuration.STANDALONE_MEMORY_STORE_DUMP);
        Thread dumphook = new Thread() {
            @Override
            public void run() {
                try {
                    self.dump(path);
                } catch (IOException ioe) {
                    ioe.printStackTrace();
                    throw new RuntimeException(ioe);
                }
            }
        };

        Runtime.getRuntime().addShutdownHook(dumphook);

        //
        // Make sure ShutdownHookManager is initialized, otherwise it will try to
        // register a shutdown hook during the shutdown hook we just registered...
        //

        ShutdownHookManager.get();
    }

    this.setDaemon(true);
    this.setName("[StandaloneChunkedMemoryStore Janitor]");
    this.setPriority(Thread.MIN_PRIORITY);
    this.start();
}

From source file:quickutils.core.image.cache.AbstractCache.java

/**
 * Creates a new cache instance./* w ww.  java2  s .  co  m*/
 * 
 * @param name
 *            a human readable identifier for this cache. Note that this value will be used to
 *            derive a directory name if the disk cache is enabled, so don't get too creative
 *            here (camel case names work great)
 * @param initialCapacity
 *            the initial element size of the cache
 * @param expirationInMinutes
 *            time in minutes after which elements will be purged from the cache
 * @param maxConcurrentThreads
 *            how many threads you think may at once access the cache; this need not be an exact
 *            number, but it helps in fragmenting the cache properly
 */
public AbstractCache(String name, int initialCapacity, long expirationInMinutes, int maxConcurrentThreads) {

    this.name = name;
    this.expirationInMinutes = expirationInMinutes;

    MapMaker mapMaker = new MapMaker();
    mapMaker.initialCapacity(initialCapacity);
    mapMaker.expiration(expirationInMinutes * 60, TimeUnit.SECONDS);
    mapMaker.concurrencyLevel(maxConcurrentThreads);
    mapMaker.softValues();
    this.cache = mapMaker.makeMap();
}

From source file:io.s4.core.ProcessingElement.java

/**
 * Set expiration. PE instances will be automatically removed once a fixed
 * duration has passed since the PE's last read or write access.
 * //from   w w  w .jav a 2  s. c  o  m
 * All existing PE instance will destroyed!
 * 
 * 
 * @param duration
 *            the fixed duration
 * @param timeUnit
 *            the time unit
 */
public void setExpiration(long duration, TimeUnit timeUnit) {

    if (!isPrototype)
        return;

    peInstances = new MapMaker().expireAfterAccess(duration, timeUnit).makeMap();
}

From source file:com.datastax.driver.core.PerHostPercentileTracker.java

private PerHostPercentileTracker(long highestTrackableLatencyMillis, int numberOfSignificantValueDigits,
        int numberOfHosts, int minRecordedValues, long intervalMs) {
    this.highestTrackableLatencyMillis = highestTrackableLatencyMillis;
    this.numberOfSignificantValueDigits = numberOfSignificantValueDigits;
    this.minRecordedValues = minRecordedValues;
    this.intervalMs = intervalMs;
    this.recorders = new MapMaker().initialCapacity(numberOfHosts).makeMap();
    this.cachedHistograms = new MapMaker().initialCapacity(numberOfHosts).makeMap();
}

From source file:com.bigfatgun.fixjures.FixtureFactory.java

/**
 * Creates a new fixture factory and initializes the fixture object compute map.
 *
 * @param sourceFactory source factory/*ww w. j a v  a2  s.c  om*/
 */
private FixtureFactory(final SourceFactory sourceFactory) {
    assert sourceFactory != null : "Source factory cannot be null.";

    srcFactory = sourceFactory;
    options = EnumSet.noneOf(Fixjure.Option.class);
    handlers = Sets.newHashSet();

    objectCache = new MapMaker().makeComputingMap(new Function<Class<?>, ConcurrentMap<String, Object>>() {
        public ConcurrentMap<String, Object> apply(final Class<?> type) {
            checkNotNull(type);

            return new MapMaker().softValues().makeComputingMap(new Function<String, Object>() {
                public Object apply(final String name) {
                    checkNotNull(name);

                    Fixjure.SourcedFixtureBuilder<?> fixtureBuilder = Fixjure.of(type)
                            .from(srcFactory.newInstance(type, name)).withOptions(ImmutableSet.copyOf(options));
                    for (final Unmarshaller<?> handler : handlers) {
                        fixtureBuilder = fixtureBuilder.with(handler);
                    }
                    fixtureBuilder = fixtureBuilder.resolveIdsWith(FixtureFactory.this);
                    return fixtureBuilder.create();
                }
            });
        }
    });
}

From source file:com.quinsoft.zeidon.standardoe.ObjectInstance.java

ObjectInstance(TaskImpl task, LodDef lodDef) {
    this.task = task;
    this.lodDef = lodDef;
    id = task.getObjectEngine().getNextObjectKey();
    uuid = task.getObjectEngine().generateUuid();
    versionedInstances = new AtomicInteger(0);
    attributeHashkeyMap = new AttributeHashKeyMap(this);

    if (lodDef.hasPhysicalMappings())
        referringViewCursors = new MapMaker().concurrencyLevel(2).weakKeys().makeMap();
    else/*from   w  w  w. ja v  a 2 s.co  m*/
        referringViewCursors = null;
}

From source file:com.mgmtp.jfunk.common.util.ExtendedProperties.java

/**
 * Creates an empty instance.
 */
public ExtendedProperties() {
    propsMap = new MapMaker().makeMap();
}