|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jgroups.util.Util
Collection of various utility routines that can not be assigned to other classes.
Field Summary | |
static java.lang.String |
DIAG_GROUP
|
static int |
MAX_PORT
|
Constructor Summary | |
Util()
|
Method Summary | |
static java.lang.String |
activeThreads()
|
static java.lang.String |
array2String(boolean[] array)
|
static java.lang.String |
array2String(int[] array)
|
static java.lang.String |
array2String(long[] array)
|
static java.util.LinkedList |
byteBufferToMessageList(byte[] buffer,
int offset,
int length)
|
static boolean |
checkForLinux()
|
static boolean |
checkForSolaris()
|
static boolean |
checkForWindows()
|
static void |
closeInputStream(java.io.InputStream inp)
|
static void |
closeOutputStream(java.io.OutputStream out)
|
static byte[] |
collectionToByteBuffer(java.util.Collection c)
|
static java.util.List |
computeFragOffsets(byte[] buf,
int frag_size)
|
static java.util.List |
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 |
crash()
|
static java.net.DatagramSocket |
createDatagramSocket(java.net.InetAddress addr,
int port)
Creates a DatagramSocket bound to addr. |
static java.net.ServerSocket |
createServerSocket(java.net.InetAddress bind_addr,
int start_port)
|
static java.net.ServerSocket |
createServerSocket(int start_port)
Finds first available port starting at start_port and returns server socket |
static byte[] |
defragmentBuffer(byte[][] fragments)
Concatenates smaller fragments into entire buffers. |
static java.util.Vector |
determineLeftMembers(java.util.Vector old_mbrs,
java.util.Vector new_mbrs)
Returns all members that left between 2 views. |
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 boolean |
fileExists(java.lang.String fname)
|
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.util.List |
getAllAvailableInterfaces()
|
static java.net.InetAddress |
getFirstNonLoopbackAddress()
|
static java.lang.String |
getHostname()
|
static int |
getJavaVersion()
|
static java.io.InputStream |
getResourceAsStream(java.lang.String name,
java.lang.Class clazz)
|
static java.lang.String |
getStackTrace(java.lang.Throwable t)
|
static boolean |
isBindAddressPropertyIgnored()
|
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 void |
main(java.lang.String[] args)
|
static boolean |
match(long[] a1,
long[] a2)
|
static boolean |
match(java.lang.Object obj1,
java.lang.Object obj2)
|
static java.lang.String |
memStats(boolean gc)
|
static Buffer |
msgListToByteBuffer(java.util.LinkedList xmit_list)
Marshalls a list of messages. |
static java.lang.Object |
objectFromByteBuffer(byte[] buffer)
Creates an object from a byte buffer |
static byte[] |
objectToByteBuffer(java.lang.Object obj)
Serializes an object into a byte buffer. |
static long[] |
parseCommaDelimitedLongs(java.lang.String s)
Parses comma-delimited longs; e.g., 2000,4000,8000. |
static java.util.List |
parseCommaDelimitedStrings(java.lang.String l)
e.g. |
static java.lang.Object |
pickRandomElement(java.util.Vector list)
|
static java.util.Vector |
pickSubset(java.util.Vector members,
double subset_percentage)
Selects a random subset of members according to subset_percentage and returns them. |
static java.lang.String |
print(java.lang.Throwable t)
|
static java.lang.String |
printBytes(long bytes)
|
static java.lang.String |
printEvent(Event evt)
|
static void |
printFragments(byte[][] frags)
|
static java.lang.String |
printMembers(java.util.Vector v)
|
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 |
printStackTrace(java.lang.Throwable t)
Use with caution: lots of overhead |
static void |
printThreads()
|
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 |
readAddresses(java.io.DataInputStream in,
java.lang.Class cl)
|
static byte[] |
readByteBuffer(java.io.DataInputStream in)
|
static Streamable |
readGenericStreamable(java.io.DataInputStream in)
|
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 boolean |
sameHost(Address one,
Address two)
Checks whether 2 Addresses are on the same host |
static java.lang.String |
shortName(java.net.InetAddress hostname)
|
static java.lang.String |
shortName(java.lang.String hostname)
|
static int |
size(Address addr)
|
static long |
size(java.util.Collection addrs)
Returns the marshalled size of a Collection of Addresses. |
static long |
sizeOf(java.lang.Object inst)
|
static long |
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 |
sleepRandom(long timeout)
Sleeps between 1 and timeout milliseconds, chosen randomly. |
static Streamable |
streamableFromByteBuffer(java.lang.Class cl,
byte[] buffer)
|
static byte[] |
streamableToByteBuffer(Streamable obj)
|
static boolean |
tossWeightedCoin(double probability)
Tosses a coin weighted with probability and returns true or false. |
static void |
writeAddress(Address addr,
java.io.DataOutputStream out)
|
static void |
writeAddresses(java.util.Collection v,
java.io.DataOutputStream out)
Writes a Vector of Addresses. |
static void |
writeByteBuffer(byte[] buf,
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.lang.String s,
java.io.DataOutputStream out)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int MAX_PORT
public static final java.lang.String DIAG_GROUP
Constructor Detail |
public Util()
Method Detail |
public static void closeInputStream(java.io.InputStream inp)
public static void closeOutputStream(java.io.OutputStream out)
public static java.lang.Object objectFromByteBuffer(byte[] buffer) throws java.lang.Exception
java.lang.Exception
public static byte[] objectToByteBuffer(java.lang.Object obj) throws java.lang.Exception
java.lang.Exception
public static Streamable streamableFromByteBuffer(java.lang.Class cl, byte[] buffer) throws java.lang.Exception
java.lang.Exception
public static byte[] streamableToByteBuffer(Streamable obj) throws java.lang.Exception
java.lang.Exception
public static byte[] collectionToByteBuffer(java.util.Collection c) throws java.lang.Exception
java.lang.Exception
public static int size(Address addr)
public static void writeAddress(Address addr, java.io.DataOutputStream out) throws java.io.IOException
java.io.IOException
public static Address readAddress(java.io.DataInputStream in) throws java.io.IOException, java.lang.IllegalAccessException, java.lang.InstantiationException
java.io.IOException
java.lang.IllegalAccessException
java.lang.InstantiationException
public static void writeAddresses(java.util.Collection v, java.io.DataOutputStream out) throws java.io.IOException
v
- A Collectionout
-
java.io.IOException
public static java.util.Collection readAddresses(java.io.DataInputStream in, java.lang.Class cl) throws java.io.IOException, java.lang.IllegalAccessException, java.lang.InstantiationException
in
- cl
- The type of Collection, e.g. Vector.class
java.io.IOException
java.lang.IllegalAccessException
java.lang.InstantiationException
public static long size(java.util.Collection addrs)
addrs
- Collection
public static void writeStreamable(Streamable obj, java.io.DataOutputStream out) throws java.io.IOException
java.io.IOException
public static Streamable readStreamable(java.lang.Class clazz, java.io.DataInputStream in) throws java.io.IOException, java.lang.IllegalAccessException, java.lang.InstantiationException
java.io.IOException
java.lang.IllegalAccessException
java.lang.InstantiationException
public static void writeGenericStreamable(Streamable obj, java.io.DataOutputStream out) throws java.io.IOException
java.io.IOException
public static Streamable readGenericStreamable(java.io.DataInputStream in) throws java.io.IOException
java.io.IOException
public static void writeObject(java.lang.Object obj, java.io.DataOutputStream out) throws java.lang.Exception
java.lang.Exception
public static java.lang.Object readObject(java.io.DataInputStream in) throws java.lang.Exception
java.lang.Exception
public static void writeString(java.lang.String s, java.io.DataOutputStream out) throws java.io.IOException
java.io.IOException
public static java.lang.String readString(java.io.DataInputStream in) throws java.io.IOException
java.io.IOException
public static void writeByteBuffer(byte[] buf, java.io.DataOutputStream out) throws java.io.IOException
java.io.IOException
public static byte[] readByteBuffer(java.io.DataInputStream in) throws java.io.IOException
java.io.IOException
public static Buffer msgListToByteBuffer(java.util.LinkedList xmit_list) throws java.io.IOException
xmit_list
- LinkedListjava.io.IOException
public static java.util.LinkedList byteBufferToMessageList(byte[] buffer, int offset, int length) throws java.lang.Exception
java.lang.Exception
public static boolean match(java.lang.Object obj1, java.lang.Object obj2)
public static boolean match(long[] a1, long[] a2)
public static void sleep(long timeout)
public static void sleep(long msecs, boolean busy_sleep)
public static long random(long range)
public static void sleepRandom(long timeout)
public static boolean tossWeightedCoin(double probability)
public static java.lang.String getHostname()
public static void dumpStack(boolean exit)
public static java.lang.String dumpQueue(Queue q)
public static java.lang.String printStackTrace(java.lang.Throwable t)
public static java.lang.String getStackTrace(java.lang.Throwable t)
public static java.lang.String print(java.lang.Throwable t)
public static void crash()
public static java.lang.String printEvent(Event evt)
public static java.lang.String printMessage(Message msg)
public static java.lang.String printMethodCall(Message msg)
MethodCall
object from the message's buffer and prints it.
Returns empty string if object is not a method call
public static void printThreads()
public static java.lang.String activeThreads()
public static java.lang.String printBytes(long bytes)
public static byte[][] fragmentBuffer(byte[] buf, int frag_size, int length)
byte[]
).public static byte[][] fragmentBuffer(byte[] buf, int frag_size)
public static java.util.List computeFragOffsets(int offset, int length, int frag_size)
frag_size
-
public static java.util.List computeFragOffsets(byte[] buf, int frag_size)
public static byte[] defragmentBuffer(byte[][] fragments)
fragments
- An array of byte buffers (byte[]
)
public static void printFragments(byte[][] frags)
public static java.lang.String array2String(long[] array)
public static java.lang.String array2String(int[] array)
public static java.lang.String array2String(boolean[] array)
public static java.util.Vector pickSubset(java.util.Vector members, double subset_percentage)
public static java.lang.Object pickRandomElement(java.util.Vector list)
public static java.util.Vector determineLeftMembers(java.util.Vector old_mbrs, java.util.Vector new_mbrs)
public static java.lang.String printMembers(java.util.Vector v)
public static void doubleWrite(byte[] buf, java.io.OutputStream out) throws java.lang.Exception
java.lang.Exception
public static void doubleWrite(byte[] buf, int offset, int length, java.io.OutputStream out) throws java.lang.Exception
java.lang.Exception
public static void writeFully(java.nio.ByteBuffer buf, java.nio.channels.WritableByteChannel out) throws java.io.IOException
java.io.IOException
public static long sizeOf(java.lang.String classname)
public static long sizeOf(java.lang.Object inst)
public static long sizeOf(Streamable inst)
public static java.lang.Class loadClass(java.lang.String classname, java.lang.Class clazz) throws java.lang.ClassNotFoundException
classname
- Desired class.clazz
- Class object used to obtain a class loader
if no context class loader is available.
java.lang.ClassNotFoundException
public static java.io.InputStream getResourceAsStream(java.lang.String name, java.lang.Class clazz)
public static boolean sameHost(Address one, Address two)
public static boolean fileExists(java.lang.String fname)
public static long[] parseCommaDelimitedLongs(java.lang.String s)
public static java.util.List parseCommaDelimitedStrings(java.lang.String l)
public static java.lang.String shortName(java.lang.String hostname)
public static java.lang.String shortName(java.net.InetAddress hostname)
public static java.net.ServerSocket createServerSocket(int start_port)
public static java.net.ServerSocket createServerSocket(java.net.InetAddress bind_addr, int start_port)
public static java.net.DatagramSocket createDatagramSocket(java.net.InetAddress addr, int port) throws java.lang.Exception
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.
java.lang.Exception
public static boolean checkForLinux()
public static boolean checkForSolaris()
public static boolean checkForWindows()
public static void prompt(java.lang.String s)
public static int getJavaVersion()
public static java.lang.String memStats(boolean gc)
public static java.net.InetAddress getFirstNonLoopbackAddress() throws java.net.SocketException
java.net.SocketException
public static java.util.List getAllAvailableInterfaces() throws java.net.SocketException
java.net.SocketException
public static boolean isBindAddressPropertyIgnored()
public static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |