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_LIST_PRINT_SIZE
          The max size of an address list, e.g.
static int MAX_PORT
           
protected static java.util.ResourceBundle resource_bundle
           
 
Constructor Summary
Util()
           
 
Method Summary
protected static void _printThreads(java.lang.management.ThreadMXBean bean, long[] ids, java.lang.StringBuilder sb)
           
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 java.lang.String bold(java.lang.String msg)
           
static Message byteBufferToMessage(byte[] buffer, int offset, int length)
           
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
<T> boolean
contains(T key, T[] list)
           
static boolean containsViewId(java.util.Collection<View> views, ViewId vid)
           
static void crash()
           
static byte[] createAuthenticationDigest(java.lang.String passcode, long t1, double q1)
           
static JChannel createChannel(Protocol... prots)
           
static
<K,V> java.util.concurrent.ConcurrentMap<K,V>
createConcurrentMap()
           
static
<K,V> java.util.concurrent.ConcurrentMap<K,V>
createConcurrentMap(int initial_capacity)
           
static
<K,V> java.util.concurrent.ConcurrentMap<K,V>
createConcurrentMap(int initial_capacity, float load_factor, int concurrency_level)
           
static java.net.DatagramSocket createDatagramSocket(SocketFactory factory, java.lang.String service_name, java.net.InetAddress addr, int port)
          Creates a DatagramSocket bound to addr.
static byte[] createDigest(java.lang.String passcode, long t1, double q1)
           
static
<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.lang.Object[][] createTimer()
           
static View createView(Address coord, long id, Address... members)
           
static long decode(byte[] buf)
           
static byte[] decodeLength(byte len)
           
static long[] decodeLongSequence(byte[] buf)
           
static byte[] defragmentBuffer(byte[][] fragments)
          Concatenates smaller fragments into entire buffers.
static java.util.List<View> detectDifferentViews(java.util.Map<Address,View> map)
           
static java.util.Collection<Address> determineActualMergeCoords(java.util.Map<Address,View> map)
          Similar to determineMergeCoords(java.util.Map) but only actual coordinators are counted: an actual coord is when the sender of a view is the first member of that view
static java.util.List<Address> determineLeftMembers(java.util.List<Address> old_mbrs, java.util.List<Address> new_mbrs)
          Returns all members that left between 2 views.
static java.util.Collection<Address> determineMergeCoords(java.util.Map<Address,View> map)
          This is the same or a subset of determineMergeParticipants(java.util.Map) and contains only members which are currently sub-partition coordinators.
static java.util.Collection<Address> determineMergeParticipants(java.util.Map<Address,View> map)
          Determines the members which take part in a merge.
static
<T> boolean
different(T one, T two)
           
static int discardUntilNewLine(java.io.InputStream in)
          Reads and discards all characters from the input stream until a \r\n or EOF is encountered
static java.lang.String dumpQueue(Queue q)
          Debugging method used to dump the content of a protocol queue in a condensed form.
static java.lang.String dumpThreads()
           
static byte[] encode(long num)
           
static byte encodeLength(byte len1, byte len2)
          Encodes the number of bytes needed into a single byte.
static byte[] encodeLongSequence(long highest_delivered, long highest_received)
          Encode the highest delivered and received seqnos.
static boolean fileExists(java.lang.String fname)
           
static java.util.List<java.lang.Class<?>> findClassesAnnotatedWith(java.lang.String packageName, java.lang.Class<? extends java.lang.annotation.Annotation> a)
           
static
<T> java.util.Set<java.lang.Class<T>>
findClassesAssignableFrom(java.lang.String packageName, java.lang.Class<T> assignableFrom)
           
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
protected static byte getByteAt(long num, int index)
           
static Address getCoordinator(View view)
           
static java.lang.reflect.Field getField(java.lang.Class clazz, java.lang.String field_name)
           
static java.lang.Object getField(java.lang.reflect.Field field, java.lang.Object target)
           
static StackType getIpStackType()
           
static java.net.InetAddress getLocalhost(StackType ip_version)
          IP related utilities
static javax.management.MBeanServer getMBeanServer()
           
static java.lang.String getMessage(java.lang.String key)
           
static java.lang.String getMessage(java.lang.String key, java.lang.Object... args)
           
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(java.util.Collection<Address> members, Address addr)
           
static int getRank(View view, Address addr)
          Returns the rank of a member in a given view
static java.io.InputStream getResourceAsStream(java.lang.String name, java.lang.Class clazz)
           
