Search in sources :

Example 76 with DistributionRegion

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);
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) KDtreeSpacePartitioner(org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner) DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) Test(org.junit.Test)

Example 77 with DistributionRegion

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);
    }
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BoundingBox(org.bboxdb.commons.math.BoundingBox) BBoxDBException(org.bboxdb.misc.BBoxDBException)

Example 78 with DistributionRegion

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);
    }
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BoundingBox(org.bboxdb.commons.math.BoundingBox) GeoPosition(org.jxmapviewer.viewer.GeoPosition)

Example 79 with DistributionRegion

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);
    }
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) DistributionRegionComponent(org.bboxdb.tools.gui.DistributionRegionComponent)

Example 80 with DistributionRegion

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;
}
Also used : DistributionGroupAdapter(org.bboxdb.distribution.zookeeper.DistributionGroupAdapter) SuccessResponse(org.bboxdb.network.packages.response.SuccessResponse) CreateDistributionGroupRequest(org.bboxdb.network.packages.request.CreateDistributionGroupRequest) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) DistributionRegionAdapter(org.bboxdb.distribution.zookeeper.DistributionRegionAdapter) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) IOException(java.io.IOException) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Aggregations

DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)91 Test (org.junit.Test)45 BBoxDBException (org.bboxdb.misc.BBoxDBException)34 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)33 BoundingBox (org.bboxdb.commons.math.BoundingBox)27 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)23 ArrayList (java.util.ArrayList)17 List (java.util.List)17 SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)16 DistributionRegionAdapter (org.bboxdb.distribution.zookeeper.DistributionRegionAdapter)15 DistributionGroupConfiguration (org.bboxdb.storage.entity.DistributionGroupConfiguration)15 KDtreeSpacePartitioner (org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner)14 DistributionGroupAdapter (org.bboxdb.distribution.zookeeper.DistributionGroupAdapter)11 ZookeeperClientFactory (org.bboxdb.distribution.zookeeper.ZookeeperClientFactory)11 DistributionRegionState (org.bboxdb.distribution.partitioner.DistributionRegionState)10 DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)10 DistributionRegionSyncer (org.bboxdb.distribution.region.DistributionRegionSyncer)10 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)10 RoutingHop (org.bboxdb.network.routing.RoutingHop)10 DistributionGroupConfigurationBuilder (org.bboxdb.storage.entity.DistributionGroupConfigurationBuilder)10