rabbit.proxy
Class Proxy

java.lang.Object
  extended byjava.lang.Thread
      extended byrabbit.proxy.Proxy
All Implemented Interfaces:
java.lang.Runnable

public class Proxy
extends java.lang.Thread

This is the central dispatcher for RabbIT. Basically it sits in a loop accepting connection and for each connection creating a handler for it. Also handles logging so it goes out nicely formatted (and synchronized).


Field Summary
static int ALL
          Show all normal messages and higher.
static Config config
          The current configuration
static int DEBUG
          Show all messages in the log.
static int ERROR
          Show error messages and higer.
static int FATAL
          Show only fatal messages.
static int INFO
          Show information messages and higher.
static int MSG
          Show important messages and above.
static java.lang.String VERSION
          Current version
static int WARN
          Show warnings and higer.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Method Summary
static NCache getCache()
          Get the cache the proxy are using.
static ConnectionHandler getConnectionHandler()
          Get the connection handler.
static int getConnectPort(int port)
          Get the port to connect to.
static Counter getCounter()
          Get the Log-handle
static java.util.Vector getCurrentConections()
          returns the current connections.
static java.util.logging.Level getErrorLevel(int errorlevel)
          Get the String description of the given error level
static int getErrorLevel(java.lang.String errorlevel)
          Get the actual error level from the given String.
static java.net.InetAddress getHost()
          Get the local host.
static java.net.InetAddress getInetAddress(java.net.URL url)
          Get the InetAddress to connect to.
static long getOffset()
          Get the offset in milis from GMT NOTE! the offset is only calculated at startup.
static int getPort()
          Get the port this proxy is using.
static java.lang.String getProxyAuthString()
          Get the authenticationstring to use for proxy.
static java.lang.String getServerIdentity()
           
static java.util.Date getStartDate()
          return the time when the proxy was started.
 java.util.TimeZone getTimeZone()
          Get the time zone the proxy is running in.
static WebConnection getWebConnection(HTTPHeader header)
          Get a WebConnection.
static boolean isAccepting()
          Returns the accepting.
static boolean isProxyConnected()
          are we connected to another proxy?
static void kill()
          shutdown
static void logConnection(Connection con)
          log a connection handled.
static void logError(int type, java.lang.String error, java.lang.String obj, java.lang.String meth)
          log errors and other important stuff.
static void logError(java.lang.String error)
          log errors and other important stuff.
static void main(java.lang.String[] args)
          Start a proxy.
static void printHelp()
          print out the helptext to the user.
static void reConfigure(Config config)
          Reconfigure the proxy during runtime.
static void releaseWebConnection(WebConnection wc)
          Release a WebConnection so that it may be reused if possible.
static void removeConnection(Connection con)
          Remove a connection (it has received full treatment)
 void run()
          while we can, accept new sockets, creating a handler for each and also save connections for statistics.
static void saveConfig()
          save the config back to file
static void startProxy()
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

VERSION

public static final java.lang.String VERSION
Current version

See Also:
Constant Field Values

DEBUG

public static final int DEBUG
Show all messages in the log.

See Also:
Constant Field Values

ALL

public static final int ALL
Show all normal messages and higher.

See Also:
Constant Field Values

INFO

public static final int INFO
Show information messages and higher.

See Also:
Constant Field Values

WARN

public static final int WARN
Show warnings and higer.

See Also:
Constant Field Values

MSG

public static final int MSG
Show important messages and above.

See Also:
Constant Field Values

ERROR

public static final int ERROR
Show error messages and higer.

See Also:
Constant Field Values

FATAL

public static final int FATAL
Show only fatal messages.

See Also:
Constant Field Values

config

public static Config config
The current configuration

Method Detail

main

public static void main(java.lang.String[] args)
Start a proxy. Parse flags and read the config, then starts the proxy.

Parameters:
args - the command-line flags given.

startProxy

public static void startProxy()

getTimeZone

public java.util.TimeZone getTimeZone()
Get the time zone the proxy is running in. This is neccessary to give dates in GMT.


getOffset

public static long getOffset()
Get the offset in milis from GMT NOTE! the offset is only calculated at startup. This means that during DST changes this may be invalid for a day or two. Restart RabbIT dayly during that time to get it right _IF_ you feel it is a problem.


getConnectionHandler

public static ConnectionHandler getConnectionHandler()
Get the connection handler.


getWebConnection

public static WebConnection getWebConnection(HTTPHeader header)
                                      throws java.io.IOException
Get a WebConnection.

Throws:
java.io.IOException

releaseWebConnection

public static void releaseWebConnection(WebConnection wc)
Release a WebConnection so that it may be reused if possible.

Parameters:
wc - the WebConnection to release.

run

public void run()
while we can, accept new sockets, creating a handler for each and also save connections for statistics.


printHelp

public static void printHelp()
print out the helptext to the user.


reConfigure

public static void reConfigure(Config config)
Reconfigure the proxy during runtime.

Parameters:
config - the new config.

saveConfig

public static void saveConfig()
save the config back to file


getErrorLevel

public static int getErrorLevel(java.lang.String errorlevel)
Get the actual error level from the given String.

Parameters:
errorlevel - the String to translate.
Returns:
the errorlevel suitable for the given String.

getErrorLevel

public static java.util.logging.Level getErrorLevel(int errorlevel)
Get the String description of the given error level

Parameters:
errorlevel - the int to translate to a String.
Returns:
the String describing the errorlevel.

logError

public static void logError(java.lang.String error)
log errors and other important stuff.

Parameters:
error - the thing that happend.

logError

public static void logError(int type,
                            java.lang.String error,
                            java.lang.String obj,
                            java.lang.String meth)
log errors and other important stuff.

Parameters:
type - the type of the error.
error - the thing that happend.

getCache

public static NCache getCache()
Get the cache the proxy are using.

Returns:
the NCache the proxy currently are using.

getCounter

public static Counter getCounter()
Get the Log-handle

Returns:
the Counter we use.

getPort

public static int getPort()
Get the port this proxy is using.

Returns:
the port number the proxy is listening on.

getHost

public static java.net.InetAddress getHost()
Get the local host.

Returns:
the InetAddress of the host the proxy is running on.

isProxyConnected

public static boolean isProxyConnected()
are we connected to another proxy?

Returns:
true if the proxy is connected to another proxy.

getInetAddress

public static java.net.InetAddress getInetAddress(java.net.URL url)
                                           throws java.net.UnknownHostException
Get the InetAddress to connect to.

Returns:
the InetAddress to give the request
Throws:
java.net.UnknownHostException

getConnectPort

public static int getConnectPort(int port)
Get the port to connect to.

Parameters:
port - the port we want to connect to.
Returns:
the port to connect to.

getProxyAuthString

public static java.lang.String getProxyAuthString()
Get the authenticationstring to use for proxy.

Returns:
an authentication string.

getCurrentConections

public static java.util.Vector getCurrentConections()
returns the current connections.

Returns:
a Vector with the current connections.

removeConnection

public static void removeConnection(Connection con)
Remove a connection (it has received full treatment)

Parameters:
con - the connection that is closing down.

getStartDate

public static java.util.Date getStartDate()
return the time when the proxy was started.

Returns:
a Date with the time the proxy was started.

getServerIdentity

public static java.lang.String getServerIdentity()

logConnection

public static void logConnection(Connection con)
log a connection handled.

Parameters:
con - the Connection that handled a request

kill

public static void kill()
shutdown


isAccepting

public static boolean isAccepting()
Returns the accepting.

Returns:
boolean