Class Util


  • public class Util
    extends java.lang.Object
    Collection of various utility routines that can not be assigned to other classes.
    Author:
    Bela Ban
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Util.AddressScope  
    • Constructor Summary

      Constructors 
      Constructor Description
      Util()  
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      protected static void add​(byte type, java.lang.Class<?> cl)  
      static Address addressFromString​(java.lang.String s)  
      static java.lang.String addressToString​(Address addr)  
      static boolean allChannelsHaveSameView​(JChannel... channels)  
      static <T> boolean allEqual​(java.util.Collection<T> elements)
      Returns true if all elements in the collection are the same
      static void assertAllChannelsHaveSameView​(JChannel... channels)  
      static int assertPositive​(int value, java.lang.String message)  
      static <T> void asyncWaitUntilTrue​(long timeout, long interval, java.util.function.BooleanSupplier cond, java.util.function.Supplier<T> on_success, java.util.function.Supplier<T> on_failure)
      In a separate thread (common ForkJoinPool): waits for the given timeout / interval until a condition is true.
      static java.lang.String attributeNameToMethodName​(java.lang.String attr_name)  
      static int available​(java.io.InputStream in)  
      static void bind​(java.net.ServerSocket srv_sock, java.net.InetAddress bind_addr, int start_port, int end_port)  
      static void bind​(java.net.Socket sock, java.net.InetAddress bind_addr, int start_port, int end_port)  
      static java.lang.String bold​(java.lang.String msg)  
      static byte[] bufferToArray​(java.nio.ByteBuffer buf)
      Returns a copy of the byte array between position and limit; requires a non-null buffer
      static void bufferToArray​(Address sender, java.nio.ByteBuffer buf, Receiver target)  
      static java.lang.String byteArrayToHexString​(byte[] b)  
      static java.lang.String byteArrayToHexString​(byte[] b, int offset, int length)  
      static java.lang.String bytesToString​(byte[] bytes)  
      static <E> java.util.List<E> car​(java.util.List<E> l)  
      static <E> java.util.List<E> cdr​(java.util.List<E> l)  
      static boolean checkForAndroid()  
      static boolean checkForHp()  
      static boolean checkForLinux()  
      static boolean checkForMac()  
      static boolean checkForSolaris()  
      static boolean checkForWindows()  
      static void checkIfValidAddress​(java.net.InetAddress bind_addr, java.lang.String prot_name)  
      static <E> boolean checkOrder​(java.util.Collection<E> perm, java.util.List<E>... lists)  
      static byte clearFlags​(byte bits, byte flag)  
      static void close​(java.io.Closeable closeable)  
      static void close​(java.io.Closeable... closeables)  
      static void closeFast​(JChannel... channels)
      Closes all non-coordinators first, in parallel, then closes the coord.
      static void closeReverse​(java.io.Closeable... closeables)  
      static byte[] collectionToByteBuffer​(java.util.Collection<Address> c)  
      static <E> E[] combine​(E[]... arrays)  
      static <E> E[] combine​(java.lang.Class<?> cl, E... array)  
      static <E> java.util.List<E> combine​(java.util.List<E> l1, java.util.List<E> l2)  
      static int compare​(byte[] left, byte[] right)
      Compares 2 byte arrays, elements are treated as unigned
      static java.lang.String[] components​(java.lang.String path, java.lang.String separator)  
      static java.util.List<Range> computeFragOffsets​(byte[] buf, int frag_size)  
      static java.util.List<Range> computeFragOffsets​(int offset, int length, int frag_size)
      Given a buffer and a fragmentation size, compute a list of fragmentation offset/length pairs, and return them in a list.
      static void connect​(java.net.Socket sock, java.net.SocketAddress dest, int sock_conn_timeout)
      Utility method.
      static boolean connect​(java.nio.channels.SocketChannel ch, java.net.SocketAddress dest)  
      static <T> boolean contains​(T key, T[] list)  
      static boolean containsId​(short id, short[] ids)  
      static boolean containsViewId​(java.util.Collection<View> views, ViewId vid)  
      static java.lang.Object convert​(java.lang.String arg, java.lang.Class<?> type, java.util.concurrent.TimeUnit unit)  
      static Message copy​(Message msg, boolean copy_buffer, short starting_id, short... copy_only_ids)
      Copies a message.
      static byte[] createAuthenticationDigest​(java.lang.String passcode, long t1, double q1)  
      static <K,​V>
      java.util.concurrent.ConcurrentMap<K,​V>
      createConcurrentMap()  
      static <K,​V>
      java.util.concurrent.ConcurrentMap<K,​V>
      createConcurrentMap​(int initial_capacity)  
      static <K,​V>
      java.util.concurrent.ConcurrentMap<K,​V>
      createConcurrentMap​(int initial_capacity, float load_factor, int concurrency_level)  
      static java.net.DatagramSocket createDatagramSocket​(SocketFactory factory, java.lang.String service_name, java.net.InetAddress addr, int port)
      Creates a DatagramSocket bound to addr.
      static byte[] createDigest​(java.lang.String passcode, long t1, double q1)  
      static <T extends java.lang.Enum<T>>
      T
      createEnum​(java.lang.String name, java.lang.reflect.Type type)
      Creates an enum from a string
      static java.net.MulticastSocket createMulticastSocket​(SocketFactory factory, java.lang.String service_name, java.net.InetAddress mcast_addr, int port, Log log)  
      static Address createRandomAddress()  
      static Address createRandomAddress​(java.lang.String name)  
      static Address[] createRandomAddresses​(int num)
      Returns an array of num random addresses, named A, B, C etc
      static Address[] createRandomAddresses​(int num, boolean use_numbers)  
      static java.net.ServerSocket createServerSocket​(SocketFactory factory, java.lang.String service_name, java.net.InetAddress bind_addr, int start_port, int end_port, int recv_buf_size)  
      static java.nio.channels.ServerSocketChannel createServerSocketChannel​(SocketFactory factory, java.lang.String service_name, java.net.InetAddress bind_addr, int start_port, int end_port, int recv_buf_size)  
      static java.lang.Object[][] createTimer()  
      static byte[] defragmentBuffer​(byte[][] fragments)
      Concatenates smaller fragments into entire buffers.
      static java.util.Collection<Address> determineActualMergeCoords​(java.util.Map<Address,​View> map)
      Similar to determineMergeCoords(java.util.Map) but only actual coordinators are counted: an actual coord is when the sender of a view is the first member of that view
      static java.util.List<Address> determineLeftMembers​(java.util.List<Address> old_mbrs, java.util.List<Address> new_mbrs)
      Returns all members that left between 2 views.
      static java.util.Collection<Address> determineMergeCoords​(java.util.Map<Address,​View> map)
      This is the same or a subset of determineMergeParticipants(java.util.Map) and contains only members which are currently sub-partition coordinators.
      static java.util.Collection<Address> determineMergeParticipants​(java.util.Map<Address,​View> map)
      Determines the members which take part in a merge.
      static <T> boolean different​(T one, T two)  
      static java.lang.String dumpThreads()  
      static <T> java.util.Enumeration<T> enumerate​(T[] array, int offset, int length)  
      static <T,​R>
      java.util.Enumeration<R>
      enumerate​(T[] array, int offset, int length, java.util.function.Function<T,​R> converter)  
      static java.lang.Throwable exceptionFromBuffer​(byte[] buf, int offset, int length)  
      static java.lang.Throwable exceptionFromStream​(java.io.DataInput in)  
      protected static java.lang.Throwable exceptionFromStream​(java.io.DataInput in, int recursion_count)  
      static ByteArray exceptionToBuffer​(java.lang.Throwable t)  
      static void exceptionToStream​(java.lang.Throwable t, java.io.DataOutput out)
      Poor man's serialization of an exception.
      protected static void exceptionToStream​(java.util.Set<java.lang.Throwable> causes, java.lang.Throwable t, java.io.DataOutput out)  
      static int factorial​(int n)  
      static boolean fibersAvailable()
      Deprecated.
      static java.util.List<java.lang.Class<?>> findClassesAnnotatedWith​(java.lang.String packageName, java.lang.Class<? extends java.lang.annotation.Annotation> a)  
      static java.util.Set<java.lang.Class<?>> findClassesAssignableFrom​(java.lang.String packageName, java.lang.Class<?> assignableFrom, java.lang.ClassLoader cl)  
      static java.util.Set<java.lang.Class<?>> findClassesAssignableFromPath​(java.lang.String packagePath, java.lang.Class<?> assignableFrom, java.lang.ClassLoader cl)  
      static java.lang.reflect.Field findField​(java.lang.Object target, java.util.List<java.lang.String> possible_names)  
      static java.lang.reflect.Method findMethod​(java.lang.Class<?> cl, java.lang.String method_name, java.lang.Class<?>... parameter_types)  
      static java.lang.reflect.Method findMethod​(java.lang.Class<?> target_class, java.lang.String method_name, java.lang.Object[] args)
      Called by the ProbeHandler impl.
      static java.lang.reflect.Method findMethod​(java.lang.Class<?> root_class, java.util.List<java.lang.String> possible_names, java.lang.Class<?>... parameter_types)  
      static java.lang.reflect.Method findMethod​(java.lang.Object target, java.util.List<java.lang.String> possible_names, java.lang.Class<?>... parameter_types)  
      static java.lang.reflect.Method findMethod2​(java.lang.Class<?> target_class, java.lang.String method_name, java.lang.Object[] args)  
      static java.lang.String flagsToString​(short flags)  
      static void forAllComponents​(java.lang.Object target, java.util.function.BiConsumer<java.lang.Object,​java.lang.String> func)
      Applies a function to all fields annotated with @Component
      static void forAllComponentTypes​(java.lang.Class<?> cl, java.util.function.BiConsumer<java.lang.Class<?>,​java.lang.String> func)  
      static void forAllFieldsAndMethods​(java.lang.Object obj, java.util.function.Predicate<? super java.lang.reflect.AccessibleObject> filter, java.util.function.BiConsumer<java.lang.reflect.Field,​java.lang.Object> field_func, java.util.function.BiConsumer<java.lang.reflect.Method,​java.lang.Object> method_func)
      Applies a function against all fields and methods of a given target object which satisfy a given predicate.
      static java.lang.String format​(double val, java.lang.String suffix)  
      static byte[][] fragmentBuffer​(byte[] buf, int frag_size, int length)
      Fragments a byte buffer into smaller fragments of (max.) frag_size.
      static byte[] generateArray​(int length)  
      static java.lang.String generateLocalName()  
      static java.net.InetAddress getAddress​(java.lang.String value, StackType ip_version)  
      static java.net.InetAddress getAddress​(java.net.NetworkInterface intf, Util.AddressScope scope, StackType ip_version)
      Returns the first address on the given interface on the current host, which satisfies scope
      static java.net.InetAddress getAddress​(Util.AddressScope scope, StackType ip_version)
      Returns the first address on any interface which satisfies scope and ip_version.
      static java.net.InetAddress getAddressByCustomCode​(java.lang.String value)  
      static java.net.InetAddress getAddressByPatternMatch​(java.lang.String pattern, StackType ip_version)
      Returns a valid interface address based on a pattern.
      static java.util.Collection<java.net.InetAddress> getAllAvailableAddresses​(java.util.function.Predicate<java.net.InetAddress> filter)
      Returns all addresses of all interfaces (that are up) that satisfy a given filter (ignored if null)
      static java.util.List<java.net.NetworkInterface> getAllAvailableInterfaces()  
      static java.lang.reflect.Field[] getAllDeclaredFieldsWithAnnotations​(java.lang.Class<?> clazz, java.lang.Class<? extends java.lang.annotation.Annotation>... annotations)  
      static java.lang.reflect.Method[] getAllDeclaredMethodsWithAnnotations​(java.lang.Class<?> clazz, java.lang.Class<? extends java.lang.annotation.Annotation>... annotations)  
      static java.lang.reflect.Method[] getAllMethods​(java.lang.Class<?> target)
      The method walks up the class hierarchy and returns all methods of this class and those inherited from superclasses and superinterfaces.
      static <A extends java.lang.annotation.Annotation>
      A
      getAnnotation​(java.lang.Class<?> clazz, java.lang.Class<A> annotationClass)  
      static java.net.NetworkInterface getByName​(java.lang.String name)
      Finds a network interface or sub-interface with the given name
      static java.net.InetAddress getByName​(java.lang.String host, StackType ip_version)
      Finds an address given a symbolic name.
      static java.lang.String getChild​(org.w3c.dom.Element root, java.lang.String path)  
      static java.util.List<java.lang.Class<?>> getComponents​(java.lang.Class<?> clazz)  
      static java.util.List<java.lang.Object> getComponents​(java.lang.Object target)
      Returns the non-null values of all fields of target annotated with @Component
      static java.lang.reflect.Field getField​(java.lang.Class<?> clazz, java.lang.String field_name)  
      static java.lang.reflect.Field getField​(java.lang.Class<?> clazz, java.lang.String field_name, boolean throw_exception)  
      static java.lang.Object getField​(java.lang.reflect.Field field, java.lang.Object target)  
      static StackType getIpStackType()  
      static java.net.InetAddress getLoopback()  
      static java.net.InetAddress getLoopback​(StackType ip_version)
      IP related utilities
      static javax.management.MBeanServer getMBeanServer()  
      static java.lang.String getMessage​(java.lang.String key)  
      static java.lang.String getNameFromAnnotation​(java.lang.reflect.AccessibleObject obj)  
      static int getNextHigherPowerOfTwo​(int num)  
      static java.net.InetAddress getNonLoopbackAddress()
      Returns the first non-loopback address on any interface on the current host
      static java.net.InetAddress getNonLoopbackAddress​(StackType ip_version)  
      static java.lang.String getObject​(Message msg)
      Tries to return a legible representation of a message's payload
      static java.lang.String getObjects​(java.lang.Iterable<Message> it)  
      static java.lang.String getProperty​(java.lang.String s)  
      static java.lang.String getProperty​(java.lang.String[] system_props, java.util.Properties props, java.lang.String prop_name, java.lang.String default_value)
      Returns a value associated wither with one or more system properties, or found in the props map
      static java.lang.String getProperty​(java.lang.String s, java.util.Properties p)  
      static int getRank​(java.util.Collection<Address> members, Address addr)  
      static int getRank​(View view, Address addr)
      Returns the rank of a member in a given view
      static java.io.InputStream getResourceAsStream​(java.lang.String name, java.lang.Class<?> clazz)  
      static java.io.InputStream getResourceAsStream​(java.lang.String name, java.lang.ClassLoader loader)  
      static java.util.Map<java.lang.String,​java.util.List<Address>> getSites​(View bridge_view, java.lang.String excluding_site)  
      static Protocol[] getTestStack​(Protocol... additional_protocols)
      Returns a default stack for testing with transport = SHARED_LOOPBACK
      static Protocol[] getTestStackNew​(Protocol... additional_protocols)  
      static java.lang.Class<? extends Protocol>[] getUnicastProtocols()  
      static java.lang.String hexToBin​(java.lang.String s)  
      protected static <E> int index​(java.util.Collection<E> list, E el)  
      static boolean interfaceHasIPAddresses​(java.net.NetworkInterface intf, StackType ip_version)
      A function to check if an interface supports an IP version (i.e.
      static boolean interruptAndWaitToDie​(java.lang.Thread t)  
      static boolean interruptAndWaitToDie​(java.lang.Thread t, long timeout)  
      static java.lang.Object invoke​(java.lang.Object target, java.lang.String method_name, java.lang.Object... args)  
      static boolean isAsciiString​(java.lang.String str)  
      static boolean isAssignableFrom​(java.lang.Class<?> left, java.lang.Class<?> right)  
      static boolean isCoordinator​(JChannel ch)  
      static boolean isCoordinator​(View view, Address local_addr)  
      static boolean isFlagSet​(byte bits, byte flag)  
      static boolean isFlagSet​(short flags, Message.Flag flag)  
      static boolean isPrimitiveType​(java.lang.Class<?> type)  
      static boolean isPrimitiveType​(java.lang.Object obj)  
      static boolean isStackAvailable​(boolean ipv4)  
      static boolean isTransientFlagSet​(short flags, Message.TransientFlag flag)  
      static boolean isUp​(java.net.NetworkInterface ni)
      Always returns true unless there is a socket exception - will be removed when GraalVM issue https://github.com/oracle/graal/pull/1076 has been fixed
      static int keyPress​(java.lang.String msg)  
      static java.util.List<Address> leftMembers​(java.util.Collection<Address> old_list, java.util.Collection<Address> new_list)  
      static java.lang.Class<?> loadClass​(java.lang.String classname, java.lang.Class<?> clazz)
      Tries to load the class from the current thread's context class loader.
      static java.lang.Class<?> loadClass​(java.lang.String classname, java.lang.ClassLoader preferredLoader)
      Tries to load the class from the preferred loader.
      static java.lang.Class<? extends Protocol> loadProtocolClass​(java.lang.String protocol_name, java.lang.Class<?> cl)  
      protected static byte[] marshalPrimitiveType​(java.lang.Byte type, java.lang.Object obj)  
      static boolean match​(java.net.InetAddress addr, Util.AddressScope scope)  
      static <T> boolean match​(T obj1, T obj2)  
      static Message messageFromBuffer​(byte[] buf, int offset, int length)  
      static Message messageFromByteBuffer​(byte[] buffer, int offset, int length)  
      static ByteArray messageToBuffer​(Message msg)  
      static ByteArray messageToByteBuffer​(Message msg)  
      static java.lang.String methodNameToAttributeName​(java.lang.String methodName)
      Converts a method name to an attribute name, e.g.
      static java.lang.String methodNameToJavaAttributeName​(java.lang.String methodName)
      Converts a method name to a Java attribute name, e.g.
      static long micros()  
      static <T> java.util.List<T> newElements​(java.util.List<T> old_list, java.util.List<T> new_list)  
      static java.util.List<Address> newMembers​(java.util.List<Address> old_list, java.util.List<Address> new_list)  
      protected static char nextChar​(java.lang.String s, int index)  
      static <T extends java.lang.Number>
      T
      nonNegativeValue​(T num)  
      static <T> T objectFromBuffer​(ByteArray b, java.lang.ClassLoader loader)  
      static <T> T objectFromByteBuffer​(byte[] buffer)
      Creates an object from a byte buffer
      static <T> T objectFromByteBuffer​(byte[] buffer, int offset, int length)  
      static <T> T objectFromByteBuffer​(byte[] buffer, int offset, int length, java.lang.ClassLoader loader)  
      static <T> T objectFromByteBuffer​(java.nio.ByteBuffer buffer, java.lang.ClassLoader loader)
      Parses an object from a ByteBuffer.
      static <T> T objectFromStream​(java.io.DataInput in)  
      static <T> T objectFromStream​(java.io.DataInput in, java.lang.ClassLoader loader)  
      static ByteArray objectToBuffer​(java.lang.Object obj)
      Serializes/Streams an object into a byte buffer.
      static byte[] objectToByteBuffer​(java.lang.Object obj)  
      static void objectToStream​(java.lang.Object obj, java.io.DataOutput out)  
      static <E> java.util.Collection<java.util.List<E>> orderedPermutation​(java.util.List<E> a, java.util.List<E> b)
      Performs an ordered permutation of the elements of a and b such that the order of elements in list a and b is preserved.
      static java.util.Collection<java.lang.String> otherSites​(View bridge_view, java.lang.String excluding_site)
      Returns the sites of the view (all addresses are SiteUUIDs) minus the given site, Example: bridge_view=A:net1,B:net1,X:net2,Y:net2, excluding_site=net1 -> ["net2"]
      static void parse​(byte[] buf, int offset, int length, java.util.function.BiConsumer<java.lang.Short,​Message> msg_consumer, java.util.function.BiConsumer<java.lang.Short,​MessageBatch> batch_consumer, java.util.function.Consumer<GossipData> gossip_consumer, boolean tcp, boolean gossip)  
      static void parse​(java.io.InputStream input, java.util.function.BiConsumer<java.lang.Short,​Message> msg_consumer, java.util.function.BiConsumer<java.lang.Short,​MessageBatch> batch_consumer, java.util.function.Consumer<GossipData> gossip_consumer, boolean tcp, boolean gossip)  
      static java.util.List<PhysicalAddress> parseCommaDelimitedHosts​(java.lang.String hosts, int port_range)
      Input is "daddy[8880],sindhu[8880],camille[5555]".
      static java.util.List<java.net.InetSocketAddress> parseCommaDelimitedHosts2​(java.lang.String hosts, int port_range)
      Input is "daddy[8880],sindhu[8880],camille[5555]".
      static boolean parseCommaDelimitedHostsInto​(java.util.Collection<PhysicalAddress> list, java.util.Collection<java.lang.String> unresolved_hosts, java.lang.String hosts, int port_range, StackType stack_type)
      Parses a string into a list of IpAddresses
      static java.util.List<java.lang.String> parseCommaDelimitedStrings​(java.lang.String l)
      e.g.
      static java.net.InetSocketAddress parseHost​(java.lang.String s)
      Parses a host:IP string into an InetSocketAddress
      static java.util.List<java.net.NetworkInterface> parseInterfaceList​(java.lang.String s)  
      static java.util.concurrent.RejectedExecutionHandler parseRejectionPolicy​(java.lang.String rejection_policy)  
      static java.lang.String[] parseStringArray​(java.lang.String s, java.lang.String separator)  
      static java.util.List<java.lang.String> parseStringList​(java.lang.String l, java.lang.String separator)  
      static boolean patternMatch​(java.lang.String pattern, java.lang.String str)  
      protected static <E> java.util.List<E> permute​(java.util.List<E> l1, java.util.List<E> l2, int remove_from_l1, int remove_from_l2)  
      protected static <E> void permute​(java.util.List<E> prefix, java.util.List<E> list, int index, java.util.List<java.util.List<E>> permutations)  
      static <E> void permute​(java.util.List<E> list, java.util.List<java.util.List<E>> permutations)
      Inefficient permutation of a generic list; uses too much copying among other things.
      static <T> T pickNext​(java.util.List<T> list, T obj)  
      static <T> java.util.List<T> pickNext​(java.util.List<T> list, T obj, int num)
      Returns the next min(N,list.size()) elements after obj
      static <T> T pickPrevious​(java.util.List<T> list, T el)  
      static <T> T pickPrevious​(T[] array, T el)
      Returns the element before el.
      static <T> T pickRandomElement​(java.util.Collection<T> set)  
      static <T> T pickRandomElement​(java.util.List<T> list)  
      static <T> T pickRandomElement​(T[] array)  
      static <T> T primitiveFromStream​(java.io.DataInput in)  
      static <T> T primitiveFromStream​(java.io.DataInput in, byte type)  
      static void primitiveToStream​(java.lang.Object obj, java.io.DataOutput out)  
      static java.lang.String print​(double time, java.util.concurrent.TimeUnit unit)  
      static java.lang.String print​(java.lang.Object[] objs)  
      static <T> java.lang.String print​(java.util.Collection<T> objs)  
      static java.lang.String print​(java.util.List<java.net.NetworkInterface> interfaces)  
      static <T> java.lang.String print​(java.util.Map<T,​T> map)  
      static java.lang.String print​(MessageBatch batch, boolean print_headers)  
      static java.lang.String printBytes​(double bytes)
      MB nowadays doesn't mean 1024 * 1024 bytes, but 1 million bytes, see http://en.wikipedia.org/wiki/Megabyte
      static <T> java.lang.String printList​(java.util.Collection<T> l)  
      static <T> java.lang.String printListWithDelimiter​(java.util.Collection<T> list, java.lang.String delimiter)  
      static <T> java.lang.String printListWithDelimiter​(java.util.Collection<T> list, java.lang.String delimiter, int limit)  
      static <T> java.lang.String printListWithDelimiter​(java.util.Collection<T> list, java.lang.String delimiter, int limit, boolean print_size)  
      static <T> java.lang.String printListWithDelimiter​(T[] list, java.lang.String delimiter, int limit)  
      static <T> java.lang.String printMapWithDelimiter​(java.util.Map<T,​T> map, java.lang.String delimiter)  
      static java.lang.String printTime​(double time, java.util.concurrent.TimeUnit unit)  
      static java.lang.String printViews​(JChannel... channels)  
      static boolean productGreaterThan​(long n1, long n2, long val)  
      static long random​(long range)
      Returns a random value in the range [1 - range].
      static <T extends Streamable>
      T[]
      read​(java.lang.Class<T> clazz, java.io.DataInput in)  
      static Address readAddress​(java.io.DataInput in)  
      static Address[] readAddresses​(java.io.DataInput in)  
      static <T extends java.util.Collection<Address>>
      T
      readAddresses​(java.io.DataInput in, java.util.function.IntFunction<T> factory)  
      static byte[] readByteBuffer​(java.io.DataInput in)  
      static ByteArray readBytes​(java.io.InputStream in)
      Reads all bytes fro, an input stream, until eof (-1) is reached
      static double readBytesDouble​(java.lang.String input)  
      static int readBytesInteger​(java.lang.String input)  
      static long readBytesLong​(java.lang.String input)  
      static java.lang.String readContents​(java.io.InputStream input)  
      static double readDoubleFromStdin​(java.lang.String message)  
      static long readDurationLong​(java.lang.String input, java.util.concurrent.TimeUnit unit)  
      protected static java.lang.Throwable readException​(java.io.DataInput in, int recursion_count)  
      static java.lang.String readFile​(java.lang.String filename)  
      static byte[] readFileContents​(java.io.InputStream input)  
      static <T extends Streamable>
      T
      readGenericStreamable​(java.io.DataInput in)  
      static <T extends Streamable>
      T
      readGenericStreamable​(java.io.DataInput in, java.lang.ClassLoader loader)  
      static int readIntFromStdin​(java.lang.String message)  
      static java.lang.String readLine​(java.io.InputStream in)
      Reads a line of text.
      static long readLongFromStdin​(java.lang.String message)  
      static Message readMessage​(java.io.DataInput in)  
      static MessageBatch[] readMessageBatch​(java.io.DataInput in, boolean multicast)
      Reads a list of messages into 2 MessageBatches: regular OOB
      static java.util.List<Message> readMessageList​(java.io.DataInput in, short transport_id)  
      static SizeStreamable readSizeStreamable​(java.io.DataInput in, java.lang.ClassLoader loader)  
      static <T extends Streamable>
      T
      readStreamable​(java.util.function.Supplier<T> factory, java.io.DataInput in)  
      static java.lang.String readString​(java.io.DataInput in)  
      static java.lang.String readStringFromStdin​(java.lang.String message)  
      static java.lang.String readTillMatchingCharacter​(java.io.InputStream in, char c)
      Returns all characters read from the current position until the next occurrence of 'c' has been read (including 'c'), or eof, whichever comes first
      static java.lang.String readToken​(java.io.InputStream in)
      Returns whitespace-separated strings from the input stream, or null if the end of the stream has been reached
      static View readView​(java.io.DataInput in)  
      static ViewId readViewId​(java.io.DataInput in)  
      static void registerChannel​(JChannel channel, java.lang.String name)  
      static void removeFromViews​(Address mbr, JChannel... channels)  
      static void resetCacheAddresses​(boolean reset_interfaces, boolean reset_addresses)  
      static boolean sameHost​(Address one, Address two)
      Checks whether 2 Addresses are on the same host
      static void setCacheAddresses​(java.util.List<java.net.NetworkInterface> interfaces, java.util.List<java.net.InetAddress> addresses)
      This is a workaround for use within android.
      static void setField​(java.lang.reflect.Field field, java.lang.Object target, java.lang.Object value)  
      static byte setFlag​(byte bits, byte flag)  
      static java.lang.String shortName​(java.lang.String hostname)  
      static java.lang.String shortName​(java.net.InetAddress hostname)  
      static <T> void shuffle​(T[] array, int from, int to)
      Reorders elements of an array in-place.
      static void shutdown​(JChannel ch)
      Drops messages to/from other members and then closes the channel.
      static int size​(byte[] buf)  
      static int size​(java.lang.Object obj)  
      static int size​(java.lang.String s)  
      static long size​(java.util.Collection<? extends Address> addrs)
      Returns the marshalled size of a Collection of Addresses.
      static int size​(Address addr)  
      static long size​(Address[] addrs)  
      static int size​(SizeStreamable s)  
      static int size​(View view)  
      static int size​(ViewId vid)  
      static int sizePrimitive​(java.lang.Object obj)  
      static void sleep​(long timeout)
      Sleep for timeout msecs.
      static void sleep​(long timeout, int nanos)  
      static void sleepRandom​(long floor, long ceiling)
      Sleeps between floor and ceiling milliseconds, chosen randomly
      static <T extends Streamable>
      T
      streamableFromBuffer​(java.util.function.Supplier<T> factory, byte[] buf, int off, int len)  
      static <T extends Streamable>
      T
      streamableFromByteBuffer​(java.lang.Class<? extends Streamable> cl, byte[] buffer)  
      static <T extends Streamable>
      T
      streamableFromByteBuffer​(java.lang.Class<? extends Streamable> cl, byte[] buffer, int offset, int length)  
      static <T extends Streamable>
      T
      streamableFromByteBuffer​(java.lang.Class<? extends Streamable> cl, java.nio.ByteBuffer buffer)  
      static <T extends Streamable>
      T
      streamableFromByteBuffer​(java.util.function.Supplier<T> factory, byte[] buffer)  
      static <T extends Streamable>
      T
      streamableFromByteBuffer​(java.util.function.Supplier<T> factory, byte[] buffer, int offset, int length)  
      static ByteArray streamableToBuffer​(Streamable obj)  
      static byte[] streamableToByteBuffer​(Streamable obj)  
      static byte[] stringToBytes​(java.lang.String str)  
      static java.lang.String substituteVariable​(java.lang.String val)
      Replaces variables of ${var:default} with System.getProperty(var, default).
      static java.lang.String substituteVariable​(java.lang.String input, java.util.Properties p)
      Replaces variables in a string.
      static java.lang.String substituteVariableOld​(java.lang.String val, java.util.Properties p)
      Replaces variables of ${var:default} with Properties then uses System.getProperty(var, default) if the value was not found.
      static java.lang.String suffix​(java.util.concurrent.TimeUnit u)  
      protected static <E> java.util.List<E> swap​(java.util.List<E> l, int index)  
      static boolean tossWeightedCoin​(double probability)
      Tosses a coin weighted with probability and returns true or false.
      static java.lang.String transientFlagsToString​(short flags)  
      static java.lang.String utcEpoch​(long milliseconds)  
      static java.lang.String utcNow()  
      static java.net.InetAddress validateBindAddressFromInterface​(java.net.InetAddress bind_addr, java.lang.String bind_interface_str, StackType ip_version)
      Method used by PropertyConverters.BindInterface to check that a bind_addr is consistent with a specified interface
      static boolean verifyArray​(byte[] array)  
      static boolean verifyByteBuffer​(java.nio.ByteBuffer buf)  
      static boolean virtualThreadsAvailable()  
      static void waitUntil​(long timeout, long interval, java.util.function.BooleanSupplier condition)  
      static void waitUntil​(long timeout, long interval, java.util.function.BooleanSupplier condition, java.util.function.Supplier<java.lang.String> msg)  
      static void waitUntilAllChannelsHaveSameView​(long timeout, long interval, java.util.Collection<JChannel> channels)  
      static void waitUntilAllChannelsHaveSameView​(long timeout, long interval, JChannel... channels)
      Blocks until all channels have the same view
      static <T> void waitUntilListHasSize​(java.util.List<T> list, int expected_size, long timeout, long interval)
      Waits until a list has the expected number of elements.
      static boolean waitUntilNoX​(long timeout, long interval, java.util.function.BooleanSupplier condition)  
      static boolean waitUntilTrue​(long timeout, long interval, java.util.function.BooleanSupplier condition)  
      static java.nio.ByteBuffer wrapDirect​(byte[] array)  
      static java.nio.ByteBuffer wrapDirect​(byte[] array, int offset, int length)  
      static <T extends Streamable>
      void
      write​(T[] array, java.io.DataOutput out)  
      static void writeAddress​(Address addr, java.io.DataOutput out)  
      static void writeAddresses​(java.util.Collection<? extends Address> v, java.io.DataOutput out)
      Writes a list of Addresses.
      static void writeAddresses​(Address[] addrs, java.io.DataOutput out)  
      static void writeByteBuffer​(byte[] buf, int offset, int length, java.io.DataOutput out)  
      static void writeByteBuffer​(byte[] buf, java.io.DataOutput out)  
      protected static void writeException​(java.util.Set<java.lang.Throwable> causes, java.lang.Throwable t, java.io.DataOutput out)  
      static void writeGenericStreamable​(Streamable obj, java.io.DataOutput out)  
      static void writeMessage​(Message msg, java.io.DataOutput dos, boolean multicast)  
      static void writeMessageList​(Address dest, Address src, byte[] cluster_name, java.util.List<Message> msgs, java.io.DataOutput dos, boolean multicast)
      Write a list of messages with the *same* destination and src addresses.
      static void writeMessageList​(Address dest, Address src, byte[] cluster_name, Message[] msgs, int offset, int length, java.io.DataOutput dos, boolean multicast)  
      static void writeMessageList​(Address dest, Address src, byte[] cluster_name, FastArray<Message> msgs, java.io.DataOutput dos, boolean multicast)  
      static void writeMessageListHeader​(Address dest, Address src, byte[] cluster_name, int numMsgs, java.io.DataOutput dos, boolean multicast)  
      protected static ByteArray writeSerializable​(java.lang.Object obj)  
      protected static ByteArray writeStreamable​(Streamable obj)  
      static void writeStreamable​(Streamable obj, java.io.DataOutput out)  
      static void writeString​(java.lang.String str, java.io.DataOutput out)  
      static void writeTypeStreamable​(Streamable obj, java.io.DataOutput out)  
      static void writeView​(View view, java.io.DataOutput out)  
      static void writeViewId​(ViewId vid, java.io.DataOutput out)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • CCHM_INITIAL_CAPACITY

        protected static int CCHM_INITIAL_CAPACITY
      • CCHM_LOAD_FACTOR

        protected static float CCHM_LOAD_FACTOR
      • CCHM_CONCURRENCY_LEVEL

        protected static int CCHM_CONCURRENCY_LEVEL
      • DEFAULT_HEADERS

        public static final int DEFAULT_HEADERS
      • JAVA_VERSION

        public static final java.lang.String JAVA_VERSION
      • MAX_LIST_PRINT_SIZE

        public static int MAX_LIST_PRINT_SIZE
        The max size of an address list, used in View or Digest when toString() is called. Limiting this reduces the amount of log data
      • can_bind_to_mcast_addr

        public static final boolean can_bind_to_mcast_addr
      • resource_bundle

        protected static java.util.ResourceBundle resource_bundle
      • SITE_UUID_PREFIX

        protected static final java.lang.String SITE_UUID_PREFIX
        See Also:
        Constant Field Values
    • Constructor Detail

      • Util

        public Util()
    • Method Detail

      • getUnicastProtocols

        public static final java.lang.Class<? extends Protocol>[] getUnicastProtocols()
      • fibersAvailable

        @Deprecated
        public static boolean fibersAvailable()
        Deprecated.
      • virtualThreadsAvailable

        public static boolean virtualThreadsAvailable()
      • getNextHigherPowerOfTwo

        public static int getNextHigherPowerOfTwo​(int num)
      • bold

        public static java.lang.String bold​(java.lang.String msg)
      • getMessage

        public static java.lang.String getMessage​(java.lang.String key)
      • getTestStack

        public static Protocol[] getTestStack​(Protocol... additional_protocols)
        Returns a default stack for testing with transport = SHARED_LOOPBACK
        Parameters:
        additional_protocols - Any number of protocols to add to the top of the returned protocol list
        Returns:
      • getTestStackNew

        public static Protocol[] getTestStackNew​(Protocol... additional_protocols)
      • waitUntilAllChannelsHaveSameView

        public static void waitUntilAllChannelsHaveSameView​(long timeout,
                                                            long interval,
                                                            JChannel... channels)
                                                     throws java.util.concurrent.TimeoutException
        Blocks until all channels have the same view
        Parameters:
        timeout - How long to wait (max in ms)
        interval - Check every interval ms
        channels - The channels which should form the view. The expected view size is channels.length. Must be non-null
        Throws:
        java.util.concurrent.TimeoutException
      • waitUntilAllChannelsHaveSameView

        public static void waitUntilAllChannelsHaveSameView​(long timeout,
                                                            long interval,
                                                            java.util.Collection<JChannel> channels)
                                                     throws java.util.concurrent.TimeoutException
        Throws:
        java.util.concurrent.TimeoutException
      • waitUntil

        public static void waitUntil​(long timeout,
                                     long interval,
                                     java.util.function.BooleanSupplier condition)
                              throws java.util.concurrent.TimeoutException
        Throws:
        java.util.concurrent.TimeoutException
      • waitUntil

        public static void waitUntil​(long timeout,
                                     long interval,
                                     java.util.function.BooleanSupplier condition,
                                     java.util.function.Supplier<java.lang.String> msg)
                              throws java.util.concurrent.TimeoutException
        Throws:
        java.util.concurrent.TimeoutException
      • waitUntilNoX

        public static boolean waitUntilNoX​(long timeout,
                                           long interval,
                                           java.util.function.BooleanSupplier condition)
      • waitUntilTrue

        public static boolean waitUntilTrue​(long timeout,
                                            long interval,
                                            java.util.function.BooleanSupplier condition)
      • asyncWaitUntilTrue

        public static <T> void asyncWaitUntilTrue​(long timeout,
                                                  long interval,
                                                  java.util.function.BooleanSupplier cond,
                                                  java.util.function.Supplier<T> on_success,
                                                  java.util.function.Supplier<T> on_failure)
        In a separate thread (common ForkJoinPool): waits for the given timeout / interval until a condition is true. When true, executes the on_success supplier, else the on_failure supplier
      • assertPositive

        public static int assertPositive​(int value,
                                         java.lang.String message)
      • allChannelsHaveSameView

        public static boolean allChannelsHaveSameView​(JChannel... channels)
      • assertAllChannelsHaveSameView

        public static void assertAllChannelsHaveSameView​(JChannel... channels)
      • printViews

        public static java.lang.String printViews​(JChannel... channels)
      • print

        public static java.lang.String print​(MessageBatch batch,
                                             boolean print_headers)
      • waitUntilListHasSize

        public static <T> void waitUntilListHasSize​(java.util.List<T> list,
                                                    int expected_size,
                                                    long timeout,
                                                    long interval)
        Waits until a list has the expected number of elements. Throws an exception if not met
        Type Parameters:
        T - The type of the list
        Parameters:
        list - The list
        expected_size - The expected size
        timeout - The time to wait (in ms)
        interval - The interval at which to get the size of the list (in ms)
      • removeFromViews

        public static void removeFromViews​(Address mbr,
                                           JChannel... channels)
      • createEnum

        public static <T extends java.lang.Enum<T>> T createEnum​(java.lang.String name,
                                                                 java.lang.reflect.Type type)
        Creates an enum from a string
      • createAuthenticationDigest

        public static byte[] createAuthenticationDigest​(java.lang.String passcode,
                                                        long t1,
                                                        double q1)
                                                 throws java.io.IOException,
                                                        java.security.NoSuchAlgorithmException
        Throws:
        java.io.IOException
        java.security.NoSuchAlgorithmException
      • createDigest

        public static byte[] createDigest​(java.lang.String passcode,
                                          long t1,
                                          double q1)
                                   throws java.io.IOException,
                                          java.security.NoSuchAlgorithmException
        Throws:
        java.io.IOException
        java.security.NoSuchAlgorithmException
      • connect

        public static void connect​(java.net.Socket sock,
                                   java.net.SocketAddress dest,
                                   int sock_conn_timeout)
                            throws java.io.IOException
        Utility method. If the dest address is IPv6, convert scoped link-local addrs into unscoped ones
        Parameters:
        sock -
        dest -
        sock_conn_timeout -
        Throws:
        java.io.IOException
      • connect

        public static boolean connect​(java.nio.channels.SocketChannel ch,
                                      java.net.SocketAddress dest)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • close

        public static void close​(java.io.Closeable closeable)
      • close

        public static void close​(java.io.Closeable... closeables)
      • closeReverse

        public static void closeReverse​(java.io.Closeable... closeables)
      • closeFast

        public static void closeFast​(JChannel... channels)
        Closes all non-coordinators first, in parallel, then closes the coord. This should produce just 2 views
      • shutdown

        public static void shutdown​(JChannel ch)
                             throws java.lang.Exception
        Drops messages to/from other members and then closes the channel. Note that this member won't get excluded from the view until failure detection has kicked in and the new coord installed the new view
        Throws:
        java.lang.Exception
      • setFlag

        public static byte setFlag​(byte bits,
                                   byte flag)
      • isFlagSet

        public static boolean isFlagSet​(byte bits,
                                        byte flag)
      • clearFlags

        public static byte clearFlags​(byte bits,
                                      byte flag)
      • flagsToString

        public static java.lang.String flagsToString​(short flags)
      • transientFlagsToString

        public static java.lang.String transientFlagsToString​(short flags)
      • isFlagSet

        public static boolean isFlagSet​(short flags,
                                        Message.Flag flag)
      • isTransientFlagSet

        public static boolean isTransientFlagSet​(short flags,
                                                 Message.TransientFlag flag)
      • copy

        public static Message copy​(Message msg,
                                   boolean copy_buffer,
                                   short starting_id,
                                   short... copy_only_ids)
        Copies a message. Copies only headers with IDs >= starting_id or IDs which are in the copy_only_ids list
        Parameters:
        copy_buffer -
        starting_id -
        copy_only_ids -
        Returns:
      • objectFromByteBuffer

        public static <T> T objectFromByteBuffer​(byte[] buffer)
                                          throws java.io.IOException,
                                                 java.lang.ClassNotFoundException
        Creates an object from a byte buffer
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • objectFromByteBuffer

        public static <T> T objectFromByteBuffer​(byte[] buffer,
                                                 int offset,
                                                 int length)
                                          throws java.io.IOException,
                                                 java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • objectFromBuffer

        public static <T> T objectFromBuffer​(ByteArray b,
                                             java.lang.ClassLoader loader)
                                      throws java.io.IOException,
                                             java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • objectFromByteBuffer

        public static <T> T objectFromByteBuffer​(byte[] buffer,
                                                 int offset,
                                                 int length,
                                                 java.lang.ClassLoader loader)
                                          throws java.io.IOException,
                                                 java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • objectFromByteBuffer

        public static <T> T objectFromByteBuffer​(java.nio.ByteBuffer buffer,
                                                 java.lang.ClassLoader loader)
                                          throws java.lang.Exception
        Parses an object from a ByteBuffer. Note that this changes the position of the buffer, so it this is not desired, use ByteBuffer.duplicate() to create a copy and pass the copy to this method.
        Throws:
        java.lang.Exception
      • objectToByteBuffer

        public static byte[] objectToByteBuffer​(java.lang.Object obj)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • objectToBuffer

        public static ByteArray objectToBuffer​(java.lang.Object obj)
                                        throws java.io.IOException
        Serializes/Streams an object into a byte buffer. The object has to implement interface Serializable or Externalizable or Streamable.
        Throws:
        java.io.IOException
      • writeStreamable

        protected static ByteArray writeStreamable​(Streamable obj)
                                            throws java.io.IOException
        Throws:
        java.io.IOException
      • writeSerializable

        protected static ByteArray writeSerializable​(java.lang.Object obj)
                                              throws java.io.IOException
        Throws:
        java.io.IOException
      • marshalPrimitiveType

        protected static byte[] marshalPrimitiveType​(java.lang.Byte type,
                                                     java.lang.Object obj)
      • writeString

        public static void writeString​(java.lang.String str,
                                       java.io.DataOutput out)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • readString

        public static java.lang.String readString​(java.io.DataInput in)
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • size

        public static int size​(java.lang.Object obj)
      • sizePrimitive

        public static int sizePrimitive​(java.lang.Object obj)
      • writeTypeStreamable

        public static void writeTypeStreamable​(Streamable obj,
                                               java.io.DataOutput out)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • primitiveToStream

        public static void primitiveToStream​(java.lang.Object obj,
                                             java.io.DataOutput out)
                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • primitiveFromStream

        public static <T> T primitiveFromStream​(java.io.DataInput in)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • primitiveFromStream

        public static <T> T primitiveFromStream​(java.io.DataInput in,
                                                byte type)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • objectToStream

        public static void objectToStream​(java.lang.Object obj,
                                          java.io.DataOutput out)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • objectFromStream

        public static <T> T objectFromStream​(java.io.DataInput in)
                                      throws java.io.IOException,
                                             java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • objectFromStream

        public static <T> T objectFromStream​(java.io.DataInput in,
                                             java.lang.ClassLoader loader)
                                      throws java.io.IOException,
                                             java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • streamableFromByteBuffer

        public static <T extends Streamable> T streamableFromByteBuffer​(java.lang.Class<? extends Streamable> cl,
                                                                        byte[] buffer)
                                                                 throws java.lang.Exception
        Throws:
        java.lang.Exception
      • streamableFromByteBuffer

        public static <T extends Streamable> T streamableFromByteBuffer​(java.util.function.Supplier<T> factory,
                                                                        byte[] buffer)
                                                                 throws java.lang.Exception
        Throws:
        java.lang.Exception
      • exceptionToStream

        public static void exceptionToStream​(java.lang.Throwable t,
                                             java.io.DataOutput out)
                                      throws java.io.IOException
        Poor man's serialization of an exception. Serializes only the message, stack trace and cause (not suppressed exceptions)
        Throws:
        java.io.IOException
      • exceptionToStream

        protected static void exceptionToStream​(java.util.Set<java.lang.Throwable> causes,
                                                java.lang.Throwable t,
                                                java.io.DataOutput out)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • exceptionToBuffer

        public static ByteArray exceptionToBuffer​(java.lang.Throwable t)
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • exceptionFromStream

        public static java.lang.Throwable exceptionFromStream​(java.io.DataInput in)
                                                       throws java.io.IOException,
                                                              java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • exceptionFromStream

        protected static java.lang.Throwable exceptionFromStream​(java.io.DataInput in,
                                                                 int recursion_count)
                                                          throws java.io.IOException,
                                                                 java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • add

        protected static void add​(byte type,
                                  java.lang.Class<?> cl)
      • writeException

        protected static void writeException​(java.util.Set<java.lang.Throwable> causes,
                                             java.lang.Throwable t,
                                             java.io.DataOutput out)
                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • readException

        protected static java.lang.Throwable readException​(java.io.DataInput in,
                                                           int recursion_count)
                                                    throws java.io.IOException,
                                                           java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • exceptionFromBuffer

        public static java.lang.Throwable exceptionFromBuffer​(byte[] buf,
                                                              int offset,
                                                              int length)
                                                       throws java.io.IOException,
                                                              java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • bufferToArray

        public static byte[] bufferToArray​(java.nio.ByteBuffer buf)
        Returns a copy of the byte array between position and limit; requires a non-null buffer
      • bufferToArray

        public static void bufferToArray​(Address sender,
                                         java.nio.ByteBuffer buf,
                                         Receiver target)
      • streamableFromByteBuffer

        public static <T extends Streamable> T streamableFromByteBuffer​(java.lang.Class<? extends Streamable> cl,
                                                                        byte[] buffer,
                                                                        int offset,
                                                                        int length)
                                                                 throws java.lang.Exception
        Throws:
        java.lang.Exception
      • streamableFromByteBuffer

        public static <T extends Streamable> T streamableFromByteBuffer​(java.lang.Class<? extends Streamable> cl,
                                                                        java.nio.ByteBuffer buffer)
                                                                 throws java.lang.Exception
        Throws:
        java.lang.Exception
      • streamableFromByteBuffer

        public static <T extends Streamable> T streamableFromByteBuffer​(java.util.function.Supplier<T> factory,
                                                                        byte[] buffer,
                                                                        int offset,
                                                                        int length)
                                                                 throws java.lang.Exception
        Throws:
        java.lang.Exception
      • streamableFromBuffer

        public static <T extends Streamable> T streamableFromBuffer​(java.util.function.Supplier<T> factory,
                                                                    byte[] buf,
                                                                    int off,
                                                                    int len)
                                                             throws java.io.IOException,
                                                                    java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • streamableToByteBuffer

        public static byte[] streamableToByteBuffer​(Streamable obj)
                                             throws java.io.IOException
        Throws:
        java.io.IOException
      • streamableToBuffer

        public static ByteArray streamableToBuffer​(Streamable obj)
                                            throws java.lang.Exception
        Throws:
        java.lang.Exception
      • messageToBuffer

        public static ByteArray messageToBuffer​(Message msg)
                                         throws java.lang.Exception
        Throws:
        java.lang.Exception
      • messageFromBuffer

        public static Message messageFromBuffer​(byte[] buf,
                                                int offset,
                                                int length)
                                         throws java.lang.Exception
        Throws:
        java.lang.Exception
      • messageToByteBuffer

        public static ByteArray messageToByteBuffer​(Message msg)
                                             throws java.lang.Exception
        Throws:
        java.lang.Exception
      • messageFromByteBuffer

        public static Message messageFromByteBuffer​(byte[] buffer,
                                                    int offset,
                                                    int length)
                                             throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getObject

        public static java.lang.String getObject​(Message msg)
        Tries to return a legible representation of a message's payload
      • getObjects

        public static java.lang.String getObjects​(java.lang.Iterable<Message> it)
      • wrapDirect

        public static java.nio.ByteBuffer wrapDirect​(byte[] array)
      • wrapDirect

        public static java.nio.ByteBuffer wrapDirect​(byte[] array,
                                                     int offset,
                                                     int length)
      • collectionToByteBuffer

        public static byte[] collectionToByteBuffer​(java.util.Collection<Address> c)
                                             throws java.io.IOException
        Throws:
        java.io.IOException
      • stringToBytes

        public static byte[] stringToBytes​(java.lang.String str)
      • bytesToString

        public static java.lang.String bytesToString​(byte[] bytes)
      • byteArrayToHexString

        public static java.lang.String byteArrayToHexString​(byte[] b)
      • byteArrayToHexString

        public static java.lang.String byteArrayToHexString​(byte[] b,
                                                            int offset,
                                                            int length)
      • isAsciiString

        public static boolean isAsciiString​(java.lang.String str)
      • hexToBin

        public static java.lang.String hexToBin​(java.lang.String s)
      • compare

        public static int compare​(byte[] left,
                                  byte[] right)
        Compares 2 byte arrays, elements are treated as unigned
      • convert

        public static java.lang.Object convert​(java.lang.String arg,
                                               java.lang.Class<?> type,
                                               java.util.concurrent.TimeUnit unit)
      • writeMessage

        public static void writeMessage​(Message msg,
                                        java.io.DataOutput dos,
                                        boolean multicast)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • readMessage

        public static Message readMessage​(java.io.DataInput in)
                                   throws java.io.IOException,
                                          java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • writeMessageList

        public static void writeMessageList​(Address dest,
                                            Address src,
                                            byte[] cluster_name,
                                            java.util.List<Message> msgs,
                                            java.io.DataOutput dos,
                                            boolean multicast)
                                     throws java.io.IOException
        Write a list of messages with the *same* destination and src addresses. The message list is marshalled as follows (see doc/design/MarshallingFormat.txt for details):
         List: * | version | flags | dest | src | cluster-name | [Message*] |
        
         Message:  | presence | leading | flags | [src] | length | [buffer] | size | [Headers*] |
        
         
        Throws:
        java.io.IOException
      • writeMessageList

        public static void writeMessageList​(Address dest,
                                            Address src,
                                            byte[] cluster_name,
                                            FastArray<Message> msgs,
                                            java.io.DataOutput dos,
                                            boolean multicast)
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • writeMessageList

        public static void writeMessageList​(Address dest,
                                            Address src,
                                            byte[] cluster_name,
                                            Message[] msgs,
                                            int offset,
                                            int length,
                                            java.io.DataOutput dos,
                                            boolean multicast)
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • writeMessageListHeader

        public static void writeMessageListHeader​(Address dest,
                                                  Address src,
                                                  byte[] cluster_name,
                                                  int numMsgs,
                                                  java.io.DataOutput dos,
                                                  boolean multicast)
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • readMessageList

        public static java.util.List<Message> readMessageList​(java.io.DataInput in,
                                                              short transport_id)
                                                       throws java.io.IOException,
                                                              java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • readMessageBatch

        public static MessageBatch[] readMessageBatch​(java.io.DataInput in,
                                                      boolean multicast)
                                               throws java.io.IOException,
                                                      java.lang.ClassNotFoundException
        Reads a list of messages into 2 MessageBatches:
        1. regular
        2. OOB
        Returns:
        an array of 2 MessageBatches in the order above, the first batch is at index 0
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • parse

        public static void parse​(byte[] buf,
                                 int offset,
                                 int length,
                                 java.util.function.BiConsumer<java.lang.Short,​Message> msg_consumer,
                                 java.util.function.BiConsumer<java.lang.Short,​MessageBatch> batch_consumer,
                                 java.util.function.Consumer<GossipData> gossip_consumer,
                                 boolean tcp,
                                 boolean gossip)
      • parse

        public static void parse​(java.io.InputStream input,
                                 java.util.function.BiConsumer<java.lang.Short,​Message> msg_consumer,
                                 java.util.function.BiConsumer<java.lang.Short,​MessageBatch> batch_consumer,
                                 java.util.function.Consumer<GossipData> gossip_consumer,
                                 boolean tcp,
                                 boolean gossip)
      • writeView

        public static void writeView​(View view,
                                     java.io.DataOutput out)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • readView

        public static View readView​(java.io.DataInput in)
                             throws java.io.IOException,
                                    java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • writeViewId

        public static void writeViewId​(ViewId vid,
                                       java.io.DataOutput out)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • readViewId

        public static ViewId readViewId​(java.io.DataInput in)
                                 throws java.io.IOException,
                                        java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • writeAddress

        public static void writeAddress​(Address addr,
                                        java.io.DataOutput out)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • readAddress

        public static Address readAddress​(java.io.DataInput in)
                                   throws java.io.IOException,
                                          java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • size

        public static int size​(Address addr)
      • size

        public static int size​(View view)
      • size

        public static int size​(ViewId vid)
      • size

        public static int size​(java.lang.String s)
      • size

        public static int size​(byte[] buf)
      • writeAddresses

        public static void writeAddresses​(java.util.Collection<? extends Address> v,
                                          java.io.DataOutput out)
                                   throws java.io.IOException
        Writes a list of Addresses. Can contain 65K addresses at most
        Parameters:
        v - A Collection
        out -
        Throws:
        java.lang.Exception
        java.io.IOException
      • writeAddresses

        public static void writeAddresses​(Address[] addrs,
                                          java.io.DataOutput out)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • readAddresses

        public static <T extends java.util.Collection<Address>> T readAddresses​(java.io.DataInput in,
                                                                                java.util.function.IntFunction<T> factory)
                                                                         throws java.io.IOException,
                                                                                java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • readAddresses

        public static Address[] readAddresses​(java.io.DataInput in)
                                       throws java.io.IOException,
                                              java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • size

        public static long size​(java.util.Collection<? extends Address> addrs)
        Returns the marshalled size of a Collection of Addresses. Assumes elements are of the same type !
        Parameters:
        addrs - Collection
        Returns:
        long size
      • size

        public static long size​(Address[] addrs)
      • addressToString

        public static java.lang.String addressToString​(Address addr)
      • addressFromString

        public static Address addressFromString​(java.lang.String s)
                                         throws java.lang.Exception
        Throws:
        java.lang.Exception
      • writeStreamable

        public static void writeStreamable​(Streamable obj,
                                           java.io.DataOutput out)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • readStreamable

        public static <T extends Streamable> T readStreamable​(java.util.function.Supplier<T> factory,
                                                              java.io.DataInput in)
                                                       throws java.io.IOException,
                                                              java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • writeGenericStreamable

        public static void writeGenericStreamable​(Streamable obj,
                                                  java.io.DataOutput out)
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • readGenericStreamable

        public static <T extends Streamable> T readGenericStreamable​(java.io.DataInput in)
                                                              throws java.io.IOException,
                                                                     java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • readGenericStreamable

        public static <T extends Streamable> T readGenericStreamable​(java.io.DataInput in,
                                                                     java.lang.ClassLoader loader)
                                                              throws java.io.IOException,
                                                                     java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • readSizeStreamable

        public static SizeStreamable readSizeStreamable​(java.io.DataInput in,
                                                        java.lang.ClassLoader loader)
                                                 throws java.io.IOException,
                                                        java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • write

        public static <T extends Streamable> void write​(T[] array,
                                                        java.io.DataOutput out)
                                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • read

        public static <T extends Streamable> T[] read​(java.lang.Class<T> clazz,
                                                      java.io.DataInput in)
                                               throws java.lang.Exception
        Throws:
        java.lang.Exception
      • readFile

        public static java.lang.String readFile​(java.lang.String filename)
                                         throws java.io.FileNotFoundException
        Throws:
        java.io.FileNotFoundException
      • readContents

        public static java.lang.String readContents​(java.io.InputStream input)
      • readFileContents

        public static byte[] readFileContents​(java.io.InputStream input)
                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • readToken

        public static java.lang.String readToken​(java.io.InputStream in)
        Returns whitespace-separated strings from the input stream, or null if the end of the stream has been reached
      • readTillMatchingCharacter

        public static java.lang.String readTillMatchingCharacter​(java.io.InputStream in,
                                                                 char c)
                                                          throws java.io.IOException
        Returns all characters read from the current position until the next occurrence of 'c' has been read (including 'c'), or eof, whichever comes first
        Throws:
        java.io.IOException
      • readStringFromStdin

        public static java.lang.String readStringFromStdin​(java.lang.String message)
                                                    throws java.lang.Exception
        Throws:
        java.lang.Exception
      • readLongFromStdin

        public static long readLongFromStdin​(java.lang.String message)
                                      throws java.lang.Exception
        Throws:
        java.lang.Exception
      • readDoubleFromStdin

        public static double readDoubleFromStdin​(java.lang.String message)
                                          throws java.lang.Exception
        Throws:
        java.lang.Exception
      • readIntFromStdin

        public static int readIntFromStdin​(java.lang.String message)
                                    throws java.lang.Exception
        Throws:
        java.lang.Exception
      • writeByteBuffer

        public static void writeByteBuffer​(byte[] buf,
                                           java.io.DataOutput out)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • writeByteBuffer

        public static void writeByteBuffer​(byte[] buf,
                                           int offset,
                                           int length,
                                           java.io.DataOutput out)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • readByteBuffer

        public static byte[] readByteBuffer​(java.io.DataInput in)
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • match

        public static <T> boolean match​(T obj1,
                                        T obj2)
      • patternMatch

        public static boolean patternMatch​(java.lang.String pattern,
                                           java.lang.String str)
      • productGreaterThan

        public static boolean productGreaterThan​(long n1,
                                                 long n2,
                                                 long val)
      • different

        public static <T> boolean different​(T one,
                                            T two)
      • sleep

        public static void sleep​(long timeout)
        Sleep for timeout msecs. Returns when timeout has elapsed or thread was interrupted
      • sleep

        public static void sleep​(long timeout,
                                 int nanos)
      • keyPress

        public static int keyPress​(java.lang.String msg)
      • available

        public static int available​(java.io.InputStream in)
      • micros

        public static long micros()
      • factorial

        public static int factorial​(int n)
      • permute

        public static <E> void permute​(java.util.List<E> list,
                                       java.util.List<java.util.List<E>> permutations)
        Inefficient permutation of a generic list; uses too much copying among other things. PR welcome! :-)
        Type Parameters:
        E - the type of the list elements
        Parameters:
        list - The list
        permutations - All permutations will be added to this list (as copies)
      • permute

        protected static <E> void permute​(java.util.List<E> prefix,
                                          java.util.List<E> list,
                                          int index,
                                          java.util.List<java.util.List<E>> permutations)
      • car

        public static <E> java.util.List<E> car​(java.util.List<E> l)
      • cdr

        public static <E> java.util.List<E> cdr​(java.util.List<E> l)
      • combine

        public static <E> java.util.List<E> combine​(java.util.List<E> l1,
                                                    java.util.List<E> l2)
      • combine

        @SafeVarargs
        public static <E> E[] combine​(E[]... arrays)
      • combine

        @SafeVarargs
        public static <E> E[] combine​(java.lang.Class<?> cl,
                                      E... array)
      • swap

        protected static <E> java.util.List<E> swap​(java.util.List<E> l,
                                                    int index)
      • orderedPermutation

        public static <E> java.util.Collection<java.util.List<E>> orderedPermutation​(java.util.List<E> a,
                                                                                     java.util.List<E> b)
        Performs an ordered permutation of the elements of a and b such that the order of elements in list a and b is preserved. Example: {A1,A2} and {B1,B2} -> {A1,B1,A2,B2} but not {A1,B2,B1,A2}
      • permute

        protected static <E> java.util.List<E> permute​(java.util.List<E> l1,
                                                       java.util.List<E> l2,
                                                       int remove_from_l1,
                                                       int remove_from_l2)
      • checkOrder

        @SafeVarargs
        public static <E> boolean checkOrder​(java.util.Collection<E> perm,
                                             java.util.List<E>... lists)
      • index

        protected static <E> int index​(java.util.Collection<E> list,
                                       E el)
      • shuffle

        public static <T> void shuffle​(T[] array,
                                       int from,
                                       int to)
        Reorders elements of an array in-place. No bounds checking is performed. Null elements are shuffled, too
        Type Parameters:
        T - the type of the array's elements
        Parameters:
        array - the array to be shuffled; the array will be modified
        from - the start index inclusive
        to - the end index (exclusive), must be >= from (not checked)
      • enumerate

        public static <T> java.util.Enumeration<T> enumerate​(T[] array,
                                                             int offset,
                                                             int length)
      • enumerate

        public static <T,​R> java.util.Enumeration<R> enumerate​(T[] array,
                                                                     int offset,
                                                                     int length,
                                                                     java.util.function.Function<T,​R> converter)
      • nonNegativeValue

        public static <T extends java.lang.Number> T nonNegativeValue​(T num)
      • random

        public static long random​(long range)
        Returns a random value in the range [1 - range]. If range is 0, 1 will be returned. If range is negative, an exception will be thrown
      • sleepRandom

        public static void sleepRandom​(long floor,
                                       long ceiling)
        Sleeps between floor and ceiling milliseconds, chosen randomly
      • tossWeightedCoin

        public static boolean tossWeightedCoin​(double probability)
        Tosses a coin weighted with probability and returns true or false. Example: if probability=0.8, chances are that in 80% of all cases, true will be returned and false in 20%.
      • dumpThreads

        public static java.lang.String dumpThreads()
      • interruptAndWaitToDie

        public static boolean interruptAndWaitToDie​(java.lang.Thread t)
      • interruptAndWaitToDie

        public static boolean interruptAndWaitToDie​(java.lang.Thread t,
                                                    long timeout)
      • printTime

        public static java.lang.String printTime​(double time,
                                                 java.util.concurrent.TimeUnit unit)
      • suffix

        public static java.lang.String suffix​(java.util.concurrent.TimeUnit u)
      • print

        public static java.lang.String print​(double time,
                                             java.util.concurrent.TimeUnit unit)
      • readBytesLong

        public static long readBytesLong​(java.lang.String input)
      • readBytesInteger

        public static int readBytesInteger​(java.lang.String input)
      • readBytesDouble

        public static double readBytesDouble​(java.lang.String input)
      • readDurationLong

        public static long readDurationLong​(java.lang.String input,
                                            java.util.concurrent.TimeUnit unit)
      • printBytes

        public static java.lang.String printBytes​(double bytes)
        MB nowadays doesn't mean 1024 * 1024 bytes, but 1 million bytes, see http://en.wikipedia.org/wiki/Megabyte
        Parameters:
        bytes -
      • format

        public static java.lang.String format​(double val,
                                              java.lang.String suffix)
      • components

        public static java.lang.String[] components​(java.lang.String path,
                                                    java.lang.String separator)
      • fragmentBuffer

        public static byte[][] fragmentBuffer​(byte[] buf,
                                              int frag_size,
                                              int length)
        Fragments a byte buffer into smaller fragments of (max.) frag_size. Example: a byte buffer of 1024 bytes and a frag_size of 248 gives 4 fragments of 248 bytes each and 1 fragment of 32 bytes.
        Returns:
        An array of byte buffers (byte[]).
      • computeFragOffsets

        public static java.util.List<Range> computeFragOffsets​(int offset,
                                                               int length,
                                                               int frag_size)
        Given a buffer and a fragmentation size, compute a list of fragmentation offset/length pairs, and return them in a list. Example:
        Buffer is 10 bytes, frag_size is 4 bytes. Return value will be ({0,4}, {4,4}, {8,2}). This is a total of 3 fragments: the first fragment starts at 0, and has a length of 4 bytes, the second fragment starts at offset 4 and has a length of 4 bytes, and the last fragment starts at offset 8 and has a length of 2 bytes.
        Parameters:
        frag_size -
        Returns:
        List. A List of offset/length pairs
      • computeFragOffsets

        public static java.util.List<Range> computeFragOffsets​(byte[] buf,
                                                               int frag_size)
      • defragmentBuffer

        public static byte[] defragmentBuffer​(byte[][] fragments)
        Concatenates smaller fragments into entire buffers.
        Parameters:
        fragments - An array of byte buffers (byte[])
        Returns:
        A byte buffer
      • allEqual

        public static <T> boolean allEqual​(java.util.Collection<T> elements)
        Returns true if all elements in the collection are the same
      • printList

        public static <T> java.lang.String printList​(java.util.Collection<T> l)
      • printListWithDelimiter

        public static <T> java.lang.String printListWithDelimiter​(java.util.Collection<T> list,
                                                                  java.lang.String delimiter)
      • printListWithDelimiter

        public static <T> java.lang.String printListWithDelimiter​(java.util.Collection<T> list,
                                                                  java.lang.String delimiter,
                                                                  int limit)
      • printListWithDelimiter

        public static <T> java.lang.String printListWithDelimiter​(java.util.Collection<T> list,
                                                                  java.lang.String delimiter,
                                                                  int limit,
                                                                  boolean print_size)
      • printListWithDelimiter

        public static <T> java.lang.String printListWithDelimiter​(T[] list,
                                                                  java.lang.String delimiter,
                                                                  int limit)
      • printMapWithDelimiter

        public static <T> java.lang.String printMapWithDelimiter​(java.util.Map<T,​T> map,
                                                                 java.lang.String delimiter)
      • leftMembers

        public static java.util.List<Address> leftMembers​(java.util.Collection<Address> old_list,
                                                          java.util.Collection<Address> new_list)
      • newMembers

        public static java.util.List<Address> newMembers​(java.util.List<Address> old_list,
                                                         java.util.List<Address> new_list)
      • newElements

        public static <T> java.util.List<T> newElements​(java.util.List<T> old_list,
                                                        java.util.List<T> new_list)
      • contains

        public static <T> boolean contains​(T key,
                                           T[] list)
      • containsViewId

        public static boolean containsViewId​(java.util.Collection<View> views,
                                             ViewId vid)
      • containsId

        public static boolean containsId​(short id,
                                         short[] ids)
      • determineMergeParticipants

        public static java.util.Collection<Address> determineMergeParticipants​(java.util.Map<Address,​View> map)
        Determines the members which take part in a merge. The resulting list consists of all merge coordinators plus members outside a merge partition, e.g. for views A={B,A,C}, B={B,C} and C={B,C}, the merge coordinator is B, but the merge participants are B and A.
        Parameters:
        map -
        Returns:
      • determineMergeCoords

        public static java.util.Collection<Address> determineMergeCoords​(java.util.Map<Address,​View> map)
        This is the same or a subset of determineMergeParticipants(java.util.Map) and contains only members which are currently sub-partition coordinators.
        Parameters:
        map -
        Returns:
      • determineActualMergeCoords

        public static java.util.Collection<Address> determineActualMergeCoords​(java.util.Map<Address,​View> map)
        Similar to determineMergeCoords(java.util.Map) but only actual coordinators are counted: an actual coord is when the sender of a view is the first member of that view
      • getRank

        public static int getRank​(View view,
                                  Address addr)
        Returns the rank of a member in a given view
        Parameters:
        view - The view
        addr - The address of a member
        Returns:
        A value between 1 and view.size(). The first member has rank 1, the second 2 and so on. If the member is not found, 0 is returned
      • getRank

        public static int getRank​(java.util.Collection<Address> members,
                                  Address addr)
      • pickRandomElement

        public static <T> T pickRandomElement​(java.util.List<T> list)
      • pickRandomElement

        public static <T> T pickRandomElement​(java.util.Collection<T> set)
      • pickRandomElement

        public static <T> T pickRandomElement​(T[] array)
      • pickNext

        public static <T> T pickNext​(java.util.List<T> list,
                                     T obj)
      • pickNext

        public static <T> java.util.List<T> pickNext​(java.util.List<T> list,
                                                     T obj,
                                                     int num)
        Returns the next min(N,list.size()) elements after obj
      • pickPrevious

        public static <T> T pickPrevious​(T[] array,
                                         T el)
        Returns the element before el. If el is the first element, returns the last element. Returns null if array.length < 2
      • pickPrevious

        public static <T> T pickPrevious​(java.util.List<T> list,
                                         T el)
      • generateArray

        public static byte[] generateArray​(int length)
      • verifyArray

        public static boolean verifyArray​(byte[] array)
      • verifyByteBuffer

        public static boolean verifyByteBuffer​(java.nio.ByteBuffer buf)
      • createRandomAddress

        public static Address createRandomAddress()
      • createRandomAddresses

        public static Address[] createRandomAddresses​(int num)
        Returns an array of num random addresses, named A, B, C etc
      • createRandomAddresses

        public static Address[] createRandomAddresses​(int num,
                                                      boolean use_numbers)
      • createRandomAddress

        public static Address createRandomAddress​(java.lang.String name)
      • createTimer

        public static java.lang.Object[][] createTimer()
      • determineLeftMembers

        public static java.util.List<Address> determineLeftMembers​(java.util.List<Address> old_mbrs,
                                                                   java.util.List<Address> new_mbrs)
        Returns all members that left between 2 views. All members that are element of old_mbrs but not element of new_mbrs are returned.
      • print

        public static <T> java.lang.String print​(java.util.Collection<T> objs)
      • print

        public static java.lang.String print​(java.lang.Object[] objs)
      • print

        public static <T> java.lang.String print​(java.util.Map<T,​T> map)
      • loadClass

        public static java.lang.Class<?> loadClass​(java.lang.String classname,
                                                   java.lang.Class<?> clazz)
                                            throws java.lang.ClassNotFoundException
        Tries to load the class from the current thread's context class loader. If not successful, tries to load the class from the current instance.
        Parameters:
        classname - Desired class.
        clazz - Class object used to obtain a class loader if no context class loader is available.
        Returns:
        Class, or null on failure.
        Throws:
        java.lang.ClassNotFoundException
      • loadClass

        public static java.lang.Class<?> loadClass​(java.lang.String classname,
                                                   java.lang.ClassLoader preferredLoader)
                                            throws java.lang.ClassNotFoundException
        Tries to load the class from the preferred loader. If not successful, tries to load the class from the current thread's context class loader or system class loader.
        Parameters:
        classname - Desired class name.
        preferredLoader - The preferred class loader
        Returns:
        the loaded class.
        Throws:
        java.lang.ClassNotFoundException - if the class could not be loaded by any loader
      • loadProtocolClass

        public static java.lang.Class<? extends Protocol> loadProtocolClass​(java.lang.String protocol_name,
                                                                            java.lang.Class<?> cl)
                                                                     throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getAllDeclaredFieldsWithAnnotations

        @SafeVarargs
        public static java.lang.reflect.Field[] getAllDeclaredFieldsWithAnnotations​(java.lang.Class<?> clazz,
                                                                                    java.lang.Class<? extends java.lang.annotation.Annotation>... annotations)
      • forAllFieldsAndMethods

        public static void forAllFieldsAndMethods​(java.lang.Object obj,
                                                  java.util.function.Predicate<? super java.lang.reflect.AccessibleObject> filter,
                                                  java.util.function.BiConsumer<java.lang.reflect.Field,​java.lang.Object> field_func,
                                                  java.util.function.BiConsumer<java.lang.reflect.Method,​java.lang.Object> method_func)
        Applies a function against all fields and methods of a given target object which satisfy a given predicate.
        Parameters:
        obj - The target object
        filter - The filter. Needs to be able to handle Fields and Methods (superclass: AccessibleObject). If null, all fields/methods will be selected
        field_func - The function to be applied to all found fields. No-op if null.
        method_func - The function to be applied to all found methods. No-op if null.
      • getNameFromAnnotation

        public static java.lang.String getNameFromAnnotation​(java.lang.reflect.AccessibleObject obj)
      • getAllDeclaredMethodsWithAnnotations

        @SafeVarargs
        public static java.lang.reflect.Method[] getAllDeclaredMethodsWithAnnotations​(java.lang.Class<?> clazz,
                                                                                      java.lang.Class<? extends java.lang.annotation.Annotation>... annotations)
      • getAnnotation

        public static <A extends java.lang.annotation.Annotation> A getAnnotation​(java.lang.Class<?> clazz,
                                                                                  java.lang.Class<A> annotationClass)
      • getField

        public static java.lang.reflect.Field getField​(java.lang.Class<?> clazz,
                                                       java.lang.String field_name)
      • getField

        public static java.lang.reflect.Field getField​(java.lang.Class<?> clazz,
                                                       java.lang.String field_name,
                                                       boolean throw_exception)
                                                throws java.lang.NoSuchFieldException
        Throws:
        java.lang.NoSuchFieldException
      • setField

        public static void setField​(java.lang.reflect.Field field,
                                    java.lang.Object target,
                                    java.lang.Object value)
      • getField

        public static java.lang.Object getField​(java.lang.reflect.Field field,
                                                java.lang.Object target)
      • findField

        public static java.lang.reflect.Field findField​(java.lang.Object target,
                                                        java.util.List<java.lang.String> possible_names)
      • findMethod

        public static java.lang.reflect.Method findMethod​(java.lang.Class<?> target_class,
                                                          java.lang.String method_name,
                                                          java.lang.Object[] args)
                                                   throws java.lang.Exception
        Called by the ProbeHandler impl. All args are strings. Needs to find a method where all parameter types are primitive types, so the strings can be converted
        Throws:
        java.lang.Exception
      • findMethod2

        public static java.lang.reflect.Method findMethod2​(java.lang.Class<?> target_class,
                                                           java.lang.String method_name,
                                                           java.lang.Object[] args)
                                                    throws java.lang.Exception
        Throws:
        java.lang.Exception
      • isAssignableFrom

        public static boolean isAssignableFrom​(java.lang.Class<?> left,
                                               java.lang.Class<?> right)
      • invoke

        public static java.lang.Object invoke​(java.lang.Object target,
                                              java.lang.String method_name,
                                              java.lang.Object... args)
                                       throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getAllMethods

        public static java.lang.reflect.Method[] getAllMethods​(java.lang.Class<?> target)
        The method walks up the class hierarchy and returns all methods of this class and those inherited from superclasses and superinterfaces.
      • getComponents

        public static java.util.List<java.lang.Object> getComponents​(java.lang.Object target)
        Returns the non-null values of all fields of target annotated with @Component
      • getComponents

        public static java.util.List<java.lang.Class<?>> getComponents​(java.lang.Class<?> clazz)
      • forAllComponents

        public static void forAllComponents​(java.lang.Object target,
                                            java.util.function.BiConsumer<java.lang.Object,​java.lang.String> func)
        Applies a function to all fields annotated with @Component
        Parameters:
        target - The target object
        func - The function accepting the value of the field and the component name (prefix)
      • forAllComponentTypes

        public static void forAllComponentTypes​(java.lang.Class<?> cl,
                                                java.util.function.BiConsumer<java.lang.Class<?>,​java.lang.String> func)
      • isPrimitiveType

        public static boolean isPrimitiveType​(java.lang.Class<?> type)
      • isPrimitiveType

        public static boolean isPrimitiveType​(java.lang.Object obj)
      • findMethod

        public static java.lang.reflect.Method findMethod​(java.lang.Object target,
                                                          java.util.List<java.lang.String> possible_names,
                                                          java.lang.Class<?>... parameter_types)
      • findMethod

        public static java.lang.reflect.Method findMethod​(java.lang.Class<?> root_class,
                                                          java.util.List<java.lang.String> possible_names,
                                                          java.lang.Class<?>... parameter_types)
      • findMethod

        public static java.lang.reflect.Method findMethod​(java.lang.Class<?> cl,
                                                          java.lang.String method_name,
                                                          java.lang.Class<?>... parameter_types)
      • findClassesAssignableFrom

        public static java.util.Set<java.lang.Class<?>> findClassesAssignableFrom​(java.lang.String packageName,
                                                                                  java.lang.Class<?> assignableFrom,
                                                                                  java.lang.ClassLoader cl)
                                                                           throws java.io.IOException,
                                                                                  java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • findClassesAssignableFromPath

        public static java.util.Set<java.lang.Class<?>> findClassesAssignableFromPath​(java.lang.String packagePath,
                                                                                      java.lang.Class<?> assignableFrom,
                                                                                      java.lang.ClassLoader cl)
                                                                               throws java.io.IOException,
                                                                                      java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • findClassesAnnotatedWith

        public static java.util.List<java.lang.Class<?>> findClassesAnnotatedWith​(java.lang.String packageName,
                                                                                  java.lang.Class<? extends java.lang.annotation.Annotation> a)
                                                                           throws java.io.IOException,
                                                                                  java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • getResourceAsStream

        public static java.io.InputStream getResourceAsStream​(java.lang.String name,
                                                              java.lang.Class<?> clazz)
      • getResourceAsStream

        public static java.io.InputStream getResourceAsStream​(java.lang.String name,
                                                              java.lang.ClassLoader loader)
      • getChild

        public static java.lang.String getChild​(org.w3c.dom.Element root,
                                                java.lang.String path)
      • sameHost

        public static boolean sameHost​(Address one,
                                       Address two)
        Checks whether 2 Addresses are on the same host
      • parseRejectionPolicy

        public static java.util.concurrent.RejectedExecutionHandler parseRejectionPolicy​(java.lang.String rejection_policy)
      • parseCommaDelimitedStrings

        public static java.util.List<java.lang.String> parseCommaDelimitedStrings​(java.lang.String l)
        e.g. "A,B,C" --> List{"A", "B", "C"}
      • parseCommaDelimitedHosts

        public static java.util.List<PhysicalAddress> parseCommaDelimitedHosts​(java.lang.String hosts,
                                                                               int port_range)
                                                                        throws java.net.UnknownHostException
        Input is "daddy[8880],sindhu[8880],camille[5555]". Returns a list of IpAddresses
        Throws:
        java.net.UnknownHostException
      • parseCommaDelimitedHostsInto

        public static boolean parseCommaDelimitedHostsInto​(java.util.Collection<PhysicalAddress> list,
                                                           java.util.Collection<java.lang.String> unresolved_hosts,
                                                           java.lang.String hosts,
                                                           int port_range,
                                                           StackType stack_type)
        Parses a string into a list of IpAddresses
        Parameters:
        list - The list to which to add parsed elements
        hosts - The string with host:port pairs
        unresolved_hosts - A list of unresolved hosts
        port_range - The port range to consider
        Returns:
        True if all hostnames resolved fine, false otherwise
      • parseCommaDelimitedHosts2

        public static java.util.List<java.net.InetSocketAddress> parseCommaDelimitedHosts2​(java.lang.String hosts,
                                                                                           int port_range)
                                                                                    throws java.net.UnknownHostException
        Input is "daddy[8880],sindhu[8880],camille[5555]". Returns a list of InetSocketAddress. If a hostname doesn't resolve, then we'll use the hostname to create an address: new InetSocketAddress(host, port)
        Throws:
        java.net.UnknownHostException
      • parseHost

        public static java.net.InetSocketAddress parseHost​(java.lang.String s)
        Parses a host:IP string into an InetSocketAddress
      • parseStringList

        public static java.util.List<java.lang.String> parseStringList​(java.lang.String l,
                                                                       java.lang.String separator)
      • parseStringArray

        public static java.lang.String[] parseStringArray​(java.lang.String s,
                                                          java.lang.String separator)
      • readLine

        public static java.lang.String readLine​(java.io.InputStream in)
                                         throws java.io.IOException
        Reads a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed.
        Returns:
        A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached
        Throws:
        java.io.IOException - If an I/O error occurs
      • readBytes

        public static ByteArray readBytes​(java.io.InputStream in)
                                   throws java.io.IOException
        Reads all bytes fro, an input stream, until eof (-1) is reached
        Throws:
        java.io.IOException
      • parseInterfaceList

        public static java.util.List<java.net.NetworkInterface> parseInterfaceList​(java.lang.String s)
                                                                            throws java.lang.Exception
        Parameters:
        s -
        Returns:
        List
        Throws:
        java.lang.Exception
      • print

        public static java.lang.String print​(java.util.List<java.net.NetworkInterface> interfaces)
      • shortName

        public static java.lang.String shortName​(java.lang.String hostname)
      • shortName

        public static java.lang.String shortName​(java.net.InetAddress hostname)
      • generateLocalName

        public static java.lang.String generateLocalName()
      • createConcurrentMap

        public static <K,​V> java.util.concurrent.ConcurrentMap<K,​V> createConcurrentMap​(int initial_capacity,
                                                                                                    float load_factor,
                                                                                                    int concurrency_level)
      • createConcurrentMap

        public static <K,​V> java.util.concurrent.ConcurrentMap<K,​V> createConcurrentMap​(int initial_capacity)
      • createConcurrentMap

        public static <K,​V> java.util.concurrent.ConcurrentMap<K,​V> createConcurrentMap()
      • createServerSocket

        public static java.net.ServerSocket createServerSocket​(SocketFactory factory,
                                                               java.lang.String service_name,
                                                               java.net.InetAddress bind_addr,
                                                               int start_port,
                                                               int end_port,
                                                               int recv_buf_size)
                                                        throws java.lang.Exception
        Throws:
        java.lang.Exception
      • bind

        public static void bind​(java.net.ServerSocket srv_sock,
                                java.net.InetAddress bind_addr,
                                int start_port,
                                int end_port)
                         throws java.lang.Exception
        Throws:
        java.lang.Exception
      • bind

        public static void bind​(java.net.Socket sock,
                                java.net.InetAddress bind_addr,
                                int start_port,
                                int end_port)
                         throws java.lang.Exception
        Throws:
        java.lang.Exception
      • createServerSocketChannel

        public static java.nio.channels.ServerSocketChannel createServerSocketChannel​(SocketFactory factory,
                                                                                      java.lang.String service_name,
                                                                                      java.net.InetAddress bind_addr,
                                                                                      int start_port,
                                                                                      int end_port,
                                                                                      int recv_buf_size)
                                                                               throws java.lang.Exception
        Throws:
        java.lang.Exception
      • createDatagramSocket

        public static java.net.DatagramSocket createDatagramSocket​(SocketFactory factory,
                                                                   java.lang.String service_name,
                                                                   java.net.InetAddress addr,
                                                                   int port)
                                                            throws java.lang.Exception
        Creates a DatagramSocket bound to addr. If addr is null, socket won't be bound. If address is already in use, start_port will be incremented until a socket can be created.
        Parameters:
        addr - The InetAddress to which the socket should be bound. If null, the socket will not be bound.
        port - The port which the socket should use. If 0, a random port will be used. If > 0, but port is already in use, it will be incremented until an unused port is found, or until MAX_PORT is reached.
        Throws:
        java.lang.Exception
      • createMulticastSocket

        public static java.net.MulticastSocket createMulticastSocket​(SocketFactory factory,
                                                                     java.lang.String service_name,
                                                                     java.net.InetAddress mcast_addr,
                                                                     int port,
                                                                     Log log)
                                                              throws java.io.IOException
        Throws:
        java.io.IOException
      • validateBindAddressFromInterface

        public static java.net.InetAddress validateBindAddressFromInterface​(java.net.InetAddress bind_addr,
                                                                            java.lang.String bind_interface_str,
                                                                            StackType ip_version)
                                                                     throws java.net.UnknownHostException,
                                                                            java.net.SocketException
        Method used by PropertyConverters.BindInterface to check that a bind_addr is consistent with a specified interface

        Idea: 1. We are passed a bind_addr, which may be null 2. If non-null, check that bind_addr is on bind_interface - if not, throw exception, otherwise, return the original bind_addr 3. If null, get first non-loopback address on bind_interface, using stack preference to get the IP version. If no non-loopback address, then just return null (i.e. bind_interface did not influence the decision).

        Throws:
        java.net.UnknownHostException
        java.net.SocketException
      • checkForLinux

        public static boolean checkForLinux()
      • checkForHp

        public static boolean checkForHp()
      • checkForSolaris

        public static boolean checkForSolaris()
      • checkForWindows

        public static boolean checkForWindows()
      • checkForAndroid

        public static boolean checkForAndroid()
      • checkForMac

        public static boolean checkForMac()
      • getLoopback

        public static java.net.InetAddress getLoopback​(StackType ip_version)
                                                throws java.net.UnknownHostException
        IP related utilities
        Throws:
        java.net.UnknownHostException
      • getLoopback

        public static java.net.InetAddress getLoopback()
                                                throws java.net.UnknownHostException
        Throws:
        java.net.UnknownHostException
      • getNonLoopbackAddress

        public static java.net.InetAddress getNonLoopbackAddress()
                                                          throws java.net.SocketException
        Returns the first non-loopback address on any interface on the current host
        Throws:
        java.net.SocketException
      • getNonLoopbackAddress

        public static java.net.InetAddress getNonLoopbackAddress​(StackType ip_version)
                                                          throws java.net.SocketException
        Throws:
        java.net.SocketException
      • getByName

        public static java.net.NetworkInterface getByName​(java.lang.String name)
                                                   throws java.net.SocketException
        Finds a network interface or sub-interface with the given name
        Throws:
        java.net.SocketException
      • getByName

        public static java.net.InetAddress getByName​(java.lang.String host,
                                                     StackType ip_version)
                                              throws java.net.UnknownHostException
        Finds an address given a symbolic name. Parameter ip_version has precedence over system props such as java.net.preferIPv4Stack or java.net.preferIPv6Addresses
        Parameters:
        host - The symbolic nbame of the host
        ip_version - The IP version, e.g. StackType.IPv4 or StackType.IPv6
        Returns:
        The resolved address
        Throws:
        java.net.UnknownHostException - Thrown if host cannot be resolved to an InetAddress
      • getAddress

        public static java.net.InetAddress getAddress​(java.lang.String value,
                                                      StackType ip_version)
                                               throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getAddress

        public static java.net.InetAddress getAddress​(Util.AddressScope scope,
                                                      StackType ip_version)
                                               throws java.net.SocketException
        Returns the first address on any interface which satisfies scope and ip_version. If ip_version is Dual, then IPv4 addresses are favored
        Throws:
        java.net.SocketException
      • getAddress

        public static java.net.InetAddress getAddress​(java.net.NetworkInterface intf,
                                                      Util.AddressScope scope,
                                                      StackType ip_version)
        Returns the first address on the given interface on the current host, which satisfies scope
        Parameters:
        intf - the interface to be checked
      • match

        public static boolean match​(java.net.InetAddress addr,
                                    Util.AddressScope scope)
      • getAddressByPatternMatch

        public static java.net.InetAddress getAddressByPatternMatch​(java.lang.String pattern,
                                                                    StackType ip_version)
                                                             throws java.lang.Exception
        Returns a valid interface address based on a pattern. Iterates over all interfaces that are up and returns the first match, based on the address or interface name
        Parameters:
        pattern - Can be "match-addr:" or "match-interface:". Example:

        match-addr:192.168.*

        Returns:
        InetAddress or null if not found
        Throws:
        java.lang.Exception
      • getAddressByCustomCode

        public static java.net.InetAddress getAddressByCustomCode​(java.lang.String value)
                                                           throws java.lang.Exception
        Throws:
        java.lang.Exception
      • isUp

        public static boolean isUp​(java.net.NetworkInterface ni)
                            throws java.net.SocketException
        Always returns true unless there is a socket exception - will be removed when GraalVM issue https://github.com/oracle/graal/pull/1076 has been fixed
        Throws:
        java.net.SocketException
      • interfaceHasIPAddresses

        public static boolean interfaceHasIPAddresses​(java.net.NetworkInterface intf,
                                                      StackType ip_version)
                                               throws java.net.UnknownHostException
        A function to check if an interface supports an IP version (i.e. has addresses defined for that IP version)
        Throws:
        java.net.UnknownHostException
      • getIpStackType

        public static StackType getIpStackType()
      • isStackAvailable

        public static boolean isStackAvailable​(boolean ipv4)
      • getAllAvailableInterfaces

        public static java.util.List<java.net.NetworkInterface> getAllAvailableInterfaces()
                                                                                   throws java.net.SocketException
        Throws:
        java.net.SocketException
      • resetCacheAddresses

        public static void resetCacheAddresses​(boolean reset_interfaces,
                                               boolean reset_addresses)
      • setCacheAddresses

        public static void setCacheAddresses​(java.util.List<java.net.NetworkInterface> interfaces,
                                             java.util.List<java.net.InetAddress> addresses)
        This is a workaround for use within android. Sometimes the standard java methods do not return all the addresses. This will allow for setting in android via the conectivity manager without needing to pass in the context. Also will allow android to update as connectivity changes.
      • getAllAvailableAddresses

        public static java.util.Collection<java.net.InetAddress> getAllAvailableAddresses​(java.util.function.Predicate<java.net.InetAddress> filter)
        Returns all addresses of all interfaces (that are up) that satisfy a given filter (ignored if null)
      • checkIfValidAddress

        public static void checkIfValidAddress​(java.net.InetAddress bind_addr,
                                               java.lang.String prot_name)
                                        throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getProperty

        public static java.lang.String getProperty​(java.lang.String[] system_props,
                                                   java.util.Properties props,
                                                   java.lang.String prop_name,
                                                   java.lang.String default_value)
        Returns a value associated wither with one or more system properties, or found in the props map
        Parameters:
        system_props -
        props - List of properties read from the configuration file
        prop_name - The name of the property, will be removed from props if found
        default_value - Used to return a default value if the properties or system properties didn't have the value
        Returns:
        The value, or null if not found
      • isCoordinator

        public static boolean isCoordinator​(JChannel ch)
      • isCoordinator

        public static boolean isCoordinator​(View view,
                                            Address local_addr)
      • getMBeanServer

        public static javax.management.MBeanServer getMBeanServer()
      • registerChannel

        public static void registerChannel​(JChannel channel,
                                           java.lang.String name)
      • substituteVariable

        public static java.lang.String substituteVariable​(java.lang.String val)
        Replaces variables of ${var:default} with System.getProperty(var, default). If no variables are found, returns the same string, otherwise a copy of the string with variables substituted
        Parameters:
        val -
        Returns:
        A string with vars replaced, or the same string if no vars found
      • substituteVariableOld

        public static java.lang.String substituteVariableOld​(java.lang.String val,
                                                             java.util.Properties p)
        Replaces variables of ${var:default} with Properties then uses System.getProperty(var, default) if the value was not found. If no variables are found, returns the same string, otherwise a copy of the string with variables substituted
        Parameters:
        val -
        p -
        Returns:
        A string with vars replaced, or the same string if no vars found
      • substituteVariable

        public static java.lang.String substituteVariable​(java.lang.String input,
                                                          java.util.Properties p)
        Replaces variables in a string.
        Parameters:
        input - The input string
        p - A Properties hashmap, may be null
        Returns:
        The string with replaced variables, might be the same string as the input string if no substitution took place.
      • nextChar

        protected static char nextChar​(java.lang.String s,
                                       int index)
      • getProperty

        public static java.lang.String getProperty​(java.lang.String s,
                                                   java.util.Properties p)
      • getProperty

        public static java.lang.String getProperty​(java.lang.String s)
      • methodNameToAttributeName

        public static java.lang.String methodNameToAttributeName​(java.lang.String methodName)
        Converts a method name to an attribute name, e.g. getFooBar() --> foo_bar, isFlag --> flag
      • methodNameToJavaAttributeName

        public static java.lang.String methodNameToJavaAttributeName​(java.lang.String methodName)
        Converts a method name to a Java attribute name, e.g. getFooBar() --> fooBar, isFlag --> flag.
        Parameters:
        methodName -
        Returns:
      • attributeNameToMethodName

        public static java.lang.String attributeNameToMethodName​(java.lang.String attr_name)
      • getSites

        public static java.util.Map<java.lang.String,​java.util.List<Address>> getSites​(View bridge_view,
                                                                                             java.lang.String excluding_site)
      • otherSites

        public static java.util.Collection<java.lang.String> otherSites​(View bridge_view,
                                                                        java.lang.String excluding_site)
        Returns the sites of the view (all addresses are SiteUUIDs) minus the given site, Example: bridge_view=A:net1,B:net1,X:net2,Y:net2, excluding_site=net1 -> ["net2"]
        Parameters:
        bridge_view -
        excluding_site -
        Returns:
        the sites of members who are _not_ in excluding_site; each site is returned onlt once
      • utcNow

        public static java.lang.String utcNow()
      • utcEpoch

        public static java.lang.String utcEpoch​(long milliseconds)