Java Code Examples for com.google.common.base.Preconditions#checkArgument()

The following examples show how to use com.google.common.base.Preconditions#checkArgument() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: joyqueue   File: DefaultMessagePoller.java    License: Apache License 2.0 6 votes vote down vote up
public DefaultMessagePoller(ConsumerConfig config, NameServerConfig nameServerConfig, ClusterManager clusterManager,
                            ClusterClientManager clusterClientManager, ConsumerClientManager consumerClientManager) {
    Preconditions.checkArgument(config != null, "consumer can not be null");
    Preconditions.checkArgument(nameServerConfig != null, "nameServer can not be null");
    Preconditions.checkArgument(clusterManager != null, "clusterManager can not be null");
    Preconditions.checkArgument(clusterClientManager != null, "clusterClientManager can not be null");
    Preconditions.checkArgument(consumerClientManager != null, "consumerClientManager can not be null");
    Preconditions.checkArgument(StringUtils.isNotBlank(config.getApp()), "consumer.app not blank");
    Preconditions.checkArgument(config.getPollTimeout() > config.getLongPollTimeout(), "consumer.pollTimeout must be greater than consumer.longPullTimeout");

    this.config = config;
    this.nameServerConfig = nameServerConfig;
    this.clusterManager = clusterManager;
    this.clusterClientManager = clusterClientManager;
    this.consumerClientManager = consumerClientManager;
}
 
Example 2
/**
 * Generate a master HD key node from a seed.
 * 
 * @param seed
 *           the seed to generate the master HD wallet key from.
 * @return a master HD key node for the seed
 * @throws KeyGenerationException
 *            if the seed is not suitable for seeding an HD wallet key
 *            generation. This is extremely unlikely
 */
public static HdKeyNode fromSeed(byte[] seed) throws KeyGenerationException {
   Preconditions.checkArgument(seed.length * 8 >= 128, "seed must be larger than 128");
   Preconditions.checkArgument(seed.length * 8 <= 512, "seed must be smaller than 512");
   byte[] I = Hmac.hmacSha512(asciiStringToBytes(BITCOIN_SEED), seed);

   // Construct private key
   byte[] IL = BitUtils.copyOfRange(I, 0, 32);
   BigInteger k = new BigInteger(1, IL);
   if (k.compareTo(Parameters.n) >= 0) {
      throw new KeyGenerationException(
            "An unlikely thing happened: The derived key is larger than the N modulus of the curve");
   }
   if (k.equals(BigInteger.ZERO)) {
      throw new KeyGenerationException("An unlikely thing happened: The derived key is zero");
   }
   InMemoryPrivateKey privateKey = new InMemoryPrivateKey(IL, true);

   // Construct chain code
   byte[] IR = BitUtils.copyOfRange(I, 32, 32 + CHAIN_CODE_SIZE);
   return new HdKeyNode(privateKey, IR, 0, 0, 0);
}
 
Example 3
Source Project: joyqueue   File: BrokerService.java    License: Apache License 2.0 5 votes vote down vote up
private NameService getNameService(BrokerContext brokerContext, Configuration configuration) {
    Property property = configuration.getProperty(NAMESERVICE_NAME);
    NameService nameService = Plugins.NAMESERVICE.get(property == null ? DEFAULT_NAMESERVICE_NAME : property.getString().trim());
    Preconditions.checkArgument(nameService != null, "nameService not found!");

    CompensatedNameService compensatedNameService = new CompensatedNameService(nameService);
    enrichIfNecessary(nameService, brokerContext);
    enrichIfNecessary(compensatedNameService, brokerContext);
    return compensatedNameService;
}
 
Example 4
Source Project: hadoop   File: CacheDirectiveInfo.java    License: Apache License 2.0 5 votes vote down vote up
private Expiration(long ms, boolean isRelative) {
  if (isRelative) {
    Preconditions.checkArgument(ms <= MAX_RELATIVE_EXPIRY_MS,
        "Expiration time is too far in the future!");
  }
  this.ms = ms;
  this.isRelative = isRelative;
}
 
Example 5
public CMODataTransport(String transportID, String developmentSystemID, Boolean isModifiable, String description, String owner) {

        Preconditions.checkArgument(! isNullOrEmpty(transportID), "transportId was null or empty.");
        this.transportID = transportID;
        this.developmentSystemID = developmentSystemID;
        this.isModifiable = isModifiable;
        this.description = description;
        this.owner = owner;
    }
 
