org.jgroups.util
Class Util

java.lang.Object
  extended by org.jgroups.util.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
static class Util.AddressScope
           
 
Field Summary
protected static int CCHM_CONCURRENCY_LEVEL
           
protected static int CCHM_INITIAL_CAPACITY
           
protected static float CCHM_LOAD_FACTOR
           
static int MAX_PORT
           
 
Constructor Summary
Util()
           
 
Method Summary
static java.lang.String activeThreads()
           
static void addFlush(Channel ch, FLUSH flush)
           
static boolean all(java.util.Collection c, java.lang.Object obj)
          Returns true if all elements of c match obj
static java.lang.String array2String(boolean[] array)
           
static java.lang.String array2String(int[] array)
           
static java.lang.String array2String(long[] array)
           
static java.lang.String array2String(java.lang.Object[] array)
           
static java.lang.String array2String(short[] array)
           
static void assertEquals(java.lang.Object val1, java.lang.Object val2)
           
static void assertEquals(java.lang.String message, java.lang.Object val1, java.lang.Object val2)
           
static void assertFalse(boolean condition)
           
static void assertFalse(java.lang.String message, boolean condition)
           
static void assertNotNull(java.lang.Object val)
           
static void assertNotNull(java.lang.String message, java.lang.Object val)
           
static void assertNull(java.lang.String message, java.lang.Object val)
           
static void assertTrue(boolean condition)
           
static void assertTrue(java.lang.String message, boolean condition)
           
static java.lang.String attributeNameToMethodName(java.lang.String attr_name)
           
static void blockUntilViewsReceived(long timeout, long interval, Channel... channels)
          Blocks until all channels have the same view
static Message byteBufferToMessage(byte[] buffer, int offset, int length)
           
static java.util.List<Message> byteBufferToMessageList(byte[] buffer, int offset, int length)
           
static boolean checkForFreeBSD()
           
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 byte clearFlags(byte bits, byte flag)
           
static void close(Channel... channels)
           
static void close(Channel ch)
           
static void close(Connection conn)
           
static void close(java.net.DatagramSocket my_sock)
           
static void close(java.io.InputStream inp)
           
static void close(java.io.OutputStream out)
           
static void close(java.net.ServerSocket s)
           
static void close(java.net.Socket s)
           
static byte[] collectionToByteBuffer(java.util.Collection<Address> c)
           
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 containsViewId(java.util.Collection<View> views, ViewId vid)
           
static void crash()
           
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
<K,V> java.util.Map<K,V>
createHashMap()
           
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 java.net.ServerSocket createServerSocket(SocketFactory factory, java.lang.String service_name, java.net.InetAddress bind_addr, int start_port)
           
static java.net.ServerSocket createServerSocket(SocketFactory factory, java.lang.String service_name, java.net.InetAddress bind_addr, int start_port, int end_port)
          Finds first available port starting at start_port and returns server socket.
static java.net.ServerSocket createServerSocket(SocketFactory factory, java.lang.String service_name, int start_port)
          Finds first available port starting at start_port and returns server socket
static java.lang.Object[][] createTimer()
           
static View createView(Address coord, long id, Address... members)
           
static byte[] defragmentBuffer(byte[][] fragments)
          Concatenates smaller fragments into entire buffers.
static java.util.Vector<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 java.util.List<Address> determineNewMembers(java.util.List<Address> old_mbrs, java.util.List<Address> new_mbrs)
          Returns the members which joined between 2 subsequent views
static int discardUntilNewLine(java.io.InputStream in)
          Reads and discards all characters from the input stream until a \r\n or EOF is encountered
static void doubleWrite(byte[] buf, int offset, int length, java.io.OutputStream out)
          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).
static void doubleWrite(byte[] buf, java.io.OutputStream out)
          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).
static java.lang.String dumpQueue(Queue q)
          Debugging method used to dump the content of a protocol queue in a condensed form.
static void dumpStack(boolean exit)
           
static java.lang.String dumpThreads()
           
static boolean fileExists(java.lang.String fname)
           
