@@ -0,0 +1,1373 @@
+package org.ethereum.listener;%0A%0Aimport org.ethereum.core.TransactionExecutionSummary;%0A%0Aimport java.util.Arrays;%0A%0A/**%0A * Calculates a 'reasonable' Gas price based on statistics of the latest transaction's Gas prices%0A *%0A * Normally the price returned should be sufficient to execute a transaction since ~25%25 of the latest%0A * transactions were executed at this or lower price.%0A *%0A * Created by Anton Nashatyrev on 22.09.2015.%0A */%0Apublic class GasPriceTracker extends EthereumListenerAdapter %7B%0A%0A    private long%5B%5D window = new long%5B512%5D;%0A    private int idx = window.length - 1;%0A    private boolean filled = false;%0A    private long defaultPrice = 70_000_000_000L;%0A%0A    private long lastVal;%0A%0A    @Override%0A    public void onTransactionExecuted(TransactionExecutionSummary summary) %7B%0A        if (idx == 0) %7B%0A            idx = window.length - 1;%0A            filled = true;%0A            lastVal = 0;  // recalculate only 'sometimes'%0A        %7D%0A        window%5Bidx--%5D = summary.getGasPrice().longValue();%0A    %7D%0A%0A    public long getGasPrice() %7B%0A        if (!filled) %7B%0A            return defaultPrice;%0A        %7D else %7B%0A            if (lastVal == 0) %7B%0A                long%5B%5D longs = Arrays.copyOf(window, window.length);%0A                Arrays.sort(longs);%0A                lastVal = longs%5Blongs.length / 4%5D;  // 25%25 percentile%0A            %7D%0A            return lastVal;%0A        %7D%0A    %7D%0A%7D%0A

Add a small utility to track fair gas price