Example 6
Source Project: hadoop-ozone   File: OmKeyInfo.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("parameternumber")
OmKeyInfo(String volumeName, String bucketName, String keyName,
    List<OmKeyLocationInfoGroup> versions, long dataSize,
    long creationTime, long modificationTime,
    HddsProtos.ReplicationType type,
    HddsProtos.ReplicationFactor factor,
    Map<String, String> metadata,
    FileEncryptionInfo encInfo, List<OzoneAcl> acls,
    long objectID, long updateID) {
  this.volumeName = volumeName;
  this.bucketName = bucketName;
  this.keyName = keyName;
  this.dataSize = dataSize;
  // it is important that the versions are ordered from old to new.
  // Do this sanity check when versions got loaded on creating OmKeyInfo.
  // TODO : this is not necessary, here only because versioning is still a
  // work in-progress, remove this following check when versioning is
  // complete and prove correctly functioning
  long currentVersion = -1;
  for (OmKeyLocationInfoGroup version : versions) {
    Preconditions.checkArgument(
          currentVersion + 1 == version.getVersion());
    currentVersion = version.getVersion();
  }
  this.keyLocationVersions = versions;
  this.creationTime = creationTime;
  this.modificationTime = modificationTime;
  this.factor = factor;
  this.type = type;
  this.metadata = metadata;
  this.encInfo = encInfo;
  this.acls = acls;
  this.objectID = objectID;
  this.updateID = updateID;
}
 
Example 7
Source Project: arcusplatform   File: TimeOfDay.java    License: Apache License 2.0 5 votes vote down vote up
public static TimeOfDay fromString(String tod) {
   Matcher m = TOD_PATTERN.matcher(tod);
   Preconditions.checkArgument(m.matches(), "Invalid time of day [" + tod + "]");
   int hours = Integer.parseInt(m.group(1));
   int min = Integer.parseInt(m.group(2));
   int sec = Integer.parseInt(m.group(3));
   return new TimeOfDay(hours, min, sec);
}
 
Example 8
Source Project: grpc-nebula-java   File: BinlogHelper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
void logTrailer(
    long seq,
    Status status,
    Metadata metadata,
    GrpcLogEntry.Logger logger,
    long callId,
    // null on server, can be non null on client if this is a trailer-only response
    @Nullable SocketAddress peerAddress) {
  Preconditions.checkArgument(
      peerAddress == null || logger == GrpcLogEntry.Logger.LOGGER_CLIENT,
      "peerSocket can only be specified for client");
  MaybeTruncated<io.grpc.binarylog.v1.Metadata.Builder> pair
      = createMetadataProto(metadata, maxHeaderBytes);

  io.grpc.binarylog.v1.Trailer.Builder trailerBuilder
      = io.grpc.binarylog.v1.Trailer.newBuilder()
      .setStatusCode(status.getCode().value())
      .setMetadata(pair.proto);
  String statusDescription = status.getDescription();
  if (statusDescription != null) {
    trailerBuilder.setStatusMessage(statusDescription);
  }
  byte[] statusDetailBytes = metadata.get(STATUS_DETAILS_KEY);
  if (statusDetailBytes != null) {
    trailerBuilder.setStatusDetails(ByteString.copyFrom(statusDetailBytes));
  }

  GrpcLogEntry.Builder entryBuilder = newTimestampedBuilder()
      .setSequenceIdWithinCall(seq)
      .setType(EventType.EVENT_TYPE_SERVER_TRAILER)
      .setTrailer(trailerBuilder)
      .setPayloadTruncated(pair.truncated)
      .setLogger(logger)
      .setCallId(callId);
  if (peerAddress != null) {
    entryBuilder.setPeer(socketToProto(peerAddress));
  }
  sink.write(entryBuilder.build());
}
 
Example 9
Source Project: joyqueue   File: BroadcastMessagePoller.java    License: Apache License 2.0 5 votes vote down vote up
public BroadcastMessagePoller(ConsumerConfig config, NameServerConfig nameServerConfig, ClusterManager clusterManager, ConsumerClientManager consumerClientManager) {
    Preconditions.checkArgument(StringUtils.isNotBlank(config.getBroadcastGroup()), "consumer.broadcastGroup must be greater than 0");
    Preconditions.checkArgument(StringUtils.isNotBlank(config.getBroadcastLocalPath()), "consumer.broadcastLocalPath must not be null");

    this.config = config;
    this.nameServerConfig = nameServerConfig;
    this.clusterManager = clusterManager;
    this.consumerClientManager = consumerClientManager;
}
 
