当前位置: 首页>>代码示例>>Java>>正文


Java Duration类代码示例

本文整理汇总了Java中com.thinkaurelius.titan.core.attribute.Duration的典型用法代码示例。如果您正苦于以下问题:Java Duration类的具体用法?Java Duration怎么用?Java Duration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Duration类属于com.thinkaurelius.titan.core.attribute包,在下文中一共展示了Duration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: configTest

import com.thinkaurelius.titan.core.attribute.Duration; //导入依赖的package包/类
@Test
public void configTest() {
    config.set("test.key","world");
    config.set("test.bar", 100);
    // This does not actually work with KCVSConfiguration, but Titan doesn't need it anyway
    //config.set("test.baz", BigInteger.ONE);
    config.set("storage.xyz", true);
    config.set("storage.abc", Boolean.FALSE);
    config.set("storage.duba", new String[]{"x", "y"});
    config.set("enum", Thread.State.RUNNABLE);
    config.set("times.60m", new StandardDuration(60, TimeUnit.MINUTES));
    config.set("obj", new Object()); // necessary for AbstractConfiguration.getSubset
    assertEquals("world", config.get("test.key", String.class));
    assertEquals(ImmutableSet.of("test.key", "test.bar"), Sets.newHashSet(config.getKeys("test")));
    //assertEquals(ImmutableSet.of("test.key", "test.bar", "test.baz"), Sets.newHashSet(config.getKeys("test")));
    assertEquals(ImmutableSet.of("storage.xyz", "storage.duba", "storage.abc"),Sets.newHashSet(config.getKeys("storage")));
    assertEquals(100,config.get("test.bar",Integer.class).intValue());
    //assertEquals(1,config.get("test.baz",Integer.class).intValue());
    assertEquals(true,config.get("storage.xyz",Boolean.class).booleanValue());
    assertEquals(false,config.get("storage.abc",Boolean.class).booleanValue());
    assertTrue(Arrays.equals(new String[]{"x", "y"},config.get("storage.duba",String[].class)));
    assertEquals(Thread.State.RUNNABLE, config.get("enum", Thread.State.class));
    assertEquals(new StandardDuration(60, TimeUnit.MINUTES), config.get("times.60m", Duration.class));
    assertTrue(Object.class.isAssignableFrom(config.get("obj", Object.class).getClass()));
}
 
开发者ID:graben1437,项目名称:titan0.5.4-hbase1.1.1-custom,代码行数:26,代码来源:WritableConfigurationTest.java

示例2: getIDBlock

import com.thinkaurelius.titan.core.attribute.Duration; //导入依赖的package包/类
@Override
public IDBlock getIDBlock(final int partition, final int idNamespace, Duration timeout) throws BackendException {
    //Delay artificially
    if (delayAcquisitionMS>0) {
        try {
            Thread.sleep(delayAcquisitionMS);
        } catch (InterruptedException e) {
            throw new TemporaryBackendException(e);
        }
    }
    Preconditions.checkArgument(partition>=0 && partition<=Integer.MAX_VALUE);
    Preconditions.checkArgument(idNamespace>=0 && idNamespace<=Integer.MAX_VALUE);
    Long p = (((long)partition)<<Integer.SIZE) + ((long)idNamespace);
    long size = blockSizer.getBlockSize(idNamespace);
    AtomicLong id = ids.get(p);
    if (id == null) {
        ids.putIfAbsent(p, new AtomicLong(1));
        id = ids.get(p);
        Preconditions.checkNotNull(id);
    }
    long lowerBound = id.getAndAdd(size);
    if (lowerBound >= blockSizeLimit) {
        throw new IDPoolExhaustedException("Reached partition limit: " + blockSizeLimit);
    }
    return new MockIDBlock(lowerBound,Math.min(size,blockSizeLimit-lowerBound));
}
 
开发者ID:graben1437,项目名称:titan0.5.4-hbase1.1.1-custom,代码行数:27,代码来源:MockIDAuthority.java

示例3: simpleWriteAndQuery

