Search in sources :

Example 6 with Timer

use of org.polymap.core.runtime.Timer in project polymap4-core by Polymap4.

the class WebDavServer method service.

public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
    Timer timer = new Timer();
    HttpServletRequest req = (HttpServletRequest) servletRequest;
    HttpServletResponse resp = (HttpServletResponse) servletResponse;
    DefaultSessionContextProvider contextProvider = FsPlugin.getDefault().sessionContextProvider;
    try {
        Request request = new io.milton.servlet.ServletRequest(req, servletRequest.getServletContext());
        Response response = new io.milton.servlet.ServletResponse(resp);
        threadRequest.set(request);
        threadResponse.set(response);
        Auth auth = request.getAuthorization();
        log.debug("Auth: " + auth);
        // map/create session context
        req.getSession(true);
        if (auth != null) {
            contextProvider.mapContext(auth.getUser(), true);
            log.debug("SessionContext: " + SessionContext.current());
        }
        httpManager.process(request, response);
        log.debug("Request: " + Request.Header.ACCEPT_ENCODING.code + ": " + request.getHeaders().get(Request.Header.ACCEPT_ENCODING.code) + " --> Response: " + Response.Header.CONTENT_ENCODING.code + ": " + response.getHeaders().get(Response.Header.CONTENT_ENCODING.code));
        log.debug("Response: " + response.getStatus());
    } finally {
        if (contextProvider.currentContext() != null) {
            contextProvider.unmapContext();
        }
        threadRequest.set(null);
        threadResponse.set(null);
        servletResponse.getOutputStream().flush();
        servletResponse.flushBuffer();
    }
    log.info("WebDAV request: " + timer.elapsedTime() + "ms");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletResponse(javax.servlet.ServletResponse) Response(io.milton.http.Response) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletResponse(javax.servlet.ServletResponse) Timer(org.polymap.core.runtime.Timer) Auth(io.milton.http.Auth) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) Request(io.milton.http.Request) HttpServletResponse(javax.servlet.http.HttpServletResponse) DefaultSessionContextProvider(org.polymap.core.runtime.session.DefaultSessionContextProvider)

Example 7 with Timer

use of org.polymap.core.runtime.Timer in project polymap4-core by Polymap4.

the class PredefinedColorMapEditor method main.

// Test ***********************************************
public static void main(String[] args) throws Exception {
    File f = new File("/home/falko/Data/ncrast/elevation_4326.tif");
    AbstractGridFormat format = GridFormatFinder.findFormat(f);
    AbstractGridCoverage2DReader reader = format.getReader(f);
    String[] names = reader.getGridCoverageNames();
    GridCoverage2D grid = reader.read(names[0], null);
    GridGeometry2D geometry = grid.getGridGeometry();
    GridEnvelope gridRange = geometry.getGridRange();
    int w = gridRange.getHigh(0);
    int h = gridRange.getHigh(1);
    // all
    Timer timer = new Timer();
    double min = Double.MAX_VALUE;
    double max = Double.MIN_VALUE;
    int c = 0;
    double[] buf = new double[1];
    for (int x = 0; x < w; x++) {
        for (int y = 0; y < h; y++) {
            double[] value = grid.evaluate(new GridCoordinates2D(x, y), buf);
            min = value[0] < min ? value[0] : min;
            max = value[0] > max ? value[0] : max;
            c++;
        }
    }
    System.out.println("min/max: " + min + ".." + max + " (" + c + " in " + timer.elapsedTime() + "ms)");
    // random
    timer.start();
    double[] minMax = new PredefinedColorMapEditor().minMax(grid);
    System.out.println("min/max: " + minMax[0] + ".." + minMax[1] + " (" + c + " in " + timer.elapsedTime() + "ms)");
// final DefaultProcessor proc = new DefaultProcessor(null);
// for (Operation o : proc.getOperations() ){
// System.out.println(o.getName());
// System.out.println(o.getDescription());
// System.out.println();
// }
}
Also used : GridCoverage2D(org.geotools.coverage.grid.GridCoverage2D) GridGeometry2D(org.geotools.coverage.grid.GridGeometry2D) GridEnvelope(org.opengis.coverage.grid.GridEnvelope) AbstractGridCoverage2DReader(org.geotools.coverage.grid.io.AbstractGridCoverage2DReader) Timer(org.polymap.core.runtime.Timer) AbstractGridFormat(org.geotools.coverage.grid.io.AbstractGridFormat) GridCoordinates2D(org.geotools.coverage.grid.GridCoordinates2D) File(java.io.File)