Example 10
Source Project: artemis   File: AddressManager.java    License: Apache License 2.0 5 votes vote down vote up
public static AddressManager getRegistryAddressManager(final String clientId, final ArtemisClientManagerConfig managerConfig) {
    Preconditions.checkArgument(!StringValues.isNullOrWhitespace(clientId), "clientId");
    Preconditions.checkArgument(managerConfig != null, "manager config");
    return new AddressManager(managerConfig,
            new AddressRepository(clientId, managerConfig, RestPaths.CLUSTER_UP_REGISTRY_NODES_FULL_PATH)){
        @Override
        protected AddressContext newAddressContext() {
            return new AddressContext(clientId, managerConfig, _addressRepository.get(), WebSocketPaths.HEARTBEAT_DESTINATION);
        }
    };
}
 
Example 11
Source Project: arcusplatform   File: Methods.java    License: Apache License 2.0 5 votes vote down vote up
public MethodDiscoveryBuilder annotatedWith(Class<? extends Annotation> annotation) {
   Preconditions.checkNotNull(annotation, "annotation may not be null");
   Preconditions.checkArgument(isRuntimeRetained(annotation), "non-runtime annotations, can't be used here");

   this.annotations.add(annotation);
   return this;
}
 
Example 12
public ShardingValueWrapper(final Comparable<?> value) {
    Preconditions.checkArgument(value instanceof Number || value instanceof Date || value instanceof String, 
            String.format("Value must be type of Number, Data or String, your value type is '%s'", value.getClass().getName()));
    this.value = value;
}
 
Example 13
Source Project: fc-java-sdk   File: CreateServiceResponse.java    License: MIT License 4 votes vote down vote up
public Boolean getInternetAccess() {
    Preconditions.checkArgument(serviceMetadata != null);
    return serviceMetadata.getInternetAccess();
}
 
Example 14
public void addRow(ReadableQMatrix A, int i) {
  Preconditions.checkArgument(i >= 0);
  A.addToVector(this, i);
}
 
Example 15
Source Project: SimFix   File: 1_NodeUtil.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * @return Whether a TRY node has a finally block.
 */
static boolean hasFinally(Node n) {
  Preconditions.checkArgument(n.getType() == Token.TRY);
  return n.getChildCount() == 3;
}
 
Example 16
@Override
public void countDown() {
  Preconditions.checkNotNull(latch, "Latch not initialized in %s at %s.", siteClass.getSimpleName(), desc);
  Preconditions.checkArgument(latch.getCount() > 0, "Counting down on latch more than intended.");
  latch.countDown();
}
 
Example 17
@Override
public Importer<?, ?> getImporter(String transferDataType) {
  Preconditions.checkState(initialized);
  Preconditions.checkArgument(SUPPORTED_IMPORT_SERVICES.contains(transferDataType));
  return importerMap.get(transferDataType);
}
 
Example 18
public RetryStrategyLibrary(@JsonProperty("strategyMappings") List<RetryMapping> retryMappings,
    @JsonProperty("defaultRetryStrategy") RetryStrategy defaultRetryStrategy) {
  Preconditions.checkArgument(defaultRetryStrategy != null, "Default retry strategy cannot be null");
  this.retryMappings = retryMappings;
  this.defaultRetryStrategy = defaultRetryStrategy;
}
 
Example 19
Source Project: fc-java-sdk   File: UpdateServiceResponse.java    License: MIT License 4 votes vote down vote up
public VpcConfig getVpcConfig() {
    Preconditions.checkArgument(serviceMetadata != null);
    return serviceMetadata.getVpcConfig();
}
 
Example 20
/**
 * 更新爬虫模板
 *
 * @param spiderInfo 爬虫模板实体
 * @return 爬虫模板id
 * @throws ExecutionException
 * @throws InterruptedException
 */
public String update(SpiderInfo spiderInfo) throws ExecutionException, InterruptedException {
    Preconditions.checkArgument(StringUtils.isNotBlank(spiderInfo.getId()), "待更新爬虫模板id不可为空");
    UpdateRequest updateRequest = new UpdateRequest(INDEX_NAME, TYPE_NAME, spiderInfo.getId());
    updateRequest.doc(gson.toJson(spiderInfo));
    UpdateResponse updateResponse = client.update(updateRequest).get();
    return updateResponse.getId();
}