public class Util extends Object
Modifier and Type | Class and Description |
---|---|
static class |
Util.AddressScope |
Modifier and Type | Field and Description |
---|---|
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 |
Constructor and Description |
---|
Util() |
Modifier and Type | Method and Description |
---|---|
protected static void |
_printThreads(ThreadMXBean bean,
long[] ids,
StringBuilder sb) |
static String |
activeThreads() |
static void |
addFlush(Channel ch,
FLUSH flush) |
static boolean |
all(Collection c,
Object obj)
Returns true if all elements of c match obj
|
static String |
array2String(boolean[] array) |
static String |
array2String(int[] array) |
static String |
array2String(long[] array) |
static String |
array2String(Object[] array) |
static String |
array2String(short[] array) |
static void |
assertEquals(Object val1,
Object val2) |
static void |
assertEquals(String message,
Object val1,
Object val2) |
static void |
assertFalse(boolean condition) |
static void |
assertFalse(String message,
boolean condition) |
static void |
assertNotNull(Object val) |
static void |
assertNotNull(String message,
Object val) |
static void |
assertNull(String message,
Object val) |
static void |
assertTrue(boolean condition) |
static void |
assertTrue(String message,
boolean condition) |
static String |
attributeNameToMethodName(String attr_name) |
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(InetAddress bind_addr,
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(DatagramSocket my_sock) |
static void |
close(InputStream inp) |
static void |
close(OutputStream out) |
static void |
close(ServerSocket s) |
static void |
close(Socket s) |
static byte[] |
collectionToByteBuffer(Collection<Address> c) |
static String[] |
components(String path,
String separator) |
static List<Range> |
computeFragOffsets(byte[] buf,
int frag_size) |
static List<Range> |
computeFragOffsets(int offset,
int length,
int frag_size)
Given a buffer and a fragmentation size, compute a list of fragmentation offset/length pairs, and
return them in a list.
|
static void |
connect(Socket sock,
SocketAddress dest,
int sock_conn_timeout)
Utility method.
|
static boolean |
containsViewId(Collection<View> views,
ViewId vid) |
static void |
crash() |
static JChannel |
createChannel(Protocol... prots) |
static <K,V> ConcurrentMap<K,V> |
createConcurrentMap() |
static <K,V> ConcurrentMap<K,V> |
createConcurrentMap(int initial_capacity) |
static <K,V> ConcurrentMap<K,V> |
createConcurrentMap(int initial_capacity,
float load_factor,
int concurrency_level) |
static DatagramSocket |
createDatagramSocket(SocketFactory factory,
String service_name,
InetAddress addr,
int port)
Creates a DatagramSocket bound to addr.
|
static <K,V> Map<K,V> |
createHashMap() |
static MulticastSocket |
createMulticastSocket(SocketFactory factory,
String service_name,
InetAddress mcast_addr,
int port,
Log log) |
static Address |
createRandomAddress() |
static Address |
createRandomAddress(String name) |
static ServerSocket |
createServerSocket(SocketFactory factory,
String service_name,
InetAddress bind_addr,
int start_port) |
static ServerSocket |
createServerSocket(SocketFactory factory,
String service_name,
InetAddress bind_addr,
int start_port,
int end_port)
Finds first available port starting at start_port and returns server
socket.
|
static 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 List<Address> |
determineLeftMembers(List<Address> old_mbrs,
List<Address> new_mbrs)
Returns all members that left between 2 views.
|
static Collection<Address> |
determineMergeCoords(Map<Address,View> map)
This is the same or a subset of
determineMergeParticipants(java.util.Map) and contains only members
which are currently sub-partition coordinators. |
static Collection<Address> |
determineMergeParticipants(Map<Address,View> map)
Determines the members which take part in a merge.
|
static int |
discardUntilNewLine(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,
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,
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 String |
dumpQueue(Queue q)
Debugging method used to dump the content of a protocol queue in a
condensed form.
|
static 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(String fname) |
static 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 String |
generateList(Collection c,
String separator) |
static String |
generateLocalName() |
static InetAddress |
getAddress(NetworkInterface intf,
Util.AddressScope scope)
Returns the first address on the given interface on the current host, which satisfies scope
|
static InetAddress |
getAddress(Util.AddressScope scope)
Returns the first address on any interface of the current host, which satisfies scope
|
static Collection<InetAddress> |
getAllAvailableAddresses() |
static List<NetworkInterface> |
getAllAvailableInterfaces() |
static Field[] |
getAllDeclaredFields(Class clazz) |
static Field[] |
getAllDeclaredFieldsWithAnnotations(Class clazz,
Class<? extends Annotation>... annotations) |
static Method[] |
getAllDeclaredMethods(Class clazz) |
static Method[] |
getAllDeclaredMethodsWithAnnotations(Class clazz,
Class<? extends Annotation>... annotations) |
static InetAddress |
getBindAddress(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 Field |
getField(Class clazz,
String field_name) |
static ThreadGroup |
getGlobalThreadGroup() |
static StackType |
getIpStackType() |
static InetAddress |
getLocalhost(StackType ip_version)
IP related utilities
|
static MBeanServer |
getMBeanServer() |
static InetAddress |
getNonLoopbackAddress()
Returns the first non-loopback address on any interface on the current host.
|
static String |
getProperty(String s) |
static String |
getProperty(String[] system_props,
Properties props,
String prop_name,
boolean ignore_sysprops,
String default_value)
Returns a value associated wither with one or more system properties, or found in the props map
|
static int |
getRank(View view,
Address addr)
Returns the rank of a member in a given view
|
static InputStream |
getResourceAsStream(String name,
Class clazz) |
static short |
getScope(Message msg) |
static String |
getStackTrace(Throwable t) |
static short |
incrCounter() |
static boolean |
interfaceHasIPAddresses(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(Thread t) |
static boolean |
interruptAndWaitToDie(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(String msg) |
static List<Address> |
leftMembers(Collection<Address> old_list,
Collection<Address> new_list) |
static List<Address> |
leftMembers(View one,
View two)
Returns a list of members which left from view one to two
|
static Class |
loadClass(String classname,
Class clazz)
Tries to load the class from the current thread's context class loader.
|
static String |
mapToString(Map<? extends Object,? extends Object> map) |
static boolean |
match(long[] a1,
long[] a2) |
static boolean |
match(Object obj1,
Object obj2) |
static String |
md5(String source)
Converts a java.lang.String in to a MD5 hashed String
|
static Buffer |
messageToByteBuffer(Message msg) |
static String |
methodNameToAttributeName(String methodName) |
static Buffer |
msgListToByteBuffer(List<Message> xmit_list)
Marshalls a list of messages.
|
static <T> List<T> |
newElements(List<T> old_list,
List<T> new_list) |
static List<Address> |
newMembers(List<Address> old_list,
List<Address> new_list) |
static Object |
objectFromByteBuffer(byte[] buffer)
Creates an object from a byte buffer
|
static Object |
objectFromByteBuffer(byte[] buffer,
int offset,
int length) |
static Object |
objectFromStream(DataInput in) |
static byte[] |
objectToByteBuffer(Object obj)
Serializes/Streams an object into a byte buffer.
|
static void |
objectToStream(Object obj,
DataOutput out) |
static List<IpAddress> |
parseCommaDelimitedHosts(String hosts,
int port_range)
Input is "daddy[8880],sindhu[8880],camille[5555].
|
static List<InetSocketAddress> |
parseCommaDelimitedHosts2(String hosts,
int port_range)
Input is "daddy[8880],sindhu[8880],camille[5555].
|
static int[] |
parseCommaDelimitedInts(String s)
Parses comma-delimited longs; e.g., 2000,4000,8000.
|
static long[] |
parseCommaDelimitedLongs(String s)
Parses comma-delimited longs; e.g., 2000,4000,8000.
|
static List<String> |
parseCommaDelimitedStrings(String l)
e.g.
|
static List<NetworkInterface> |
parseInterfaceList(String s) |
static RejectedExecutionHandler |
parseRejectionPolicy(String rejection_policy) |
static String |
parseString(ByteBuffer buf) |
static String |
parseString(ByteBuffer buf,
boolean discard_whitespace) |
static String |
parseString(DataInput in) |
static List<String> |
parseStringList(String l,
String separator) |
static <T> T |
pickNext(List<T> list,
T obj)
Returns the object next to element in list
|
static <T> List<T> |
pickNext(List<T> list,
T obj,
int num)
Returns the next min(N,list.size()) elements after obj
|
static Object |
pickRandomElement(List list) |
static Object |
pickRandomElement(Object[] array) |
static List<Address> |
pickSubset(List<Address> members,
double subset_percentage)
Selects a random subset of members according to subset_percentage and returns them.
|
static <T> String |
print(Collection<T> objs) |
static String |
print(List<NetworkInterface> interfaces) |
static <T> String |
print(Map<T,T> map) |
static String |
print(Throwable t) |
static String |
printBytes(double bytes) |
static String |
printBytes(long bytes)
MByte nowadays doesn't mean 1024 * 1024 bytes, but 1 million bytes, see http://en.wikipedia.org/wiki/Megabyte
|
static String |
printEvent(Event evt) |
static void |
printFragments(byte[][] frags) |
static <T> String |
printListWithDelimiter(Collection<T> list,
String delimiter) |
static <T> String |
printListWithDelimiter(Collection<T> list,
String delimiter,
int limit) |
static <T> String |
printMapWithDelimiter(Map<T,T> map,
String delimiter) |
static String |
printMessage(Message msg)
Tries to read an object from the message's buffer and prints it
|
static String |
printPingData(List<PingData> rsps) |
static String |
printStackTrace(Throwable t)
Use with caution: lots of overhead
|
static void |
printThreads() |
static String |
printTime(long time,
TimeUnit unit) |
static String |
printViews(Collection<View> views) |
static void |
prompt(String s) |
static long |
random(long range)
Returns a random value in the range [1 - range]
|
static Address |
readAddress(DataInput in) |
static Collection<? extends Address> |
readAddresses(DataInput in,
Class cl) |
static AuthToken |
readAuthToken(DataInput in) |
static byte[] |
readByteBuffer(DataInput in) |
static double |
readBytesDouble(String input) |
static int |
readBytesInteger(String input) |
static long |
readBytesLong(String input) |
static Class<?> |
readClass(DataInput in) |
static String |
readContents(InputStream input) |
static double |
readDoubleFromStdin(String message) |
static String |
readFile(String filename) |
static Streamable |
readGenericStreamable(DataInput in) |
static int |
readIntFromStdin(String message) |
static String |
readLine(InputStream in)
Reads a line of text.
|
static long |
readLong(DataInput in) |
static long |
readLongFromStdin(String message) |
static long[] |
readLongSequence(DataInput in) |
static int |
readNewLine(ByteBuffer buf) |
static Object |
readObject(DataInput in) |
static Streamable |
readStreamable(Class clazz,
DataInput in) |
static String |
readString(DataInput in) |
static String |
readStringFromStdin(String message) |
static View |
readView(DataInput in) |
static ViewId |
readViewId(DataInput in) |
static void |
registerChannel(JChannel channel,
String name) |
static String |
replaceProperties(String string,
Properties props)
Go through the input string and replace any occurance of ${p} with the
props.getProperty(p) value.
|
static void |
runAsync(Runnable task,
ThreadFactory factory,
ThreadGroup group,
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 byte |
setFlag(byte bits,
byte flag) |
static void |
setScope(Message msg,
short scope) |
static String |
sha(String source)
Converts a java.lang.String in to a SHA hashed String
|
static String |
shortName(InetAddress hostname) |
static String |
shortName(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(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(View view) |
static int |
size(ViewId vid) |
static long |
sizeOf(Object inst) |
static int |
sizeOf(Streamable inst) |
static long |
sizeOf(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 List<String> |
split(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,
List<Address> flushParticipants) |
static boolean |
startFlush(Channel c,
List<Address> flushParticipants,
int numberOfAttempts,
long randomSleepTimeoutFloor,
long randomSleepTimeoutCeiling) |
static Streamable |
streamableFromByteBuffer(Class<? extends Streamable> cl,
byte[] buffer) |
static Streamable |
streamableFromByteBuffer(Class<? extends Streamable> cl,
byte[] buffer,
int offset,
int length) |
static byte[] |
streamableToByteBuffer(Streamable obj) |
static String |
substituteVariable(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 InetAddress |
validateBindAddressFromInterface(InetAddress bind_addr,
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(String str) |
static void |
waitUntilAllChannelsHaveSameSize(long timeout,
long interval,
Channel... channels)
Blocks until all channels have the same view
|
static void |
writeAddress(Address addr,
DataOutput out) |
static void |
writeAddresses(Collection<? extends Address> v,
DataOutput out)
Writes a Vector of Addresses.
|
static void |
writeAuthToken(AuthToken token,
DataOutput out) |
static void |
writeByteBuffer(byte[] buf,
DataOutput out) |
static void |
writeByteBuffer(byte[] buf,
int offset,
int length,
DataOutput out) |
static void |
writeClass(Class<?> classObject,
DataOutput out) |
static void |
writeFully(ByteBuffer buf,
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,
DataOutput out) |
static void |
writeLong(long num,
DataOutput out) |
static void |
writeLongSequence(long highest_delivered,
long highest_received,
DataOutput out) |
static void |
writeObject(Object obj,
DataOutput out) |
static void |
writeStreamable(Streamable obj,
DataOutput out) |
static void |
writeString(ByteBuffer buf,
String s) |
static void |
writeString(String s,
DataOutput out) |
static void |
writeView(View view,
DataOutput out) |
static void |
writeViewId(ViewId vid,
DataOutput out) |
public static final int MAX_PORT
protected static int CCHM_INITIAL_CAPACITY
protected static float CCHM_LOAD_FACTOR
protected static int CCHM_CONCURRENCY_LEVEL
public static int MAX_LIST_PRINT_SIZE
public static ThreadGroup getGlobalThreadGroup()
public static void assertTrue(boolean condition)
public static void assertTrue(String message, boolean condition)
public static void assertFalse(boolean condition)
public static void assertFalse(String message, boolean condition)
public static void assertNotNull(Object val)
public static void waitUntilAllChannelsHaveSameSize(long timeout, long interval, Channel... channels) throws TimeoutException
timeout
- How long to wait (max in ms)interval
- Check every interval mschannels
- The channels which should form the view. The expected view size is channels.length.
Must be non-nullTimeoutException
public static void setScope(Message msg, short scope)
public static short getScope(Message msg)
public static void connect(Socket sock, SocketAddress dest, int sock_conn_timeout) throws IOException
sock
- dest
- sock_conn_timeout
- IOException
public static void close(InputStream inp)
public static void close(OutputStream out)
public static void close(Socket s)
public static void close(ServerSocket s)
public static void close(DatagramSocket my_sock)
public static void close(Channel ch)
public static void close(Channel... channels)
public static void close(Connection conn)
public static void shutdown(Channel ch) throws Exception
Exception
public static byte setFlag(byte bits, byte flag)
public static boolean isFlagSet(byte bits, byte flag)
public static byte clearFlags(byte bits, byte flag)
public static Object objectFromByteBuffer(byte[] buffer) throws Exception
Exception
public static Object objectFromByteBuffer(byte[] buffer, int offset, int length) throws Exception
Exception
public static byte[] objectToByteBuffer(Object obj) throws Exception
Exception
public static void objectToStream(Object obj, DataOutput out) throws Exception
Exception
public static Object objectFromStream(DataInput in) throws Exception
Exception
public static Streamable streamableFromByteBuffer(Class<? extends Streamable> cl, byte[] buffer) throws Exception
Exception
public static Streamable streamableFromByteBuffer(Class<? extends Streamable> cl, byte[] buffer, int offset, int length) throws Exception
Exception
public static byte[] streamableToByteBuffer(Streamable obj) throws Exception
Exception
public static byte[] collectionToByteBuffer(Collection<Address> c) throws Exception
Exception
public static void writeAuthToken(AuthToken token, DataOutput out) throws Exception
Exception
public static AuthToken readAuthToken(DataInput in) throws Exception
Exception
public static void writeView(View view, DataOutput out) throws Exception
Exception
public static void writeViewId(ViewId vid, DataOutput out) throws Exception
Exception
public static void writeAddress(Address addr, DataOutput out) throws Exception
Exception
public static int size(Address addr)
public static int size(View view)
public static int size(ViewId vid)
public static void writeAddresses(Collection<? extends Address> v, DataOutput out) throws Exception
v
- A Collectionout
- Exception
public static Collection<? extends Address> readAddresses(DataInput in, Class cl) throws Exception
in
- cl
- The type of Collection, e.g. ArrayList.classException
public static long size(Collection<? extends Address> addrs)
addrs
- Collectionpublic static void writeStreamable(Streamable obj, DataOutput out) throws Exception
Exception
public static Streamable readStreamable(Class clazz, DataInput in) throws Exception
Exception
public static void writeGenericStreamable(Streamable obj, DataOutput out) throws Exception
Exception
public static Streamable readGenericStreamable(DataInput in) throws Exception
Exception
public static void writeClass(Class<?> classObject, DataOutput out) throws Exception
Exception
public static void writeObject(Object obj, DataOutput out) throws Exception
Exception
public static void writeString(String s, DataOutput out) throws Exception
Exception
public static String readFile(String filename) throws FileNotFoundException
FileNotFoundException
public static String readContents(InputStream input)
public static String readStringFromStdin(String message) throws Exception
Exception
public static long readLongFromStdin(String message) throws Exception
Exception
public static double readDoubleFromStdin(String message) throws Exception
Exception
public static int readIntFromStdin(String message) throws Exception
Exception
public static void writeByteBuffer(byte[] buf, DataOutput out) throws Exception
Exception
public static void writeByteBuffer(byte[] buf, int offset, int length, DataOutput out) throws Exception
Exception
public static Buffer messageToByteBuffer(Message msg) throws Exception
Exception
public static Message byteBufferToMessage(byte[] buffer, int offset, int length) throws Exception
Exception
public static Buffer msgListToByteBuffer(List<Message> xmit_list) throws Exception
xmit_list
- LinkedListException
public static boolean match(long[] a1, long[] a2)
public static void sleep(long timeout)
public static void sleep(long timeout, int nanos)
public static void sleep(long msecs, boolean busy_sleep)
public static int keyPress(String msg)
public static long random(long range)
public static void sleepRandom(long floor, long ceiling)
public static boolean tossWeightedCoin(double probability)
public static String dumpThreads()
protected static void _printThreads(ThreadMXBean bean, long[] ids, StringBuilder sb)
public static boolean interruptAndWaitToDie(Thread t)
public static boolean interruptAndWaitToDie(Thread t, long timeout)
public static String dumpQueue(Queue q)
public static String printStackTrace(Throwable t)
public static void crash()
public static String printMessage(Message msg)
public static void printThreads()
public static String activeThreads()
public static String printBytes(long bytes)
bytes
- public static String format(double value)
public static long readBytesLong(String input)
public static int readBytesInteger(String input)
public static double readBytesDouble(String input)
public static String printBytes(double bytes)
public static byte[][] fragmentBuffer(byte[] buf, int frag_size, int length)
byte[]
).public static byte[][] fragmentBuffer(byte[] buf, int frag_size)
public static List<Range> computeFragOffsets(int offset, int length, int frag_size)
frag_size
- public static byte[] defragmentBuffer(byte[][] fragments)
fragments
- An array of byte buffers (byte[]
)public static void printFragments(byte[][] frags)
public static byte[] encode(long num)
protected static byte getByteAt(long num, int index)
public static long decode(byte[] buf)
public static void writeLong(long num, DataOutput out) throws Exception
Exception
public static byte[] encodeLongSequence(long highest_delivered, long highest_received)
highest_delivered
- highest_received
- public static byte size(long number)
public static byte size(long hd, long hr)
hd
- hr
- public static long[] decodeLongSequence(byte[] buf)
public static void writeLongSequence(long highest_delivered, long highest_received, DataOutput out) throws Exception
Exception
public static long[] readLongSequence(DataInput in) throws Exception
Exception
public static byte encodeLength(byte len1, byte len2)
len1
- The number of bytes needed to store a long. Must be between 0 and 8len2
- The number of bytes needed to store a long. Must be between 0 and 8public static byte[] decodeLength(byte len)
public static <T> String printListWithDelimiter(Collection<T> list, String delimiter)
public static <T> String printListWithDelimiter(Collection<T> list, String delimiter, int limit)
public static <T> String printMapWithDelimiter(Map<T,T> map, String delimiter)
public static String array2String(long[] array)
public static String array2String(short[] array)
public static String array2String(int[] array)
public static String array2String(boolean[] array)
public static boolean all(Collection c, Object obj)
public static List<Address> leftMembers(View one, View two)
one
- two
- public static List<Address> leftMembers(Collection<Address> old_list, Collection<Address> new_list)
public static List<Address> pickSubset(List<Address> members, double subset_percentage)
public static boolean containsViewId(Collection<View> views, ViewId vid)
public static Collection<Address> determineMergeParticipants(Map<Address,View> map)
map
- public static Collection<Address> determineMergeCoords(Map<Address,View> map)
determineMergeParticipants(java.util.Map)
and contains only members
which are currently sub-partition coordinators.map
- public static int getRank(View view, Address addr)
view
- The viewaddr
- The address of a memberpublic static <T> T pickNext(List<T> list, T obj)
T
- list
- obj
- public static <T> List<T> pickNext(List<T> list, T obj, int num)
public static JChannel createChannel(Protocol... prots) throws Exception
Exception
public static Address createRandomAddress()
public static Object[][] createTimer()
public static List<Address> determineLeftMembers(List<Address> old_mbrs, List<Address> new_mbrs)
public static String printViews(Collection<View> views)
public static <T> String print(Collection<T> objs)
public static void doubleWrite(byte[] buf, OutputStream out) throws Exception
Exception
public static void doubleWrite(byte[] buf, int offset, int length, OutputStream out) throws Exception
Exception
public static void writeFully(ByteBuffer buf, WritableByteChannel out) throws Exception
Exception
public static long sizeOf(String classname)
public static long sizeOf(Object inst)
public static int sizeOf(Streamable inst)
public static Class loadClass(String classname, Class clazz) throws ClassNotFoundException
classname
- Desired class.clazz
- Class object used to obtain a class loader
if no context class loader is available.ClassNotFoundException
public static Field[] getAllDeclaredFieldsWithAnnotations(Class clazz, Class<? extends Annotation>... annotations)
public static Method[] getAllDeclaredMethodsWithAnnotations(Class clazz, Class<? extends Annotation>... annotations)
public static InputStream getResourceAsStream(String name, Class clazz)
public static boolean sameHost(Address one, Address two)
public static boolean fileExists(String fname)
public static void verifyRejectionPolicy(String str) throws Exception
Exception
public static RejectedExecutionHandler parseRejectionPolicy(String rejection_policy)
public static int[] parseCommaDelimitedInts(String s)
public static long[] parseCommaDelimitedLongs(String s)
public static List<String> parseCommaDelimitedStrings(String l)
public static List<IpAddress> parseCommaDelimitedHosts(String hosts, int port_range) throws UnknownHostException
UnknownHostException
public static List<InetSocketAddress> parseCommaDelimitedHosts2(String hosts, int port_range)
public static String parseString(ByteBuffer buf)
public static String parseString(ByteBuffer buf, boolean discard_whitespace)
public static int readNewLine(ByteBuffer buf)
public static int discardUntilNewLine(InputStream in)
in
- public static String readLine(InputStream in) throws IOException
IOException
- If an I/O error occurspublic static void writeString(ByteBuffer buf, String s)
public static List<NetworkInterface> parseInterfaceList(String s) throws Exception
s
- Exception
public static String print(List<NetworkInterface> interfaces)
public static boolean startFlush(Channel c, List<Address> flushParticipants, int numberOfAttempts, long randomSleepTimeoutFloor, long randomSleepTimeoutCeiling)
public static boolean startFlush(Channel c, int numberOfAttempts, long randomSleepTimeoutFloor, long randomSleepTimeoutCeiling)
public static boolean startFlush(Channel c)
public static String shortName(InetAddress hostname)
public static String generateLocalName()
public static short incrCounter()
public static <K,V> ConcurrentMap<K,V> createConcurrentMap(int initial_capacity, float load_factor, int concurrency_level)
public static <K,V> ConcurrentMap<K,V> createConcurrentMap(int initial_capacity)
public static <K,V> ConcurrentMap<K,V> createConcurrentMap()
public static <K,V> Map<K,V> createHashMap()
public static ServerSocket createServerSocket(SocketFactory factory, String service_name, InetAddress bind_addr, int start_port)
public static ServerSocket createServerSocket(SocketFactory factory, String service_name, InetAddress bind_addr, int start_port, int end_port) throws Exception
Exception
public static DatagramSocket createDatagramSocket(SocketFactory factory, String service_name, InetAddress addr, int port) throws 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.Exception
public static MulticastSocket createMulticastSocket(SocketFactory factory, String service_name, InetAddress mcast_addr, int port, Log log) throws IOException
IOException
public static InetAddress getBindAddress(Properties props) throws UnknownHostException, SocketException
props
- UnknownHostException
SocketException
public static InetAddress validateBindAddressFromInterface(InetAddress bind_addr, String bind_interface_str) throws UnknownHostException, SocketException
UnknownHostException
SocketException
public static boolean checkForLinux()
public static boolean checkForHp()
public static boolean checkForSolaris()
public static boolean checkForWindows()
public static boolean checkForMac()
public static void prompt(String s)
public static InetAddress getLocalhost(StackType ip_version) throws UnknownHostException
UnknownHostException
public static InetAddress getNonLoopbackAddress() throws SocketException
SocketException
public static InetAddress getAddress(Util.AddressScope scope) throws SocketException
SocketException
public static InetAddress getAddress(NetworkInterface intf, Util.AddressScope scope)
intf
- the interface to be checkedpublic static boolean interfaceHasIPAddresses(NetworkInterface intf, StackType ip_version) throws UnknownHostException
intf
- UnknownHostException
public static StackType getIpStackType()
public static boolean isStackAvailable(boolean ipv4)
public static List<NetworkInterface> getAllAvailableInterfaces() throws SocketException
SocketException
public static Collection<InetAddress> getAllAvailableAddresses()
public static void checkIfValidAddress(InetAddress bind_addr, String prot_name) throws Exception
Exception
public static String getProperty(String[] system_props, Properties props, String prop_name, boolean ignore_sysprops, String default_value)
system_props
- props
- List of properties read from the configuration fileprop_name
- The name of the property, will be removed from props if foundignore_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 valuepublic static boolean isBindAddressPropertyIgnored()
public static boolean isCoordinator(JChannel ch)
public static MBeanServer getMBeanServer()
public static String generateList(Collection c, String separator)
public static String replaceProperties(String string, Properties props)
string
- -
the string with possible ${} referencesprops
- -
the source for ${x} property ref values, null means use
System.getProperty(){@link
- java.security.AccessControlException}
when not authorised to retrieved system propertiespublic static String substituteVariable(String val)
val
- public static String md5(String source)
source
- the source Stringpublic static String sha(String source)
source
- the source Stringpublic static void runAsync(Runnable task, ThreadFactory factory, ThreadGroup group, String thread_name)
task
- factory
- group
- thread_name
- Copyright © 2012 JBoss by Red Hat. All Rights Reserved.