List of usage examples for com.google.common.primitives UnsignedBytes lexicographicalComparator
@CheckReturnValue public static Comparator<byte[]> lexicographicalComparator()
From source file:com.palantir.atlasdb.keyvalue.partition.DynamicPartitionMapManager.java
public static void main(String[] args) { System.out.println("AtlasDb Dynamic Partition Map Manager"); System.out.print("Enter PMS Uri to download initial map (empty for empty map): "); final DynamicPartitionMapManager instance; try (Scanner scanner = new Scanner(System.in)) { String initialPmsUri = scanner.nextLine(); if (!initialPmsUri.equals("")) { instance = new DynamicPartitionMapManager(initialPmsUri); } else {//from w w w. j a v a 2s . c om System.out.println("This is new partition map wizard"); System.out.print("replication factor: "); int repf = Integer.parseInt(scanner.nextLine()); System.out.print("read factor: "); int readf = Integer.parseInt(scanner.nextLine()); System.out.print("write factor: "); int writef = Integer.parseInt(scanner.nextLine()); QuorumParameters parameters = new QuorumParameters(repf, readf, writef); NavigableMap<byte[], KeyValueEndpoint> initialRing = Maps .newTreeMap(UnsignedBytes.lexicographicalComparator()); while (initialRing.size() < repf) { System.out.print("kvs URI: "); String kvsUri = scanner.nextLine(); System.out.print("pms URI: "); String pmsUri = scanner.nextLine(); System.out.print("rack: "); String rack = scanner.nextLine(); byte[] key = readKey(scanner); SimpleKeyValueEndpoint kve = SimpleKeyValueEndpoint.create(kvsUri, pmsUri, rack); initialRing.put(key, kve); } DynamicPartitionMapImpl dpmi = DynamicPartitionMapImpl.create(parameters, initialRing, PTExecutors.newCachedThreadPool()); instance = new DynamicPartitionMapManager(dpmi); } boolean exit = false; while (!exit) { System.out.println("Local partition map:"); System.out.println(instance.partitionMap); System.out.println("MAIN MENU"); System.out.println("1. Add endpoint"); System.out.println("2. Remove endpoint"); System.out.println("3. Update local map"); System.out.println("4. Set version (deprecated, test only)"); System.out.println("5. Push local map to Uri"); System.out.println("6. Clear all endpoint kvss"); System.out.println("0. Exit"); System.out.print("Choice: "); try { switch (Integer.parseInt(scanner.nextLine())) { case 1: instance.addEndpointInteractive(scanner); continue; case 2: instance.removeEndpointInteractive(scanner); continue; case 3: instance.updateLocalMapInteractive(scanner); continue; case 4: instance.setVersionInteractive(scanner); continue; case 5: instance.pushToUriInteractive(scanner); continue; case 6: instance.clearAllEndpointKvssInteractive(scanner); continue; case 0: exit = true; continue; } } catch (NumberFormatException e) { e.printStackTrace(System.out); continue; } catch (RuntimeException e) { System.out.println("ERROR DURING OPERATION"); e.printStackTrace(System.out); System.out.println("\n\nReturning to main menu\n\n"); continue; } System.out.println("Unrecognized command."); } } }
From source file:com.palantir.atlasdb.keyvalue.api.RowResult.java
public static <T> RowResult<T> of(Cell cell, T value) { return new RowResult<T>(cell.getRowName(), ImmutableSortedMap.<byte[], T>orderedBy(UnsignedBytes.lexicographicalComparator()) .put(cell.getColumnName(), value).build()); }
From source file:com.palantir.atlasdb.keyvalue.api.ColumnSelection.java
public static ColumnSelection valueOf(String serialized) { Set<byte[]> columns = Sets.newTreeSet(UnsignedBytes.lexicographicalComparator()); for (String strColumn : serialized.split("\\s*,\\s*")) { strColumn = strColumn.trim();//w ww . jav a2 s . c o m if (strColumn.equals("")) { continue; } byte[] column = PtBytes.decodeBase64(strColumn); assert !columns.contains(column); columns.add(column); } if (columns.isEmpty()) { return all(); } return ColumnSelection.create(columns); }
From source file:com.jivesoftware.os.upena.amza.shared.RowIndexKey.java
@Override final public int compareTo(RowIndexKey o) { return UnsignedBytes.lexicographicalComparator().compare(key, o.key); }
From source file:com.palantir.atlasdb.keyvalue.partition.util.RowResultUtil.java
public static RowResult<Value> mergeResults(PeekingIterator<RowResult<Value>> it, QuorumParameters.QuorumRequestParameters quorumRequestParameters) { Preconditions.checkArgument(it.hasNext()); byte[] row = it.peek().getRowName(); final SortedMap<byte[], Value> result = Maps.newTreeMap(UnsignedBytes.lexicographicalComparator()); int failCount = 0; int succCount = 0; RuntimeException lastSuppressedException = null; while (it.hasNext() && Arrays.equals(it.peek().getRowName(), row)) { try {// w w w .j av a 2 s. c o m for (Map.Entry<Cell, Value> e : it.next().getCells()) { final byte[] col = e.getKey().getColumnName(); // Assert that there is not contradictory data if (result.containsKey(col) && e.getValue().getTimestamp() == result.get(col).getTimestamp()) { assert Arrays.equals(result.get(col).getContents(), e.getValue().getContents()); } if (!result.containsKey(col) || result.get(col).getTimestamp() < e.getValue().getTimestamp()) { result.put(col, e.getValue()); } } succCount++; } catch (RuntimeException e) { System.err.println("Could not read for rangeRequest."); failCount++; if (failCount >= quorumRequestParameters.getFailureFactor()) { throw Throwables.rewrapAndThrowUncheckedException("Could not get enough reads.", e); } lastSuppressedException = e; } } if (succCount < quorumRequestParameters.getSuccessFactor()) { if (lastSuppressedException != null) { throw lastSuppressedException; } else { throw new RuntimeException("Not enough reads for row " + Arrays.toString(row)); } } return RowResult.create(row, result); }
From source file:com.cloudera.dataflow.spark.ByteArray.java
@Override public int compareTo(ByteArray other) { return UnsignedBytes.lexicographicalComparator().compare(value, other.value); }
From source file:co.cask.tephra.visibility.WriteFence.java
@Override public void startTx(Transaction tx) { this.tx = tx; if (inProgressChanges == null) { inProgressChanges = new TreeSet<>(UnsignedBytes.lexicographicalComparator()); for (long inProgressTx : tx.getInProgress()) { inProgressChanges.add(Bytes.concat(fenceId, Longs.toByteArray(inProgressTx))); }/*from ww w . j ava 2s . c om*/ } }
From source file:com.palantir.atlasdb.keyvalue.impl.RowWrapper.java
@Override public int compareTo(RowWrapper o) { return UnsignedBytes.lexicographicalComparator().compare(row, o.row); }
From source file:org.apache.storm.hbase.state.HBaseClientTestUtil.java
public static HBaseClient mockedHBaseClient() throws Exception { return mockedHBaseClient( new ConcurrentSkipListMap<byte[], NavigableMap<byte[], NavigableMap<byte[], byte[]>>>( UnsignedBytes.lexicographicalComparator())); }
From source file:info.exascale.guanaco.ByteArray.java
@Override public int compareTo(ByteArray o) { if (o == null) throw new IllegalArgumentException(); return UnsignedBytes.lexicographicalComparator().compare(bytes, o.bytes); }