@SuppressWarnings("unchecked") public static <P extends VertxPojo, R extends UpdatableRecord<R>,T,F> F insertReturningPrimaryAsync(P object, DAO<R,P,T> dao,BiFunction<Query,Function<Long,T>,F> function){ Arguments.require(INSERT_RETURNING_SUPPORT.contains(dao.configuration().dialect()), "Only MySQL supported"); UniqueKey<?> key = dao.getTable().getPrimaryKey(); TableField<? extends Record, ?> tableField = key.getFieldsArray()[0]; Function<Long,T> keyConverter = lastId -> { T checkedResult; if(tableField.getType().equals(Integer.class)){ checkedResult = (T) Integer.valueOf(lastId.intValue()); }else{ checkedResult = (T) lastId; } return checkedResult; }; DSLContext dslContext = DSL.using(dao.configuration()); return function.apply(dslContext.insertInto(dao.getTable()).set(dslContext.newRecord(dao.getTable(), object)).returning(key.getFields()), keyConverter); }
/** * 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"); } }
@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; }
/** * 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; }
@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; }
/** * 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; }
/** * 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"); AsynchronousLock lock = this.localLocks .computeIfAbsent(name, (n) -> new AsynchronousLock(this.vertx)); lock.acquire(timeout, resultHandler); }
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); }
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")); }
@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); }
/** * Flip the parser into fixed size mode, where the record size is specified by {@code size} in bytes.<p> * This method can be called multiple times with different values of size while data is being parsed. */ private void fixedSizeMode(int size) { Arguments.require(size > 0, "Size must be > 0"); recordSize = size; reset = true; }
private String requireOpt(String key, String errorMsg) { Arguments.require(options.containsKey(key), errorMsg); return options.get(key); }
private String requireOpt(String key, String errorMsg) { Arguments.require(config.containsKey(key), errorMsg); return config.get(key); }