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

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

Introduction

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

Prototype

@Fluent
FileSystem props(String path, Handler<AsyncResult<FileProps>> handler);

Source Link

Document

Obtain properties for the file represented by path , asynchronously.

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  w  w . j a  v  a 2 s  .  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()));
        }
    }
}