/** * Checks if two double numbers are equals, considering a precision error or 0.01. * That is, if the different between the two numbers are lower or equal to 0.01, they are considered equal. * @param first the first number to check * @param second the second number to check * @return true if the numbers are equal considering the precision error */ public static boolean same(final double first, final double second){ return same(first,second, 0.01); }
/** * Process a Host removal request received during simulation runtime. * @param srcEvt the received event */ private void processHostRemovalRequest(final SimEvent srcEvt) { final long hostId = (long)srcEvt.getData(); final Host host = getHostById(hostId); if(host == Host.NULL) { LOGGER.warn( "{}: {}: Host {} was not found to be removed from {}.", getSimulation().clock(), getClass().getSimpleName(), hostId, this); return; } HostFaultInjection fault = new HostFaultInjection(this); try { LOGGER.error( "{}: {}: Host {} removed from {} due to injected failure.", getSimulation().clock(), getClass().getSimpleName(), host.getId(), this); fault.generateHostFault(host); } finally{ fault.shutdownEntity(); } /*If the Host was found in this Datacenter, cancel the message sent to others * Datacenters to try to find the Host for removal.*/ getSimulation().cancelAll( getSimulation().getCloudInfoService(), evt -> MathUtil.same(evt.getTime(), srcEvt.getTime()) && evt.getTag() == CloudSimTags.HOST_REMOVE && (long)evt.getData() == host.getId()); }