static java.lang.String format(double value)
           
static byte[][] fragmentBuffer(byte[] buf, int frag_size)
           
static byte[][] fragmentBuffer(byte[] buf, int frag_size, int length)
          Fragments a byte buffer into smaller fragments of (max.) frag_size.
static java.lang.String generateList(java.util.Collection c, java.lang.String separator)
           
static java.lang.String generateLocalName()
           
static java.net.InetAddress getAddress(java.net.NetworkInterface intf, Util.AddressScope scope)
          Returns the first address on the given interface on the current host, which satisfies scope
static java.net.InetAddress getAddress(Util.AddressScope scope)
          Returns the first address on any interface of the current host, which satisfies scope
static java.util.Collection<java.net.InetAddress> getAllAvailableAddresses()
           
static java.util.List<java.net.NetworkInterface> getAllAvailableInterfaces()
           
static java.lang.reflect.Field[] getAllDeclaredFields(java.lang.Class clazz)
           
static java.lang.reflect.Field[] getAllDeclaredFieldsWithAnnotations(java.lang.Class clazz, java.lang.Class<? extends java.lang.annotation.Annotation>... annotations)
           
static java.lang.reflect.Method[] getAllDeclaredMethods(java.lang.Class clazz)
           
static java.lang.reflect.Method[] getAllDeclaredMethodsWithAnnotations(java.lang.Class clazz, java.lang.Class<? extends java.lang.annotation.Annotation>... annotations)
           
static java.net.InetAddress getBindAddress(java.util.Properties props)
          Returns the address of the interface to use defined by bind_addr and bind_interface
static java.lang.reflect.Field getField(java.lang.Class clazz, java.lang.String field_name)
           
static java.lang.ThreadGroup getGlobalThreadGroup()
           
static java.lang.String getHostname()
           
static StackType getIpStackType()
           
static java.net.InetAddress getLocalhost(StackType ip_version)
          IP related utilities
static javax.management.MBeanServer getMBeanServer()
           
static java.net.InetAddress getNonLoopbackAddress()
          Returns the first non-loopback address on any interface on the current host.
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, boolean ignore_sysprops, java.lang.String default_value)
          Returns a value associated wither with one or more system properties, or found in the props map
static int getRank(View view, Address addr)
           
static java.io.InputStream getResourceAsStream(java.lang.String name, java.lang.Class clazz)
           
static short getScope(Message msg)
           
static SCOPE.ScopeHeader getScopeHeader(Message msg)
           
static java.lang.String getStackTrace(java.lang.Throwable t)
           
static short incrCounter()
           
static boolean interfaceHasIPAddresses(java.net.NetworkInterface intf, StackType ip_version)
          A function to check if an interface supports an IP version (i.e has addresses defined for that IP version).
static boolean interruptAndWaitToDie(java.lang.Thread t)
           
static boolean interruptAndWaitToDie(java.lang.Thread t, long timeout)
           
static boolean isBindAddressPropertyIgnored()
           
static boolean isCoordinator(JChannel ch)
           
static boolean isCoordinator(View view, Address local_addr)
           
static boolean isFlagSet(byte bits, byte flag)
           
static boolean isStackAvailable(boolean ipv4)
           
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.util.List<Address> leftMembers(View one, View two)
          Returns a list of members which left from view one to two
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.String mapToString(java.util.Map<? extends java.lang.Object,? extends java.lang.Object> map)
           
static boolean match(long[] a1, long[] a2)
           
static boolean match(java.lang.Object obj1, java.lang.Object obj2)
           
static java.lang.String md5(java.lang.String source)
          Converts a java.lang.String in to a MD5 hashed String
static Buffer messageToByteBuffer(Message msg)
           
static java.lang.String methodNameToAttributeName(java.lang.String methodName)
           
static Buffer msgListToByteBuffer(java.util.List<Message> xmit_list)
          Marshalls a list of messages.
static java.util.List<Address> newMembers(java.util.List<Address> old_list, java.util.List<Address> new_list)
           
static java.lang.Object objectFromByteBuffer(byte[] buffer)
          Creates an object from a byte buffer
