List of usage examples for java.lang Long BYTES
int BYTES
To view the source code for java.lang Long BYTES.
Click Source Link
From source file:org.neo4j.io.pagecache.PageCacheTest.java
@Test(timeout = SHORT_TIMEOUT_MILLIS, expected = IllegalArgumentException.class) public void mappingFileWithPageZeroPageSizeMustThrowEvenWithExistingMapping() throws Exception { getPageCache(fs, maxPages, pageCachePageSize, PageCacheTracer.NULL); File file = file("a"); //noinspection unused try (PagedFile oldMapping = pageCache.map(file, filePageSize)) { pageCache.map(file, Long.BYTES - 1); // this must throw }/*from w w w . j a va 2 s .c o m*/ }
From source file:org.apache.bookkeeper.bookie.storage.ldb.SingleDirectoryDbLedgerStorage.java
@Override public long getLastAddConfirmed(long ledgerId) throws IOException { TransientLedgerInfo ledgerInfo = transientLedgerInfoCache.get(ledgerId); long lac = null != ledgerInfo ? ledgerInfo.getLastAddConfirmed() : TransientLedgerInfo.NOT_ASSIGNED_LAC; if (lac == TransientLedgerInfo.NOT_ASSIGNED_LAC) { ByteBuf bb = getEntry(ledgerId, BookieProtocol.LAST_ADD_CONFIRMED); try {//from www . j a v a 2 s . c o m bb.skipBytes(2 * Long.BYTES); // skip ledger id and entry id lac = bb.readLong(); lac = getOrAddLedgerInfo(ledgerId).setLastAddConfirmed(lac); } finally { bb.release(); } } return lac; }
From source file:edu.umass.cs.gigapaxos.paxospackets.RequestPacket.java
/** * The weird constant above is to try to avoid mistakes in the painful (but * totally worth it) byte'ification method below. Using bytes as opposed to * json strings makes a non-trivial difference (~2x over json-smart and >4x * over org.json. So we just chuck json libraries and use our own byte[] * serializer for select packets.//from w w w . j a va 2s. co m * * The serialization overhead really matters most for RequestPacket and * AcceptPacket. Every request, even with batching, must be deserialized by * the coordinator and must be serialized back while sending out the * AcceptPacket. The critical path is the following at a coordinator and is * incurred at least in part even with batching for every request: (1) * receive request, (2) send accept, (3) receive accept_replies, (4) send * commit Accordingly, we use byteification for {@link RequestPacket}, * {@link AcceptPacket}, {@link BatchedAcceptReply} and * {@link BatchedCommit}. * * */ protected byte[] toBytes(boolean instrument) { // return cached value if already present if ((this.getType() == PaxosPacketType.REQUEST || this.getType() == PaxosPacketType.ACCEPT) && this.byteifiedSelf != null && !instrument) return this.byteifiedSelf; // check if we can use byteification at all; if not, use toString() if (!((BYTEIFICATION && IntegerMap.allInt()) || instrument)) { try { if (this.getType() == PaxosPacketType.REQUEST || this.getType() == PaxosPacketType.ACCEPT) return this.byteifiedSelf = this.toString().getBytes(CHARSET); // cache return this.toString().getBytes(CHARSET); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); return null; } } // else byteify try { int exactLength = 0; byte[] array = new byte[this.lengthEstimate()]; ByteBuffer bbuf = ByteBuffer.wrap(array); assert (bbuf.position() == 0); // paxospacket stuff super.toBytes(bbuf); int ppPos = bbuf.position(); // for assertion assert (bbuf.position() == ByteBuffer.wrap(array, SIZEOF_PAXOSPACKET_FIXED - 1, 1).get() + SIZEOF_PAXOSPACKET_FIXED) : bbuf.position() + " != " + ByteBuffer.wrap(array, SIZEOF_PAXOSPACKET_FIXED - 1, 1).get() + SIZEOF_PAXOSPACKET_FIXED; exactLength += (bbuf.position()); bbuf.putLong(this.requestID); bbuf.put(this.stop ? (byte) 1 : (byte) 0); exactLength += (Long.BYTES + 1); // addresses /* Note: 0 is ambiguous with wildcard address, but that's okay * because an incoming packet will never come with a wildcard * address. */ bbuf.put(this.clientAddress != null ? this.clientAddress.getAddress().getAddress() : new byte[4]); // 0 (not -1) means invalid port bbuf.putShort(this.clientAddress != null ? (short) this.clientAddress.getPort() : 0); /* Note: 0 is an ambiguous wildcard address that could also be a * legitimate value of the listening socket address. If the request * happens to have no listening address, we will end up assuming it * was received on the wildcard address. At worst, the matching for * the corresponding response back to the client can fail. */ bbuf.put(this.listenAddress != null ? this.listenAddress.getAddress().getAddress() : new byte[4]); // 0 (not -1) means invalid port bbuf.putShort(this.listenAddress != null ? (short) this.listenAddress.getPort() : 0); exactLength += 2 * (Integer.BYTES + Short.BYTES); // other non-final fields bbuf.putInt(this.entryReplica); bbuf.putLong(this.entryTime); bbuf.put(this.shouldReturnRequestValue ? (byte) 1 : (byte) 0); bbuf.putInt(this.forwardCount); exactLength += (Integer.BYTES + Long.BYTES + 1 + Integer.BYTES); // digest related fields: broadcasted, digest // whether this request was already broadcasted bbuf.put(this.broadcasted ? (byte) 1 : (byte) 0); exactLength += 1; assert (exactLength == // where parent left us off ppPos + SIZEOF_REQUEST_FIXED // for the three int fields not yet filled - 4 * Integer.BYTES) : exactLength + " != [" + ppPos + " + " + SIZEOF_REQUEST_FIXED + " - " + 4 * Integer.BYTES + "]"; // digest length and digest iteself bbuf.putInt(this.digest != null ? this.digest.length : 0); exactLength += Integer.BYTES; if (this.digest != null) bbuf.put(this.digest); exactLength += (this.digest != null ? this.digest.length : 0); // /////////// end of digest related fields ////////// // highly variable length fields // requestValue byte[] reqValBytes = this.requestValue != null ? this.requestValue.getBytes(CHARSET) : new byte[0]; bbuf.putInt(reqValBytes != null ? reqValBytes.length : 0); bbuf.put(reqValBytes); exactLength += (4 + reqValBytes.length); // responseValue byte[] respValBytes = this.responseValue != null ? this.responseValue.getBytes(CHARSET) : new byte[0]; bbuf.putInt(respValBytes != null ? respValBytes.length : 0); bbuf.put(respValBytes); exactLength += (4 + respValBytes.length); // batched requests batchSize|(length:batchedReqBytes)+ bbuf.putInt(this.batchSize()); exactLength += (4); if (this.batchSize() > 0) for (RequestPacket req : this.batched) { byte[] element = req.toBytes(); bbuf.putInt(element.length); bbuf.put(element); exactLength += (4 + element.length); } // bbuf.array() was a generous allocation byte[] exactBytes = new byte[exactLength]; bbuf.flip(); assert (bbuf.remaining() == exactLength) : bbuf.remaining() + " != " + exactLength; bbuf.get(exactBytes); if (this.getType() == PaxosPacketType.REQUEST) this.byteifiedSelf = exactBytes; return exactBytes; } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; }
From source file:io.pravega.controller.store.stream.PersistentStreamBase.java
@Override public CompletableFuture<Void> setColdMarker(int segmentNumber, long timestamp) { return verifyLegalState().thenCompose(v -> getMarkerData(segmentNumber)).thenCompose(x -> { if (x != null) { byte[] b = new byte[Long.BYTES]; BitConverter.writeLong(b, 0, timestamp); final Data<T> data = new Data<>(b, x.getVersion()); return updateMarkerData(segmentNumber, data); } else {//from ww w. j ava 2 s .co m return createMarkerData(segmentNumber, timestamp); } }); }