use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.
the class TestSpacePartitionerCache method testRootNodeRefresh.
@Test(timeout = 60000)
public void testRootNodeRefresh() throws Exception {
final DistributionGroupConfiguration configuration = DistributionGroupConfigurationBuilder.create(2).withPlacementStrategy("org.bboxdb.distribution.placement.DummyResourcePlacementStrategy", "").build();
distributionGroupZookeeperAdapter.deleteDistributionGroup(TEST_GROUP);
distributionGroupZookeeperAdapter.createDistributionGroup(TEST_GROUP, configuration);
final KDtreeSpacePartitioner oldSpacepartitionier = (KDtreeSpacePartitioner) SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(TEST_GROUP);
final DistributionRegion oldRootNode = oldSpacepartitionier.getRootNode();
final DistributionRegionIdMapper mapper = oldSpacepartitionier.getDistributionRegionIdMapper();
Assert.assertEquals(0, mapper.getAllRegionIds().size());
mapper.addMapping(3, BoundingBox.FULL_SPACE);
Assert.assertEquals(1, mapper.getAllRegionIds().size());
distributionGroupZookeeperAdapter.deleteDistributionGroup(TEST_GROUP);
distributionGroupZookeeperAdapter.createDistributionGroup(TEST_GROUP, configuration);
final KDtreeSpacePartitioner newSpacepartitionier1 = (KDtreeSpacePartitioner) SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(TEST_GROUP);
final DistributionRegion newRootNode = newSpacepartitionier1.getRootNode();
Assert.assertFalse(oldRootNode == newRootNode);
Assert.assertEquals(0, mapper.getAllRegionIds().size());
distributionGroupZookeeperAdapter.deleteDistributionGroup(TEST_GROUP);
distributionGroupZookeeperAdapter.createDistributionGroup(TEST_GROUP, configuration);
Thread.sleep(1000);
final KDtreeSpacePartitioner newSpacepartitionier2 = (KDtreeSpacePartitioner) SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(TEST_GROUP);
final DistributionRegion newRootNode2 = newSpacepartitionier2.getRootNode();
Assert.assertFalse(newRootNode2 == newRootNode);
}
use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.
the class OSMOverlayPainter method drawKDTree.
/**
* Draw the KD Tree
* @param graphicsContext
* @param map
*/
protected void drawKDTree(final Graphics2D graphicsContext, final JXMapViewer map) {
try {
// No distribution group is selected
if (guiModel.getTreeAdapter() == null || guiModel.getTreeAdapter().getRootNode() == null) {
return;
}
final DistributionRegion distributionRegion = guiModel.getTreeAdapter().getRootNode();
final BoundingBox bbox = distributionRegion.getConveringBox();
if (bbox.getDimension() != 2) {
System.err.println("Unable to print dimensions: " + bbox.getDimension());
return;
}
drawBoundingBox(graphicsContext, map, distributionRegion);
} catch (BBoxDBException e) {
logger.error("Got an exception", e);
}
}
use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.
the class OSMOverlayPainter method drawBoundingBox.
/**
* Draw a bounding box on the screen
*/
protected void drawBoundingBox(final Graphics2D graphicsContext, final JXMapViewer map, final DistributionRegion distributionRegion) {
final BoundingBox bbox = distributionRegion.getConveringBox();
final BoundingBox paintBox = bbox.getIntersection(coverBox);
final GeoPosition bl = new GeoPosition(paintBox.getCoordinateLow(0), paintBox.getCoordinateLow(1));
final GeoPosition br = new GeoPosition(paintBox.getCoordinateLow(0), paintBox.getCoordinateHigh(1));
final GeoPosition ul = new GeoPosition(paintBox.getCoordinateHigh(0), paintBox.getCoordinateLow(1));
final GeoPosition ur = new GeoPosition(paintBox.getCoordinateHigh(0), paintBox.getCoordinateHigh(1));
drawLine(graphicsContext, bl, br, map);
drawLine(graphicsContext, br, ur, map);
drawLine(graphicsContext, ur, ul, map);
drawLine(graphicsContext, ul, bl, map);
for (final DistributionRegion region : distributionRegion.getDirectChildren()) {
drawBoundingBox(graphicsContext, map, region);
}
}
use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.
the class TreeJPanel method createDistribtionRegionComponents.
/**
* Create the distribution region components
* @param distributionRegion
* @param maxChildren
*/
protected void createDistribtionRegionComponents(final DistributionRegion distributionRegion, final int maxChildren) {
if (distributionRegion == null) {
return;
}
final DistributionRegionComponent distributionRegionComponent = new DistributionRegionComponent(distributionRegion, this, guiModel, maxChildren);
regions.add(distributionRegionComponent);
for (final DistributionRegion region : distributionRegion.getDirectChildren()) {
createDistribtionRegionComponents(region, maxChildren);
}
}
use of org.bboxdb.distribution.region.DistributionRegion in project bboxdb by jnidzwetzki.
the class CreateDistributionGroupHandler method handleRequest.
@Override
public /**
* Create a new distribution group
*/
boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
try {
final CreateDistributionGroupRequest createPackage = CreateDistributionGroupRequest.decodeTuple(encodedPackage);
final String distributionGroup = createPackage.getDistributionGroup();
logger.info("Create distribution group: {}", distributionGroup);
final DistributionGroupAdapter distributionGroupAdapter = ZookeeperClientFactory.getZookeeperClient().getDistributionGroupAdapter();
final DistributionRegionAdapter distributionRegionAdapter = ZookeeperClientFactory.getZookeeperClient().getDistributionRegionAdapter();
final List<String> knownGroups = distributionGroupAdapter.getDistributionGroups();
if (knownGroups.contains(distributionGroup)) {
logger.error("Untable to create distributon group {}, already exists", distributionGroup);
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_DGROUP_EXISTS);
clientConnectionHandler.writeResultPackage(responsePackage);
return true;
}
distributionGroupAdapter.createDistributionGroup(distributionGroup, createPackage.getDistributionGroupConfiguration());
final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroup);
final DistributionRegion region = spacePartitioner.getRootNode();
distributionRegionAdapter.setStateForDistributionRegion(region, DistributionRegionState.ACTIVE);
clientConnectionHandler.writeResultPackage(new SuccessResponse(packageSequence));
} catch (Exception e) {
logger.warn("Error while create distribution group", e);
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION);
clientConnectionHandler.writeResultPackage(responsePackage);
}
return true;
}
Aggregations