static short getScope(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
<T> boolean
match(T obj1, T 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
<T> java.util.List<T>
newElements(java.util.List<T> old_list, java.util.List<T> new_list)
           
static java.util.List<Address> newMembers(java.util.List<Address> old_list, java.util.List<Address> new_list)
           
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.DataInput 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.DataOutput 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 int[] parseCommaDelimitedInts(java.lang.String s)
          Parses comma-delimited longs; e.g., 2000,4000,8000.
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.util.concurrent.RejectedExecutionHandler parseRejectionPolicy(java.lang.String rejection_policy)
           
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.DataInput in)
           
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.List<Address> pickSubset(java.util.List<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
printListWithDelimiter(java.util.Collection<T> list, java.lang.String delimiter, int limit)
           
static
<T> java.lang.String
printMapWithDelimiter(java.util.Map<T,T> map, java.lang.String delimiter)
           
static java.lang.String printMessage(Message msg)
          Tries to read an 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.DataInput in)
           
static java.util.Collection<? extends Address> readAddresses(java.io.DataInput in, java.lang.Class cl)
           
static AuthToken readAuthToken(java.io.DataInput in)
           
static byte[] readByteBuffer(java.io.DataInput 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.DataInput in)
           
static java.lang.String readContents(java.io.InputStream input)
           
static double readDoubleFromStdin(java.lang.String message)
           
static java.lang.String readFile(java.lang.String filename)
           
static byte[] readFileContents(java.io.InputStream input)
           
static byte[] readFileContents(java.lang.String filename)
           
static Streamable readGenericStreamable(java.io.DataInput in)
           
static int readIntFromStdin(java.lang.String message)
           
static java.lang.String readLine(java.io.InputStream in)
          Reads a line of text.
static long readLong(java.io.DataInput in)
           
static long readLongFromStdin(java.lang.String message)
           
static long[] readLongSequence(java.io.DataInput in)
           
static int readNewLine(java.nio.ByteBuffer buf)
           
static java.lang.Object readObject(java.io.DataInput in)
           
static Streamable readStreamable(java.lang.Class clazz, java.io.DataInput in)
           
static java.lang.String readString(java.io.DataInput in)
           
static java.lang.String readStringFromStdin(java.lang.String message)
           
static View readView(java.io.DataInput in)
           
static ViewId readViewId(java.io.DataInput 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.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 void setField(java.lang.reflect.Field field, java.lang.Object target, java.lang.Object value)
           
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 int size(byte[] buf)
           
static long size(java.util.Collection<? extends Address> addrs)
          Returns the marshalled size of a Collection of Addresses.
static byte size(long number)
           
static byte size(long hd, long hr)
          Writes 2 longs, where the second long needs to be >= the first (we only write the delta !)
static int size(java.lang.String s)
           
static int size(View view)
           
static int size(ViewId vid)
           
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 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<? extends Streamable> cl, byte[] buffer)
           
static Streamable streamableFromByteBuffer(java.lang.Class<? extends Streamable> 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 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 verifyRejectionPolicy(java.lang.String str)
           
static void waitUntilAllChannelsHaveSameSize(long timeout, long interval, Channel... channels)
          Blocks until all channels have the same view
static void writeAddress(Address addr, java.io.DataOutput out)
           
static void writeAddresses(java.util.Collection<? extends Address> v, java.io.DataOutput out)
          Writes a Vector of Addresses.
static void writeAuthToken(AuthToken token, java.io.DataOutput out)
           
static void writeByteBuffer(byte[] buf, java.io.DataOutput out)
           
static void writeByteBuffer(byte[] buf, int offset, int length, java.io.DataOutput out)
           
static void writeClass(java.lang.Class<?> classObject, java.io.DataOutput 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.DataOutput out)
           
static void writeLong(long num, java.io.DataOutput out)
           
static void writeLongSequence(long highest_delivered, long highest_received, java.io.DataOutput out)
           
static void writeObject(java.lang.Object obj, java.io.DataOutput out)
           
static void writeStreamable(Streamable obj, java.io.DataOutput out)
           
static void writeString(java.nio.ByteBuffer buf, java.lang.String s)
           
static void writeString(java.lang.String s, java.io.DataOutput out)
           
static void writeView(View view, java.io.DataOutput out)
           
static void writeViewId(ViewId vid, java.io.DataOutput out)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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

MAX_LIST_PRINT_SIZE

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


resource_bundle

protected static java.util.ResourceBundle resource_bundle
Constructor Detail

Util

public Util()
Method Detail

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)

bold

public static java.lang.String bold(java.lang.String msg)

getMessage

public static java.lang.String getMessage(java.lang.String key)

getMessage

public static java.lang.String getMessage(java.lang.String key,
                                          java.lang.Object... args)

waitUntilAllChannelsHaveSameSize

public static void waitUntilAllChannelsHaveSameSize(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)

createAuthenticationDigest

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

createDigest

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

connect

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

Parameters:
sock -
dest -
sock_conn_timeout -
Throws:
java.io.IOException

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.DataOutput out)
                           throws java.lang.Exception