import com.thinkaurelius.titan.core.attribute.Duration; //导入依赖的package包/类
private void simpleWriteAndQuery(IndexProvider idx) throws BackendException, InterruptedException {

        final Duration maxWrite = new StandardDuration(2000L, TimeUnit.MILLISECONDS);
        final String storeName = "jvmlocal_test_store";
        final KeyInformation.IndexRetriever indexRetriever = IndexProviderTest.getIndexRetriever(IndexProviderTest.getMapping(idx.getFeatures()));

        BaseTransactionConfig txConfig = StandardBaseTransactionConfig.of(Timestamps.MILLI);
        IndexTransaction itx = new IndexTransaction(idx, indexRetriever, txConfig, maxWrite);
        assertEquals(0, itx.query(new IndexQuery(storeName, PredicateCondition.of(IndexProviderTest.NAME, Text.PREFIX, "ali"))).size());
        itx.add(storeName, "doc", IndexProviderTest.NAME, "alice", false);
        itx.commit();
        Thread.sleep(1500L); // Slightly longer than default 1s index.refresh_interval
        itx = new IndexTransaction(idx, indexRetriever, txConfig, maxWrite);
        assertEquals(0, itx.query(new IndexQuery(storeName, PredicateCondition.of(IndexProviderTest.NAME, Text.PREFIX, "zed"))).size());
        assertEquals(1, itx.query(new IndexQuery(storeName, PredicateCondition.of(IndexProviderTest.NAME, Text.PREFIX, "ali"))).size());
        itx.rollback();
    }
 
开发者ID:graben1437,项目名称:titan0.5.4-hbase1.1.1-custom,代码行数:18,代码来源:ElasticSearchConfigTest.java

示例4: set

import com.thinkaurelius.titan.core.attribute.Duration; //导入依赖的package包/类
@Override
public <O> void set(String key, O value) {

    final String internalKey = getInternalKey(key);

    Class<?> datatype = value.getClass();

    if (datatype.isArray()) {
        Preconditions.checkArgument(datatype.getComponentType()==String.class,"Only string arrays are supported: %s",datatype);
        config.setStrings(internalKey, (String[])value);
    } else if (Number.class.isAssignableFrom(datatype)) {
        config.set(internalKey, value.toString());
    } else if (datatype==String.class) {
        config.set(internalKey, value.toString());
    } else if (datatype==Boolean.class) {
        config.setBoolean(internalKey, (Boolean)value);
    } else if (datatype.isEnum()) {
        config.set(internalKey, value.toString());
    } else if (datatype==Object.class) {
        config.set(internalKey, value.toString());
    } else if (Duration.class.isAssignableFrom(datatype)) {
        // This is a conceptual leak; the config layer should ideally only handle standard library types
        String millis = String.valueOf(((Duration)value).getLength(TimeUnit.MILLISECONDS));
        config.set(internalKey, millis);
    } else throw new IllegalArgumentException("Unsupported data type: " + datatype);
}
 
开发者ID:graben1437,项目名称:titan0.5.4-hbase1.1.1-custom,代码行数:27,代码来源:HadoopConfiguration.java

示例5: timeSinceFirstMsg

import com.thinkaurelius.titan.core.attribute.Duration; //导入依赖的package包/类
private Duration timeSinceFirstMsg() {

            Duration sinceFirst =  ZeroDuration.INSTANCE;

            if (!toSend.isEmpty()) {
                Timepoint firstTimestamp = toSend.get(0).message.getMessage().getTimestampMicro();
                Timepoint nowTimestamp   = times.getTime();

                if (firstTimestamp.compareTo(nowTimestamp) < 0) {
                    long firstRaw = firstTimestamp.getTimestamp(times.getUnit());
                    long nowRaw = nowTimestamp.getTimestamp(times.getUnit());
                    assert firstRaw < nowRaw;
                    sinceFirst = new StandardDuration(nowRaw - firstRaw, times.getUnit());
                }
            }

            return sinceFirst;
        }
 
开发者ID:graben1437,项目名称:titan0.5.4-hbase1.1.1-custom,代码行数:19,代码来源:KCVSLog.java

示例6: testExpiration

