@Override protected boolean isAcceptableConsumption(final ResourceConsumption con) { final ResourceSpreader consumer = con.getConsumer(); final boolean internalConsumer = (consumer == directConsumer) && (directConsumerUsageMoratory ? (onOffEvent == null ? false : onOffEvent.currentConsumption == con) : true); final boolean runningVirtualMachine; if (internalConsumer) { runningVirtualMachine = false; } else { if (consumer instanceof VirtualMachine) { runningVirtualMachine = vms.contains((VirtualMachine) consumer); } else { runningVirtualMachine = false; } } return internalConsumer || runningVirtualMachine ? super.isAcceptableConsumption(con) : false; }
private void sendTask() { // Did we finish all the tasks for the state change? if (tasksDue.size() == 0) { // Mark the completion of the state change onOffEvent = null; setState(newState); return; } // No we did not, lets send some more to our direct consumer final double totalConsumption = tasksDue.removeAt(0); final double limit = tasksDue.removeAt(0); currentConsumption = new ResourceConsumption( totalConsumption, limit, directConsumer, PhysicalMachine.this, this); if (!currentConsumption.registerConsumption()) { throw new IllegalStateException( "PowerStateChange was not successful because resource consumption could not be registered"); } }