Class GridClientUtils


  • public abstract class GridClientUtils
    extends Object
    Java client utils.
    • Constructor Detail

      • GridClientUtils

        public GridClientUtils()
    • Method Detail

      • closeQuiet

        public static void closeQuiet​(@Nullable
                                      @Nullable Closeable closeable)
        Closes resource without reporting any error.
        Parameters:
        closeable - Resource to close.
      • contains

        public static <T> GridClientPredicate<T> contains​(Collection<T> c)
        Creates a predicates that checks if given value is contained in collection c.
        Type Parameters:
        T - Type of elements in collection.
        Parameters:
        c - Collection to check.
        Returns:
        Predicate.
      • first

        @Nullable
        public static <T> T first​(@Nullable
                                  @Nullable Iterable<? extends T> c)
        Gets first element from given collection or returns null if the collection is empty.
        Type Parameters:
        T - Type of the collection.
        Parameters:
        c - A collection.
        Returns:
        Collections' first element or null in case if the collection is empty.
      • applyFilter

        public static <T> Collection<T> applyFilter​(Iterable<? extends T> elements,
                                                    GridClientPredicate<? super T>... filters)
        Applies filter and returns filtered collection of nodes.
        Parameters:
        elements - Nodes to be filtered.
        filters - Filters to apply. Elements of this array are allowed to be null.
        Returns:
        Filtered collection.
      • restAvailable

        public static boolean restAvailable​(GridClientNode node,
                                            GridClientProtocol p)
        Checks if given REST protocol available for given node.
        Parameters:
        node - Node.
        p - Protocol.
        Returns:
        true if protocol p available for node, false otherwise.
      • shutdownNow

        public static void shutdownNow​(Class<?> owner,
                                       ExecutorService exec,
                                       Logger log)
        Shutdowns given ExecutorService and wait for executor service to stop.
        Parameters:
        owner - The ExecutorService owner.
        exec - ExecutorService to shutdown.
        log - The logger to possible exceptions and warnings.
      • getSimpleName

        public static String getSimpleName​(Class<?> cls)
        Gets simple class name taking care of empty names.
        Parameters:
        cls - Class to get the name for.
        Returns:
        Simple class name.
      • safeAbs

        public static int safeAbs​(int i)
        Gets absolute value for integer. If integer is Integer.MIN_VALUE, then 0 is returned.
        Parameters:
        i - Integer.
        Returns:
        Absolute value.