/** * Set the maximum number of boss threads. * Optional. * If not provided, 1 is used. */ public AsyncKuduClientBuilder bossCount(int bossCount) { Preconditions.checkArgument(bossCount > 0, "bossCount should be greater than 0"); this.bossCount = bossCount; return this; }
GetTableSchemaRequest(KuduTable masterTable, String id, String name) { super(masterTable); Preconditions.checkArgument(id != null ^ name != null, "Only one of table ID or the table name should be provided"); this.id = id; this.name = name; }
/** * Set the maximum number of worker threads. * Optional. * If not provided, (2 * the number of available processors) is used. If * this client instance will be used on a machine running many client * instances, it may be wise to lower this count, for example to avoid * resource limits, at the possible cost of some performance of this client * instance. */ public AsyncKuduClientBuilder workerCount(int workerCount) { Preconditions.checkArgument(workerCount > 0, "workerCount should be greater than 0"); this.workerCount = workerCount; return this; }
/** * Shorten the vector to be {@code len} elements long. * If {@code len} is greater than the vector's current length, * this has no effect. * @param len the new length of the vector */ public void truncate(int len) { Preconditions.checkArgument(len >= 0, "negative len"); this.len = Math.min(this.len, len); }
/** * Create a new error collector with a maximum capacity. * @param maxCapacity how many errors can be stored, has to be higher than 0 */ public ErrorCollector(int maxCapacity) { Preconditions.checkArgument(maxCapacity > 0, "Need to be able to store at least one row error"); this.maxCapacity = maxCapacity; this.errorQueue = new ArrayDeque<>(maxCapacity); }
/** * Reserves capacity for exactly {@code additional} more elements to be * inserted into the vector. * * If the vector already has sufficient capacity, no reallocation will happen. * * @param additional capacity to reserve */ public void reserveExact(int additional) { Preconditions.checkArgument(additional >= 0, "negative additional"); if (data.length - len >= additional) { return; } data = Arrays.copyOf(data, len + additional); }
private BloomFilter(BitSet bitSet, int nHashes, HashFunction hashFunction) { Preconditions.checkArgument(bitSet.size() >= 8, "Number of bits in " + "bitset should be at least 8, but found %s.", bitSet.size()); this.bitSet = bitSet; this.nHashes = nHashes; this.hashFunction = hashFunction; byteBuffer = new byte[8]; }
/** * Reserves capacity for at least {@code additional} more elements to be * inserted into the vector. * * The vector may reserve more space to avoid frequent reallocations. If the * vector already has sufficient capacity, no reallocation will happen. * * @param additional capacity to reserve */ public void reserveAdditional(int additional) { Preconditions.checkArgument(additional >= 0, "negative additional"); if (data.length - len >= additional) { return; } // Use a 1.5x growth factor. According to // https://stackoverflow.com/questions/1100311/what-is-the-ideal-growth-rate-for-a-dynamically-allocated-array // this is close to the ideal ratio, although it isn't clear if that holds // for managed languages. data = Arrays.copyOf(data, Math.max(len + additional, data.length + data.length / 2)); }
private void updateBitset(byte[] byteBuffer, int length) { Preconditions.checkArgument(byteBuffer.length >= length); long h = Murmur2.hash64(byteBuffer, length, 0); long h1 = (0xFFFFFFFFL & h); long h2 = (h >>> 32); long tmp = h1; for (int i = 0; i < nHashes; i++) { long bitPos = tmp % bitSet.size(); bitSet.set((int)bitPos); tmp += h2; } }
Preconditions.checkArgument(cert instanceof X509Certificate, "can only handle X509 certs"); X509Certificate x509 = (X509Certificate)cert;
private void handleTokenExchangeResponse(Channel chan, NegotiatePB response) throws SaslException { Preconditions.checkArgument(response.getStep() == NegotiateStep.TOKEN_EXCHANGE, "expected TOKEN_EXCHANGE, got step: {}", response.getStep()); // The token response doesn't have any actual data in it, so we can just move on. finish(chan); }
/** * Constructor for all the fields. The intent is that there should only be one ServerInfo * instance per UUID the client is connected to. * @param uuid server's UUID * @param hostPort server's hostname and port * @param resolvedAddr resolved address used to check if the server is local */ public ServerInfo(String uuid, HostAndPort hostPort, InetAddress resolvedAddr) { Preconditions.checkNotNull(uuid); Preconditions.checkArgument(hostPort.getPort() > 0); this.uuid = uuid; this.hostPort = hostPort; this.resolvedAddr = new InetSocketAddress(resolvedAddr, hostPort.getPort()); Boolean isLocal = isLocalAddressCache.get(resolvedAddr); if (isLocal == null) { isLocal = NetUtil.isLocalAddress(resolvedAddr); isLocalAddressCache.put(resolvedAddr, isLocal); } this.local = isLocal; }
public static CreateTableOptions getCreateTableOptions(Schema schema, int numReplicas, int rangePartitions, int hashPartitions) { Preconditions.checkArgument(rangePartitions > 0); Preconditions.checkArgument(hashPartitions > 0); CreateTableOptions options = new CreateTableOptions().setNumReplicas(numReplicas); if (rangePartitions > 1) { options.setRangePartitionColumns(ImmutableList.of(COLUMN_KEY_ONE)); BigInteger min = BigInteger.valueOf(Long.MIN_VALUE); BigInteger max = BigInteger.valueOf(Long.MAX_VALUE); BigInteger step = max.multiply(BigInteger.valueOf(2)) .divide(BigInteger.valueOf(rangePartitions)); PartialRow splitRow = schema.newPartialRow(); for (int i = 1; i < rangePartitions; i++) { long key = min.add(step.multiply(BigInteger.valueOf(i))).longValue(); splitRow.addLong(COLUMN_KEY_ONE_IDX, key); options.addSplitRow(splitRow); } } else { options.setRangePartitionColumns(Collections.<String>emptyList()); } if (hashPartitions > 1) { options.addHashPartitions(ImmutableList.of(COLUMN_KEY_ONE), hashPartitions); } return options; }
private AuthenticationTypePB.TypeCase chooseAuthenticationType(NegotiatePB response) { Preconditions.checkArgument(response.getAuthnTypesCount() <= 1, "Expected server to reply with at most one authn type"); if (response.getAuthnTypesCount() == 0) { // Default to SASL for compatibility with old servers. return AuthenticationTypePB.TypeCase.SASL; } AuthenticationTypePB.TypeCase type = response.getAuthnTypes(0).getTypeCase(); switch (type) { case SASL: if (authnToken != null) { authnTokenNotUsedReason = AuthnTokenNotUsedReason.NOT_CHOSEN_BY_SERVER; } break; case TOKEN: if (authnToken == null) { // TODO(todd): should we also check whether we have a CA cert? // it seems like this should have the same logic as whether we advertised it throw new IllegalArgumentException("server chose token authentication " + "but client had no valid token"); } break; default: throw new IllegalArgumentException("server chose bad authn type " + chosenAuthnType); } return type; }
/** * @param columnsSpecification the list of columns to parse out, comma separated. * @param separatorStr The 1 byte separator. */ public CsvParser(String columnsSpecification, String separatorStr) { // Configure separator byte[] separator = Bytes.fromString(separatorStr); Preconditions.checkArgument(separator.length == 1, "CsvParser only supports single-byte " + "separators"); separatorByte = separator[0]; // Configure columns columnNames = Lists.newArrayList(Splitter.on(',').trimResults().split(columnsSpecification)); maxColumnCount = columnNames.size(); }
case DOUBLE: case DECIMAL: { Preconditions.checkArgument(value.length == column.getTypeSize()); System.arraycopy(value, 0, rowAlloc, getPositionInRowAllocAndSetBitSet(index), value.length);
@Override public Deferred<LocatedTablet> call(List<LocatedTablet> tablets) { Preconditions.checkArgument(tablets.size() <= 1, "found more than one tablet for a single partition key"); if (tablets.isEmpty()) { // Most likely this indicates a non-covered range, but since this // could race with an alter table partitioning operation (which // clears the local table locations cache), we check again. TableLocationsCache.Entry entry = getTableLocationEntry(table.getTableId(), partitionKey); if (entry == null) { // This should be extremely rare, but a potential source of tight loops. LOG.debug("Table location expired before it could be processed; retrying."); return Deferred.fromError(new RecoverableException(Status.NotFound( "Table location expired before it could be processed"))); } if (entry.isNonCoveredRange()) { return Deferred.fromError( new NonCoveredRangeException(entry.getLowerBoundPartitionKey(), entry.getUpperBoundPartitionKey())); } return Deferred.fromResult(new LocatedTablet(entry.getTablet())); } return Deferred.fromResult(tablets.get(0)); } });
Preconditions.checkArgument(!response.getTlsHandshake().isEmpty(), "empty TLS message from server");
Preconditions.checkNotNull(lowerBound); Preconditions.checkNotNull(upperBound); Preconditions.checkArgument(lowerBound.getSchema().equals(upperBound.getSchema()));
Preconditions.checkNotNull(lowerBound); Preconditions.checkNotNull(upperBound); Preconditions.checkArgument(lowerBound.getSchema().equals(upperBound.getSchema()));