Throws:
java.lang.Exception

objectFromStream

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

streamableFromByteBuffer

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

streamableFromByteBuffer

public static Streamable streamableFromByteBuffer(java.lang.Class<? extends Streamable> 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.DataOutput out)
                           throws java.lang.Exception
Throws:
java.lang.Exception

readAuthToken

public static AuthToken readAuthToken(java.io.DataInput in)
                               throws java.lang.Exception
Throws:
java.lang.Exception

writeView

public static void writeView(View view,
                             java.io.DataOutput out)
                      throws java.lang.Exception
Throws:
java.lang.Exception

readView

public static View readView(java.io.DataInput in)
                     throws java.lang.Exception
Throws:
java.lang.Exception

writeViewId

public static void writeViewId(ViewId vid,
                               java.io.DataOutput out)
                        throws java.lang.Exception
Throws:
java.lang.Exception

readViewId

public static ViewId readViewId(java.io.DataInput in)
                         throws java.lang.Exception
Throws:
java.lang.Exception

writeAddress

public static void writeAddress(Address addr,
                                java.io.DataOutput out)
                         throws java.lang.Exception
Throws:
java.lang.Exception

readAddress

public static Address readAddress(java.io.DataInput in)
                           throws java.lang.Exception
Throws:
java.lang.Exception

size

public static int size(Address addr)

size

public static int size(View view)

size

public static int size(ViewId vid)

size

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

size

public static int size(byte[] buf)

writeAddresses

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

Parameters:
v - A Collection
out -
Throws:
java.lang.Exception

readAddresses

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

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.DataOutput out)
                            throws java.lang.Exception
Throws:
java.lang.Exception

readStreamable

public static Streamable readStreamable(java.lang.Class clazz,
                                        java.io.DataInput in)
                                 throws java.lang.Exception
Throws:
java.lang.Exception

writeGenericStreamable

public static void writeGenericStreamable(Streamable obj,
                                          java.io.DataOutput out)
                                   throws java.lang.Exception
Throws:
java.lang.Exception

readGenericStreamable

public static Streamable readGenericStreamable(java.io.DataInput in)
                                        throws java.lang.Exception
Throws:
java.lang.Exception

writeClass

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

readClass

public static java.lang.Class<?> readClass(java.io.DataInput in)
                                    throws java.lang.Exception
Throws:
java.lang.Exception

writeObject

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

readObject

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

writeString

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

readString

public static java.lang.String readString(java.io.DataInput in)
                                   throws java.lang.Exception
Throws:
java.lang.Exception

readFile

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

readContents

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

readFileContents

public static byte[] readFileContents(java.lang.String filename)
                               throws java.io.IOException
Throws:
java.io.IOException

readFileContents

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

parseString

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

readStringFromStdin

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

readLongFromStdin

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

readDoubleFromStdin

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

readIntFromStdin

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

writeByteBuffer

public static void writeByteBuffer(byte[] buf,
                                   java.io.DataOutput out)
                            throws java.lang.Exception
Throws:
java.lang.Exception

writeByteBuffer

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

readByteBuffer

public static byte[] readByteBuffer(java.io.DataInput in)
                             throws java.lang.Exception
Throws:
java.lang.Exception

messageToByteBuffer

public static Buffer messageToByteBuffer(Message msg)
                                  throws java.lang.Exception
Throws:
java.lang.Exception

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.lang.Exception
Marshalls a list of messages.

Parameters:
xmit_list - LinkedList
Returns:
Buffer
Throws:
java.lang.Exception

match

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

match

public static boolean match(long[] a1,
                            long[] a2)

different

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

sleep

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


sleep

public static void sleep(long timeout,
                         int nanos)

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 floor,
                               long ceiling)
Sleeps between floor and ceiling milliseconds, chosen randomly


tossWeightedCoin

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


dumpThreads

public static java.lang.String dumpThreads()

_printThreads

protected static void _printThreads(java.lang.management.ThreadMXBean bean,
                                    long[] ids,
                                    java.lang.StringBuilder sb)

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)

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)