Example 8 with Timer

use of org.polymap.core.runtime.Timer in project polymap4-core by Polymap4.

the class PerformanceEventTests method testSyncPublishNoDelay.

public void testSyncPublishNoDelay() throws InterruptedException {
    count = 0;
    size = 100000;
    // handler
    Object handler = new Object() {

        @EventHandler(scope = Scope.JVM)
        public void countEvent(PerformanceTestEvent ev) {
            count++;
        }
    };
    EventManager.instance().subscribe(handler);
    // loop: publish event
    Timer timer = new Timer();
    for (int i = 0; i < size; i++) {
        EventManager.instance().syncPublish(new PerformanceTestEvent(this));
    }
    log.info("sync events: " + size + " - " + timer.elapsedTime() + "ms");
    assertEquals(count, size);
    EventManager.instance().unsubscribe(handler);
}
Also used : Timer(org.polymap.core.runtime.Timer)

Example 9 with Timer

use of org.polymap.core.runtime.Timer in project polymap4-core by Polymap4.

the class PerformanceEventTests method testPublishDelay.

public void testPublishDelay() throws InterruptedException {
    count = 0;
    size = 1000000;
    // handler
    Object handler = new Object() {

        @EventHandler(scope = Scope.JVM, delay = 10)
        public void countEvent(List<PerformanceTestEvent> evs) {
            count += evs.size();
            log.info("    handle delayed (10ms): " + evs.size() + " - " + count);
            synchronized (this) {
                notifyAll();
            }
        }
    };
    EventManager.instance().subscribe(handler, ev -> ev instanceof PerformanceTestEvent);
    // loop: publish event
    Timer timer = new Timer();
    for (int i = 0; i < size; i++) {
        EventManager.instance().publish(new PerformanceTestEvent(this));
    // Thread.sleep( 10 );
    }
    log.info("delayed async events: " + size + " - " + timer.elapsedTime() + "ms");
    // wait for results
    while (count < size - 1) {
        synchronized (handler) {
            handler.wait(100);
        }
    }
    log.info("    count: " + count + " - " + timer.elapsedTime() + "ms");
    EventManager.instance().unsubscribe(handler);
}
Also used : Timer(org.polymap.core.runtime.Timer) List(java.util.List)

Example 10 with Timer

use of org.polymap.core.runtime.Timer in project polymap4-core by Polymap4.

the class PerformanceEventTests method testPublishNoDelay.

public void testPublishNoDelay() throws InterruptedException {
    count = 0;
    size = 1000000;
    // handler
    Object handler = new Object() {

        @EventHandler(scope = Scope.JVM)
        public void countEvent(PerformanceTestEvent ev) {
            count++;
            synchronized (this) {
                notifyAll();
            }
        }
    };
    EventManager.instance().subscribe(handler, ev -> ev instanceof PerformanceTestEvent);
    // loop: publish event
    Timer timer = new Timer();
    for (int i = 0; i < size; i++) {
        EventManager.instance().publish(new PerformanceTestEvent(this));
    }
    log.info("async events: " + size + " - " + timer.elapsedTime() + "ms");
    // wait for results
    while (count < size) {
        synchronized (handler) {
            handler.wait(10);
        }
    }
    log.info("    count: " + count + " - " + timer.elapsedTime() + "ms");
    EventManager.instance().unsubscribe(handler);
}
Also used : Timer(org.polymap.core.runtime.Timer)

Aggregations

Timer (org.polymap.core.runtime.Timer)24 IOException (java.io.IOException)4 IRecordState (org.polymap.recordstore.IRecordState)4 ResultSet (org.polymap.recordstore.ResultSet)4 Random (java.util.Random)3 Iterator (java.util.Iterator)2 Log (org.apache.commons.logging.Log)2 LogFactory (org.apache.commons.logging.LogFactory)2 GridCoordinates2D (org.geotools.coverage.grid.GridCoordinates2D)2 GridGeometry2D (org.geotools.coverage.grid.GridGeometry2D)2 GridEnvelope (org.opengis.coverage.grid.GridEnvelope)2 Filter (org.opengis.filter.Filter)2 RecordQuery (org.polymap.recordstore.RecordQuery)2 SimpleQuery (org.polymap.recordstore.SimpleQuery)2 LuceneRecordQuery (org.polymap.recordstore.lucene.LuceneRecordQuery)2 Auth (io.milton.http.Auth)1 Request (io.milton.http.Request)1 Response (io.milton.http.Response)1 RenderedImage (java.awt.image.RenderedImage)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1