Java源码示例:io.vertx.core.impl.Arguments

示例1
@SuppressWarnings("unchecked")
protected AbstractAsyncVertxDAO(Table<R> table, Class<P> type, QueryExecutor<R, T, FIND_MANY, FIND_ONE, EXECUTE, INSERT_RETURNING> queryExecutor) {
    super(table, type, queryExecutor);
    Arguments.require(isMysql(queryExecutor.configuration()) || isPostgres(queryExecutor.configuration()),"Only Postgres and MySQL supported");
    if(isMysql(queryExecutor.configuration())){
        keyConverter = keyConverter();
    }else{
        keyConverter = o -> {
            JsonArray j = (JsonArray) o;
            int pkLength = getTable().getPrimaryKey().getFieldsArray().length;
            if(pkLength == 1){
                return (T)j.getValue(0);
            }
            Object[] values = new Object[j.size()];
            for(int i=0;i<j.size();i++){
                values[i] = j.getValue(i);
            }
            return compositeKeyRecord(values);
        };
    }
}
 
示例2
/**
 * Create an options from JSON
 *
 * @param json the JSON
 */
public MqttServerOptions(JsonObject json) {
  super(json);
  // override the default port
  this.setPort(json.getInteger("port", DEFAULT_PORT));
  this.maxMessageSize =  json.getInteger("maxMessageSize", DEFAULT_MAX_MESSAGE_SIZE);
  this.isAutoClientId = json.getBoolean("isAutoClientId", true);
  this.timeoutOnConnect = json.getInteger("timeoutOnConnect", DEFAULT_TIMEOUT_ON_CONNECT);

  if ((this.maxMessageSize > 0) && (this.getReceiveBufferSize() > 0)) {
    Arguments.require(this.getReceiveBufferSize() >= this.maxMessageSize,
      "Receiver buffer size can't be lower than max message size");
  }
}
 
示例3
@Override
public MqttServerOptions setReceiveBufferSize(int receiveBufferSize) {
  if ((this.maxMessageSize > 0) && (receiveBufferSize > 0)) {
    Arguments.require(receiveBufferSize >= this.maxMessageSize,
      "Receiver buffer size can't be lower than max message size");
  }
  super.setReceiveBufferSize(receiveBufferSize);
  return this;
}
 
示例4
/**
 * Set max MQTT message size
 *
 * @param maxMessageSize  max MQTT message size (variable header + payload)
 * @return  MQTT server options instance
 */
public MqttServerOptions setMaxMessageSize(int maxMessageSize) {
  Arguments.require(maxMessageSize > 0 || maxMessageSize == DEFAULT_MAX_MESSAGE_SIZE, "maxMessageSize must be > 0");
  if ((maxMessageSize > 0) && (this.getReceiveBufferSize() > 0)) {
    Arguments.require(this.getReceiveBufferSize() >= maxMessageSize,
      "Receiver buffer size can't be lower than max message size");
  }
  this.maxMessageSize = maxMessageSize;
  return this;
}
 
示例5
@Override
public MqttClientOptions setReceiveBufferSize(int receiveBufferSize) {
  if ((this.maxMessageSize > 0) && (receiveBufferSize > 0)) {
    Arguments.require(receiveBufferSize >= this.maxMessageSize,
      "Receiver buffer size can't be lower than max message size");
  }
  super.setReceiveBufferSize(receiveBufferSize);
  return this;
}
 
示例6
/**
 * Set max MQTT message size
 *
 * @param maxMessageSize  max MQTT message size
 * @return  MQTT client options instance
 */
public MqttClientOptions setMaxMessageSize(int maxMessageSize) {
  Arguments.require(maxMessageSize > 0 || maxMessageSize == DEFAULT_MAX_MESSAGE_SIZE, "maxMessageSize must be > 0");
  if ((maxMessageSize > 0) && (this.getReceiveBufferSize() > 0)) {
    Arguments.require(this.getReceiveBufferSize() >= maxMessageSize,
      "Receiver buffer size can't be lower than max message size");
  }
  this.maxMessageSize = maxMessageSize;
  return this;
}
 
示例7
@Override
public EXECUTE insert(Collection<P> pojos, boolean onDuplicateKeyIgnore) {
    Arguments.require(!pojos.isEmpty(), "No elements");
    return queryExecutor().execute(dslContext -> {
        InsertSetStep<R> insertSetStep = dslContext.insertInto(getTable());
        InsertValuesStepN<R> insertValuesStepN = null;
        for (P pojo : pojos) {
            insertValuesStepN = insertSetStep.values(newRecord(dslContext, pojo).intoArray());
        }
        return onDuplicateKeyIgnore?insertValuesStepN.onDuplicateKeyIgnore():insertValuesStepN;
    });
}
 