static java.lang.Object objectFromByteBuffer(byte[] buffer, int offset, int length)
           
static java.lang.Object objectFromStream(java.io.DataInputStream in)
           
static byte[] objectToByteBuffer(java.lang.Object obj)
          Serializes/Streams an object into a byte buffer.
static void objectToStream(java.lang.Object obj, java.io.DataOutputStream out)
           
static java.util.List<IpAddress> 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 long[] parseCommaDelimitedLongs(java.lang.String s)
          Parses comma-delimited longs; e.g., 2000,4000,8000.
static java.util.List<java.lang.String> parseCommaDelimitedStrings(java.lang.String l)
          e.g.
static java.util.List<java.net.NetworkInterface> parseInterfaceList(java.lang.String s)
           
static java.lang.String parseString(java.nio.ByteBuffer buf)
           
static java.lang.String parseString(java.nio.ByteBuffer buf, boolean discard_whitespace)
           
static java.lang.String parseString(java.io.DataInputStream in)
           
static java.lang.String parseString(java.io.DataInputStream in, boolean break_on_newline)
           
static java.util.List<java.lang.String> parseStringList(java.lang.String l, java.lang.String separator)
           
static
<T> T
pickNext(java.util.List<T> list, T obj)
          Returns the object next to element in list
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 java.lang.Object pickRandomElement(java.util.List list)
           
static java.lang.Object pickRandomElement(java.lang.Object[] array)
           
static java.util.Vector<Address> pickSubset(java.util.Vector<Address> members, double subset_percentage)
          Selects a random subset of members according to subset_percentage and returns them.
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(java.lang.Throwable t)
           
static java.lang.String printBytes(double bytes)
           
static java.lang.String printBytes(long bytes)
          MByte nowadays doesn't mean 1024 * 1024 bytes, but 1 million bytes, see http://en.wikipedia.org/wiki/Megabyte
static java.lang.String printEvent(Event evt)
           
static void printFragments(byte[][] frags)
           
static
<T> java.lang.String
printListWithDelimiter(java.util.Collection<T> list, java.lang.String delimiter)
           
static
<T> java.lang.String
printMapWithDelimiter(java.util.Map<T,T> map, java.lang.String delimiter)
           
static java.lang.String printMessage(Message msg)
          Tries to read an object from the message's buffer and prints it
static java.lang.String printMethodCall(Message msg)
          Tries to read a MethodCall object from the message's buffer and prints it.
static java.lang.String printPingData(java.util.List<PingData> rsps)
           
static java.lang.String printStackTrace(java.lang.Throwable t)
          Use with caution: lots of overhead
static void printThreads()
           
static java.lang.String printTime(long time, java.util.concurrent.TimeUnit unit)
           
static java.lang.String printViews(java.util.Collection<View> views)
           
static void prompt(java.lang.String s)
           
static long random(long range)
          Returns a random value in the range [1 - range]
static Address readAddress(java.io.DataInputStream in)
           
static java.util.Collection<? extends Address> readAddresses(java.io.DataInputStream in, java.lang.Class cl)
           
static java.lang.String readAsciiString(java.io.DataInputStream in)
           
static AuthToken readAuthToken(java.io.DataInputStream in)
           
static byte[] readByteBuffer(java.io.DataInputStream in)
           
static double readBytesDouble(java.lang.String input)
           
static int readBytesInteger(java.lang.String input)
           
static long readBytesLong(java.lang.String input)
           
static java.lang.Class<?> readClass(java.io.DataInputStream in)
           
static double readDoubleFromStdin(java.lang.String message)
           
static Streamable readGenericStreamable(java.io.DataInputStream in)
           
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 int readNewLine(java.nio.ByteBuffer buf)
           
static java.lang.Object readObject(java.io.DataInputStream in)
           
static Streamable readStreamable(java.lang.Class clazz, java.io.DataInputStream in)
           
static java.lang.String readString(java.io.DataInputStream in)
           
static java.lang.String readStringFromStdin(java.lang.String message)
           
