private void addDataToTiles( String layer, AnnotationData<?> data, TilePyramid pyramid ) { // get list of the indices for all levels List< TileAndBinIndices > indices = _indexer.getIndices( data, pyramid ); // get all affected tiles List< AnnotationTile > tiles = readTilesFromIO( layer, convert( indices ) ); // add new data certificate to tiles addDataCertificateToTiles( tiles, indices, data ); // write tiles back to io writeTilesToIO( layer, tiles ); // write data to io writeDataToIO( layer, data ); }
@Override protected void configure() { // Bind REST end points for clients MapBinder<String, Class<? extends ServerResource>> resourceBinder = MapBinder.newMapBinder( binder(), new TypeLiteral<String>() {}, new TypeLiteral<Class<? extends ServerResource>>() {} ); resourceBinder.addBinding( "/{version}/annotation" ).toInstance( AnnotationResource.class ); resourceBinder.addBinding( "/annotation" ).toInstance( AnnotationResource.class ); resourceBinder.addBinding( "/annotation/{layer}/{level}/{x}/{y}.{ext}" ).toInstance( AnnotationResource.class ); resourceBinder.addBinding( "/{version}/annotation/{layer}/{level}/{x}/{y}.{ext}" ).toInstance( AnnotationResource.class ); } }
private void removeDataFromTiles( String layer, Pair<String, Long> certificate, TilePyramid pyramid ) { // read the annotation data List< Pair<String, Long> > certificates = new ArrayList<>(); certificates.add( certificate ); AnnotationData<?> data = readDataFromIO( layer, certificates ).get(0); // get list of the indices for all levels List< TileAndBinIndices > indices = _indexer.getIndices( data, pyramid ); // read existing tiles List< AnnotationTile > tiles = readTilesFromIO( layer, convert( indices ) ); // maintain lists of what bins to modify and what bins to remove List< AnnotationTile > tilesToWrite = new LinkedList<>(); List< TileIndex > tilesToRemove = new LinkedList<>(); // remove data from tiles and organize into lists to write and remove removeDataCertificateFromTiles( tilesToWrite, tilesToRemove, tiles, data, pyramid ); // write modified tiles writeTilesToIO( layer, tilesToWrite ); // remove empty tiles and data removeTilesFromIO( layer, tilesToRemove ); }
if ( getRemainingAnnotations() == 0 && _annotations.size() == 0 ) { randomAnnotation = getRandomPublicAnnotation(); modify( randomAnnotation ); break; remove( randomAnnotation ); break; read(); break; AnnotationWrapper annotation = _annotations.get( index ); _annotations.remove( index ); write( annotation ); break;
private void modify( AnnotationWrapper annotation ) { AnnotationData<?> oldAnnotation = annotation.clone(); AnnotationData<?> newAnnotation = editAnnotation( oldAnnotation ); try { long start = System.currentTimeMillis(); _service.modify( _layerId, newAnnotation ); long end = System.currentTimeMillis(); double time = ((end-start)/1000.0); annotation.update( newAnnotation ); LOGGER.debug( "Thread " + _name + " successfully modified " + newAnnotation.getUUID() + " in " + time + " sec" ); } catch (Exception e) { LOGGER.debug( "Thread " + _name + " unsuccessfully modified " + newAnnotation.getUUID() ); } }
private void write( AnnotationWrapper annotation ) { AnnotationData<?> clone = annotation.clone(); long start = System.currentTimeMillis(); _service.write( _layerId, annotation.clone() ); long end = System.currentTimeMillis(); double time = ((end-start)/1000.0); LOGGER.debug( "Thread " + _name + " successfully wrote " + clone.getUUID() + " in " + time + " sec" ); addAnnotationToPublic( annotation ); }
public void remove( String layer, Pair<String, Long> certificate ) throws IllegalArgumentException { _lock.writeLock().lock(); try { LayerConfiguration config = getLayerConfiguration( layer, null ); TilePyramid pyramid = config.produce(TilePyramid.class); /* * ensure request is coherent with server state, if client is operating * on a previous data state, prevent io corruption by throwing an exception */ if ( isRequestOutOfDate( layer, certificate ) ) { throw new IllegalArgumentException("Client is out of sync with Server, " + "REMOVE operation aborted. It is recommended " + "upon receiving this exception to refresh all client annotations"); } // remove the certificates from tiles removeDataFromTiles( layer, certificate, pyramid ); // remove data from io removeDataFromIO( layer, certificate ); } catch ( Exception e ) { throw new IllegalArgumentException( e.getMessage() ); } finally { _lock.writeLock().unlock(); } }
private void remove( AnnotationWrapper annotation ) { AnnotationData<?> clone = annotation.clone(); try { long start = System.currentTimeMillis(); _service.remove( _layerId, clone.getCertificate() ); long end = System.currentTimeMillis(); double time = ((end-start)/1000.0); removeAnnotationFromPublic(annotation); LOGGER.debug("Thread " + _name + " successfully removed " + clone.getUUID() + " in " + time + " sec"); } catch (Exception e) { LOGGER.debug("Thread " + _name + " unsuccessfully removed " + clone.getUUID() ); } }
private List<AnnotationData<?>> readTile( TileIndex tile ) { List<AnnotationData<?>> annotations = new ArrayList<>(); List<List<AnnotationData<?>>> data = _service.read( _layerId, tile, null ); if ( data != null ) { for ( List<AnnotationData<?>> bin : data ) { for ( AnnotationData<?> annotation : bin ) { annotations.add( annotation ); } } Assert.assertTrue( validateTile( annotations ) ); } return annotations; }
public List<List<AnnotationData<?>>> read( String layer, TileIndex index, JSONObject query ) { _lock.readLock().lock(); try { LayerConfiguration config = getLayerConfiguration( layer, query ); TilePyramid pyramid = config.produce( TilePyramid.class ); AnnotationFilter filter = config.produce( AnnotationFilter.class ); return getDataFromTiles( layer, index, filter, pyramid ); } catch ( Exception e ) { throw new IllegalArgumentException( e.getMessage() ); } finally { _lock.readLock().unlock(); } }
protected void writeDataToIO( String layer, AnnotationData<?> data ) { List<AnnotationData<?>> dataList = new LinkedList<>(); dataList.add( data ); try { LayerConfiguration config = getLayerConfiguration( layer, null ); AnnotationIO io = config.produce( AnnotationIO.class ); String dataId = config.getPropertyValue(LayerConfiguration.DATA_ID); io.writeData( dataId, _dataSerializer, dataList ); } catch ( Exception e ) { throw new IllegalArgumentException( e.getMessage() ); } }
private boolean checkForCollision( String layer, AnnotationData<?> annotation ) { List<Pair<String,Long>> certificate = new LinkedList<>(); certificate.add( annotation.getCertificate() ); return ( readDataFromIO( layer, certificate ).size() > 0 ) ; }
private List<AnnotationData<?>> readAll() { // scan all return readTile( new TileIndex( 0, 0, 0 ) ); }
Tester( String name ) { // set thread name _name = name; AnnotationGenerator generator = new AnnotationGenerator( BOUNDS, _groups ); // generate private local annotations for ( int i=0; i<NUM_ENTRIES; i++ ) { _annotations.add( new AnnotationWrapper( generator.generateJSONAnnotation() ) ); } }
public LayerConfiguration getLayerConfiguration( String layer, JSONObject query ) { LayerConfiguration config = _layerService.getLayerConfiguration( layer, query ); config.addProperty( GROUPS, GROUPS_PATH ); config.addChildFactory( _annotationIOFactoryProvider.createFactory(config, LayerConfiguration.PYRAMID_IO_PATH) ); config.addChildFactory( _annotationFilterFactoryProvider.createFactory(config, LayerConfiguration.FILTER_PATH) ); JSONObject layerConfig = _layerService.getLayerJSON( layer ); try { config.readConfiguration( mergeQueryConfigOptions( layerConfig, query ) ); return config; } catch ( Exception e ) { return null; } }
protected void removeDataFromIO( String layer, Pair<String, Long> data ) { List<Pair<String, Long>> dataList = new LinkedList<>(); dataList.add( data ); try { LayerConfiguration config = getLayerConfiguration( layer, null ); AnnotationIO io = config.produce( AnnotationIO.class ); String dataId = config.getPropertyValue(LayerConfiguration.DATA_ID); io.removeData( dataId, dataList ); } catch ( Exception e ) { throw new IllegalArgumentException( e.getMessage() ); } }
public boolean isRequestOutOfDate( String layer, Pair<String, Long> certificate ) { List<Pair<String, Long>> certificates = new LinkedList<>(); certificates.add( certificate ); List<AnnotationData<?>> annotations = readDataFromIO( layer, certificates ); if ( annotations.size() == 0 ) { // removed since client update, abort return true; } if ( !annotations.get(0).getTimestamp().equals( certificate.getSecond() ) ) { // clients timestamp doesn't not match most up to date, abort return true; } // everything seems to be in order return false; }
protected void removeTilesFromIO( String layer, List<TileIndex> tiles ) { if ( tiles.size() == 0 ) { return; } try { LayerConfiguration config = getLayerConfiguration( layer, null ); PyramidIO io = config.produce( PyramidIO.class ); String dataId = config.getPropertyValue(LayerConfiguration.DATA_ID); io.removeTiles( dataId, tiles ); } catch ( Exception e ) { throw new IllegalArgumentException( e.getMessage() ); } }
protected List<AnnotationData<?>> readDataFromIO( String layer, List<Pair<String,Long>> certificates ) { List<AnnotationData<?>> data = new LinkedList<>(); if ( certificates.size() == 0 ) { return data; } try { LayerConfiguration config = getLayerConfiguration( layer, null ); String dataId = config.getPropertyValue(LayerConfiguration.DATA_ID); AnnotationIO io = config.produce( AnnotationIO.class ); data = io.readData( dataId, _dataSerializer, certificates ); } catch ( Exception e ) { throw new IllegalArgumentException( e.getMessage() ); } return data; } }