Search in sources :

Example 1 with FormattedMessage

use of org.apache.logging.log4j.message.FormattedMessage in project logging-log4j2 by apache.

the class LoggerSupplierTest method flowTracing_SupplierOfFormattedMessage.

@Test
public void flowTracing_SupplierOfFormattedMessage() {
    logger.traceEntry(() -> new FormattedMessage("int foo={}", 1234567890));
    assertThat(results).hasSize(1);
    String entry = results.get(0);
    assertThat(entry).startsWith("ENTER[ FLOW ] TRACE Enter").contains("(int foo=1234567890)").doesNotContain("FormattedMessage");
}
Also used : FormattedMessage(org.apache.logging.log4j.message.FormattedMessage) StringFormattedMessage(org.apache.logging.log4j.message.StringFormattedMessage) Test(org.junit.jupiter.api.Test)

Example 2 with FormattedMessage

use of org.apache.logging.log4j.message.FormattedMessage in project GregTech by GregTechCE.

the class CoverFluidRegulator method doKeepExact.

/**
 * Performs one tick worth of Keep Exact behavior.
 * @param transferLimit the maximum amount in milliBuckets that may be transferred in one tick
 * @param sourceHandler source(s) to move fluids from
 * @param destHandler destination(s) to move fluids to
 * @param fluidFilter a predicate which determines what fluids may be moved
 * @param keepAmount the desired amount in milliBuckets of a particular fluid in the destination
 * @return the total amount in milliBuckets of all fluids transferred from source to dest by this method
 */
protected int doKeepExact(final int transferLimit, final IFluidHandler sourceHandler, final IFluidHandler destHandler, final Predicate<FluidStack> fluidFilter, final int keepAmount) {
    if (sourceHandler == null || destHandler == null || fluidFilter == null || keepAmount <= 0)
        return 0;
    final Map<FluidStack, Integer> sourceFluids = collectDistinctFluids(sourceHandler, IFluidTankProperties::canDrain, fluidFilter);
    final Map<FluidStack, Integer> destFluids = collectDistinctFluids(destHandler, IFluidTankProperties::canFill, fluidFilter);
    int transferred = 0;
    for (FluidStack fluidStack : sourceFluids.keySet()) {
        if (transferred >= transferLimit)
            break;
        // if fluid needs to be moved to meet the Keep Exact value
        int amountInDest;
        if ((amountInDest = destFluids.getOrDefault(fluidStack, 0)) < keepAmount) {
            // move the lesser of the remaining transfer limit and the difference in actual vs keep exact amount
            int amountToMove = Math.min(transferLimit - transferred, keepAmount - amountInDest);
            // Nothing to do here, try the next fluid.
            if (amountToMove <= 0)
                continue;
            // Simulate a drain of this fluid from the source tanks
            FluidStack drainedResult = sourceHandler.drain(copyFluidStackWithAmount(fluidStack, amountToMove), false);
            // Can't drain this fluid. Try the next one.
            if (drainedResult == null || drainedResult.amount <= 0 || !fluidStack.equals(drainedResult))
                continue;
            // account for the possibility that the drain might give us less than requested
            final int drainable = Math.min(amountToMove, drainedResult.amount);
            // Simulate a fill of the drained amount
            int fillResult = destHandler.fill(copyFluidStackWithAmount(fluidStack, drainable), false);
            // Can't fill, try the next fluid.
            if (fillResult <= 0)
                continue;
            // This Fluid can be drained and filled, so let's move the most that will actually work.
            int fluidToMove = Math.min(drainable, fillResult);
            FluidStack drainedActual = sourceHandler.drain(copyFluidStackWithAmount(fluidStack, fluidToMove), true);
            // Account for potential error states from the drain
            if (drainedActual == null)
                throw new RuntimeException("Misbehaving fluid container: drain produced null after simulation succeeded");
            if (!fluidStack.equals(drainedActual))
                throw new RuntimeException("Misbehaving fluid container: drain produced a different fluid than the simulation");
            if (drainedActual.amount != fluidToMove)
                throw new RuntimeException(new FormattedMessage("Misbehaving fluid container: drain expected: {}, actual: {}", fluidToMove, drainedActual.amount).getFormattedMessage());
            // Perform Fill
            int filledActual = destHandler.fill(copyFluidStackWithAmount(fluidStack, fluidToMove), true);
            // Account for potential error states from the fill
            if (filledActual != fluidToMove)
                throw new RuntimeException(new FormattedMessage("Misbehaving fluid container: fill expected: {}, actual: {}", fluidToMove, filledActual).getFormattedMessage());
            // update the transferred amount
            transferred += fluidToMove;
        }
    }
    return transferred;
}
Also used : IFluidTankProperties(net.minecraftforge.fluids.capability.IFluidTankProperties) FluidStack(net.minecraftforge.fluids.FluidStack) FormattedMessage(org.apache.logging.log4j.message.FormattedMessage)

Example 3 with FormattedMessage

use of org.apache.logging.log4j.message.FormattedMessage in project Gaspunk by Ladysnake.

the class GasDeserializer method loadGases.

private static boolean loadGases(Path root, Path file) {
    String relative = root.relativize(file).toString();
    if (!"json".equals(FilenameUtils.getExtension(file.toString())) || relative.startsWith("_"))
        return true;
    String name = FilenameUtils.removeExtension(relative).replaceAll("\\\\", "/");
    try (BufferedReader reader = Files.newBufferedReader(file)) {
        Gas gas = GSON.fromJson(reader, Gas.class);
        ModGases.REGISTRY.register(gas.setRegistryName(name));
    } catch (Exception e) {
        GasPunk.LOGGER.error(new FormattedMessage("Error trying to load a gas from file {}", file), e);
    }
    return true;
}
Also used : BufferedReader(java.io.BufferedReader) AbstractGas(ladysnake.gaspunk.api.AbstractGas) IGas(ladysnake.gaspunk.api.IGas) Gas(ladysnake.gaspunk.gas.Gas) IOException(java.io.IOException) FormattedMessage(org.apache.logging.log4j.message.FormattedMessage)

Aggregations

FormattedMessage (org.apache.logging.log4j.message.FormattedMessage)3 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 AbstractGas (ladysnake.gaspunk.api.AbstractGas)1 IGas (ladysnake.gaspunk.api.IGas)1 Gas (ladysnake.gaspunk.gas.Gas)1 FluidStack (net.minecraftforge.fluids.FluidStack)1 IFluidTankProperties (net.minecraftforge.fluids.capability.IFluidTankProperties)1 StringFormattedMessage (org.apache.logging.log4j.message.StringFormattedMessage)1 Test (org.junit.jupiter.api.Test)1