static View readView(java.io.DataInputStream in)
           
static void registerChannel(JChannel channel, java.lang.String name)
           
static java.lang.String replaceProperties(java.lang.String string, java.util.Properties props)
          Go through the input string and replace any occurance of ${p} with the props.getProperty(p) value.
static void runAsync(java.lang.Runnable task, ThreadFactory factory, java.lang.ThreadGroup group, java.lang.String thread_name)
          Runs a task on a separate thread
static boolean sameHost(Address one, Address two)
          Checks whether 2 Addresses are on the same host
static boolean sameViewId(ViewId one, ViewId two)
           
static byte setFlag(byte bits, byte flag)
           
static void setScope(Message msg, short scope)
           
static java.lang.String sha(java.lang.String source)
          Converts a java.lang.String in to a SHA hashed String
static java.lang.String shortName(java.net.InetAddress hostname)
           
static java.lang.String shortName(java.lang.String hostname)
           
static void shutdown(Channel ch)
          Drops messages to/from other members and then closes the channel.
static int size(Address addr)
           
static long size(java.util.Collection<? extends Address> addrs)
          Returns the marshalled size of a Collection of Addresses.
static int size(View view)
           
static long sizeOf(java.lang.Object inst)
           
static int sizeOf(Streamable inst)
           
static long sizeOf(java.lang.String classname)
           
static void sleep(long timeout)
          Sleep for timeout msecs.
static void sleep(long msecs, boolean busy_sleep)
          On most UNIX systems, the minimum sleep time is 10-20ms.
static void sleep(long timeout, int nanos)
           
static void sleepRandom(long timeout)
          Sleeps between 1 and timeout milliseconds, chosen randomly.
static void sleepRandom(long floor, long ceiling)
          Sleeps between floor and ceiling milliseconds, chosen randomly
static java.util.List<java.lang.String> split(java.lang.String input, int separator)
           
static boolean startFlush(Channel c)
           
static boolean startFlush(Channel c, int numberOfAttempts, long randomSleepTimeoutFloor, long randomSleepTimeoutCeiling)
           
static boolean startFlush(Channel c, java.util.List<Address> flushParticipants)
           
static boolean startFlush(Channel c, java.util.List<Address> flushParticipants, int numberOfAttempts, long randomSleepTimeoutFloor, long randomSleepTimeoutCeiling)
           
static Streamable streamableFromByteBuffer(java.lang.Class cl, byte[] buffer)
           
static Streamable streamableFromByteBuffer(java.lang.Class cl, byte[] buffer, int offset, int length)
           
static byte[] streamableToByteBuffer(Streamable obj)
           
static java.lang.String substituteVariable(java.lang.String val)
          Replaces variables of ${var:default} with System.getProperty(var, default).
static boolean tossWeightedCoin(double probability)
          Tosses a coin weighted with probability and returns true or false.
static
<T> java.util.Vector<T>
unmodifiableVector(java.util.Vector<? extends T> v)
           
static java.net.InetAddress validateBindAddressFromInterface(java.net.InetAddress bind_addr, java.lang.String bind_interface_str)
          Method used by PropertyConverters.BindInterface to check that a bind_address is consistent with a specified interface Idea: 1.
static void writeAddress(Address addr, java.io.DataOutputStream out)
           
static void writeAddresses(java.util.Collection<? extends Address> v, java.io.DataOutputStream out)
          Writes a Vector of Addresses.
static void writeAsciiString(java.lang.String str, java.io.DataOutputStream out)
           
static void writeAuthToken(AuthToken token, java.io.DataOutputStream out)
           
static void writeByteBuffer(byte[] buf, java.io.DataOutputStream out)
           
static void writeByteBuffer(byte[] buf, int offset, int length, java.io.DataOutputStream out)
           
static void writeClass(java.lang.Class<?> classObject, java.io.DataOutputStream out)
           
static void writeFully(java.nio.ByteBuffer buf, java.nio.channels.WritableByteChannel out)
          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.
static void writeGenericStreamable(Streamable obj, java.io.DataOutputStream out)
           
