CTL
Class RUtil

java.lang.Object
  extended by CTL.RUtil

public class RUtil
extends java.lang.Object

Static utility functions which did not fit anywhere else


Field Summary
private static int halt
          Keeps track of recursive calls to avoid infinite loops
static java.lang.reflect.Method serialrd
          Method objects for serialRead() and serialWrite()
static java.lang.reflect.Method serialrd2
          Method objects for serialRead() and serialWrite()
static java.lang.reflect.Method serialwr
          Method objects for serialRead() and serialWrite()
 
Constructor Summary
RUtil()
           
 
Method Summary
private static java.lang.String __stackTrace(java.lang.StackTraceElement[] trace)
          Stacktrace printer helper function
private static java.lang.String __stackTrace(java.lang.StackTraceElement[] trace, int len)
          Stacktrace printer helper function
static java.lang.Class classToRI(java.lang.Class klas)
          Find the remote interface class for an implementation class
static java.lang.String converter(java.lang.String type, java.lang.String convert_me)
          Retrieve a conversion code snippet for a certain type
static void except(java.lang.Exception e)
          Properly decode and display an exception
static java.lang.String getBase(java.lang.String name)
          Get the implementation class of some CI/RI
static char getCID(java.lang.reflect.Constructor construct)
          Get the FID for a certain constructor
static char getFID(java.lang.reflect.Method method)
          Get the FID for a certain method
static java.lang.reflect.Method getReader(java.lang.String type)
          Returns a reader function for the specified type
static java.lang.reflect.Method getReceiver(java.lang.String type)
          Returns a receiver function for the specified type
static java.lang.reflect.Method getWriter(java.lang.String type)
          Returns a writer function for the specified type
static void main(java.lang.String[] args)
           
static int objSize(java.lang.Object obj)
          Calculate the serialized size of an object
static int optInt(gnu.getopt.Getopt g)
          Extract an integer from a CLI option
static PeerID optPeerID(gnu.getopt.Getopt g)
          Extract a PeerID from a CLI option
static PeerID optPeerID(java.lang.String arg)
          Extract a PeerID from a CLI option
static java.lang.String optString(gnu.getopt.Getopt g)
          Extract a String from a CLI option
static java.lang.String reader2str(java.lang.String reader)
          Convert a reader function to string
static java.lang.String stackTrace()
          Pretty print stacktrace of the current thread
static java.lang.String stackTrace(java.lang.Exception e)
          Print the backtrace of an exception
static int tryInt(java.lang.String str)
          Fault-tolerant string to integer conversion
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialrd

public static java.lang.reflect.Method serialrd
Method objects for serialRead() and serialWrite()


serialrd2

public static java.lang.reflect.Method serialrd2
Method objects for serialRead() and serialWrite()


serialwr

public static java.lang.reflect.Method serialwr
Method objects for serialRead() and serialWrite()


halt

private static int halt
Keeps track of recursive calls to avoid infinite loops

Constructor Detail

RUtil

public RUtil()
Method Detail

stackTrace

public static java.lang.String stackTrace(java.lang.Exception e)
Print the backtrace of an exception

Parameters:
e - Exception
Returns:
String

__stackTrace

private static java.lang.String __stackTrace(java.lang.StackTraceElement[] trace)
Stacktrace printer helper function

Parameters:
trace - Stacktrace element
Returns:
String

__stackTrace

private static java.lang.String __stackTrace(java.lang.StackTraceElement[] trace,
                                             int len)
Stacktrace printer helper function

Parameters:
trace - Stacktrace element
len - Length
Returns:
String

stackTrace

public static java.lang.String stackTrace()
Pretty print stacktrace of the current thread

Returns:
String

except

public static void except(java.lang.Exception e)
Properly decode and display an exception

Parameters:
e - Exception

getFID

public static char getFID(java.lang.reflect.Method method)
Get the FID for a certain method

Parameters:
method - Method
Returns:
FunctionID

getCID

public static char getCID(java.lang.reflect.Constructor construct)
Get the FID for a certain constructor

Parameters:
construct - Constructor
Returns:
FunctionID

getReader

public static java.lang.reflect.Method getReader(java.lang.String type)
Returns a reader function for the specified type

Parameters:
type - Type to read
Returns:
Method which can read the type

getWriter

public static java.lang.reflect.Method getWriter(java.lang.String type)
Returns a writer function for the specified type

Parameters:
type - Type to write
Returns:
Method which can write the type

getReceiver

public static java.lang.reflect.Method getReceiver(java.lang.String type)
Returns a receiver function for the specified type

Parameters:
type - Type to receive
Returns:
Method which can receive the type

reader2str

public static java.lang.String reader2str(java.lang.String reader)
Convert a reader function to string

Parameters:
reader - Reader function
Returns:
String

classToRI

public static java.lang.Class classToRI(java.lang.Class klas)
                                 throws java.lang.ClassNotFoundException
Find the remote interface class for an implementation class

Parameters:
klas - Implementation class
Returns:
RI class
Throws:
java.lang.ClassNotFoundException

objSize

public static int objSize(java.lang.Object obj)
                   throws java.io.IOException,
                          java.lang.IllegalAccessException,
                          java.lang.reflect.InvocationTargetException,
                          CTLException
Calculate the serialized size of an object

Parameters:
obj - Object
Returns:
Size
Throws:
java.io.IOException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
CTLException

converter

public static java.lang.String converter(java.lang.String type,
                                         java.lang.String convert_me)
Retrieve a conversion code snippet for a certain type

Parameters:
type - Type
convert_me - Name of the variable to convert
Returns:
Code

tryInt

public static int tryInt(java.lang.String str)
Fault-tolerant string to integer conversion

Parameters:
str - String to convert
Returns:
Integer

optPeerID

public static PeerID optPeerID(java.lang.String arg)
Extract a PeerID from a CLI option

Parameters:
arg - String
Returns:
PeerID

optPeerID

public static PeerID optPeerID(gnu.getopt.Getopt g)
Extract a PeerID from a CLI option

Parameters:
g - Getopt parser object
Returns:
PeerID

optInt

public static int optInt(gnu.getopt.Getopt g)
Extract an integer from a CLI option

Parameters:
g - Getopt parser object
Returns:
Integer

optString

public static java.lang.String optString(gnu.getopt.Getopt g)
Extract a String from a CLI option

Parameters:
g - Getopt parser object
Returns:
String

getBase

public static java.lang.String getBase(java.lang.String name)
Get the implementation class of some CI/RI

Parameters:
name - CI/RI name
Returns:
Name of the implementation class or null if it does not have any / is not an RI

main

public static void main(java.lang.String[] args)