List of usage examples for org.apache.commons.lang3.mutable MutableDouble add
public void add(final Number operand)
From source file:de.sanandrew.mods.claysoldiers.util.soldier.upgrade.misc.UpgradeGlass.java
@Override public void getLookRange(EntityClayMan clayMan, SoldierUpgradeInst upgradeInst, MutableDouble radius) { radius.add(radius); }
From source file:org.apache.apex.malhar.lib.window.accumulation.SumDouble.java
@Override public MutableDouble accumulate(MutableDouble accumulatedValue, Double input) { accumulatedValue.add(input); return accumulatedValue; }
From source file:org.apache.apex.malhar.lib.window.accumulation.SumDouble.java
@Override public MutableDouble merge(MutableDouble accumulatedValue1, MutableDouble accumulatedValue2) { accumulatedValue1.add(accumulatedValue2); return accumulatedValue1; }
From source file:org.apache.pulsar.broker.loadbalance.impl.OverloadShedder.java
/** * Attempt to shed some bundles off every broker which is overloaded. * * @param loadData// w w w . j a v a 2s. c om * The load data to used to make the unloading decision. * @param conf * The service configuration. * @return A map from bundles to unload to the brokers on which they are loaded. */ public Multimap<String, String> findBundlesForUnloading(final LoadData loadData, final ServiceConfiguration conf) { selectedBundlesCache.clear(); final double overloadThreshold = conf.getLoadBalancerBrokerOverloadedThresholdPercentage() / 100.0; final Map<String, Long> recentlyUnloadedBundles = loadData.getRecentlyUnloadedBundles(); // Check every broker and select loadData.getBrokerData().forEach((broker, brokerData) -> { final LocalBrokerData localData = brokerData.getLocalData(); final double currentUsage = localData.getMaxResourceUsage(); if (currentUsage < overloadThreshold) { if (log.isDebugEnabled()) { log.debug("[{}] Broker is not overloaded, ignoring at this point", broker); } return; } // We want to offload enough traffic such that this broker will go below the overload threshold // Also, add a small margin so that this broker won't be very close to the threshold edge. double percentOfTrafficToOffload = currentUsage - overloadThreshold + ADDITIONAL_THRESHOLD_PERCENT_MARGIN; double brokerCurrentThroughput = localData.getMsgThroughputIn() + localData.getMsgThroughputOut(); double minimumThroughputToOffload = brokerCurrentThroughput * percentOfTrafficToOffload; log.info( "Attempting to shed load on {}, which has max resource usage above threshold {}% > {}% -- Offloading at least {} MByte/s of traffic", broker, currentUsage, overloadThreshold, minimumThroughputToOffload / 1024 / 1024); MutableDouble trafficMarkedToOffload = new MutableDouble(0); MutableBoolean atLeastOneBundleSelected = new MutableBoolean(false); if (localData.getBundles().size() > 1) { // Sort bundles by throughput, then pick the biggest N which combined make up for at least the minimum throughput to offload loadData.getBundleData().entrySet().stream().map((e) -> { // Map to throughput value // Consider short-term byte rate to address system resource burden String bundle = e.getKey(); BundleData bundleData = e.getValue(); TimeAverageMessageData shortTermData = bundleData.getShortTermData(); double throughput = shortTermData.getMsgThroughputIn() + shortTermData.getMsgThroughputOut(); return Pair.of(bundle, throughput); }).filter(e -> { // Only consider bundles that were not already unloaded recently return !recentlyUnloadedBundles.containsKey(e.getLeft()); }).sorted((e1, e2) -> { // Sort by throughput in reverse order return Double.compare(e2.getRight(), e1.getRight()); }).forEach(e -> { if (trafficMarkedToOffload.doubleValue() < minimumThroughputToOffload || atLeastOneBundleSelected.isFalse()) { selectedBundlesCache.put(broker, e.getLeft()); trafficMarkedToOffload.add(e.getRight()); atLeastOneBundleSelected.setTrue(); } }); } else if (localData.getBundles().size() == 1) { log.warn( "HIGH USAGE WARNING : Sole namespace bundle {} is overloading broker {}. " + "No Load Shedding will be done on this broker", localData.getBundles().iterator().next(), broker); } else { log.warn("Broker {} is overloaded despite having no bundles", broker); } }); return selectedBundlesCache; }
From source file:org.matsim.contrib.drt.analysis.DynModePassengerStats.java
@Override public void handleEvent(LinkEnterEvent event) { if (inVehicleDistance.containsKey(event.getVehicleId())) { double distance = network.getLinks().get(event.getLinkId()).getLength(); for (MutableDouble d : inVehicleDistance.get(event.getVehicleId()).values()) { d.add(distance); }//from ww w . j a v a2 s. co m this.vehicleDistances.get(event.getVehicleId())[0] += distance; // overall distance drive int occupancy = inVehicleDistance.get(event.getVehicleId()).size(); this.vehicleDistances.get(event.getVehicleId())[1] += distance * occupancy; // overall revenue distance if (occupancy > 0) { this.vehicleDistances.get(event.getVehicleId())[2] += distance; // overall occupied distance this.vehicleDistances.get(event.getVehicleId())[2 + occupancy] += distance; // overall occupied distance with n passengers } } }