示例8
/**
 * Get a local lock with the specified name with specifying a timeout. The lock will be passed to
 * the handler when it is available.  If the lock is not obtained within the timeout a failure
 * will be sent to the handler
 *
 * @param name the name of the lock
 * @param timeout the timeout in ms
 * @param resultHandler the handler
 */
public void getLockWithTimeout(String name, long timeout,
    Handler<AsyncResult<Lock>> resultHandler) {
  Objects.requireNonNull(name, "name");
  Objects.requireNonNull(resultHandler, "resultHandler");
  Arguments.require(timeout >= 0L, "timeout must be >= 0");
  LocalAsyncLocks lock = this.localLocks
      .computeIfAbsent(name, (n) -> new LocalAsyncLocks());
  lock.acquire(this.vertx.getOrCreateContext(),name,timeout, resultHandler);

}
 
示例9
public HttpResourceFetcher(Vertx vertx, URI uri, Map<String, String> config, boolean isHttps) {
    this.vertx = vertx;
    this.uri = uri;
    this.isHttps = isHttps;
    this.config = config;

    String authString = config.getOrDefault("auth", "NONE").toUpperCase();
    Arguments.require(EnumUtils.isValidEnum(AuthType.class, authString), "auth must be one of: " + AuthType.all());
    authenticator = AuthType.valueOf(authString).getAuthenticator();
    authenticator.validateConfig(config);
}
 
示例10
public URILoadingRegistry(Vertx vertx, IEngineConfig vxConfig, Map<String, String> options) {
    super();
    this.vertx = vertx;
    this.options = options;
    Arguments.require(options.containsKey("configUri"), "configUri is required in configuration");
    uri = URI.create(options.get("configUri"));
}
 
示例11
@SuppressWarnings("unchecked")
private <T, K> List<T> requireJsonArray(String keyName, JsonObject json, Class<K> klazz) {
    // Contains key.
    Arguments.require(json.containsKey(keyName),
            String.format("Must provide array of %s objects for key '%s'", StringUtils.capitalize(keyName), keyName));
    // Is of type array.
    Arguments.require(json.getValue(keyName) instanceof JsonArray,
            String.format("'%s' must be a Json array", keyName));
    // Transform into List<T>.
    return Json.decodeValue(json.getJsonArray(keyName).encode(), List.class, klazz);
}
 
示例12
@SuppressWarnings("unchecked")
private <T, K> List<T> requireJsonArray(String keyName, JsonObject json, Class<K> klazz) {
    // Contains key.
    Arguments.require(json.containsKey(keyName),
            String.format("Must provide array of %s objects for key '%s'", StringUtils.capitalize(keyName), keyName));
    // Is of type array.
    Arguments.require(json.getValue(keyName) instanceof JsonArray,
            String.format("'%s' must be a Json array", keyName));
    // Transform into List<T>.
    return Json.decodeValue(json.getJsonArray(keyName).encode(), List.class, klazz);
}
 
示例13
public byte[] getBytes(int start, int end) {
  Arguments.require(end >= start, "end must be greater or equal than start");
  byte[] arr = new byte[end - start];
  buffer.getBytes(start, arr, 0, end - start);
  return arr;
}
 
示例14
@Override
public Buffer getBytes(int start, int end, byte[] dst, int dstIndex) {
  Arguments.require(end >= start, "end must be greater or equal than start");
  buffer.getBytes(start, dst, dstIndex, end - start);
  return this;
}
 
示例15
public byte[] getBytes(int start, int end) {
    Arguments.require(end >= start, "end must be greater or equal than start");
    byte[] arr = new byte[end - start];
    buffer.getBytes(start, arr, 0, end - start);
    return arr;
}
 
示例16
@Override
public Buffer getBytes(int start, int end, byte[] dst, int dstIndex) {
    Arguments.require(end >= start, "end must be greater or equal than start");
    buffer.getBytes(start, dst, dstIndex, end - start);
    return this;
}
 
示例17
@Override
public void setStrategy(GeneratorStrategy strategy) {
    Arguments.require(strategy instanceof VertxGeneratorStrategy, "Requires instance of VertxGeneratorStrategy");
    super.setStrategy(strategy);
    this.vertxGeneratorStrategy = (VertxGeneratorStrategy) strategy;
}
 
示例18
private String requireOpt(String key, String errorMsg) {
    Arguments.require(options.containsKey(key), errorMsg);
    return options.get(key);
}
 
示例19
private String requireOpt(String key, String errorMsg) {
    Arguments.require(config.containsKey(key), errorMsg);
    return config.get(key);
}