import com.thinkaurelius.titan.core.attribute.Duration; //导入依赖的package包/类
private void testExpiration(Duration expirationTime) throws Exception {
    final int numKeys = 100, numCols = 10;
    loadStore(numKeys,numCols);
    //Replace cache with proper times
    cache = getCache(store,expirationTime,ZeroDuration.INSTANCE);

    StaticBuffer key = BufferUtil.getIntBuffer(81);
    List<StaticBuffer> keys = new ArrayList<StaticBuffer>();
    keys.add(key);
    keys.add(BufferUtil.getIntBuffer(37));
    keys.add(BufferUtil.getIntBuffer(2));
    SliceQuery query = getQuery(2,8);

    verifyResults(key,keys,query,6);
    //Modify store directly
    StoreTransaction txs = getStoreTx();
    store.mutate(key,KeyColumnValueStore.NO_ADDITIONS, Lists.newArrayList(BufferUtil.getIntBuffer(5)),txs);
    txs.commit();
    Timepoint utime = times.getTime();

    //Should still see cached results
    verifyResults(key,keys,query,6);
    times.sleepPast(utime.add(expirationTime.multiply(0.5))); //Sleep half way through expiration time
    verifyResults(key, keys, query, 6);
    times.sleepPast(utime.add(expirationTime)); //Sleep past expiration time...
    times.sleepFor(new StandardDuration(5,TimeUnit.MILLISECONDS)); //...and just a little bit longer
    //Now the results should be different
    verifyResults(key, keys, query, 5);
    //If we modify through cache store...
    CacheTransaction tx = getCacheTx();
    cache.mutateEntries(key, KeyColumnValueStore.NO_ADDITIONS, Lists.newArrayList(getEntry(4, 4)), tx);
    tx.commit();
    store.resetCounter();
    //...invalidation should happen and the result set is updated immediately
    verifyResults(key, keys, query, 4);
}
 
开发者ID:graben1437,项目名称:titan0.5.4-hbase1.1.1-custom,代码行数:37,代码来源:ExpirationCacheTest.java

示例7: CacheTransaction

import com.thinkaurelius.titan.core.attribute.Duration; //导入依赖的package包/类
public CacheTransaction(StoreTransaction tx, KeyColumnValueStoreManager manager, int persistChunkSize,
                        Duration maxWriteTime, boolean batchLoading, int expectedNumStores) {
    Preconditions.checkArgument(tx != null && manager != null && persistChunkSize > 0);
    this.tx = tx;
    this.manager = manager;
    this.batchLoading = batchLoading;
    this.numMutations = 0;
    this.persistChunkSize = persistChunkSize;
    this.maxWriteTime = maxWriteTime;
    this.mutations = new HashMap<KCVSCache, Map<StaticBuffer, KCVEntryMutation>>(expectedNumStores);
}
 
开发者ID:graben1437,项目名称:titan0.5.4-hbase1.1.1-custom,代码行数:12,代码来源:CacheTransaction.java

示例8: IndexTransaction

import com.thinkaurelius.titan.core.attribute.Duration; //导入依赖的package包/类
public IndexTransaction(final IndexProvider index, final KeyInformation.IndexRetriever keyInformations,
                        BaseTransactionConfig config,
                        Duration maxWriteTime) throws BackendException {
    Preconditions.checkNotNull(index);
    Preconditions.checkNotNull(keyInformations);
    this.index=index;
    this.keyInformations = keyInformations;
    this.indexTx=index.beginTransaction(config);
    Preconditions.checkNotNull(indexTx);
    this.maxWriteTime = maxWriteTime;
    this.mutations = new HashMap<String,Map<String,IndexMutation>>(DEFAULT_OUTER_MAP_SIZE);
}
 
开发者ID:graben1437,项目名称:titan0.5.4-hbase1.1.1-custom,代码行数:13,代码来源:IndexTransaction.java

示例9: maxWaitTime

import com.thinkaurelius.titan.core.attribute.Duration; //导入依赖的package包/类
private Duration maxWaitTime() {
    if (!toSend.isEmpty()) {
        return maxSendDelay.sub(timeSinceFirstMsg());
    }

    return FOREVER;
}
 
开发者ID:graben1437,项目名称:titan0.5.4-hbase1.1.1-custom,代码行数:8,代码来源:KCVSLog.java

示例10: BackendTransaction

