Class Util

java.lang.Object
org.jgroups.util.Util

public class Util extends Object
Collection of various utility routines that can not be assigned to other classes.
Author:
Bela Ban
  • Field Details

    • MAX_PORT

      public static final int MAX_PORT
      See Also:
    • 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
  • Constructor Details

    • Util

      public Util()
  • Method Details

    • getGlobalThreadGroup

      public static ThreadGroup getGlobalThreadGroup()
    • assertTrue

      public static void assertTrue(boolean condition)
    • assertTrue

      public static void assertTrue(String message, boolean condition)
    • assertFalse

      public static void assertFalse(boolean condition)
    • assertFalse

      public static void assertFalse(String message, boolean condition)
    • assertEquals

      public static void assertEquals(String message, Object val1, Object val2)
    • assertEquals

      public static void assertEquals(Object val1, Object val2)
    • assertNotNull

      public static void assertNotNull(String message, Object val)
    • assertNotNull

      public static void assertNotNull(Object val)
    • assertNull

      public static void assertNull(String message, Object val)
    • blockUntilViewsReceived

      public static void blockUntilViewsReceived(long timeout, long interval, Channel... channels) throws 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:
      TimeoutException
    • addFlush

      public static void addFlush(Channel ch, FLUSH flush)
    • setScope

      public static void setScope(Message msg, short scope)
    • getScope

      public static short getScope(Message msg)
    • getScopeHeader

      public static SCOPE.ScopeHeader getScopeHeader(Message msg)
    • connect

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

      public static void close(InputStream inp)
    • close

      public static void close(OutputStream out)
    • close

      public static void close(Socket s)
    • close

      public static void close(ServerSocket s)
    • close

      public static void close(DatagramSocket my_sock)
    • close

      public static void close(Channel ch)
    • close

      public static void close(Channel... channels)
    • close

      public static void close(Connection conn)
    • shutdown

      public static void shutdown(Channel ch) throws 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:
      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)
    • objectFromByteBuffer

      public static Object objectFromByteBuffer(byte[] buffer) throws Exception
      Creates an object from a byte buffer
      Throws:
      Exception
    • objectFromByteBuffer

      public static Object objectFromByteBuffer(byte[] buffer, int offset, int length) throws Exception
      Throws:
      Exception
    • objectToByteBuffer

      public static byte[] objectToByteBuffer(Object obj) throws Exception
      Serializes/Streams an object into a byte buffer. The object has to implement interface Serializable or Externalizable or Streamable.
      Throws:
      Exception
    • objectToStream

      public static void objectToStream(Object obj, DataOutputStream out) throws Exception
      Throws:
      Exception
    • objectFromStream

      public static Object objectFromStream(DataInputStream in) throws Exception
      Throws:
      Exception
    • streamableFromByteBuffer

      public static Streamable streamableFromByteBuffer(Class cl, byte[] buffer) throws Exception
      Throws:
      Exception
    • streamableFromByteBuffer

      public static Streamable streamableFromByteBuffer(Class cl, byte[] buffer, int offset, int length) throws Exception
      Throws:
      Exception
    • streamableToByteBuffer

      public static byte[] streamableToByteBuffer(Streamable obj) throws Exception
      Throws:
      Exception
    • collectionToByteBuffer

      public static byte[] collectionToByteBuffer(Collection<Address> c) throws Exception
      Throws:
      Exception
    • writeAuthToken

      public static void writeAuthToken(AuthToken token, DataOutputStream out) throws IOException
      Throws:
      IOException
    • readAuthToken

      Throws:
      IOException
      IllegalAccessException
      InstantiationException
    • writeView

      public static void writeView(View view, DataOutputStream out) throws IOException
      Throws:
      IOException
    • readView

      Throws:
      IOException
      InstantiationException
      IllegalAccessException
    • writeAddress

      public static void writeAddress(Address addr, DataOutputStream out) throws IOException
      Throws:
      IOException
    • readAddress

      Throws:
      IOException
      IllegalAccessException
      InstantiationException
    • size

      public static int size(Address addr)
    • size

      public static int size(View view)
    • writeAddresses

      public static void writeAddresses(Collection<? extends Address> v, DataOutputStream out) throws IOException
      Writes a Vector of Addresses. Can contain 65K addresses at most
      Parameters:
      v - A Collection
      out -
      Throws:
      IOException
    • readAddresses

      public static Collection<? extends Address> readAddresses(DataInputStream in, Class cl) throws IOException, IllegalAccessException, InstantiationException
      Parameters:
      in -
      cl - The type of Collection, e.g. Vector.class
      Returns:
      Collection of Address objects
      Throws:
      IOException
      IllegalAccessException
      InstantiationException
    • size

      public static long size(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
    • writeStreamable

      public static void writeStreamable(Streamable obj, DataOutputStream out) throws IOException
      Throws:
      IOException
    • readStreamable

      public static Streamable readStreamable(Class clazz, DataInputStream in) throws IOException, IllegalAccessException, InstantiationException
      Throws:
      IOException
      IllegalAccessException
      InstantiationException
    • writeGenericStreamable

      public static void writeGenericStreamable(Streamable obj, DataOutputStream out) throws IOException
      Throws:
      IOException
    • readGenericStreamable

      public static Streamable readGenericStreamable(DataInputStream in) throws IOException
      Throws:
      IOException
    • writeClass

      public static void writeClass(Class<?> classObject, DataOutputStream out) throws IOException
      Throws:
      IOException
    • readClass

      public static Class<?> readClass(DataInputStream in) throws IOException, ClassNotFoundException
      Throws:
      IOException
      ClassNotFoundException
    • writeObject

      public static void writeObject(Object obj, DataOutputStream out) throws Exception
      Throws:
      Exception
    • readObject

      public static Object readObject(DataInputStream in) throws Exception
      Throws:
      Exception
    • writeString

      public static void writeString(String s, DataOutputStream out) throws IOException
      Throws:
      IOException
    • readString

      public static String readString(DataInputStream in) throws IOException
      Throws:
      IOException
    • writeAsciiString

      public static void writeAsciiString(String str, DataOutputStream out) throws IOException
      Throws:
      IOException
    • readAsciiString

      public static String readAsciiString(DataInputStream in) throws IOException
      Throws:
      IOException
    • parseString

      public static String parseString(DataInputStream in)
    • parseString

      public static String parseString(DataInputStream in, boolean break_on_newline)
    • readStringFromStdin

      public static String readStringFromStdin(String message) throws Exception
      Throws:
      Exception
    • readLongFromStdin

      public static long readLongFromStdin(String message) throws Exception
      Throws:
      Exception
    • readDoubleFromStdin

      public static double readDoubleFromStdin(String message) throws Exception
      Throws:
      Exception
    • readIntFromStdin

      public static int readIntFromStdin(String message) throws Exception
      Throws:
      Exception
    • writeByteBuffer

      public static void writeByteBuffer(byte[] buf, DataOutputStream out) throws IOException
      Throws:
      IOException
    • writeByteBuffer

      public static void writeByteBuffer(byte[] buf, int offset, int length, DataOutputStream out) throws IOException
      Throws:
      IOException
    • readByteBuffer

      public static byte[] readByteBuffer(DataInputStream in) throws IOException
      Throws:
      IOException
    • messageToByteBuffer

      public static Buffer messageToByteBuffer(Message msg) throws IOException
      Throws:
      IOException
    • byteBufferToMessage

      public static Message byteBufferToMessage(byte[] buffer, int offset, int length) throws Exception
      Throws:
      Exception
    • msgListToByteBuffer

      public static Buffer msgListToByteBuffer(List<Message> xmit_list) throws IOException
      Marshalls a list of messages.
      Parameters:
      xmit_list - LinkedList
      Returns:
      Buffer
      Throws:
      IOException
    • byteBufferToMessageList

      public static List<Message> byteBufferToMessageList(byte[] buffer, int offset, int length) throws Exception
      Throws:
      Exception
    • match

      public static boolean match(Object obj1, Object obj2)
    • sameViewId

      public static boolean sameViewId(ViewId one, ViewId two)
    • match

      public static boolean match(long[] a1, long[] a2)
    • 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)
    • sleep

      public static void sleep(long msecs, boolean busy_sleep)
      On most UNIX systems, the minimum sleep time is 10-20ms. Even if we specify sleep(1), the thread will sleep for at least 10-20ms. On Windows, sleep() seems to be implemented as a busy sleep, that is the thread never relinquishes control and therefore the sleep(x) is exactly x ms long.
    • keyPress

      public static int keyPress(String msg)
    • random

      public static long random(long range)
      Returns a random value in the range [1 - range]
    • sleepRandom

      public static void sleepRandom(long timeout)
      Sleeps between 1 and timeout milliseconds, chosen randomly. Timeout must be > 1
    • 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%.
    • getHostname

      public static String getHostname()
    • dumpStack

      public static void dumpStack(boolean exit)
    • dumpThreads

      public static String dumpThreads()
    • interruptAndWaitToDie

      public static boolean interruptAndWaitToDie(Thread t)
    • interruptAndWaitToDie

      public static boolean interruptAndWaitToDie(Thread t, long timeout)
    • dumpQueue

      public static String dumpQueue(Queue q)
      Debugging method used to dump the content of a protocol queue in a condensed form. Useful to follow the evolution of the queue's content in time.
    • printStackTrace

      public static String printStackTrace(Throwable t)
      Use with caution: lots of overhead
    • getStackTrace

      public static String getStackTrace(Throwable t)
    • print

      public static String print(Throwable t)
    • crash

      public static void crash()
    • printEvent

      public static String printEvent(Event evt)
    • printMessage

      public static String printMessage(Message msg)
      Tries to read an object from the message's buffer and prints it
    • mapToString

      public static String mapToString(Map<? extends Object,? extends Object> map)
    • printMethodCall

      public static String printMethodCall(Message msg)
      Tries to read a MethodCall object from the message's buffer and prints it. Returns empty string if object is not a method call
    • printThreads

      public static void printThreads()
    • activeThreads

      public static String activeThreads()
    • printBytes

      public static String printBytes(long bytes)
      MByte nowadays doesn't mean 1024 * 1024 bytes, but 1 million bytes, see http://en.wikipedia.org/wiki/Megabyte
      Parameters:
      bytes -
      Returns:
    • printTime

      public static String printTime(long time, TimeUnit unit)
    • format

      public static String format(double value)
    • readBytesLong

      public static long readBytesLong(String input)
    • readBytesInteger

      public static int readBytesInteger(String input)
    • readBytesDouble

      public static double readBytesDouble(String input)
    • printBytes

      public static String printBytes(double bytes)
    • split

      public static List<String> split(String input, int separator)
    • components

      public static String[] components(String path, 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[]).
    • fragmentBuffer

      public static byte[][] fragmentBuffer(byte[] buf, int frag_size)
    • computeFragOffsets

      public static 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 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
    • printFragments

      public static void printFragments(byte[][] frags)
    • printListWithDelimiter

      public static <T> String printListWithDelimiter(Collection<T> list, String delimiter)
    • printMapWithDelimiter

      public static <T> String printMapWithDelimiter(Map<T,T> map, String delimiter)
    • array2String

      public static String array2String(long[] array)
    • array2String

      public static String array2String(short[] array)
    • array2String

      public static String array2String(int[] array)
    • array2String

      public static String array2String(boolean[] array)
    • array2String

      public static String array2String(Object[] array)
    • all

      public static boolean all(Collection c, Object obj)
      Returns true if all elements of c match obj
    • leftMembers

      public static List<Address> leftMembers(View one, View two)
      Returns a list of members which left from view one to two
      Parameters:
      one -
      two -
      Returns:
    • leftMembers

      public static List<Address> leftMembers(Collection<Address> old_list, Collection<Address> new_list)
    • newMembers

      public static List<Address> newMembers(List<Address> old_list, List<Address> new_list)
    • pickSubset

      public static Vector<Address> pickSubset(Vector<Address> members, double subset_percentage)
      Selects a random subset of members according to subset_percentage and returns them. Picks no member twice from the same membership. If the percentage is smaller than 1 -> picks 1 member.
    • containsViewId

      public static boolean containsViewId(Collection<View> views, ViewId vid)
    • determineMergeParticipants

      public static Collection<Address> determineMergeParticipants(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 Collection<Address> determineMergeCoords(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:
    • getRank

      public static int getRank(View view, Address addr)
    • pickRandomElement

      public static Object pickRandomElement(List list)
    • pickRandomElement

      public static Object pickRandomElement(Object[] array)
    • pickNext

      public static <T> T pickNext(List<T> list, T obj)
      Returns the object next to element in list
      Type Parameters:
      T -
      Parameters:
      list -
      obj -
      Returns:
    • pickNext

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

      public static View createView(Address coord, long id, Address... members)
    • createRandomAddress

      public static Address createRandomAddress()
    • createRandomAddress

      public static Address createRandomAddress(String name)
    • createTimer

      public static Object[][] createTimer()
    • determineLeftMembers

      public static Vector<Address> determineLeftMembers(List<Address> old_mbrs, 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.
    • determineNewMembers

      public static List<Address> determineNewMembers(List<Address> old_mbrs, List<Address> new_mbrs)
      Returns the members which joined between 2 subsequent views
      Parameters:
      old_mbrs -
      new_mbrs -
      Returns:
    • printViews

      public static String printViews(Collection<View> views)
    • print

      public static <T> String print(Collection<T> objs)
    • print

      public static <T> String print(Map<T,T> map)
    • printPingData

      public static String printPingData(List<PingData> rsps)
    • doubleWrite

      public static void doubleWrite(byte[] buf, OutputStream out) throws Exception
      Makes sure that we detect when a peer connection is in the closed state (not closed while we send data, but before we send data). Two writes ensure that, if the peer closed the connection, the first write will send the peer from FIN to RST state, and the second will cause a signal (IOException).
      Throws:
      Exception
    • doubleWrite

      public static void doubleWrite(byte[] buf, int offset, int length, OutputStream out) throws Exception
      Makes sure that we detect when a peer connection is in the closed state (not closed while we send data, but before we send data). Two writes ensure that, if the peer closed the connection, the first write will send the peer from FIN to RST state, and the second will cause a signal (IOException).
      Throws:
      Exception
    • writeFully

      public static void writeFully(ByteBuffer buf, WritableByteChannel out) throws IOException
      if we were to register for OP_WRITE and send the remaining data on readyOps for this channel we have to either block the caller thread or queue the message buffers that may arrive while waiting for OP_WRITE. Instead of the above approach this method will continuously write to the channel until the buffer sent fully.
      Throws:
      IOException
    • sizeOf

      public static long sizeOf(String classname)
    • sizeOf

      public static long sizeOf(Object inst)
    • sizeOf

      public static int sizeOf(Streamable inst)
    • loadClass

      public static Class loadClass(String classname, Class clazz) throws 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:
      ClassNotFoundException
    • getAllDeclaredFields

      public static Field[] getAllDeclaredFields(Class clazz)
    • getAllDeclaredFieldsWithAnnotations

      public static Field[] getAllDeclaredFieldsWithAnnotations(Class clazz, Class<? extends Annotation>... annotations)
    • getAllDeclaredMethods

      public static Method[] getAllDeclaredMethods(Class clazz)
    • getAllDeclaredMethodsWithAnnotations

      public static Method[] getAllDeclaredMethodsWithAnnotations(Class clazz, Class<? extends Annotation>... annotations)
    • getField

      public static Field getField(Class clazz, String field_name)
    • getResourceAsStream

      public static InputStream getResourceAsStream(String name, Class clazz)
    • sameHost

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

      public static boolean fileExists(String fname)
    • parseCommaDelimitedLongs

      public static long[] parseCommaDelimitedLongs(String s)
      Parses comma-delimited longs; e.g., 2000,4000,8000. Returns array of long, or null.
    • parseCommaDelimitedStrings

      public static List<String> parseCommaDelimitedStrings(String l)
      e.g. "bela,jeannette,michelle" --> List{"bela", "jeannette", "michelle"}
    • parseCommaDelimitedHosts

      public static List<IpAddress> parseCommaDelimitedHosts(String hosts, int port_range) throws UnknownHostException
      Input is "daddy[8880],sindhu[8880],camille[5555]. Returns a list of IpAddresses
      Throws:
      UnknownHostException
    • parseCommaDelimitedHosts2

      public static List<InetSocketAddress> parseCommaDelimitedHosts2(String hosts, int port_range) throws UnknownHostException
      Input is "daddy[8880],sindhu[8880],camille[5555]. Return List of InetSocketAddress
      Throws:
      UnknownHostException
    • parseStringList

      public static List<String> parseStringList(String l, String separator)
    • parseString

      public static String parseString(ByteBuffer buf)
    • parseString

      public static String parseString(ByteBuffer buf, boolean discard_whitespace)
    • readNewLine

      public static int readNewLine(ByteBuffer buf)
    • discardUntilNewLine

      public static int discardUntilNewLine(InputStream in)
      Reads and discards all characters from the input stream until a \r\n or EOF is encountered
      Parameters:
      in -
      Returns:
    • readLine

      public static String readLine(InputStream in) throws 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:
      IOException - If an I/O error occurs
    • writeString

      public static void writeString(ByteBuffer buf, String s)
    • parseInterfaceList

      public static List<NetworkInterface> parseInterfaceList(String s) throws Exception
      Parameters:
      s -
      Returns:
      List
      Throws:
      Exception
    • print

      public static String print(List<NetworkInterface> interfaces)
    • shortName

      public static String shortName(String hostname)
    • startFlush

      public static boolean startFlush(Channel c, List<Address> flushParticipants, int numberOfAttempts, long randomSleepTimeoutFloor, long randomSleepTimeoutCeiling)
    • startFlush

      public static boolean startFlush(Channel c, List<Address> flushParticipants)
    • startFlush

      public static boolean startFlush(Channel c, int numberOfAttempts, long randomSleepTimeoutFloor, long randomSleepTimeoutCeiling)
    • startFlush

      public static boolean startFlush(Channel c)
    • shortName

      public static String shortName(InetAddress hostname)
    • generateLocalName

      public static String generateLocalName()
    • incrCounter

      public static short incrCounter()
    • createConcurrentMap

      public static <K, V> ConcurrentMap<K,V> createConcurrentMap(int initial_capacity, float load_factor, int concurrency_level)
    • createConcurrentMap

      public static <K, V> ConcurrentMap<K,V> createConcurrentMap(int initial_capacity)
    • createConcurrentMap

      public static <K, V> ConcurrentMap<K,V> createConcurrentMap()
    • createHashMap

      public static <K, V> Map<K,V> createHashMap()
    • createServerSocket

      public static ServerSocket createServerSocket(SocketFactory factory, String service_name, int start_port)
      Finds first available port starting at start_port and returns server socket
    • createServerSocket

      public static ServerSocket createServerSocket(SocketFactory factory, String service_name, InetAddress bind_addr, int start_port)
    • createServerSocket

      public static ServerSocket createServerSocket(SocketFactory factory, String service_name, InetAddress bind_addr, int start_port, int end_port) throws Exception
      Finds first available port starting at start_port and returns server socket. Will not bind to port >end_port. Sets srv_port
      Throws:
      Exception
    • createDatagramSocket

      public static DatagramSocket createDatagramSocket(SocketFactory factory, String service_name, InetAddress addr, int port) throws 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:
      Exception
    • createMulticastSocket

      public static MulticastSocket createMulticastSocket(SocketFactory factory, String service_name, InetAddress mcast_addr, int port, Log log) throws IOException
      Throws:
      IOException
    • getBindAddress

      public static InetAddress getBindAddress(Properties props) throws UnknownHostException, SocketException
      Returns the address of the interface to use defined by bind_addr and bind_interface
      Parameters:
      props -
      Returns:
      Throws:
      UnknownHostException
      SocketException
    • validateBindAddressFromInterface

      public static InetAddress validateBindAddressFromInterface(InetAddress bind_addr, String bind_interface_str) throws UnknownHostException, SocketException
      Method used by PropertyConverters.BindInterface to check that a bind_address 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. the bind_interface did not influence the decision).
      Throws:
      UnknownHostException
      SocketException
    • checkForFreeBSD

      public static boolean checkForFreeBSD()
    • checkForLinux

      public static boolean checkForLinux()
    • checkForHp

      public static boolean checkForHp()
    • checkForSolaris

      public static boolean checkForSolaris()
    • checkForWindows

      public static boolean checkForWindows()
    • checkForMac

      public static boolean checkForMac()
    • prompt

      public static void prompt(String s)
    • unmodifiableVector

      public static <T> Vector<T> unmodifiableVector(Vector<? extends T> v)
    • getLocalhost

      public static InetAddress getLocalhost(StackType ip_version) throws UnknownHostException
      IP related utilities
      Throws:
      UnknownHostException
    • getNonLoopbackAddress

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

      public static InetAddress getAddress(Util.AddressScope scope) throws SocketException
      Returns the first address on any interface of the current host, which satisfies scope
      Throws:
      SocketException
    • getAddress

      public static InetAddress getAddress(NetworkInterface intf, Util.AddressScope scope) throws SocketException
      Returns the first address on the given interface on the current host, which satisfies scope
      Parameters:
      intf - the interface to be checked
      Throws:
      SocketException
    • interfaceHasIPAddresses

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

      public static StackType getIpStackType()
    • isStackAvailable

      public static boolean isStackAvailable(boolean ipv4)
    • getAllAvailableInterfaces

      public static List<NetworkInterface> getAllAvailableInterfaces() throws SocketException
      Throws:
      SocketException
    • getAllAvailableAddresses

      public static Collection<InetAddress> getAllAvailableAddresses()
    • checkIfValidAddress

      public static void checkIfValidAddress(InetAddress bind_addr, String prot_name) throws Exception
      Throws:
      Exception
    • getProperty

      public static String getProperty(String[] system_props, Properties props, String prop_name, boolean ignore_sysprops, 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
      ignore_sysprops - If true, system properties are not used and the values will only be retrieved from props (not system_props)
      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
    • isBindAddressPropertyIgnored

      public static boolean isBindAddressPropertyIgnored()
    • isCoordinator

      public static boolean isCoordinator(JChannel ch)
    • isCoordinator

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

      public static MBeanServer getMBeanServer()
    • registerChannel

      public static void registerChannel(JChannel channel, String name)
    • generateList

      public static String generateList(Collection c, String separator)
    • replaceProperties

      public static String replaceProperties(String string, Properties props)
      Go through the input string and replace any occurance of ${p} with the props.getProperty(p) value. If there is no such property p defined, then the ${p} reference will remain unchanged. If the property reference is of the form ${p:v} and there is no such property p, then the default value v will be returned. If the property reference is of the form ${p1,p2} or ${p1,p2:v} then the primary and the secondary properties will be tried in turn, before returning either the unchanged input, or the default value. The property ${/} is replaced with System.getProperty("file.separator") value and the property ${:} is replaced with System.getProperty("path.separator").
      Parameters:
      string - - the string with possible ${} references
      props - - the source for ${x} property ref values, null means use System.getProperty()
      Returns:
      the input string with all property references replaced if any. If there are no valid references the input string will be returned.
    • substituteVariable

      public static String substituteVariable(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
    • getProperty

      public static String getProperty(String s)
    • md5

      public static String md5(String source)
      Converts a java.lang.String in to a MD5 hashed String
      Parameters:
      source - the source String
      Returns:
      the MD5 hashed version of the string
    • sha

      public static String sha(String source)
      Converts a java.lang.String in to a SHA hashed String
      Parameters:
      source - the source String
      Returns:
      the MD5 hashed version of the string
    • methodNameToAttributeName

      public static String methodNameToAttributeName(String methodName)
    • attributeNameToMethodName

      public static String attributeNameToMethodName(String attr_name)
    • runAsync

      public static void runAsync(Runnable task, ThreadFactory factory, ThreadGroup group, String thread_name)
      Runs a task on a separate thread
      Parameters:
      task -
      factory -
      group -
      thread_name -