/*******************************************************************************
 *
 *    Copyright (C) 2015-2018 the BBoxDB project
 *  
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *  
 *      http://www.apache.org/licenses/LICENSE-2.0
 *  
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License. 
 *    
 *******************************************************************************/
package org.bboxdb.distribution.placement;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Random;

import org.bboxdb.distribution.membership.BBoxDBInstance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RandomResourcePlacementStrategy extends ResourcePlacementStrategy {

	/**
	 * The random generator
	 */
	protected final Random randomGenerator;
	
	/**
	 * The Logger
	 */
	protected final static Logger logger = LoggerFactory.getLogger(RandomResourcePlacementStrategy.class);
	
	public RandomResourcePlacementStrategy() {
		randomGenerator = new Random();
	}
	
	@Override
	public BBoxDBInstance getInstancesForNewRessource(final List<BBoxDBInstance> systems, 
			final Collection<BBoxDBInstance> blacklist) throws ResourceAllocationException {
		
		if(systems.isEmpty()) {
			throw new ResourceAllocationException("Unable to choose a system, list of systems is empty");
		}
		
		final List<BBoxDBInstance> availableSystems = new ArrayList<>(systems);
		availableSystems.removeAll(blacklist);
		removeAllNonReadySystems(availableSystems);
		
		if(availableSystems.isEmpty()) {
			throw new ResourceAllocationException("Unable to choose a system, all systems are blacklisted. Blacklisted: " + blacklist + " / All: " + systems);
		}
		
		final int element = Math.abs(randomGenerator.nextInt()) % availableSystems.size();
		return availableSystems.get(element);
	}
}

@@ -950,16 +950,38 @@
 til.
+concurrent.ThreadLocal
 Random;%0A
 %0Aimp
@@ -976,16 +976,16 @@
 Random;%0A
-
 %0Aimport 
@@ -1038,65 +1038,8 @@
 nce;
-%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0Apu
@@ -1122,300 +1122,8 @@
  %7B%0A%0A
-%09/**%0A%09 * The random generator%0A%09 */%0A%09protected final Random randomGenerator;%0A%09%0A%09/**%0A%09 * The Logger%0A%09 */%0A%09protected final static Logger logger = LoggerFactory.getLogger(RandomResourcePlacementStrategy.class);%0A%09%0A%09public RandomResourcePlacementStrategy() %7B%0A%09%09randomGenerator = new Random();%0A%09%7D%0A%09%0A
 %09@Ov
@@ -1816,32 +1816,35 @@
 t = 
-Math.abs(randomGenerator
+ThreadLocalRandom.current()
 .nex
@@ -1852,13 +1852,8 @@
 Int(
-)) %25 
 avai
@@ -1871,16 +1871,17 @@
 s.size()
+)
 ;%0A%09%09retu

Replaced possible non negative value