Class VertxContextPRNG

java.lang.Object
io.vertx.mutiny.ext.auth.prng.VertxContextPRNG
All Implemented Interfaces:
MutinyDelegate

public class VertxContextPRNG extends Object implements MutinyDelegate
A secure non blocking random number generator isolated to the current context. The PRNG is bound to the vert.x context and setup to close when the context shuts down.

When applicable, use of VertxContextPRNG rather than create new PRNG objects is helpful to keep the system entropy usage to the minimum avoiding potential blocking across the application.

The use of VertxContextPRNG is particularly appropriate when multiple handlers use random numbers.

NOTE: This class has been automatically generated from the original non Mutiny-ified interface.

Author:
Paulo Lopes
See Also:
  • VertxContextPRNG
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    VertxContextPRNG(io.vertx.ext.auth.prng.VertxContextPRNG delegate)
    Create a new instance of VertxContextPRNG delegating to the given (non-null) instance of VertxContextPRNG.
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    stop seeding the PRNG
    Get or create a secure non blocking random number generator using the current vert.x context.
    current(Vertx vertx)
    Get or create a secure non blocking random number generator using the current vert.x instance.
    boolean
     
    io.vertx.ext.auth.prng.VertxContextPRNG
    Get the delegate instance.
    int
     
    newInstance(io.vertx.ext.auth.prng.VertxContextPRNG delegate)
    Creates a new instance of the VertxContextPRNG.
    boolean
    Returns a secure random boolean
    void
    nextBytes(byte[] bytes)
    Fills the given byte array with random bytes.
    double
    Returns a secure random double value.
    float
    Returns a secure random float value.
    double
    Returns a secure random double value.
    int
    Returns a secure random int
    int
    nextInt(int bound)
    Returns a secure random int, between 0 (inclusive) and the specified bound (exclusive).
    long
    Returns a secure random long
    nextString(int length)
    Returns a Base64 url encoded String of random data with the given length.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • VertxContextPRNG

      public VertxContextPRNG(io.vertx.ext.auth.prng.VertxContextPRNG delegate)
      Create a new instance of VertxContextPRNG delegating to the given (non-null) instance of VertxContextPRNG.
    • VertxContextPRNG

      public VertxContextPRNG(Object delegate)
  • Method Details

    • getDelegate

      public io.vertx.ext.auth.prng.VertxContextPRNG getDelegate()
      Get the delegate instance.

      This method returns the instance on which this shim is delegating the calls. And so, give you access to the bare API.

      Specified by:
      getDelegate in interface MutinyDelegate
      Returns:
      the delegate instance
    • current

      public static VertxContextPRNG current()
      Get or create a secure non blocking random number generator using the current vert.x context. If there is no current context (i.e.: not running on the eventloop) then a IllegalStateException is thrown.

      Note, if a context isn't allowed to be used, for example, exceptions are thrown on getting and putting data, the VertxContextPRNG falls back to instantiate a new instance of the PRNG per call.

      Returns:
      A secure non blocking random number generator.
      Throws:
      when - there is no Context instance available.
    • current

      public static VertxContextPRNG current(Vertx vertx)
      Get or create a secure non blocking random number generator using the current vert.x instance. Since the context might be different this method will attempt to use the current context first if available and then fall back to create a new instance of the PRNG.

      Note, if a context isn't allowed to be used, for example, exceptions are thrown on getting and putting data, the VertxContextPRNG falls back to instantiate a new instance of the PRNG per call.

      Parameters:
      vertx - a Vert.x instance.
      Returns:
      A secure non blocking random number generator.
    • close

      public void close()
      stop seeding the PRNG
    • nextBytes

      public void nextBytes(byte[] bytes)
      Fills the given byte array with random bytes.
      Parameters:
      bytes - a byte array.
    • nextString

      public String nextString(int length)
      Returns a Base64 url encoded String of random data with the given length. The length parameter refers to the length of the String before the encoding step.
      Parameters:
      length - the desired string length before Base64 encoding.
      Returns:
      A base 64 encoded string.
    • nextInt

      public int nextInt()
      Returns a secure random int
      Returns:
      random int.
    • nextInt

      public int nextInt(int bound)
      Returns a secure random int, between 0 (inclusive) and the specified bound (exclusive).
      Parameters:
      bound - the upper bound (exclusive), which must be positive.
      Returns:
      random int.
    • nextBoolean

      public boolean nextBoolean()
      Returns a secure random boolean
      Returns:
      random boolean.
    • nextLong

      public long nextLong()
      Returns a secure random long
      Returns:
      random long.
    • nextFloat

      public float nextFloat()
      Returns a secure random float value. The value is uniformly distributed between 0.0 and 1.0
      Returns:
      random float.
    • nextDouble

      public double nextDouble()
      Returns a secure random double value. The value is uniformly distributed between 0.0 and 1.0
      Returns:
      random double.
    • nextGaussian

      public double nextGaussian()
      Returns a secure random double value. The value is Gaussian ("normally") distributed with mean 0.0 and standard deviation 1.0
      Returns:
      random double.
    • newInstance

      public static VertxContextPRNG newInstance(io.vertx.ext.auth.prng.VertxContextPRNG delegate)
      Creates a new instance of the VertxContextPRNG.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object