List of usage examples for java.lang Long toHexString
public static String toHexString(long i)
From source file:com.mellanox.jxio.ClientSession.java
/** * Constructor of ClientSession./* w ww .ja va2 s . c om*/ * * @param eqh * - EventQueueHAndler on which the events * (onResponse, onSessionEstablished etc) of this client will arrive * @param uri * - URI of the server to which this Client will connect * of the server * @param callbacks * - implementation of Interface ClientSession.Callbacks */ public ClientSession(EventQueueHandler eqh, URI uri, Callbacks callbacks) { if (LOG.isDebugEnabled()) { LOG.debug("CS CTOR entry"); } this.eqh = eqh; this.callbacks = callbacks; if (!uri.getScheme().equals("rdma") && !uri.getScheme().equals("tcp")) { LOG.fatal("mal formatted URI: " + uri); } String uriStr = uri.toString(); long cacheId = eqh.getId(); if (uri.getPath().compareTo("") == 0) { uriStr += "/"; } if (uri.getQuery() == null) { uriStr += "?" + WorkerCache.CACHE_TAG + "=" + cacheId; } else { uriStr += "&" + WorkerCache.CACHE_TAG + "=" + cacheId; } final long id = Bridge.startSessionClient(uriStr, eqh.getId()); this.name = "jxio.CS[" + Long.toHexString(id) + "]"; this.nameForLog = this.name + ": "; if (id == 0) { LOG.error(this.toLogString() + "there was an error creating session"); } if (LOG.isDebugEnabled()) { LOG.debug(this.toLogString() + "connecting to " + uriStr); } this.setId(id); this.eqh.addEventable(this); if (LOG.isDebugEnabled()) { LOG.debug(this.toLogString() + "CS CTOR done"); } }
From source file:com.chiorichan.util.ObjectUtil.java
/** * Appends the prefix of each hex dump row. Uses the look-up table for the buffer <= 64 KiB. *//*from www .j a va 2s. co m*/ private static void appendHexDumpRowPrefix(StringBuilder dump, int row, int rowStartIndex) { if (row < HEXDUMP_ROWPREFIXES.length) { dump.append(HEXDUMP_ROWPREFIXES[row]); } else { dump.append(NEWLINE); dump.append(Long.toHexString(rowStartIndex & 0xFFFFFFFFL | 0x100000000L)); dump.setCharAt(dump.length() - 9, '|'); dump.append('|'); } }
From source file:com.wealdtech.gcm.GCMClient.java
/** * Returns a random message id to uniquely identify a message. * <p/>//from w w w.j a v a 2s .c o m * <p>Note: This is generated by a pseudo random number generator for illustration purpose, and is not guaranteed to be unique. */ public String getRandomMessageId() { return "m-" + Long.toHexString(random.nextLong()); }
From source file:com.github.carlomicieli.rest.PlayerRepresentation.java
/** * Compute the ETag for the current player representation. * @return the ETag value./*from w w w . ja v a2 s . c o m*/ */ public EntityTag tag() { return new EntityTag(Long.toHexString(this.hashCode())); }
From source file:net.urosk.mifss.core.pools.FsContentPoolImpl.java
/** * Creates left padded string from int to hex, splited in folder from 0-255 * in hex/*w w w . ja va 2 s. co m*/ * * @param id content id * @return path in hex */ public String getHexStorePath(long id) { String s = Long.toHexString(id); s = s.toLowerCase(); s = StringUtils.leftPad(s, hexPaddingLength, "0"); String a = ""; for (int i = 0; i < hexPaddingLength; i = i + 2) { a = a + s.substring(i, i + 2) + File.separator; } return a.substring(0, a.length() - 1); }
From source file:org.apache.bookkeeper.bookie.BookieJournalTest.java
private void writePreV2Journal(File journalDir, int numEntries) throws Exception { long logId = System.currentTimeMillis(); File fn = new File(journalDir, Long.toHexString(logId) + ".txn"); FileChannel fc = new RandomAccessFile(fn, "rw").getChannel(); ByteBuffer zeros = ByteBuffer.allocate(512); fc.write(zeros, 4 * 1024 * 1024);//from ww w.j av a2 s.c o m fc.position(0); byte[] data = "JournalTestData".getBytes(); long lastConfirmed = LedgerHandle.INVALID_ENTRY_ID; for (int i = 1; i <= numEntries; i++) { ByteBuffer packet = ClientUtil.generatePacket(1, i, lastConfirmed, i * data.length, data) .toByteBuffer(); lastConfirmed = i; ByteBuffer lenBuff = ByteBuffer.allocate(4); lenBuff.putInt(packet.remaining()); lenBuff.flip(); fc.write(lenBuff); fc.write(packet); } }
From source file:org.apache.bookkeeper.bookie.EntryLogTest.java
@Test(timeout = 60000) public void testMissingLogId() throws Exception { File tmpDir = createTempDir("entryLogTest", ".dir"); File curDir = Bookie.getCurrentDirectory(tmpDir); Bookie.checkDirectoryStructure(curDir); ServerConfiguration conf = TestBKConfiguration.newServerConfiguration(); conf.setLedgerDirNames(new String[] { tmpDir.toString() }); Bookie bookie = new Bookie(conf); // create some entries int numLogs = 3; int numEntries = 10; long[][] positions = new long[2 * numLogs][]; for (int i = 0; i < numLogs; i++) { positions[i] = new long[numEntries]; EntryLogger logger = new EntryLogger(conf, bookie.getLedgerDirsManager()); for (int j = 0; j < numEntries; j++) { positions[i][j] = logger.addEntry(i, generateEntry(i, j)); }/*from ww w . ja v a2s. c o m*/ logger.flush(); } // delete last log id File lastLogId = new File(curDir, "lastId"); lastLogId.delete(); // write another entries for (int i = numLogs; i < 2 * numLogs; i++) { positions[i] = new long[numEntries]; EntryLogger logger = new EntryLogger(conf, bookie.getLedgerDirsManager()); for (int j = 0; j < numEntries; j++) { positions[i][j] = logger.addEntry(i, generateEntry(i, j)); } logger.flush(); } EntryLogger newLogger = new EntryLogger(conf, bookie.getLedgerDirsManager()); for (int i = 0; i < (2 * numLogs + 1); i++) { File logFile = new File(curDir, Long.toHexString(i) + ".log"); assertTrue(logFile.exists()); } for (int i = 0; i < 2 * numLogs; i++) { for (int j = 0; j < numEntries; j++) { String expectedValue = "ledger-" + i + "-" + j; byte[] value = newLogger.readEntry(i, j, positions[i][j]); ByteBuffer buf = ByteBuffer.wrap(value); long ledgerId = buf.getLong(); long entryId = buf.getLong(); byte[] data = new byte[buf.remaining()]; buf.get(data); assertEquals(i, ledgerId); assertEquals(j, entryId); assertEquals(expectedValue, new String(data)); } } }
From source file:org.eclipse.ecr.core.api.impl.blob.LazyBlob.java
@Override public InputStream getStream() throws IOException { // Get the client. CoreSession client;// ww w .ja v a 2 s . com try { client = getClient(); } catch (ClientException ce) { throw new IOException(ce.getMessage()); } if (in == null) { // this should be a remote invocation StreamManager sm = Framework.getLocalService(StreamManager.class); String uri = null; try { if (sm == null) { throw new IOException("No Streaming service was registered"); } uri = client.getStreamURI(dataKey); StreamSource src = sm.getStream(uri); file = new File(TMP_DIR, Long.toHexString(RANDOM.nextLong())); file.deleteOnExit(); src.copyTo(file); // persist the content in = new FileInputStream(file); } catch (IOException e) { throw e; } catch (Exception e) { log.error(e); throw new IOException("Failed to load lazy content for: " + dataKey); } finally { // destroy the remote blob and close any opened stream on the server if (uri != null) { sm.removeStream(uri); // destroy the remote stream } } } else if (file != null) { in = new FileInputStream(file); } // Close the session because it means we opened a new one. if (sid == null) { CoreInstance.getInstance().close(client); } return in; }
From source file:com.uber.jaeger.httpclient.JaegerRequestAndResponseInterceptorIntegrationTest.java
private void verifyTracing(Span parentSpan) { //Assert that traces are correctly emitted by the client List<Span> spans = reporter.getSpans(); assertEquals(2, spans.size());/*from ww w . java 2 s . c om*/ Span span = spans.get(1); assertEquals("GET", span.getOperationName()); assertEquals(parentSpan.context().getSpanID(), span.context().getParentID()); //Assert traces and baggage are propagated correctly to server HttpRequest[] httpRequests = mockServerClient.retrieveRecordedRequests(null); assertEquals(1, httpRequests.length); String traceData = httpRequests[0].getFirstHeader("uber-trace-id"); String[] split = traceData.split("%3A"); assertEquals(Long.toHexString(span.context().getTraceID()), split[0]); assertEquals(Long.toHexString(span.context().getSpanID()), split[1]); String baggage = httpRequests[0].getFirstHeader("uberctx-" + BAGGAGE_KEY); assertEquals(BAGGAGE_VALUE, baggage); }
From source file:org.apache.bookkeeper.bookie.InterleavedStorageRegenerateIndexOp.java
public void initiate(boolean dryRun) throws IOException { LOG.info("Starting index rebuilding"); DiskChecker diskChecker = Bookie.createDiskChecker(conf); LedgerDirsManager ledgerDirsManager = Bookie.createLedgerDirsManager(conf, diskChecker, NullStatsLogger.INSTANCE);//from w w w. j a v a2 s .co m LedgerDirsManager indexDirsManager = Bookie.createIndexDirsManager(conf, diskChecker, NullStatsLogger.INSTANCE, ledgerDirsManager); EntryLogger entryLogger = new EntryLogger(conf, ledgerDirsManager); final LedgerCache ledgerCache; if (dryRun) { ledgerCache = new DryRunLedgerCache(); } else { ledgerCache = new LedgerCacheImpl(conf, new SnapshotMap<Long, Boolean>(), indexDirsManager, NullStatsLogger.INSTANCE); } Set<Long> entryLogs = entryLogger.getEntryLogsSet(); int totalEntryLogs = entryLogs.size(); int completedEntryLogs = 0; long startTime = System.nanoTime(); LOG.info("Scanning {} entry logs", totalEntryLogs); Map<Long, RecoveryStats> stats = new HashMap<>(); for (long entryLogId : entryLogs) { LOG.info("Scanning {}", entryLogId); entryLogger.scanEntryLog(entryLogId, new EntryLogScanner() { @Override public void process(long ledgerId, long offset, ByteBuf entry) throws IOException { long entryId = entry.getLong(8); stats.computeIfAbsent(ledgerId, (ignore) -> new RecoveryStats()).registerEntry(entryId); // Actual location indexed is pointing past the entry size long location = (entryLogId << 32L) | (offset + 4); if (LOG.isDebugEnabled()) { LOG.debug("Rebuilding {}:{} at location {} / {}", ledgerId, entryId, location >> 32, location & (Integer.MAX_VALUE - 1)); } if (!ledgerCache.ledgerExists(ledgerId)) { ledgerCache.setMasterKey(ledgerId, masterKey); ledgerCache.setFenced(ledgerId); } ledgerCache.putEntryOffset(ledgerId, entryId, location); } @Override public boolean accept(long ledgerId) { return ledgerIds.contains(ledgerId); } }); ledgerCache.flushLedger(true); ++completedEntryLogs; LOG.info("Completed scanning of log {}.log -- {} / {}", Long.toHexString(entryLogId), completedEntryLogs, totalEntryLogs); } LOG.info("Rebuilding indices done"); for (long ledgerId : ledgerIds) { RecoveryStats ledgerStats = stats.get(ledgerId); if (ledgerStats == null || ledgerStats.getNumEntries() == 0) { LOG.info(" {} - No entries found", ledgerId); } else { LOG.info(" {} - Found {} entries, from {} to {}", ledgerId, ledgerStats.getNumEntries(), ledgerStats.getFirstEntry(), ledgerStats.getLastEntry()); } } LOG.info("Total time: {}", DurationFormatUtils .formatDurationHMS(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime))); }