public IndexTransaction openTx() throws BackendException { BaseTransactionConfig config = StandardBaseTransactionConfig.of(Timestamps.MILLI); return new IndexTransaction(index, indexRetriever, config, new StandardDuration(2000L, TimeUnit.MILLISECONDS)); }
@Override public Duration sub(Duration subtrahend) { long result = getLength(unit) - subtrahend.getLength(unit); if (0 > result) { result = 0; } return new StandardDuration(result, unit); }
@Override public Duration multiply(double multiplier) { Preconditions.checkArgument(0 <= multiplier, "Time multiplier %d is negative", multiplier); if (isZeroLength() || multiplier==0) return ZeroDuration.INSTANCE; else if (multiplier==1.0) return this; double actualLength = length * multiplier; long newLength = Math.round(actualLength); if (multiplier>=1.0 && newLength < length) { //Detect overflow /* * Trying to be clever with unit conversions to avoid overflow is a * waste of effort. A duration long enough to trigger this condition * probably reflects a bug in the caller, even with a very * fine-resolution TimeUnit. For example, 2^63 microseconds is more * than 292 thousand years. */ log.warn("Duration overflow detected: {} * {} exceeds representable range of long; using Long.MAX_VALUE instead", length, multiplier); return new StandardDuration(Long.MAX_VALUE,unit); } else if (Math.abs(newLength-actualLength)/actualLength>MULTIPLY_PRECISION) { //Detect loss of precision /* We are going directly to the most precise-unit to make things easier. This could trigger a subsequent overflow, however, in practice this if conditions should only be triggered for values of around 100 days or less (days being the longest TimeUnit) which is less than 10^17 nano seconds (and hence fits into a long). */ return new StandardDuration(TimeUnit.NANOSECONDS.convert(length,unit),TimeUnit.NANOSECONDS).multiply(multiplier); } else { return new StandardDuration(newLength, unit); } }
StandardDuration customCommitTime = new StandardDuration(456L, TimeUnit.MILLISECONDS); Preconditions.checkState(true == ALLOW_STALE_CONFIG.getDefaultValue()); Preconditions.checkState(ALLOW_STALE_CONFIG.getType().equals(ConfigOption.Type.MASKABLE)); Preconditions.checkState(!customCommitTime.equals(MAX_COMMIT_TIME.getDefaultValue())); WriteConfiguration wc = getConfiguration(); wc.set(ConfigElement.getPath(ALLOW_STALE_CONFIG), false); wc.set(ConfigElement.getPath(MAX_COMMIT_TIME), customCommitTime.getLength(TimeUnit.MILLISECONDS)); try { graph = (StandardTitanGraph) TitanFactory.open(wc); wc = getConfiguration(); wc.set(ConfigElement.getPath(ALLOW_STALE_CONFIG), true); wc.set(ConfigElement.getPath(MAX_COMMIT_TIME), customCommitTime.getLength(TimeUnit.MILLISECONDS)); graph = (StandardTitanGraph) TitanFactory.open(wc); wc.set(ConfigElement.getPath(MAX_COMMIT_TIME), customCommitTime.getLength(TimeUnit.MILLISECONDS)); try { graph = (StandardTitanGraph) TitanFactory.open(wc); wc.set(ConfigElement.getPath(MAX_COMMIT_TIME), customCommitTime.getLength(TimeUnit.MILLISECONDS)); graph = (StandardTitanGraph) TitanFactory.open(wc);
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; StandardDuration other = (StandardDuration) obj; return other.getLength(unit) == length; }
public static final int getTTLSeconds(long time, TimeUnit unit) { return getTTLSeconds(new StandardDuration(time,unit)); }
@Override public Duration add(Duration addend) { return new StandardDuration(getLength(unit) + addend.getLength(unit), unit); }
@Override public Duration getTTL(final TitanSchemaType type) { Preconditions.checkArgument(type != null); int ttl; if (type instanceof VertexLabelVertex) { ttl = ((VertexLabelVertex) type).getTTL(); } else if (type instanceof RelationTypeVertex) { ttl = ((RelationTypeVertex) type).getTTL(); } else { throw new IllegalArgumentException("given type does not support TTL: " + type.getClass()); } return new StandardDuration(ttl, TimeUnit.SECONDS); }
public void newTx() throws BackendException { if (tx!=null) tx.commit(); tx = new CacheTransaction(manager.beginTransaction(getTxConfig()), manager, bufferSize, new StandardDuration(100, TimeUnit.MILLISECONDS), true); }
/** * Clears out the entire graph. This will delete ALL of the data stored in this graph and the data will NOT be * recoverable. This method is intended only for development and testing use. * * @param graph * @throws IllegalArgumentException if the graph has not been shut down * @throws com.thinkaurelius.titan.core.TitanException if clearing the storage is unsuccessful */ public static final void clear(TitanGraph graph) { Preconditions.checkNotNull(graph); Preconditions.checkArgument(graph instanceof StandardTitanGraph,"Invalid graph instance detected: %s",graph.getClass()); StandardTitanGraph g = (StandardTitanGraph)graph; Preconditions.checkArgument(!g.isOpen(),"Graph needs to be shut down before it can be cleared."); final GraphDatabaseConfiguration config = g.getConfiguration(); BackendOperation.execute(new Callable<Boolean>(){ @Override public Boolean call() throws Exception { config.getBackend().clearStorage(); return true; } @Override public String toString() { return "ClearBackend"; } },new StandardDuration(20, TimeUnit.SECONDS)); }
public static ModifiableConfiguration getBasicConfig() { ModifiableConfiguration c = GraphDatabaseConfiguration.buildConfiguration(); c.set(IDAUTHORITY_WAIT, new StandardDuration(100L, TimeUnit.MILLISECONDS)); c.set(IDS_BLOCK_SIZE,400); return c; }
throw new IllegalArgumentException("Cannot parse time duration from: " + o.toString()); return (O) new StandardDuration(Long.valueOf(comps[0]), unit);
public Duration elapsed() { if (null == start) { return ZeroDuration.INSTANCE; } final Timepoint stopTime = (null==stop? times.getTime() : stop); return new StandardDuration(stopTime.getNativeTimestamp() - start.getNativeTimestamp(), times.getUnit()); }
public void open() throws BackendException { manager = openStorageManager(); tx = new CacheTransaction(manager.beginTransaction(getTxConfig()), manager, bufferSize, new StandardDuration(100, TimeUnit.MILLISECONDS), true); store1 = new NoKCVSCache(manager.openDatabase(storeName1)); store2 = new NoKCVSCache(manager.openDatabase(storeName2)); }
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; }
futureTime = futureTime.add(new StandardDuration(1L, TimeUnit.MILLISECONDS));
@Override public LogManager openLogManager(String senderId) throws BackendException { storeManager = openStorageManager(); ModifiableConfiguration config = GraphDatabaseConfiguration.buildConfiguration(); config.set(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID,senderId); config.set(GraphDatabaseConfiguration.LOG_READ_INTERVAL, new StandardDuration(500L, TimeUnit.MILLISECONDS), LOG_NAME); return new KCVSLogManager(storeManager,config.restrictTo(LOG_NAME)); }
@Parameterized.Parameters public static Collection<Object[]> configs() { List<Object[]> configurations = new ArrayList<Object[]>(); ModifiableConfiguration c = getBasicConfig(); configurations.add(new Object[]{c.getConfiguration()}); c = getBasicConfig(); c.set(IDAUTHORITY_CAV_BITS,9); c.set(IDAUTHORITY_CAV_TAG,511); configurations.add(new Object[]{c.getConfiguration()}); c = getBasicConfig(); c.set(IDAUTHORITY_CAV_RETRIES,10); c.set(IDAUTHORITY_WAIT, new StandardDuration(10L, TimeUnit.MILLISECONDS)); c.set(IDAUTHORITY_CAV_BITS,7); //c.set(IDAUTHORITY_RANDOMIZE_UNIQUEID,true); c.set(IDAUTHORITY_CONFLICT_AVOIDANCE, ConflictAvoidanceMode.GLOBAL_AUTO); configurations.add(new Object[]{c.getConfiguration()}); return configurations; }
private Log openLog(String logManagerName, String logName) { try { ModifiableConfiguration configuration = new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS,config.copy(), BasicConfiguration.Restriction.NONE); configuration.set(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID, "reader"); configuration.set(GraphDatabaseConfiguration.LOG_READ_INTERVAL, new StandardDuration(500L, TimeUnit.MILLISECONDS), logManagerName); if (logStoreManager==null) { logStoreManager = Backend.getStorageManager(configuration); } StoreFeatures f = logStoreManager.getFeatures(); boolean part = f.isDistributed() && f.isKeyOrdered(); configuration.set(GraphDatabaseConfiguration.CLUSTER_PARTITION, part); assert logStoreManager!=null; if (!logManagers.containsKey(logManagerName)) { //Open log manager - only supports KCVSLog Configuration logConfig = configuration.restrictTo(logManagerName); Preconditions.checkArgument(logConfig.get(LOG_BACKEND).equals(LOG_BACKEND.getDefaultValue())); logManagers.put(logManagerName,new KCVSLogManager(logStoreManager,logConfig)); } assert logManagers.containsKey(logManagerName); return logManagers.get(logManagerName).openLog(logName); } catch (BackendException e) { throw new TitanException("Could not open log: "+ logName,e); } }
@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())); } }