List of usage examples for java.util UUID getMostSignificantBits
public long getMostSignificantBits()
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java
@Override public byte[] encodeAppDelete(UUID uuid) { if (mFwMajor >= 3) { if (UUID_PEBBLE_HEALTH.equals(uuid)) { return encodeActivateHealth(false); }// ww w . ja v a2s . co m if (UUID_WORKOUT.equals(uuid)) { return encodeActivateHRM(false); } if (UUID_WEATHER.equals(uuid)) { //TODO: probably it wasn't present in firmware 3 return encodeActivateWeather(false); } return encodeBlobdb(uuid, BLOBDB_DELETE, BLOBDB_APP, null); } else { final short LENGTH_REMOVEAPP_2X = 17; ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_REMOVEAPP_2X); buf.order(ByteOrder.BIG_ENDIAN); buf.putShort(LENGTH_REMOVEAPP_2X); buf.putShort(ENDPOINT_APPMANAGER); buf.put(APPMANAGER_REMOVEAPP); buf.putLong(uuid.getMostSignificantBits()); buf.putLong(uuid.getLeastSignificantBits()); return buf.array(); } }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java
byte[] encodeApplicationMessagePush(short endpoint, UUID uuid, ArrayList<Pair<Integer, Object>> pairs) { int length = LENGTH_UUID + 3; // UUID + (PUSH + id + length of dict) for (Pair<Integer, Object> pair : pairs) { if (pair.first == null || pair.second == null) continue; length += 7; // key + type + length if (pair.second instanceof Integer) { length += 4;//from w w w. j ava2 s. com } else if (pair.second instanceof Short) { length += 2; } else if (pair.second instanceof Byte) { length += 1; } else if (pair.second instanceof String) { length += ((String) pair.second).getBytes().length + 1; } else if (pair.second instanceof byte[]) { length += ((byte[]) pair.second).length; } else { LOG.warn("unknown type: " + pair.second.getClass().toString()); } } ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + length); buf.order(ByteOrder.BIG_ENDIAN); buf.putShort((short) length); buf.putShort(endpoint); // 48 or 49 buf.put(APPLICATIONMESSAGE_PUSH); buf.put(++last_id); buf.putLong(uuid.getMostSignificantBits()); buf.putLong(uuid.getLeastSignificantBits()); buf.put((byte) pairs.size()); buf.order(ByteOrder.LITTLE_ENDIAN); for (Pair<Integer, Object> pair : pairs) { if (pair.first == null || pair.second == null) continue; buf.putInt(pair.first); if (pair.second instanceof Integer) { buf.put(TYPE_INT); buf.putShort((short) 4); // length buf.putInt((int) pair.second); } else if (pair.second instanceof Short) { buf.put(TYPE_INT); buf.putShort((short) 2); // length buf.putShort((short) pair.second); } else if (pair.second instanceof Byte) { buf.put(TYPE_INT); buf.putShort((short) 1); // length buf.put((byte) pair.second); } else if (pair.second instanceof String) { String str = (String) pair.second; buf.put(TYPE_CSTRING); buf.putShort((short) (str.getBytes().length + 1)); buf.put(str.getBytes()); buf.put((byte) 0); } else if (pair.second instanceof byte[]) { byte[] bytes = (byte[]) pair.second; buf.put(TYPE_BYTEARRAY); buf.putShort((short) bytes.length); buf.put(bytes); } } return buf.array(); }
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);// w w w. jav a 2 s . 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); } }); }