Java Code Examples for scala.concurrent.duration.Duration#apply()

The following examples show how to use scala.concurrent.duration.Duration#apply() . 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 File: FailureRateRestartStrategy.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public static FailureRateRestartStrategyFactory createFactory(Configuration configuration) throws Exception {
	int maxFailuresPerInterval = configuration.getInteger(ConfigConstants.RESTART_STRATEGY_FAILURE_RATE_MAX_FAILURES_PER_INTERVAL, 1);
	String failuresIntervalString = configuration.getString(
			ConfigConstants.RESTART_STRATEGY_FAILURE_RATE_FAILURE_RATE_INTERVAL, Duration.apply(1, TimeUnit.MINUTES).toString()
	);
	String timeoutString = configuration.getString(AkkaOptions.WATCH_HEARTBEAT_INTERVAL);
	String delayString = configuration.getString(ConfigConstants.RESTART_STRATEGY_FAILURE_RATE_DELAY, timeoutString);

	Duration failuresInterval = Duration.apply(failuresIntervalString);
	Duration delay = Duration.apply(delayString);


	return new FailureRateRestartStrategyFactory(maxFailuresPerInterval, Time.milliseconds(failuresInterval.toMillis()), Time.milliseconds(delay.toMillis()));
}
 
Example 2
Source File: FailureRateRestartStrategy.java    From flink with Apache License 2.0 5 votes vote down vote up
public static FailureRateRestartStrategyFactory createFactory(Configuration configuration) throws Exception {
	int maxFailuresPerInterval = configuration.getInteger(ConfigConstants.RESTART_STRATEGY_FAILURE_RATE_MAX_FAILURES_PER_INTERVAL, 1);
	String failuresIntervalString = configuration.getString(
			ConfigConstants.RESTART_STRATEGY_FAILURE_RATE_FAILURE_RATE_INTERVAL, Duration.apply(1, TimeUnit.MINUTES).toString()
	);
	String timeoutString = configuration.getString(AkkaOptions.WATCH_HEARTBEAT_INTERVAL);
	String delayString = configuration.getString(ConfigConstants.RESTART_STRATEGY_FAILURE_RATE_DELAY, timeoutString);

	Duration failuresInterval = Duration.apply(failuresIntervalString);
	Duration delay = Duration.apply(delayString);


	return new FailureRateRestartStrategyFactory(maxFailuresPerInterval, Time.milliseconds(failuresInterval.toMillis()), Time.milliseconds(delay.toMillis()));
}
 
Example 3
Source File: PoolConfiguration.java    From AsyncDao with MIT License 5 votes vote down vote up
public Configuration getConfig() {
    return new Configuration(
            username,
            host,
            port,
            Option.apply(password),
            Option.apply(database),
            SSLConfiguration.apply(buildSslConfig()),
            charset,
            16777216,
            PooledByteBufAllocator.DEFAULT,
            Duration.apply(connectTimeout, TimeUnit.MILLISECONDS),
            Duration.apply(testTimeout, TimeUnit.MILLISECONDS),
            Option.apply(Duration.apply(queryTimeout, TimeUnit.MILLISECONDS)));
}
 
Example 4
Source File: MySqlAsyncConnection.java    From ob1k with Apache License 2.0 5 votes vote down vote up
public static Configuration createConfiguration(final String host, final int port, final Option<String> database, final String userName, final Option<String> password,
                                                final long connectTimeoutMilliSeconds, final long queryTimeoutMilliSeconds) {
  final Option<Duration> queryTimeout = queryTimeoutMilliSeconds == -1 ?
    Option.<Duration>apply(null) :
    Option.<Duration>apply(Duration.apply(queryTimeoutMilliSeconds, TimeUnit.MILLISECONDS));

  return new Configuration(userName, host, port, password, database, CharsetUtil.UTF_8, MAXIMUM_MESSAGE_SIZE,
    PooledByteBufAllocator.DEFAULT, Duration.apply(connectTimeoutMilliSeconds, TimeUnit.MILLISECONDS), Duration.apply(4, TimeUnit.SECONDS),
    queryTimeout);
}
 
Example 5
Source File: BaseSqlTest.java    From AsyncDao with MIT License 4 votes vote down vote up
@Test
public void origin() throws Exception {
    CountDownLatch latch = new CountDownLatch(1);
    Vertx vertx = Vertx.vertx();

    Configuration configuration = new Configuration(
            "root",
            "localhost",
            3306,
            Option.apply("admin"),
            Option.apply("test"),
            SSLConfiguration.apply(Map$.MODULE$.empty()),
            Charset.forName("UTF-8"),
            16777216,
            PooledByteBufAllocator.DEFAULT,
            Duration.apply(10000, TimeUnit.MILLISECONDS),
            Duration.apply(10000, TimeUnit.MILLISECONDS),
            Option.apply(Duration.apply(10000, TimeUnit.MILLISECONDS)));

    Connection connection = new MySQLConnection(configuration,
            CharsetMapper.Instance(),
            vertx.nettyEventLoopGroup().next(),
            VertxEventLoopExecutionContext.create(vertx));

    System.out.println(connection.isConnected());

    connection.connect().onComplete(ScalaUtils.toFunction1(asyncResult -> {

        if(asyncResult.failed()){
            asyncResult.cause().printStackTrace();
            latch.countDown();
        }

        Future<QueryResult> qr = asyncResult.result().sendQuery("insert into T_User(username) values('twogoods')");
        qr.onComplete(ScalaUtils.toFunction1(ar -> {
            if (ar.succeeded()) {
                QueryResult queryResult = ar.result();
                System.out.println("rowsAffected: " + queryResult.rowsAffected());
                System.out.println("insert id: " + ((MySQLQueryResult) queryResult).lastInsertId());

                System.out.println(queryResult.rows().get().columnNames().toList());
                queryResult.rows().get().foreach(new AbstractFunction1<RowData, Void>() {
                    @Override
                    public Void apply(RowData row) {
                        row.foreach(new AbstractFunction1<Object, Void>() {
                            @Override
                            public Void apply(Object value) {
                                System.out.println("value" + value);
                                return null;
                            }
                        });
                        latch.countDown();
                        return null;
                    }
                });
            } else {
                ar.cause().printStackTrace();
            }
        }), VertxEventLoopExecutionContext.create(vertx));

    }), VertxEventLoopExecutionContext.create(vertx));

    latch.await();
}