static void writeObject(java.lang.Object obj, java.io.DataOutputStream out)
           
static void writeStreamable(Streamable obj, java.io.DataOutputStream out)
           
static void writeString(java.nio.ByteBuffer buf, java.lang.String s)
           
static void writeString(java.lang.String s, java.io.DataOutputStream out)
           
static void writeView(View view, java.io.DataOutputStream out)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_PORT

public static final int MAX_PORT
See Also:
Constant Field Values

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 Detail

Util

public Util()
Method Detail

getGlobalThreadGroup

public static java.lang.ThreadGroup getGlobalThreadGroup()

assertTrue

public static void assertTrue(boolean condition)

assertTrue

public static void assertTrue(java.lang.String message,
                              boolean condition)

assertFalse

public static void assertFalse(boolean condition)

assertFalse

public static void assertFalse(java.lang.String message,
                               boolean condition)

assertEquals

public static void assertEquals(java.lang.String message,
                                java.lang.Object val1,
                                java.lang.Object val2)

assertEquals

public static void assertEquals(java.lang.Object val1,
                                java.lang.Object val2)

assertNotNull

public static void assertNotNull(java.lang.String message,
                                 java.lang.Object val)

assertNotNull

public static void assertNotNull(java.lang.Object val)

assertNull

public static void assertNull(java.lang.String message,
                              java.lang.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(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

close

public static void close(java.io.InputStream inp)

close

public static void close(java.io.OutputStream out)

close

public static void close(java.net.Socket s)

close

public static void close(java.net.ServerSocket s)

close

public static void close(java.net.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 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)

objectFromByteBuffer

public static java.lang.Object objectFromByteBuffer(byte[] buffer)
                                             throws java.lang.Exception
Creates an object from a byte buffer

Throws:
java.lang.Exception

objectFromByteBuffer

public static java.lang.Object objectFromByteBuffer(byte[] buffer,
                                                    int offset,
                                                    int length)
                                             throws java.lang.Exception
Throws:
java.lang.Exception

objectToByteBuffer

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

Throws:
java.lang.Exception

objectToStream

public static void objectToStream(java.lang.Object obj,
                                  java.io.DataOutputStream out)
                           throws java.lang.Exception
Throws:
java.lang.Exception

objectFromStream

public static java.lang.Object objectFromStream(java.io.DataInputStream in)
                                         throws java.lang.Exception
Throws:
java.lang.Exception

streamableFromByteBuffer

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

streamableFromByteBuffer

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

streamableToByteBuffer

public static byte[] streamableToByteBuffer(Streamable obj)
                                     throws java.lang.Exception
Throws:
java.lang.Exception

collectionToByteBuffer

public static byte[] collectionToByteBuffer(java.util.Collection<Address> c)
                                     throws java.lang.Exception
Throws:
java.lang.Exception

writeAuthToken

public static void writeAuthToken(AuthToken token,
                                  java.io.DataOutputStream out)
                           throws java.io.IOException
Throws:
java.io.IOException

readAuthToken

public static AuthToken readAuthToken(java.io.DataInputStream in)
                               throws java.io.IOException,
                                      java.lang.IllegalAccessException,
                                      java.lang.InstantiationException
Throws:
java.io.IOException
java.lang.IllegalAccessException
java.lang.InstantiationException

writeView

public static void writeView(View view,
                             java.io.DataOutputStream out)
                      throws java.io.IOException
Throws:
java.io.IOException

readView

public static View readView(java.io.DataInputStream in)
                     throws java.io.IOException,
                            java.lang.InstantiationException,
                            java.lang.IllegalAccessException
Throws:
java.io.IOException
java.lang.InstantiationException
java.lang.IllegalAccessException

writeAddress

public static void writeAddress(Address addr,
                                java.io.DataOutputStream out)
                         throws java.io.IOException
Throws:
java.io.IOException

readAddress

public static Address readAddress(java.io.DataInputStream in)
                           throws java.io.IOException,
                                  java.lang.IllegalAccessException,
                                  java.lang.InstantiationException
Throws:
java.io.IOException
java.lang.IllegalAccessException
java.lang.InstantiationException

size

public static int size(Address addr)

size

public static int size(View view)

writeAddresses

public static void writeAddresses(java.util.Collection<? extends Address> v,
                                  java.io.DataOutputStream out)
                           throws java.io.IOException
Writes a Vector of Addresses. Can contain 65K addresses at most

Parameters:
v - A Collection
out -
Throws:
java.io.IOException

readAddresses

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

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

writeStreamable

public static void writeStreamable(Streamable obj,
                                   java.io.DataOutputStream out)
                            throws java.io.IOException
Throws:
java.io.IOException

readStreamable

public static Streamable readStreamable(java.lang.Class clazz,
                                        java.io.DataInputStream in)
                                 throws java.io.IOException,
                                        java.lang.IllegalAccessException,
                                        java.lang.InstantiationException
Throws:
java.io.IOException
java.lang.IllegalAccessException
java.lang.InstantiationException

writeGenericStreamable

public static void writeGenericStreamable(Streamable obj,
                                          java.io.DataOutputStream out)
                                   throws java.io.IOException
Throws:
java.io.IOException

readGenericStreamable

public static Streamable readGenericStreamable(java.io.DataInputStream in)
                                        throws java.io.IOException
Throws:
java.io.IOException

writeClass

public static void writeClass(java.lang.Class<?> classObject,
                              java.io.DataOutputStream out)
                       throws java.io.IOException
Throws:
java.io.IOException

readClass

public static java.lang.Class<?> readClass(java.io.DataInputStream in)
                                    throws java.io.IOException,
                                           java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

writeObject

public static void writeObject(java.lang.Object obj,
                               java.io.DataOutputStream out)
                        throws java.lang.Exception
Throws:
java.lang.Exception

readObject

public static java.lang.Object readObject(java.io.DataInputStream in)
                                   throws java.lang.Exception
Throws:
java.lang.Exception

writeString

public static void writeString(java.lang.String s,
                               java.io.DataOutputStream out)
                        throws java.io.IOException
Throws:
java.io.IOException

readString

public static java.lang.String readString(java.io.DataInputStream in)
                                   throws java.io.IOException
Throws:
java.io.IOException

writeAsciiString

public static void writeAsciiString(java.lang.String str,
                                    java.io.DataOutputStream out)
                             throws java.io.IOException
Throws:
java.io.IOException

readAsciiString

public static java.lang.String readAsciiString(java.io.DataInputStream in)
                                        throws java.io.IOException
Throws:
java.io.IOException

parseString

public static java.lang.String parseString(java.io.DataInputStream in)

parseString

public static java.lang.String parseString(java.io.DataInputStream in,
                                           boolean break_on_newline)

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.DataOutputStream out)
                            throws java.io.IOException
Throws:
java.io.IOException

writeByteBuffer

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

readByteBuffer

public static byte[] readByteBuffer(java.io.DataInputStream in)
                             throws java.io.IOException
Throws:
java.io.IOException

messageToByteBuffer

public static Buffer messageToByteBuffer(Message msg)
                                  throws java.io.IOException
Throws:
java.io.IOException

byteBufferToMessage

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

msgListToByteBuffer

public static Buffer msgListToByteBuffer(java.util.List<Message> xmit_list)
                                  throws java.io.IOException
Marshalls a list of messages.

Parameters:
xmit_list - LinkedList
Returns:
Buffer
Throws:
java.io.IOException

byteBufferToMessageList

public static java.util.List<Message> byteBufferToMessageList(byte[] buffer,
                                                              int offset,
                                                              int length)
                                                       throws java.lang.Exception
Throws:
java.lang.Exception

match

public static boolean match(java.lang.Object obj1,
                            java.lang.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(java.lang.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 java.lang.String getHostname()

dumpStack

public static void dumpStack(boolean exit)

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)

dumpQueue

public static java.lang.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 java.lang.String printStackTrace(java.lang.Throwable t)
Use with caution: lots of overhead


getStackTrace

public static java.lang.String getStackTrace(java.lang.Throwable t)

print

public static java.lang.String print(java.lang.Throwable t)

crash

public static void crash()

printEvent

public static java.lang.String printEvent(Event evt)

printMessage

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


mapToString

public static java.lang.String mapToString(java.util.Map<? extends java.lang.Object,? extends java.lang.Object> map)

printMethodCall

public static java.lang.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 java.lang.String activeThreads()

printBytes

public static java.lang.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 java.lang.String printTime(long time,
                                         java.util.concurrent.TimeUnit unit)

format

public static java.lang.String format(double value)

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)

printBytes

public static java.lang.String printBytes(double bytes)

split

public static java.util.List<java.lang.String> split(java.lang.String input,
                                                     int separator)

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[]).

