<T> void fetchWithRetry(Logger logger, Callable<T> blockingHandler, Future<T> done) { vertx.executeBlocking((Future<T> fut) -> { try { fut.complete(blockingHandler.call()); } catch (Exception e) { fut.fail(e); } }, ar -> { if (ar.failed() && !(ar.cause() instanceof AcmeRetryAfterException)) { done.fail(ar.cause()); return; } if (ar.succeeded() && ar.result() != null) { done.complete(ar.result()); return; } long nextSleep = ar.succeeded() ? 3000 : ((AcmeRetryAfterException) ar.cause()).getRetryAfter().getTime() - currentTimeMillis(); logger.info("Recheck in {}ms @ {}", nextSleep, new Date(System.currentTimeMillis() + nextSleep)); vertx.setTimer(nextSleep, timerId -> fetchWithRetry(logger, blockingHandler, done)); }); }
public void init(String[] args, Handler<AsyncResult<Vertx>> fut) { final Logger logger = OkapiLogger.get(); if (args.length < 1) { fut.handle(Future.failedFuture("Missing command; use help")); return; } if (parseOptions(args, fut)) { return; } final String mode = conf.getString("mode", "dev"); switch (mode) { case "dev": case "initdatabase": case "purgedatabase": deploy(new MainVerticle(), conf, Vertx.vertx(vopt), fut); break; case "cluster": case "proxy": case "deployment": deployClustered(logger, fut); break; default: fut.handle(Future.failedFuture("Unknown command '" + mode + "'")); } }
@Override public Statement apply(Statement base, Description description) { return new Statement() { @Override public void evaluate() throws Throwable { vertx = createVertx.get(); try { Context context = vertx != null ? vertx.getOrCreateContext() : null; VertxUnitRunner.pushContext(context); base.evaluate(); } finally { VertxUnitRunner.popContext(); CountDownLatch latch = new CountDownLatch(1); closeVertx.accept(vertx, latch); try { if (!latch.await(30 * 1000, TimeUnit.MILLISECONDS)) { Logger logger = LoggerFactory.getLogger(description.getTestClass()); logger.warn("Could not close Vert.x in tme"); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } } }; }
public static void main(String[] args) { MainDeploy d = new MainDeploy(); d.init(args, res -> { if (res.failed()) { Logger logger = OkapiLogger.get(); logger.error(res.cause()); exit(1); } }); }
public PostgresHandle(Vertx vertx, JsonObject conf) { JsonObject pgconf = new JsonObject(); String val; val = Config.getSysConf("postgres_host", "", conf); if (!val.isEmpty()) { pgconf.put("host", val); } val = Config.getSysConf("postgres_port", "", conf); Logger logger = OkapiLogger.get(); if (!val.isEmpty()) { try { Integer x = Integer.parseInt(val); pgconf.put("port", x); } catch (NumberFormatException e) { logger.warn("Bad postgres_port value: " + val + ": " + e.getMessage()); } } val = Config.getSysConf("postgres_username", Config.getSysConf("postgres_user", "okapi", conf), conf); if (!val.isEmpty()) { pgconf.put("username", val); } val = Config.getSysConf("postgres_password", "okapi25", conf); if (!val.isEmpty()) { pgconf.put("password", val); } val = Config.getSysConf("postgres_database", "okapi", conf); if (!val.isEmpty()) { pgconf.put("database", val); } logger.debug("Connecting to postgres with " + pgconf.encode()); cli = PostgreSQLClient.createNonShared(vertx, pgconf); logger.debug("created"); }
public AsyncFileWriterImpl(long startPosition, WriteQueueSupport<AsyncFileWriter> writeQueueSupport, Context context, AsynchronousFileChannel dataFile, Logger log) { this.log = log; this.startPosition = startPosition; this.writePos = startPosition; this.ch = dataFile; this.context = context; this.writeQueueSupport = writeQueueSupport; this.lastWriteTime = System.currentTimeMillis(); }
public AsyncFileReaderImpl(Context context, long startPosition, int bufferSize, long length, AsynchronousFileChannel dataFile, Logger log) { this.log = log; this.bufferSize = bufferSize; this.readPos = startPosition; this.bytesRemaining = length; this.startPosition = startPosition; this.ch = dataFile; this.context = context; }
static <T> Handler<AsyncResult<T>> logIfFailed(final String msg, final Logger log) { return res -> { if (res.failed()) { if (msg != null) { log.error(msg, res.cause()); } else { log.error(res.cause()); } } }; }
protected Logger getLogger() { return LoggerFactory.getLogger(getClass()); }
public static void jvm(final Logger logger, final Throwable ex) { Fn.safeNull(logger::warn, ex); ex.printStackTrace(); }
public static void zero(final Logger logger, final ZeroException ex) { Fn.safeNull(logger::warn, ex); }
public static void vertx(final Logger logger, final VertxException ex) { Fn.safeNull(logger::warn, ex); }
public static void info(final Logger logger, final String pattern, final Object... rest) { log(logger::isInfoEnabled, logger::info, pattern, rest); }
public static void debug(final Logger logger, final String pattern, final Object... rest) { log(() -> true, logger::debug, pattern, rest); }
public static void warn(final Logger logger, final String pattern, final Object... rest) { log(() -> true, logger::warn, pattern, rest); }
public static void error(final Logger logger, final String pattern, final Object... rest) { log(() -> true, logger::error, pattern, rest); }
<T> Future<T> fetchWithRetry(Logger logger, Callable<T> blockingHandler) { return future((Future<T> fut) -> fetchWithRetry(logger, blockingHandler, fut)); }
public VerticleHelper(Logger logger) { this.logger = logger; }
public static Logger get() { System.setProperty("vertx.logger-delegate-factory-class-name", "io.vertx.core.logging.SLF4JLogDelegateFactory"); return LoggerFactory.getLogger("okapi"); }
public EventBusServiceHelper(Vertx vertx, Logger logger) { this.vertx = vertx; this.logger = logger; }
/** * <p>Create a function that can be passed to {@link rx.Observable#retryWhen(Func1)} * in order to create a stream that is retried multiple times before failing.</p> * <p>Example:</p> * <pre> * Observable.create(subscriber -> { * // retryWhen will re-subscribe in case of error so this code * // will be executed 5 times and finally fail with the given exception * Observable.<String>error(new IllegalStateException()).subscribe(subscriber); * }).retryWhen(RxUtils.makeRetry(5, 1000, null)); * </pre> * @param retries the number of retries * @param interval the number of milliseconds to wait before a retry * @param log optional logger used to record failed attempts (may be null) * @return a function that can be passed to {@link rx.Observable#retryWhen(Func1)} */ public static Func1<Observable<? extends Throwable>, Observable<Long>> makeRetry( int retries, int interval, Logger log) { return attempts -> { return attempts.zipWith(Observable.range(1, retries + 1), (n, i) -> Pair.of(n, i)).flatMap(t -> { if (t.getValue() > retries) { return Observable.error(t.getKey()); } if (log != null) { log.warn("Operation failed", t.getKey()); log.info("Retry " + t.getValue() + " in " + interval + " milliseconds"); } return Observable.timer(interval, TimeUnit.MILLISECONDS); }); }; }
public JGroupsLoggerAdapter(Logger logger) { this.logger = logger; }
@Override public Logger log() { return LOG; }
@Override public Logger log() { return log; }
public VertxApimanLogger(Logger logger) { this.logger = logger; }
protected Logger getLogger() { return log; }