Search in sources :

Example 16 with BigInteger

use of java.math.BigInteger in project hadoop by apache.

the class ProcfsBasedProcessTree method getCpuUsagePercent.

/**
   * Get the CPU usage by all the processes in the process-tree in Unix.
   * Note: UNAVAILABLE will be returned in case when CPU usage is not
   * available. It is NOT advised to return any other error code.
   *
   * @return percentage CPU usage since the process-tree was created,
   * {@link #UNAVAILABLE} if CPU usage cannot be calculated or not available.
   */
@Override
public float getCpuUsagePercent() {
    BigInteger processTotalJiffies = getTotalProcessJiffies();
    cpuTimeTracker.updateElapsedJiffies(processTotalJiffies, clock.getTime());
    return cpuTimeTracker.getCpuTrackerUsagePercent();
}
Also used : BigInteger(java.math.BigInteger)

Example 17 with BigInteger

use of java.math.BigInteger in project hadoop by apache.

the class ProcfsBasedProcessTree method getTotalProcessJiffies.

private BigInteger getTotalProcessJiffies() {
    BigInteger totalStime = BigInteger.ZERO;
    long totalUtime = 0;
    for (ProcessInfo p : processTree.values()) {
        if (p != null) {
            totalUtime += p.getUtime();
            totalStime = totalStime.add(p.getStime());
        }
    }
    return totalStime.add(BigInteger.valueOf(totalUtime));
}
Also used : BigInteger(java.math.BigInteger)

Example 18 with BigInteger

use of java.math.BigInteger in project hadoop by apache.

the class WindowsBasedProcessTree method getCpuUsagePercent.

/**
   * Get the CPU usage by all the processes in the process-tree in Windows.
   * Note: UNAVAILABLE will be returned in case when CPU usage is not
   * available. It is NOT advised to return any other error code.
   *
   * @return percentage CPU usage since the process-tree was created,
   * {@link #UNAVAILABLE} if CPU usage cannot be calculated or not available.
   */
@Override
public float getCpuUsagePercent() {
    BigInteger processTotalMs = getTotalProcessMs();
    cpuTimeTracker.updateElapsedJiffies(processTotalMs, clock.getTime());
    return cpuTimeTracker.getCpuTrackerUsagePercent();
}
Also used : BigInteger(java.math.BigInteger)

Example 19 with BigInteger

use of java.math.BigInteger in project hbase by apache.

the class Bytes method iterateOnSplits.

/**
   * Iterate over keys within the passed range.
   */
public static Iterable<byte[]> iterateOnSplits(final byte[] a, final byte[] b, boolean inclusive, final int num) {
    byte[] aPadded;
    byte[] bPadded;
    if (a.length < b.length) {
        aPadded = padTail(a, b.length - a.length);
        bPadded = b;
    } else if (b.length < a.length) {
        aPadded = a;
        bPadded = padTail(b, a.length - b.length);
    } else {
        aPadded = a;
        bPadded = b;
    }
    if (compareTo(aPadded, bPadded) >= 0) {
        throw new IllegalArgumentException("b <= a");
    }
    if (num <= 0) {
        throw new IllegalArgumentException("num cannot be <= 0");
    }
    byte[] prependHeader = { 1, 0 };
    final BigInteger startBI = new BigInteger(add(prependHeader, aPadded));
    final BigInteger stopBI = new BigInteger(add(prependHeader, bPadded));
    BigInteger diffBI = stopBI.subtract(startBI);
    if (inclusive) {
        diffBI = diffBI.add(BigInteger.ONE);
    }
    final BigInteger splitsBI = BigInteger.valueOf(num + 1);
    //when diffBI < splitBI, use an additional byte to increase diffBI
    if (diffBI.compareTo(splitsBI) < 0) {
        byte[] aPaddedAdditional = new byte[aPadded.length + 1];
        byte[] bPaddedAdditional = new byte[bPadded.length + 1];
        for (int i = 0; i < aPadded.length; i++) {
            aPaddedAdditional[i] = aPadded[i];
        }
        for (int j = 0; j < bPadded.length; j++) {
            bPaddedAdditional[j] = bPadded[j];
        }
        aPaddedAdditional[aPadded.length] = 0;
        bPaddedAdditional[bPadded.length] = 0;
        return iterateOnSplits(aPaddedAdditional, bPaddedAdditional, inclusive, num);
    }
    final BigInteger intervalBI;
    try {
        intervalBI = diffBI.divide(splitsBI);
    } catch (Exception e) {
        LOG.error("Exception caught during division", e);
        return null;
    }
    final Iterator<byte[]> iterator = new Iterator<byte[]>() {

        private int i = -1;

        @Override
        public boolean hasNext() {
            return i < num + 1;
        }

        @Override
        public byte[] next() {
            i++;
            if (i == 0)
                return a;
            if (i == num + 1)
                return b;
            BigInteger curBI = startBI.add(intervalBI.multiply(BigInteger.valueOf(i)));
            byte[] padded = curBI.toByteArray();
            if (padded[1] == 0)
                padded = tail(padded, padded.length - 2);
            else
                padded = tail(padded, padded.length - 1);
            return padded;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
    return new Iterable<byte[]>() {

        @Override
        public Iterator<byte[]> iterator() {
            return iterator;
        }
    };
}
Also used : Iterator(java.util.Iterator) BigInteger(java.math.BigInteger) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 20 with BigInteger

use of java.math.BigInteger in project hbase by apache.

the class ByteBufferUtils method toBigDecimal.

/**
   * Reads a BigDecimal value at the given buffer's offset.
   * @param buffer
   * @param offset
   * @return BigDecimal value at offset
   */
public static BigDecimal toBigDecimal(ByteBuffer buffer, int offset, int length) {
    if (buffer == null || length < Bytes.SIZEOF_INT + 1 || (offset + length > buffer.limit())) {
        return null;
    }
    int scale = toInt(buffer, offset);
    byte[] tcBytes = new byte[length - Bytes.SIZEOF_INT];
    copyFromBufferToArray(tcBytes, buffer, offset + Bytes.SIZEOF_INT, 0, length - Bytes.SIZEOF_INT);
    return new BigDecimal(new BigInteger(tcBytes), scale);
}
Also used : BigInteger(java.math.BigInteger) BigDecimal(java.math.BigDecimal)

Aggregations

BigInteger (java.math.BigInteger)3139 BigDecimal (java.math.BigDecimal)604 Test (org.junit.Test)207 IOException (java.io.IOException)101 ArrayList (java.util.ArrayList)95 MessageDigest (java.security.MessageDigest)93 RoundingMode (java.math.RoundingMode)88 Date (java.util.Date)72 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)71 MathContext (java.math.MathContext)70 Random (java.util.Random)62 QuickTest (com.hazelcast.test.annotation.QuickTest)47 ParallelTest (com.hazelcast.test.annotation.ParallelTest)46 KeyFactory (java.security.KeyFactory)45 HashMap (java.util.HashMap)42 X509Certificate (java.security.cert.X509Certificate)39 EllipticCurve (java.security.spec.EllipticCurve)39 List (java.util.List)39 GwtIncompatible (com.google.common.annotations.GwtIncompatible)36 SecureRandom (java.security.SecureRandom)35