List of usage examples for java.util.concurrent TimeUnit MICROSECONDS
TimeUnit MICROSECONDS
To view the source code for java.util.concurrent TimeUnit MICROSECONDS.
Click Source Link
From source file:com.netflix.dyno.jedis.DynoJedisPipeline.java
private void discardPipeline(boolean recordLatency) { try {//ww w.j ava2 s . c o m if (jedisPipeline != null) { long startTime = System.nanoTime() / 1000; jedisPipeline.sync(); if (recordLatency) { long duration = System.nanoTime() / 1000 - startTime; opMonitor.recordLatency(duration, TimeUnit.MICROSECONDS); } jedisPipeline = null; } } catch (Exception e) { Logger.warn(String.format("Failed to discard jedis pipeline, %s", getHostInfo()), e); } }
From source file:org.apache.geode.internal.InternalDataSerializer.java
/** * Reads a {@code TimeUnit} from a {@code DataInput}. * * @throws IOException A problem occurs while writing to {@code out} *///from w w w. j a va 2 s .c o m private static TimeUnit readTimeUnit(DataInput in) throws IOException { InternalDataSerializer.checkIn(in); byte type = in.readByte(); TimeUnit unit; switch (type) { case TIME_UNIT_NANOSECONDS: unit = TimeUnit.NANOSECONDS; break; case TIME_UNIT_MICROSECONDS: unit = TimeUnit.MICROSECONDS; break; case TIME_UNIT_MILLISECONDS: unit = TimeUnit.MILLISECONDS; break; case TIME_UNIT_SECONDS: unit = TimeUnit.SECONDS; break; default: throw new IOException(LocalizedStrings.DataSerializer_UNKNOWN_TIMEUNIT_TYPE_0.toLocalizedString(type)); } if (logger.isTraceEnabled(LogMarker.SERIALIZER)) { logger.trace(LogMarker.SERIALIZER, "Read TimeUnit: {}", unit); } return unit; }
From source file:com.netflix.dyno.jedis.DynoJedisPipeline.java
@Override public Response<byte[]> get(final byte[] key) { return new PipelineOperation<byte[]>() { @Override// w w w. j av a 2s . c o m Response<byte[]> execute(Pipeline jedisPipeline) throws DynoException { long startTime = System.nanoTime() / 1000; try { return jedisPipeline.get(key); } finally { long duration = System.nanoTime() / 1000 - startTime; opMonitor.recordSendLatency(OpName.GET.name(), duration, TimeUnit.MICROSECONDS); } } }.execute(key, OpName.GET); }
From source file:org.apache.hadoop.hbase.HBaseTestingUtility.java
/** * Tool to get the reference to the region server object that holds the * region of the specified user table./*from ww w.j a v a 2s. co m*/ * It first searches for the meta rows that contain the region of the * specified table, then gets the index of that RS, and finally retrieves * the RS's reference. * @param tableName user table to lookup in hbase:meta * @return region server that holds it, null if the row doesn't exist * @throws IOException */ public HRegionServer getRSForFirstRegionInTable(TableName tableName) throws IOException, InterruptedException { List<byte[]> metaRows = getMetaTableRows(tableName); if (metaRows == null || metaRows.isEmpty()) { return null; } LOG.debug("Found " + metaRows.size() + " rows for table " + tableName); byte[] firstrow = metaRows.get(0); LOG.debug("FirstRow=" + Bytes.toString(firstrow)); long pause = getConfiguration().getLong(HConstants.HBASE_CLIENT_PAUSE, HConstants.DEFAULT_HBASE_CLIENT_PAUSE); int numRetries = getConfiguration().getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER); RetryCounter retrier = new RetryCounter(numRetries + 1, (int) pause, TimeUnit.MICROSECONDS); while (retrier.shouldRetry()) { int index = getMiniHBaseCluster().getServerWith(firstrow); if (index != -1) { return getMiniHBaseCluster().getRegionServerThreads().get(index).getRegionServer(); } // Came back -1. Region may not be online yet. Sleep a while. retrier.sleepUntilNextRetry(); } return null; }
From source file:org.apache.hadoop.hbase.client.RawAsyncHBaseAdmin.java
@Override public CompletableFuture<Void> execProcedure(String signature, String instance, Map<String, String> props) { CompletableFuture<Void> future = new CompletableFuture<>(); ProcedureDescription procDesc = ProtobufUtil.buildProcedureDescription(signature, instance, props); addListener(this.<Long>newMasterCaller() .action((controller, stub) -> this.<ExecProcedureRequest, ExecProcedureResponse, Long>call( controller, stub, ExecProcedureRequest.newBuilder().setProcedure(procDesc).build(), (s, c, req, done) -> s.execProcedure(c, req, done), resp -> resp.getExpectedTimeout())) .call(), (expectedTimeout, err) -> { if (err != null) { future.completeExceptionally(err); return; }/* w w w .j a va 2s. c om*/ TimerTask pollingTask = new TimerTask() { int tries = 0; long startTime = EnvironmentEdgeManager.currentTime(); long endTime = startTime + expectedTimeout; long maxPauseTime = expectedTimeout / maxAttempts; @Override public void run(Timeout timeout) throws Exception { if (EnvironmentEdgeManager.currentTime() < endTime) { addListener(isProcedureFinished(signature, instance, props), (done, err2) -> { if (err2 != null) { future.completeExceptionally(err2); return; } if (done) { future.complete(null); } else { // retry again after pauseTime. long pauseTime = ConnectionUtils .getPauseTime(TimeUnit.NANOSECONDS.toMillis(pauseNs), ++tries); pauseTime = Math.min(pauseTime, maxPauseTime); AsyncConnectionImpl.RETRY_TIMER.newTimeout(this, pauseTime, TimeUnit.MICROSECONDS); } }); } else { future.completeExceptionally( new IOException("Procedure '" + signature + " : " + instance + "' wasn't completed in expectedTime:" + expectedTimeout + " ms")); } } }; // Queue the polling task into RETRY_TIMER to poll procedure state asynchronously. AsyncConnectionImpl.RETRY_TIMER.newTimeout(pollingTask, 1, TimeUnit.MILLISECONDS); }); return future; }
From source file:org.apache.hadoop.hive.conf.HiveConf.java
public static TimeUnit unitFor(String unit, TimeUnit defaultUnit) { unit = unit.trim().toLowerCase();// w ww. j ava 2 s . c o m if (unit.isEmpty() || unit.equals("l")) { if (defaultUnit == null) { throw new IllegalArgumentException("Time unit is not specified"); } return defaultUnit; } else if (unit.equals("d") || unit.startsWith("day")) { return TimeUnit.DAYS; } else if (unit.equals("h") || unit.startsWith("hour")) { return TimeUnit.HOURS; } else if (unit.equals("m") || unit.startsWith("min")) { return TimeUnit.MINUTES; } else if (unit.equals("s") || unit.startsWith("sec")) { return TimeUnit.SECONDS; } else if (unit.equals("ms") || unit.startsWith("msec")) { return TimeUnit.MILLISECONDS; } else if (unit.equals("us") || unit.startsWith("usec")) { return TimeUnit.MICROSECONDS; } else if (unit.equals("ns") || unit.startsWith("nsec")) { return TimeUnit.NANOSECONDS; } throw new IllegalArgumentException("Invalid time unit " + unit); }