List of usage examples for java.util UUID UUID
public UUID(long mostSigBits, long leastSigBits)
From source file:org.apache.geode.internal.InternalDataSerializer.java
private static UUID readUUID(DataInput in) throws IOException { InternalDataSerializer.checkIn(in);//from ww w . ja v a 2 s .c o m long mb = DataSerializer.readPrimitiveLong(in); long lb = DataSerializer.readPrimitiveLong(in); UUID result = new UUID(mb, lb); if (logger.isTraceEnabled(LogMarker.SERIALIZER)) { logger.trace(LogMarker.SERIALIZER, "Read UUID: {}", result); } return result; }
From source file:org.apache.hadoop.hbase.regionserver.wal.HLogSplitter.java
/** * This function is used to construct mutations from a WALEntry. It also reconstructs HLogKey & * WALEdit from the passed in WALEntry//from ww w . ja v a 2s .c om * @param entry * @param cells * @param logEntry pair of HLogKey and WALEdit instance stores HLogKey and WALEdit instances * extracted from the passed in WALEntry. * @param addLogReplayTag * @return list of Pair<MutationType, Mutation> to be replayed * @throws IOException */ public static List<MutationReplay> getMutationsFromWALEntry(WALEntry entry, CellScanner cells, Pair<HLogKey, WALEdit> logEntry, boolean addLogReplayTag) throws IOException { if (entry == null) { // return an empty array return new ArrayList<MutationReplay>(); } int count = entry.getAssociatedCellCount(); List<MutationReplay> mutations = new ArrayList<MutationReplay>(); Cell previousCell = null; Mutation m = null; HLogKey key = null; WALEdit val = null; if (logEntry != null) val = new WALEdit(); for (int i = 0; i < count; i++) { // Throw index out of bounds if our cell count is off if (!cells.advance()) { throw new ArrayIndexOutOfBoundsException("Expected=" + count + ", index=" + i); } Cell cell = cells.current(); if (val != null) val.add(KeyValueUtil.ensureKeyValue(cell)); boolean isNewRowOrType = previousCell == null || previousCell.getTypeByte() != cell.getTypeByte() || !CellUtil.matchingRow(previousCell, cell); if (isNewRowOrType) { // Create new mutation if (CellUtil.isDelete(cell)) { m = new Delete(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength()); // Deletes don't have nonces. mutations.add( new MutationReplay(MutationType.DELETE, m, HConstants.NO_NONCE, HConstants.NO_NONCE)); } else { m = new Put(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength()); // Puts might come from increment or append, thus we need nonces. long nonceGroup = entry.getKey().hasNonceGroup() ? entry.getKey().getNonceGroup() : HConstants.NO_NONCE; long nonce = entry.getKey().hasNonce() ? entry.getKey().getNonce() : HConstants.NO_NONCE; mutations.add(new MutationReplay(MutationType.PUT, m, nonceGroup, nonce)); } } if (CellUtil.isDelete(cell)) { ((Delete) m).addDeleteMarker(KeyValueUtil.ensureKeyValue(cell)); } else { Cell tmpNewCell = cell; if (addLogReplayTag) { tmpNewCell = tagReplayLogSequenceNumber(entry, cell); } ((Put) m).add(KeyValueUtil.ensureKeyValue(tmpNewCell)); } previousCell = cell; } // reconstruct HLogKey if (logEntry != null) { WALKey walKey = entry.getKey(); List<UUID> clusterIds = new ArrayList<UUID>(walKey.getClusterIdsCount()); for (HBaseProtos.UUID uuid : entry.getKey().getClusterIdsList()) { clusterIds.add(new UUID(uuid.getMostSigBits(), uuid.getLeastSigBits())); } key = new HLogKey(walKey.getEncodedRegionName().toByteArray(), TableName.valueOf(walKey.getTableName().toByteArray()), walKey.getLogSequenceNumber(), walKey.getWriteTime(), clusterIds, walKey.getNonceGroup(), walKey.getNonce()); logEntry.setFirst(key); logEntry.setSecond(val); } return mutations; }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java
private GBDeviceEvent[] decodeAction(ByteBuffer buf) { buf.order(ByteOrder.LITTLE_ENDIAN); byte command = buf.get(); if (command == NOTIFICATIONACTION_INVOKE) { int id;//from www . j a v a 2 s . c o m UUID uuid = new UUID(0, 0); if (mFwMajor >= 3) { uuid = getUUID(buf); id = (int) (uuid.getLeastSignificantBits() & 0xffffffffL); } else { id = buf.getInt(); } byte action = buf.get(); if (action >= 0x00 && action <= 0x05) { GBDeviceEventNotificationControl devEvtNotificationControl = new GBDeviceEventNotificationControl(); devEvtNotificationControl.handle = id; String caption = "undefined"; int icon_id = 1; boolean needsAck2x = true; switch (action) { case 0x01: devEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.OPEN; caption = "Opened"; icon_id = PebbleIconID.DURING_PHONE_CALL; break; case 0x02: devEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.DISMISS; caption = "Dismissed"; icon_id = PebbleIconID.RESULT_DISMISSED; needsAck2x = false; break; case 0x03: devEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.DISMISS_ALL; caption = "All dismissed"; icon_id = PebbleIconID.RESULT_DISMISSED; needsAck2x = false; break; case 0x04: devEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.MUTE; caption = "Muted"; icon_id = PebbleIconID.RESULT_MUTE; break; case 0x05: case 0x00: boolean failed = true; byte attribute_count = buf.get(); if (attribute_count > 0) { byte attribute = buf.get(); if (attribute == 0x01) { // reply string is in attribute 0x01 short length = buf.getShort(); if (length > 64) length = 64; byte[] reply = new byte[length]; buf.get(reply); devEvtNotificationControl.phoneNumber = null; if (buf.remaining() > 1 && buf.get() == 0x0c) { short phoneNumberLength = buf.getShort(); byte[] phoneNumberBytes = new byte[phoneNumberLength]; buf.get(phoneNumberBytes); devEvtNotificationControl.phoneNumber = new String(phoneNumberBytes); } devEvtNotificationControl.event = GBDeviceEventNotificationControl.Event.REPLY; devEvtNotificationControl.reply = new String(reply); caption = "SENT"; icon_id = PebbleIconID.RESULT_SENT; failed = false; } } if (failed) { caption = "FAILED"; icon_id = PebbleIconID.RESULT_FAILED; devEvtNotificationControl = null; // error } break; } GBDeviceEventSendBytes sendBytesAck = null; if (mFwMajor >= 3 || needsAck2x) { sendBytesAck = new GBDeviceEventSendBytes(); if (mFwMajor >= 3) { sendBytesAck.encodedBytes = encodeActionResponse(uuid, icon_id, caption); } else { sendBytesAck.encodedBytes = encodeActionResponse2x(id, action, 6, caption); } } return new GBDeviceEvent[] { sendBytesAck, devEvtNotificationControl }; } LOG.info("unexpected action: " + action); } return null; }
From source file:org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl.java
private void asyncDeleteLedger(long ledgerId, LedgerInfo info) { if (!info.getOffloadContext().getBookkeeperDeleted()) { // only delete if it hasn't been previously deleted for offload asyncDeleteLedger(ledgerId, DEFAULT_LEDGER_DELETE_RETRIES); }//from w w w. j a v a 2 s.c om if (info.getOffloadContext().hasUidMsb()) { UUID uuid = new UUID(info.getOffloadContext().getUidMsb(), info.getOffloadContext().getUidLsb()); cleanupOffloaded(ledgerId, uuid, OffloadUtils.getOffloadDriverName(info, config.getLedgerOffloader().getOffloadDriverName()), OffloadUtils.getOffloadDriverMetadata(info, config.getLedgerOffloader().getOffloadDriverMetadata()), "Trimming"); } }
From source file:org.apache.hadoop.hbase.wal.WALSplitter.java
/** * This function is used to construct mutations from a WALEntry. It also * reconstructs WALKey & WALEdit from the passed in WALEntry * @param entry//from ww w . j av a 2s . com * @param cells * @param logEntry pair of WALKey and WALEdit instance stores WALKey and WALEdit instances * extracted from the passed in WALEntry. * @return list of Pair<MutationType, Mutation> to be replayed * @throws IOException */ public static List<MutationReplay> getMutationsFromWALEntry(WALEntry entry, CellScanner cells, Pair<WALKey, WALEdit> logEntry, Durability durability) throws IOException { if (entry == null) { // return an empty array return new ArrayList<MutationReplay>(); } long replaySeqId = (entry.getKey().hasOrigSequenceNumber()) ? entry.getKey().getOrigSequenceNumber() : entry.getKey().getLogSequenceNumber(); int count = entry.getAssociatedCellCount(); List<MutationReplay> mutations = new ArrayList<MutationReplay>(); Cell previousCell = null; Mutation m = null; WALKey key = null; WALEdit val = null; if (logEntry != null) val = new WALEdit(); for (int i = 0; i < count; i++) { // Throw index out of bounds if our cell count is off if (!cells.advance()) { throw new ArrayIndexOutOfBoundsException("Expected=" + count + ", index=" + i); } Cell cell = cells.current(); if (val != null) val.add(cell); boolean isNewRowOrType = previousCell == null || previousCell.getTypeByte() != cell.getTypeByte() || !CellUtil.matchingRow(previousCell, cell); if (isNewRowOrType) { // Create new mutation if (CellUtil.isDelete(cell)) { m = new Delete(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength()); // Deletes don't have nonces. mutations.add( new MutationReplay(MutationType.DELETE, m, HConstants.NO_NONCE, HConstants.NO_NONCE)); } else { m = new Put(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength()); // Puts might come from increment or append, thus we need nonces. long nonceGroup = entry.getKey().hasNonceGroup() ? entry.getKey().getNonceGroup() : HConstants.NO_NONCE; long nonce = entry.getKey().hasNonce() ? entry.getKey().getNonce() : HConstants.NO_NONCE; mutations.add(new MutationReplay(MutationType.PUT, m, nonceGroup, nonce)); } } if (CellUtil.isDelete(cell)) { ((Delete) m).addDeleteMarker(cell); } else { ((Put) m).add(cell); } m.setDurability(durability); previousCell = cell; } // reconstruct WALKey if (logEntry != null) { org.apache.hadoop.hbase.protobuf.generated.WALProtos.WALKey walKeyProto = entry.getKey(); List<UUID> clusterIds = new ArrayList<UUID>(walKeyProto.getClusterIdsCount()); for (HBaseProtos.UUID uuid : entry.getKey().getClusterIdsList()) { clusterIds.add(new UUID(uuid.getMostSigBits(), uuid.getLeastSigBits())); } // we use HLogKey here instead of WALKey directly to support legacy coprocessors. key = new HLogKey(walKeyProto.getEncodedRegionName().toByteArray(), TableName.valueOf(walKeyProto.getTableName().toByteArray()), replaySeqId, walKeyProto.getWriteTime(), clusterIds, walKeyProto.getNonceGroup(), walKeyProto.getNonce()); logEntry.setFirst(key); logEntry.setSecond(val); } return mutations; }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java
private UUID getUUID(ByteBuffer buf) { ByteOrder byteOrder = buf.order(); buf.order(ByteOrder.BIG_ENDIAN); long uuid_high = buf.getLong(); long uuid_low = buf.getLong(); buf.order(byteOrder);/*w w w .j a v a 2 s .c om*/ return new UUID(uuid_high, uuid_low); }
From source file:org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl.java
private CompletableFuture<Void> prepareLedgerInfoForOffloaded(long ledgerId, UUID uuid, String offloadDriverName, Map<String, String> offloadDriverMetadata) { log.info("[{}] Preparing metadata to offload ledger {} with uuid {}", name, ledgerId, uuid); return transformLedgerInfo(ledgerId, (oldInfo) -> { if (oldInfo.getOffloadContext().hasUidMsb()) { UUID oldUuid = new UUID(oldInfo.getOffloadContext().getUidMsb(), oldInfo.getOffloadContext().getUidLsb()); log.info("[{}] Found previous offload attempt for ledger {}, uuid {}" + ", cleaning up", name, ledgerId, uuid);//from w w w . j a v a 2s . c o m cleanupOffloaded(ledgerId, oldUuid, OffloadUtils.getOffloadDriverName(oldInfo, config.getLedgerOffloader().getOffloadDriverName()), OffloadUtils.getOffloadDriverMetadata(oldInfo, config.getLedgerOffloader().getOffloadDriverMetadata()), "Previous failed offload"); } LedgerInfo.Builder builder = oldInfo.toBuilder(); builder.getOffloadContextBuilder().setUidMsb(uuid.getMostSignificantBits()) .setUidLsb(uuid.getLeastSignificantBits()); OffloadUtils.setOffloadDriverMetadata(builder, offloadDriverName, offloadDriverMetadata); return builder.build(); }).whenComplete((result, exception) -> { if (exception != null) { log.warn("[{}] Failed to prepare ledger {} for offload, uuid {}", name, ledgerId, uuid, exception); } else { log.info("[{}] Metadata prepared for offload of ledger {} with uuid {}", name, ledgerId, uuid); } }); }
From source file:org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl.java
private CompletableFuture<Void> completeLedgerInfoForOffloaded(long ledgerId, UUID uuid) { log.info("[{}] Completing metadata for offload of ledger {} with uuid {}", name, ledgerId, uuid); return transformLedgerInfo(ledgerId, (oldInfo) -> { UUID existingUuid = new UUID(oldInfo.getOffloadContext().getUidMsb(), oldInfo.getOffloadContext().getUidLsb()); if (existingUuid.equals(uuid)) { LedgerInfo.Builder builder = oldInfo.toBuilder(); builder.getOffloadContextBuilder().setTimestamp(clock.millis()).setComplete(true); String driverName = OffloadUtils.getOffloadDriverName(oldInfo, config.getLedgerOffloader().getOffloadDriverName()); Map<String, String> driverMetadata = OffloadUtils.getOffloadDriverMetadata(oldInfo, config.getLedgerOffloader().getOffloadDriverMetadata()); OffloadUtils.setOffloadDriverMetadata(builder, driverName, driverMetadata); return builder.build(); } else {// ww w . j a v a 2 s. c o m throw new OffloadConflict("Existing UUID(" + existingUuid + ") in metadata for offload" + " of ledgerId " + ledgerId + " does not match the UUID(" + uuid + ") for the offload we are trying to complete"); } }).whenComplete((result, exception) -> { if (exception == null) { log.info("[{}] End Offload. ledger={}, uuid={}", name, ledgerId, uuid); } else { log.warn("[{}] Failed to complete offload of ledger {}, uuid {}", name, ledgerId, uuid, exception); } }); }