fragmentBuffer

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

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

printFragments

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

printListWithDelimiter

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

printMapWithDelimiter

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

array2String

public static java.lang.String array2String(long[] array)

array2String

public static java.lang.String array2String(short[] array)

array2String

public static java.lang.String array2String(int[] array)

array2String

public static java.lang.String array2String(boolean[] array)

array2String

public static java.lang.String array2String(java.lang.Object[] array)

all

public static boolean all(java.util.Collection c,
                          java.lang.Object obj)
Returns true if all elements of c match obj


leftMembers

public static java.util.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 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)

pickSubset

public static java.util.Vector<Address> pickSubset(java.util.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(java.util.Collection<View> views,
                                     ViewId vid)

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:

getRank

public static int getRank(View view,
                          Address addr)

pickRandomElement

public static java.lang.Object pickRandomElement(java.util.List list)

pickRandomElement

public static java.lang.Object pickRandomElement(java.lang.Object[] array)

pickNext

public static <T> T pickNext(java.util.List<T> list,
                             T obj)
Returns the object next to element in list

Type Parameters:
T -
Parameters:
list -
obj -
Returns:

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


createView

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

createRandomAddress

public static Address createRandomAddress()

createRandomAddress

public static Address createRandomAddress(java.lang.String name)

createTimer

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

determineLeftMembers

public static java.util.Vector<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.


determineNewMembers

public static java.util.List<Address> determineNewMembers(java.util.List<Address> old_mbrs,
                                                          java.util.List<Address> new_mbrs)
Returns the members which joined between 2 subsequent views

Parameters:
old_mbrs -
new_mbrs -
Returns:

printViews

public static java.lang.String printViews(java.util.Collection<View> views)

print

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

print

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

printPingData

public static java.lang.String printPingData(java.util.List<PingData> rsps)

doubleWrite

public static void doubleWrite(byte[] buf,
                               java.io.OutputStream out)
                        throws java.lang.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:
java.lang.Exception

doubleWrite

public static void doubleWrite(byte[] buf,
                               int offset,
                               int length,
                               java.io.OutputStream out)
                        throws java.lang.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:
java.lang.Exception

writeFully

public static void writeFully(java.nio.ByteBuffer buf,
                              java.nio.channels.WritableByteChannel out)
                       throws java.io.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:
java.io.IOException

sizeOf

public static long sizeOf(java.lang.String classname)

sizeOf

public static long sizeOf(java.lang.Object inst)

sizeOf

public static int sizeOf(Streamable inst)

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

getAllDeclaredFields

public static java.lang.reflect.Field[] getAllDeclaredFields(java.lang.Class clazz)

getAllDeclaredFieldsWithAnnotations

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

getAllDeclaredMethods

public static java.lang.reflect.Method[] getAllDeclaredMethods(java.lang.Class clazz)

getAllDeclaredMethodsWithAnnotations

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

getField

public static java.lang.reflect.Field getField(java.lang.Class clazz,
                                               java.lang.String field_name)

getResourceAsStream

public static java.io.InputStream getResourceAsStream(java.lang.String name,
                                                      java.lang.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(java.lang.String fname)

parseCommaDelimitedLongs

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


parseCommaDelimitedStrings

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


parseCommaDelimitedHosts

public static java.util.List<IpAddress> 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

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]. Return List of InetSocketAddress

Throws:
java.net.UnknownHostException

parseStringList

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

parseString

public static java.lang.String parseString(java.nio.ByteBuffer buf)

parseString

public static java.lang.String parseString(java.nio.ByteBuffer buf,
                                           boolean discard_whitespace)

readNewLine

public static int readNewLine(java.nio.ByteBuffer buf)

discardUntilNewLine

public static int discardUntilNewLine(java.io.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 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

writeString

public static void writeString(java.nio.ByteBuffer buf,
                               java.lang.String s)

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)

startFlush

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

startFlush

public static boolean startFlush(Channel c,
                                 java.util.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 java.lang.String shortName(java.net.InetAddress hostname)

generateLocalName

public static java.lang.String generateLocalName()

incrCounter

public static short incrCounter()

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()

createHashMap

public static <K,V> java.util.Map<K,V> createHashMap()

createServerSocket

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


createServerSocket

public static java.net.ServerSocket createServerSocket(SocketFactory factory,
                                                       java.lang.String service_name,
                                                       java.net.InetAddress bind_addr,
                                                       int start_port)

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)
                                                throws java.lang.Exception
Finds first available port starting at start_port and returns server socket. Will not bind to port >end_port. Sets srv_port

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

getBindAddress

public static java.net.InetAddress getBindAddress(java.util.Properties props)
                                           throws java.net.UnknownHostException,
                                                  java.net.SocketException
Returns the address of the interface to use defined by bind_addr and bind_interface

Parameters:
props -
Returns:
Throws:
java.net.UnknownHostException
java.net.SocketException

validateBindAddressFromInterface

public static java.net.InetAddress validateBindAddressFromInterface(java.net.InetAddress bind_addr,
                                                                    java.lang.String bind_interface_str)
                                                             throws java.net.UnknownHostException,
                                                                    java.net.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:
java.net.UnknownHostException
java.net.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(java.lang.String s)

unmodifiableVector

public static <T> java.util.Vector<T> unmodifiableVector(java.util.Vector<? extends T> v)

getLocalhost

public static java.net.InetAddress getLocalhost(StackType ip_version)
                                         throws java.net.UnknownHostException
IP related utilities

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

getAddress

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

Throws:
java.net.SocketException

getAddress

public static java.net.InetAddress getAddress(java.net.NetworkInterface intf,
                                              Util.AddressScope scope)
                                       throws java.net.SocketException
Returns the first address on the given interface on the current host, which satisfies scope

Parameters:
intf - the interface to be checked
Throws:
java.net.SocketException

interfaceHasIPAddresses

public static boolean interfaceHasIPAddresses(java.net.NetworkInterface intf,
                                              StackType ip_version)
                                       throws java.net.SocketException,
                                              java.net.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:
java.net.SocketException
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

getAllAvailableAddresses

public static java.util.Collection<java.net.InetAddress> getAllAvailableAddresses()

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,
                                           boolean ignore_sysprops,
                                           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
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 javax.management.MBeanServer getMBeanServer()

registerChannel

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

generateList

public static java.lang.String generateList(java.util.Collection c,
                                            java.lang.String separator)

replaceProperties

public static java.lang.String replaceProperties(java.lang.String string,
                                                 java.util.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.
Throws:
{@link - java.security.AccessControlException} when not authorised to retrieved system properties

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

getProperty

public static java.lang.String getProperty(java.lang.String s)

md5

public static java.lang.String md5(java.lang.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 java.lang.String sha(java.lang.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 java.lang.String methodNameToAttributeName(java.lang.String methodName)

attributeNameToMethodName

public static java.lang.String attributeNameToMethodName(java.lang.String attr_name)

runAsync

public static void runAsync(java.lang.Runnable task,
                            ThreadFactory factory,
                            java.lang.ThreadGroup group,
                            java.lang.String thread_name)
Runs a task on a separate thread

Parameters:
task -
factory -
group -
thread_name -


Copyright © 1998-2009 Bela Ban / Red Hat. All Rights Reserved.