encode

public static byte[] encode(long num)

getByteAt

protected static byte getByteAt(long num,
                                int index)

decode

public static long decode(byte[] buf)

writeLong

public static void writeLong(long num,
                             java.io.DataOutput out)
                      throws java.lang.Exception
Throws:
java.lang.Exception

readLong

public static long readLong(java.io.DataInput in)
                     throws java.lang.Exception
Throws:
java.lang.Exception

encodeLongSequence

public static byte[] encodeLongSequence(long highest_delivered,
                                        long highest_received)
Encode the highest delivered and received seqnos. The assumption is that the latter is always >= the former, and highest received is not much higher than highest delivered.

Parameters:
highest_delivered -
highest_received -
Returns:

size

public static byte size(long number)

size

public static byte size(long hd,
                        long hr)
Writes 2 longs, where the second long needs to be >= the first (we only write the delta !)

Parameters:
hd -
hr -
Returns:

decodeLongSequence

public static long[] decodeLongSequence(byte[] buf)

writeLongSequence

public static void writeLongSequence(long highest_delivered,
                                     long highest_received,
                                     java.io.DataOutput out)
                              throws java.lang.Exception
Throws:
java.lang.Exception

readLongSequence

public static long[] readLongSequence(java.io.DataInput in)
                               throws java.lang.Exception
Throws:
java.lang.Exception

encodeLength

public static byte encodeLength(byte len1,
                                byte len2)
Encodes the number of bytes needed into a single byte. The first number is encoded in the first nibble (the first 4 bits), the second number in the second nibble

Parameters:
len1 - The number of bytes needed to store a long. Must be between 0 and 8
len2 - The number of bytes needed to store a long. Must be between 0 and 8
Returns:
The byte storing the 2 numbers len1 and len2

decodeLength

public static byte[] decodeLength(byte len)

printListWithDelimiter

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

printListWithDelimiter

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

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)

newElements

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

pickSubset

public static java.util.List<Address> pickSubset(java.util.List<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.


contains

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

containsViewId

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

detectDifferentViews

public static java.util.List<View> detectDifferentViews(java.util.Map<Address,View> map)

determineMergeParticipants

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

Parameters:
map -
Returns:

determineMergeCoords

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

Parameters:
map -
Returns:

determineActualMergeCoords

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

Parameters:
map -
Returns:

getRank

public static int getRank(View view,
                          Address addr)
Returns the rank of a member in a given view

Parameters:
view - The view
addr - The address of a member
Returns:
A value between 1 and view.size(). The first member has rank 1, the second 2 and so on. If the member is not found, 0 is returned

getRank

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

pickRandomElement

public static 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)

createChannel

public static JChannel createChannel(Protocol... prots)
                              throws java.lang.Exception
Throws:
java.lang.Exception

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.List<Address> determineLeftMembers(java.util.List<Address> old_mbrs,
                                                           java.util.List<Address> new_mbrs)
Returns all members that left between 2 views. All members that are element of old_mbrs but not element of new_mbrs are returned.


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)

writeFully

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

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)

setField

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

getField

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

findClassesAssignableFrom

public static <T> java.util.Set<java.lang.Class<T>> findClassesAssignableFrom(java.lang.String packageName,
                                                                              java.lang.Class<T> assignableFrom)
                                                                   throws java.io.IOException,
                                                                          java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

findClassesAnnotatedWith

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

getResourceAsStream

public static java.io.InputStream getResourceAsStream(java.lang.String name,
                                                      java.lang.Class clazz)

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)

verifyRejectionPolicy

public static void verifyRejectionPolicy(java.lang.String str)
                                  throws java.lang.Exception
Throws:
java.lang.Exception

parseRejectionPolicy

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

parseCommaDelimitedInts

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


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)
Input is "daddy[8880],sindhu[8880],camille[5555]. Return List of InetSocketAddress


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,
                                                       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

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)

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)
Returns the first address on the given interface on the current host, which satisfies scope

Parameters:
intf - the interface to be checked

interfaceHasIPAddresses

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

Parameters:
intf -
Returns:
Throws:
java.net.UnknownHostException

getIpStackType

public static StackType getIpStackType()

isStackAvailable

public static boolean isStackAvailable(boolean ipv4)

getAllAvailableInterfaces

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

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)

getCoordinator

public static Address getCoordinator(View view)

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.String thread_name)
Runs a task on a separate thread

Parameters:
task -
factory -
group -
thread_name -


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