import com.thinkaurelius.titan.core.attribute.Duration; //导入依赖的package包/类
public BackendTransaction(CacheTransaction storeTx, BaseTransactionConfig txConfig,
                          StoreFeatures features, KCVSCache edgeStore, KCVSCache indexStore,
                          KCVSCache txLogStore, Duration maxReadTime,
                          Map<String, IndexTransaction> indexTx, Executor threadPool) {
    this.storeTx = storeTx;
    this.txConfig = txConfig;
    this.storeFeatures = features;
    this.edgeStore = edgeStore;
    this.indexStore = indexStore;
    this.txLogStore = txLogStore;
    this.maxReadTime = maxReadTime;
    this.indexTx = indexTx;
    this.threadPool = threadPool;
}
 
开发者ID:graben1437,项目名称:titan0.5.4-hbase1.1.1-custom,代码行数:15,代码来源:BackendTransaction.java

示例11: sleepAndConvertInterrupts

import com.thinkaurelius.titan.core.attribute.Duration; //导入依赖的package包/类
private void sleepAndConvertInterrupts(Duration d) throws BackendException {
    try {
        times.sleepPast(times.getTime().add(d));
    } catch (InterruptedException e) {
        throw new PermanentBackendException(e);
    }
}
 
开发者ID:graben1437,项目名称:titan0.5.4-hbase1.1.1-custom,代码行数:8,代码来源:ConsistentKeyIDAuthority.java

示例12: ConsistentKeyLocker

import com.thinkaurelius.titan.core.attribute.Duration; //导入依赖的package包/类
/**
 * Create a new locker.
 *
 */
private ConsistentKeyLocker(KeyColumnValueStore store, StoreManager manager, StaticBuffer rid,
                            TimestampProvider times, ConsistentKeyLockerSerializer serializer,
                            LocalLockMediator<StoreTransaction> llm, Duration lockWait,
                            int lockRetryCount, Duration lockExpire,
                            LockerState<ConsistentKeyLockStatus> lockState,
                            LockCleanerService cleanerService) {
    super(rid, times, serializer, llm, lockState, lockExpire, log);
    this.store = store;
    this.manager = manager;
    this.lockWait = lockWait;
    this.lockRetryCount = lockRetryCount;
    this.cleanerService = cleanerService;
}
 
开发者ID:graben1437,项目名称:titan0.5.4-hbase1.1.1-custom,代码行数:18,代码来源:ConsistentKeyLocker.java

示例13: ExpectedValueCheckingStoreManager

import com.thinkaurelius.titan.core.attribute.Duration; //导入依赖的package包/类
public ExpectedValueCheckingStoreManager(KeyColumnValueStoreManager storeManager, String lockStoreSuffix,
                                         LockerProvider lockerProvider, Duration maxReadTime) {
    super(storeManager);
    this.lockStoreSuffix = lockStoreSuffix;
    this.lockerProvider = lockerProvider;
    this.maxReadTime = maxReadTime;
    this.storeFeatures = new StandardStoreFeatures.Builder(storeManager.getFeatures()).locking(true).build();
    this.stores = new HashMap<String,ExpectedValueCheckingStore>(6);
}
 
开发者ID:graben1437,项目名称:titan0.5.4-hbase1.1.1-custom,代码行数:10,代码来源:ExpectedValueCheckingStoreManager.java

示例14: AbstractLocker

import com.thinkaurelius.titan.core.attribute.Duration; //导入依赖的package包/类
public AbstractLocker(StaticBuffer rid, TimestampProvider times,
        ConsistentKeyLockerSerializer serializer,
        LocalLockMediator<StoreTransaction> llm, LockerState<S> lockState,
        Duration lockExpire, Logger log) {
    this.rid = rid;
    this.times = times;
    this.timeUnit = times.getUnit();
    this.serializer = serializer;
    this.llm = llm;
    this.lockState = lockState;
    this.lockExpire = lockExpire;
    this.log = log;
}
 
开发者ID:graben1437,项目名称:titan0.5.4-hbase1.1.1-custom,代码行数:14,代码来源:AbstractLocker.java

示例15: sub

import com.thinkaurelius.titan.core.attribute.Duration; //导入依赖的package包/类
@Override
public Duration sub(Duration subtrahend) {
    long result = getLength(unit) - subtrahend.getLength(unit);
    if (0 > result) {
        result = 0;
    }
    return new StandardDuration(result, unit);
}
 
开发者ID:graben1437,项目名称:titan0.5.4-hbase1.1.1-custom,代码行数:9,代码来源:StandardDuration.java


注:本文中的com.thinkaurelius.titan.core.attribute.Duration类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。