Search in sources :

Example 1 with Timer

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

the class ImageEncodeProcessor method encodeImageResponse.

@Consumes(ImageResponse.class)
@Produces({ EncodedImageResponse.class, EndOfProcessing.class })
public void encodeImageResponse(ImageResponse response, ProcessorContext context) throws Exception {
    Timer timer = new Timer();
    // chunked reponse output stream
    ChunkedResponseOutputStream out = new ChunkedResponseOutputStream(context) {

        protected ProcessorResponse createResponse(byte[] buf, int buflen) {
            // log.debug( "sending: buflen= " + buflen );
            return new EncodedImageResponse(buf, buflen);
        }
    };
    // load image data
    // new javax.swing.ImageIcon( image ).getImage();
    String format = (String) context.get("format");
    if ("image/jpeg".equals(format)) {
        imageioEncodeJPEG(response.getImage(), out);
    } else {
        opEncodePNG(response.getImage(), out);
    }
    log.debug("encode: ready. (" + timer.elapsedTime() + "ms)");
    out.flush();
    context.sendResponse(ProcessorResponse.EOP);
    log.debug("...all data sent. (" + out.getTotalSent() + " bytes " + format + ")");
}
Also used : Timer(org.polymap.core.runtime.Timer) ChunkedResponseOutputStream(org.polymap.core.data.util.ChunkedResponseOutputStream) Consumes(org.polymap.core.data.pipeline.Consumes) Produces(org.polymap.core.data.pipeline.Produces)

Example 2 with Timer

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

the class LuceneRecordQuery method execute.

public ResultSet execute() throws IOException {
    Timer timer = new Timer();
    // Lucene does not have a firstResult feature
    int requestedResults = getMaxResults() + getFirstResult();
    return store.readLocked(() -> {
        String sortKey = getSortKey();
        if (sortKey != null) {
            int sortType = SortField.STRING;
            if (getSortType() == String.class) {
                sortType = SortField.STRING;
            } else if (getSortType() == Integer.class) {
                sortType = SortField.INT;
            } else if (getSortType() == Long.class) {
                sortType = SortField.LONG;
            } else if (getSortType() == Float.class) {
                sortType = SortField.FLOAT;
            } else if (getSortType() == Double.class) {
                sortType = SortField.DOUBLE;
            } else if (getSortType() == Date.class) {
                sortType = SortField.LONG;
                sortKey = sortKey + DateValueCoder.SUFFIX;
            }
            Sort sort = new Sort(new SortField(sortKey, sortType, getSortOrder() == DESC));
            TopDocs topDocs = store.searcher.search(luceneQuery, requestedResults, sort);
            logResult(topDocs.scoreDocs.length, timer);
            return new LuceneResultSet(topDocs.scoreDocs);
        } else {
            TopDocs topDocs = store.searcher.search(luceneQuery, requestedResults);
            logResult(topDocs.scoreDocs.length, timer);
            return new LuceneResultSet(topDocs.scoreDocs);
        }
    });
}
Also used : TopDocs(org.apache.lucene.search.TopDocs) Timer(org.polymap.core.runtime.Timer) Sort(org.apache.lucene.search.Sort) SortField(org.apache.lucene.search.SortField) Date(java.util.Date)

Example 3 with Timer

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

the class AbstractRecordStoreTest method createRecords.

// public void tstThreaded() throws Exception {
// final int loops = 250;
// final int threads = 4;
// createRecords( loops*threads );
// 
// List<Future> results = new ArrayList();
// for (int i=0; i<threads; i++) {
// results.add( Polymap.executorService().submit( new Callable() {
// public Object call() throws Exception {
// //                    readRecords( loops );
// queryRecords( loops );
// return new Object();
// }
// } ) );
// }
// // wait for results
// for (Future result : results) {
// result.get();
// }
// }
protected void createRecords(int loops) throws Exception {
    start = System.currentTimeMillis();
    final Timer timer = new Timer();
    Updater updater = store.prepareUpdate();
    try {
        for (int i = 0; i < loops; i++) {
            TestRecord record = new TestRecord(store.newRecord());
            record.payload.put("LuceneRecordStore store = new LuceneRecordStore( new File LuceneRecordStore store = new LuceneRecordStore( new File LuceneRecordStore store = new LuceneRecordStore( new File");
            record.type.put("2");
            record.count.put(i);
            updater.store(record.state());
        }
        updater.apply();
    } catch (Exception e) {
        updater.discard();
        throw e;
    }
    log.info("Records created: " + loops + " in " + timer.elapsedTime() + "ms -> " + (double) timer.elapsedTime() / loops + "ms/loop");
}
Also used : Timer(org.polymap.core.runtime.Timer) Updater(org.polymap.recordstore.IRecordStore.Updater)

Example 4 with Timer

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

the class StyleRepository method toSLD.

protected String toSLD(org.geotools.styling.Style style) {
    Timer timer = new Timer();
    try {
        SLDTransformer styleTransform = new SLDTransformer();
        styleTransform.setIndentation(4);
        styleTransform.setOmitXMLDeclaration(false);
        return styleTransform.transform(style);
    } catch (TransformerException e) {
        throw new RuntimeException("Unable to transform style.", e);
    } finally {
        log.info("Style to SLD: " + timer.elapsedTime() + "ms.");
    }
}
Also used : Timer(org.polymap.core.runtime.Timer) SLDTransformer(org.geotools.styling.SLDTransformer) TransformerException(javax.xml.transform.TransformerException)

Example 5 with Timer

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

the class Sequence method main.

// test ***********************************************
/**
 * @throws Exception
 * @throws ExecutionException
 */
public static void main(String[] args) throws Exception {
    int loops = 100000;
    int elements = 1000;
    Integer[] numbers = new Integer[elements];
    Arrays.fill(numbers, 1);
    // 
    Timer timer = new Timer();
    int result = 0;
    for (int i = 0; i < loops; i++) {
        result += Sequence.of(numbers).filter(elm -> nonzero(elm)).filter(elm -> elm < 3).count();
    }
    System.out.println(result + " - loops: " + loops + "x" + elements + " in " + timer.elapsedTime() + "ms");
    // 
    timer = new Timer();
    result = 0;
    for (int i = 0; i < loops; i++) {
        result += Arrays.asList(numbers).stream().filter(elm -> nonzero(elm)).filter(elm -> elm < 3).count();
    }
    System.out.println(result + " - loops: " + loops + "x" + elements + " in " + timer.elapsedTime() + "ms");
    // 
    timer = new Timer();
    result = 0;
    for (int i = 0; i < loops; i++) {
        int count = 0;
        for (Integer elm : numbers) {
            if (nonzero(elm)) {
                if (elm < 3) {
                    count++;
                }
            }
        }
        result += count;
    }
    System.out.println(result + " - loops: " + loops + "x" + elements + " in " + timer.elapsedTime() + "ms");
}
Also used : ExecutionException(java.util.concurrent.ExecutionException) Arrays(java.util.Arrays) Timer(org.polymap.core.runtime.Timer) Iterator(java.util.Iterator) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) 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