List of usage examples for java.lang Long toHexString
public static String toHexString(long i)
From source file:io.orchestrate.client.itest.KvTest.java
@Theory public void upsertMergePatchKey(@ForAll(sampleSize = 10) final String key) throws InterruptedException { assumeThat(key, not(isEmptyString())); KvObject<ObjectNode> kvBefore = client.kv(collection(), key).get(ObjectNode.class).get(); // assert the object is not present before the patch assertNull(kvBefore);// w w w. j a va2 s .c om String name = Long.toHexString(RAND.nextLong()); final KvMetadata patched = client.kv(collection(), key).upsert().merge("{\"name\":\"" + name + "\"}").get(); assertNotNull(patched); final KvObject<ObjectNode> kvObject = client.kv(patched.getCollection(), patched.getKey()) .get(ObjectNode.class).get(); assertEquals(patched.getRef(), kvObject.getRef()); assertEquals(name, kvObject.getValue().get("name").asText()); }
From source file:org.diorite.config.serialization.snakeyaml.emitter.Emitter.java
private void writeDoubleQuoted(String text, boolean split) throws IOException { this.writeIndicator("\"", true, false, false); int start = 0; int end = 0;//from w w w. j a va 2 s . c o m while (end <= text.length()) { Character ch = null; if (end < text.length()) { ch = text.charAt(end); } if ((ch == null) || ("\"\\\u0085\u2028\u2029\uFEFF".indexOf(ch) != -1) || !(('\u0020' <= ch) && (ch <= '\u007E'))) { if (start < end) { int len = end - start; this.column += len; this.stream.write(text, start, len); start = end; } if (ch != null) { String data; if (ESCAPE_REPLACEMENTS.containsKey(ch)) { data = "\\" + ESCAPE_REPLACEMENTS.get(ch); } else if (!this.allowUnicode || !StreamReader.isPrintable(ch)) { // if !allowUnicode or the character is not printable, // we must encode it if (ch <= '\u00FF') { String s = "0" + Integer.toString(ch, HEX_RADIX); data = "\\x" + s.substring(s.length() - 2); } else if ((ch >= '\uD800') && (ch <= '\uDBFF')) { if ((end + 1) < text.length()) { Character ch2 = text.charAt(++end); String s = "000" + Long.toHexString(Character.toCodePoint(ch, ch2)); data = "\\U" + s.substring(s.length() - 8); } else { String s = "000" + Integer.toString(ch, HEX_RADIX); data = "\\u" + s.substring(s.length() - 4); } } else { String s = "000" + Integer.toString(ch, HEX_RADIX); data = "\\u" + s.substring(s.length() - 4); } } else { data = String.valueOf(ch); } this.column += data.length(); this.stream.write(data); start = end + 1; } } if (((0 < end) && (end < (text.length() - 1))) && ((Objects.equals(ch, ' ')) || (start >= end)) && ((this.column + (end - start)) > this.bestWidth) && split) { String data; if (start >= end) { data = "\\"; } else { data = text.substring(start, end) + "\\"; } if (start < end) { start = end; } this.column += data.length(); this.stream.write(data); this.writeIndent(); this.whitespace = false; this.indention = false; if (text.charAt(start) == ' ') { data = "\\"; this.column += data.length(); this.stream.write(data); } } end += 1; } this.writeIndicator("\"", false, false, false); }
From source file:io.orchestrate.client.itest.KvTest.java
@Theory public void upsertMergePatchKeyAsync(@ForAll(sampleSize = 10) final String key) throws InterruptedException { assumeThat(key, not(isEmptyString())); KvObject<ObjectNode> kvBefore = client.kv(collection(), key).get(ObjectNode.class).get(); // assert the object is not present before the patch assertNull(kvBefore);/*from w ww . j a va 2 s .c om*/ String name = Long.toHexString(RAND.nextLong()); final BlockingQueue<KvMetadata> queue = DataStructures.getLTQInstance(KvMetadata.class); client.kv(collection(), key).upsert().merge("{\"name\":\"" + name + "\"}") .on(new ResponseAdapter<KvMetadata>() { @Override public void onFailure(final Throwable error) { fail(error.getMessage()); } @Override public void onSuccess(final KvMetadata object) { queue.add(object); } }); final KvMetadata patched = queue.poll(5000, TimeUnit.MILLISECONDS); assertNotNull(patched); final KvObject<ObjectNode> kvObject = client.kv(patched.getCollection(), patched.getKey()) .get(ObjectNode.class).get(); assertEquals(patched.getRef(), kvObject.getRef()); assertEquals(name, kvObject.getValue().get("name").asText()); }
From source file:com.peterbochs.sourceleveldebugger.SourceLevelDebugger3.java
private JTable getSymbolTable() { if (symbolTable == null) { symbolTable = new JTable() { public String getToolTipText(MouseEvent event) { Point p = event.getPoint(); int row = rowAtPoint(p); int col = columnAtPoint(p); if (row == -1 || col == -1) { return null; }//from w ww. j a v a 2 s.c o m Elf32_Sym symbol = (Elf32_Sym) getValueAt(row, col); String str = "<html><table>"; str += "<tr><td>name</td><td>:</td><td>" + symbol.name + "</td></tr>"; str += "<tr><td>st_name</td><td>:</td><td>" + symbol.st_name + "</td></tr>"; str += "<tr><td>st_value</td><td>:</td><td>0x" + Long.toHexString(symbol.st_value) + "</td></tr>"; str += "<tr><td>st_size</td><td>:</td><td>" + symbol.st_size + "</td></tr>"; str += "<tr><td>st_info</td><td>:</td><td>" + symbol.st_info + "</td></tr>"; str += "<tr><td>st_other</td><td>:</td><td>" + symbol.st_other + "</td></tr>"; str += "<tr><td>st_shndx</td><td>:</td><td>" + symbol.st_shndx + "</td></tr>"; str += "</table></html>"; return str; } }; symbolTable.setModel(symbolTableModel); symbolTable.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { symbolTableMouseClicked(evt); } }); } return symbolTable; }
From source file:com.gst.accounting.journalentry.service.JournalEntryWritePlatformServiceJpaRepositoryImpl.java
/** * TODO: Need a better implementation with guaranteed uniqueness (but not a * long UUID)...maybe something tied to system clock.. *//*w ww . jav a 2 s. co m*/ private String generateTransactionId(final Long officeId) { final AppUser user = this.context.authenticatedUser(); final Long time = System.currentTimeMillis(); final String uniqueVal = String.valueOf(time) + user.getId() + officeId; final String transactionId = Long.toHexString(Long.parseLong(uniqueVal)); return transactionId; }
From source file:com.cloud.network.vpc.VpcManagerImpl.java
@Override @ActionEvent(eventType = EventTypes.EVENT_VPC_CREATE, eventDescription = "creating vpc", create = true) public Vpc createVpc(final long zoneId, final long vpcOffId, final long vpcOwnerId, final String vpcName, final String displayText, final String cidr, String networkDomain, final Boolean displayVpc) throws ResourceAllocationException { final Account caller = CallContext.current().getCallingAccount(); final Account owner = _accountMgr.getAccount(vpcOwnerId); // Verify that caller can perform actions in behalf of vpc owner _accountMgr.checkAccess(caller, null, false, owner); // check resource limit _resourceLimitMgr.checkResourceLimit(owner, ResourceType.vpc); // Validate vpc offering final VpcOfferingVO vpcOff = _vpcOffDao.findById(vpcOffId); if (vpcOff == null || vpcOff.getState() != State.Enabled) { final InvalidParameterValueException ex = new InvalidParameterValueException( "Unable to find vpc offering in " + State.Enabled + " state by specified id"); if (vpcOff == null) { ex.addProxyObject(String.valueOf(vpcOffId), "vpcOfferingId"); } else {/*from w ww. j a v a2s. c o m*/ ex.addProxyObject(vpcOff.getUuid(), "vpcOfferingId"); } throw ex; } final boolean isRegionLevelVpcOff = vpcOff.offersRegionLevelVPC(); if (isRegionLevelVpcOff && networkDomain == null) { throw new InvalidParameterValueException("Network domain must be specified for region level VPC"); } // Validate zone final DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId); if (zone == null) { throw new InvalidParameterValueException("Can't find zone by id specified"); } if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getId())) { // See DataCenterVO.java final PermissionDeniedException ex = new PermissionDeniedException( "Cannot perform this operation since specified Zone is currently disabled"); ex.addProxyObject(zone.getUuid(), "zoneId"); throw ex; } if (networkDomain == null) { // 1) Get networkDomain from the corresponding account networkDomain = _ntwkModel.getAccountNetworkDomain(owner.getId(), zoneId); // 2) If null, generate networkDomain using domain suffix from the // global config variables if (networkDomain == null) { networkDomain = "cs" + Long.toHexString(owner.getId()) + NetworkOrchestrationService.GuestDomainSuffix.valueIn(zoneId); } } final boolean useDistributedRouter = vpcOff.supportsDistributedRouter(); final VpcVO vpc = new VpcVO(zoneId, vpcName, displayText, owner.getId(), owner.getDomainId(), vpcOffId, cidr, networkDomain, useDistributedRouter, isRegionLevelVpcOff, vpcOff.getRedundantRouter()); return createVpc(displayVpc, vpc); }
From source file:com.peterbochs.sourceleveldebugger.SourceLevelDebugger3.java
private void symbolTableMouseClicked(MouseEvent evt) { if (evt.getClickCount() == 2) { Elf32_Sym symbol = (Elf32_Sym) symbolTable.getValueAt(symbolTable.getSelectedRow(), 0); if (symbol != null) { long address = symbol.st_value; jInstructionComboBox.setSelectedItem("0x" + Long.toHexString(address)); jMainTabbedPane.setSelectedIndex(0); peterBochsDebugger.jumpToRowInstructionTable(BigInteger.valueOf(address)); }/* ww w . java 2 s.c o m*/ } }
From source file:com.google.wave.api.AbstractRobot.java
/** * Computes this robot's hash, based on the capabilities. * * @return a hash of this robot, computed from it's capabilities. *//*from w w w .ja va 2 s .c o m*/ private String computeHash() { long version = 0l; for (Entry<String, Capability> entry : capabilityMap.entrySet()) { long hash = entry.getKey().hashCode(); Capability capability = entry.getValue(); if (capability != null) { for (Context context : capability.contexts()) { hash = hash * 31 + context.name().hashCode(); } hash = hash * 31 + capability.filter().hashCode(); } version = version * 17 + hash; } return Long.toHexString(version); }
From source file:org.apache.hadoop.hdfs.server.datanode.BPOfferService.java
/** * Report the list blocks to the Namenode * * @throws IOException/*from www. j ava2 s .com*/ */ List<DatanodeCommand> blockReport() throws IOException { // send block report if timer has expired. final long startTime = now(); if (startTime - lastBlockReport <= dnConf.blockReportInterval) { return null; } nextBlockReportOverwritten = false; ArrayList<DatanodeCommand> cmds = new ArrayList<DatanodeCommand>(); // Flush any block information that precedes the block report. Otherwise // we have a chance that we will miss the delHint information // or we will report an RBW replica after the BlockReport already reports // a FINALIZED one. reportReceivedDeletedBlocks(); lastHeartbeat = startTime; long brCreateStartTime = now(); Map<DatanodeStorage, BlockReport> perVolumeBlockLists = dn.getFSDataset().getBlockReports(getBlockPoolId()); // Convert the reports to the format expected by the NN. int i = 0; int totalBlockCount = 0; StorageBlockReport reports[] = new StorageBlockReport[perVolumeBlockLists.size()]; DatanodeStorage[] storages = new DatanodeStorage[reports.length]; for (Map.Entry<DatanodeStorage, BlockReport> kvPair : perVolumeBlockLists.entrySet()) { BlockReport blockList = kvPair.getValue(); reports[i] = new StorageBlockReport(kvPair.getKey(), blockList); totalBlockCount += blockList.getNumberOfBlocks(); storages[i] = kvPair.getKey(); i++; } // Get a namenode to send the report(s) to ActiveNode an = nextNNForBlkReport(totalBlockCount); int numReportsSent = 0; int numRPCs = 0; boolean success = false; long brSendStartTime; try { if (an != null) { blkReportHander = getAnActor(an.getRpcServerAddressForDatanodes()); if (blkReportHander == null || !blkReportHander.isRunning()) { return null; //no one is ready to handle the request, return now without changing the values of lastBlockReport. it will be retried in next cycle } } else { LOG.warn("Unable to send block report"); return null; } // Send the reports to the NN. brSendStartTime = now(); long reportId = generateUniqueBlockReportId(); try { if (totalBlockCount < dnConf.blockReportSplitThreshold) { // Below split threshold, send all reports in a single message. DatanodeCommand buckets = blkReportHander.reportHashes(bpRegistration, getBlockPoolId(), slimBlockReports(reports)); removeMatchingBuckets(buckets, reports); DatanodeCommand cmd = blkReportHander.blockReport(bpRegistration, getBlockPoolId(), reports, new BlockReportContext(1, 0, reportId)); numRPCs = 1; numReportsSent = reports.length; if (cmd != null) { cmds.add(cmd); } } else { // Send one block report per message. for (int r = 0; r < reports.length; r++) { StorageBlockReport singleReport[] = { reports[r] }; DatanodeCommand buckets = blkReportHander.reportHashes(bpRegistration, getBlockPoolId(), slimBlockReports(singleReport)); removeMatchingBuckets(buckets, singleReport); DatanodeCommand cmd = blkReportHander.blockReport(bpRegistration, getBlockPoolId(), singleReport, new BlockReportContext(reports.length, r, reportId)); numReportsSent++; numRPCs++; if (cmd != null) { cmds.add(cmd); } } } success = true; } finally { // Log the block report processing stats from Datanode perspective long brSendCost = now() - brSendStartTime; long brCreateCost = brSendStartTime - brCreateStartTime; dn.getMetrics().addBlockReport(brSendCost); dn.getMetrics().incrBlocReportCounter(numReportsSent); final int nCmds = cmds.size(); LOG.info((success ? "S" : "Uns") + "uccessfully sent block report 0x" + Long.toHexString(reportId) + ", containing " + reports.length + " storage report(s), of which we sent " + numReportsSent + "." + " The reports had " + totalBlockCount + " total blocks and used " + numRPCs + " RPC(s). This took " + brCreateCost + " msec to generate and " + brSendCost + " msecs for RPC and NN processing." + " Got back " + ((nCmds == 0) ? "no commands" : ((nCmds == 1) ? "one command: " + cmds.get(0) : (nCmds + " commands: " + Joiner.on("; ").join(cmds)))) + "."); } } finally { // In case of un/successful block reports we have to inform the leader that // block reporting has finished for now. if (blkReportHander != null) { for (BPServiceActor actor : bpServices) { actor.blockReportCompleted(bpRegistration, storages, success); } } } scheduleNextBlockReport(startTime); return cmds.size() == 0 ? null : cmds; }
From source file:io.requery.android.database.sqlite.SQLiteConnection.java
/** * Dumps debugging information about this connection, in the case where the * caller might not actually own the connection. * * This function is written so that it may be called by a thread that does not * own the connection. We need to be very careful because the connection state is * not synchronized.//from w w w . j a v a2s. com * * At worst, the method may return stale or slightly wrong data, however * it should not crash. This is ok as it is only used for diagnostic purposes. * * @param printer The printer to receive the dump, not null. * @param verbose True to dump more verbose information. */ void dumpUnsafe(Printer printer, boolean verbose) { printer.println("Connection #" + mConnectionId + ":"); if (verbose) { printer.println(" connectionPtr: 0x" + Long.toHexString(mConnectionPtr)); } printer.println(" isPrimaryConnection: " + mIsPrimaryConnection); printer.println(" onlyAllowReadOnlyOperations: " + mOnlyAllowReadOnlyOperations); mRecentOperations.dump(printer, verbose); if (verbose) { mPreparedStatementCache.dump(printer); } }