Example usage for io.vertx.core.file FileSystem propsBlocking

List of usage examples for io.vertx.core.file FileSystem propsBlocking

Introduction

In this page you can find the example usage for io.vertx.core.file FileSystem propsBlocking.

Prototype

FileProps propsBlocking(String path);

Source Link

Document

Blocking version of #props(String,Handler)

Usage

From source file:com.klwork.spring.vertx.render.MyStaticHandlerImpl.java

License:Open Source License

private synchronized void getFileProps(RoutingContext context, String file,
        Handler<AsyncResult<FileProps>> resultHandler) {
    // FileSystem fs = context.vertx().fileSystem();
    FileSystem fs = new WindowsFileSystem((VertxInternal) context.vertx());
    if (alwaysAsyncFS || useAsyncFS) {
        wrapInTCCLSwitch(() -> fs.props(file, resultHandler), resultHandler);
    } else {//  w  ww  . j a  v  a  2s  .  co m
        // Use synchronous access - it might well be faster!
        long start = 0;
        if (tuning) {
            start = System.nanoTime();
        }
        try {
            FileProps props = wrapInTCCLSwitch(() -> fs.propsBlocking(file), resultHandler);

            if (tuning) {
                long end = System.nanoTime();
                long dur = end - start;
                totalTime += dur;
                numServesBlocking++;
                if (numServesBlocking == Long.MAX_VALUE) {
                    // Unlikely.. but...
                    resetTuning();
                } else if (numServesBlocking == nextAvgCheck) {
                    double avg = (double) totalTime / numServesBlocking;
                    if (avg > maxAvgServeTimeNanoSeconds) {
                        useAsyncFS = true;
                        log.info(
                                "Switching to async file system access in static file server as fs access is slow! (Average access time of "
                                        + avg + " ns)");
                        tuning = false;
                    }
                    nextAvgCheck += NUM_SERVES_TUNING_FS_ACCESS;
                }
            }
            resultHandler.handle(Future.succeededFuture(props));
        } catch (FileSystemException e) {
            resultHandler.handle(Future.failedFuture(e.getCause()));
        }
    }
}