com.Prominic.jFTPd
Class AdminConnection

java.lang.Object
  extended by java.lang.Thread
      extended by com.Prominic.jFTPd.AdminConnection
All Implemented Interfaces:
java.lang.Runnable

public class AdminConnection
extends java.lang.Thread

jFTPd opens up an administrative port which you can use to control it. It is a plain text socket used to send various commands to which jFTPd reacts. These commands are "shutdown", "version" and "stats".
The "shutdown" command stops the jftpd server (active transfers are stopped too)
The "version" command returns a string with jFTPd version
The "stats" command returns a string containg some basic statistics (such as numner of files/bytes transferred). Creation date: (4/19/2001 4:50:42 PM)


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected static FTPHandler ftpHandler
          The server object.
private  java.lang.String localAddress
           
private  int port
           
private static boolean running
           
private  java.net.ServerSocket server
           
private  int SIG_CHK
           
private  int SIG_DUMM
           
private  int SIG_KILL
           
private  int SIG_STAT
           
private static java.util.Vector vectorOfThreads
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
AdminConnection(int portToListenTo)
          Default constructor.
 
Method Summary
static void deletePidFile()
          Delets jFTPd pid file (it does nothing on Windows).
private  java.lang.String getAddressAsString(java.net.InetAddress address)
          Given an InetAddress, it returns it's IP in a string form.
 void processConnection(java.net.Socket client)
          Handles the communication with the clients that connect to the admin port.
 java.lang.String readMessage(java.net.Socket client)
          Reads a message from the client.
 void run()
          When an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread.
 void sendMessage(java.net.Socket client, java.lang.String message)
          Sends a message to the client.
static void shutdownJFTPD()
          Stops the server and shuts down the admin connection.
static void stopAdminConnection()
          This stops the admin connection, breaking the internal loop.
 int talkWithClient(java.net.Socket client)
          Talks with the client in order to find out which signal to send to the Shutdownable thread.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

vectorOfThreads

private static java.util.Vector vectorOfThreads

running

private static boolean running

server

private java.net.ServerSocket server

port

private int port

localAddress

private java.lang.String localAddress

SIG_KILL

private int SIG_KILL

SIG_STAT

private int SIG_STAT

SIG_CHK

private int SIG_CHK

SIG_DUMM

private int SIG_DUMM

ftpHandler

protected static FTPHandler ftpHandler
The server object.

Constructor Detail

AdminConnection

public AdminConnection(int portToListenTo)
Default constructor. Opens a port on local address only (you can only control jFTPd if you are already connected to localhost).

Parameters:
portToListenTo - the port where the admin connection should be bound to.
Method Detail

deletePidFile

public static void deletePidFile()
Delets jFTPd pid file (it does nothing on Windows). Used when shutting down jFTPd.


getAddressAsString

private java.lang.String getAddressAsString(java.net.InetAddress address)
Given an InetAddress, it returns it's IP in a string form.

Parameters:
address - - InetAddress object
Returns:
- string in a form of "XXX.XXX.XXX.XXX"

processConnection

public void processConnection(java.net.Socket client)
Handles the communication with the clients that connect to the admin port.
It rejects clients which are not connected from localhost.
Accepts only one client at a time.

Parameters:
client - - socket where the client is connected. Creation date: (4/19/2001 5:19:17 PM)

readMessage

public java.lang.String readMessage(java.net.Socket client)
                             throws java.io.IOException
Reads a message from the client. The message is supposed to end with a new-line character.

Returns:
String message.
Throws:
java.io.IOException

run

public void run()
When an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread.

The general contract of the method run is that it may take any action whatsoever. This opens up a server socket on the port passed to the constructor.
Sets thje timeout to 10 seconds.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread
See Also:
Thread.run()

sendMessage

public void sendMessage(java.net.Socket client,
                        java.lang.String message)
                 throws java.io.IOException
Sends a message to the client. The message is supposed to end with a new-line char.

Parameters:
message - message to be sent to the client.
Throws:
java.io.IOException

shutdownJFTPD

public static void shutdownJFTPD()
Stops the server and shuts down the admin connection.
Active transfers are stopped immediatly. Creation date: (02-Aug-02 13:22:56)


stopAdminConnection

public static void stopAdminConnection()
This stops the admin connection, breaking the internal loop. Creation date: (21-Mar-02 18:39:53)


talkWithClient

public int talkWithClient(java.net.Socket client)
                   throws java.io.IOException
Talks with the client in order to find out which signal to send to the Shutdownable thread. The supported messages from the client are "shutdown" (sends a SIG_KILL) and "reload" (sends a SIG_HUP).

Parameters:
client - - client socket.
Returns:
int shutdown signal, -1 if the client sent an invalid request (other than shutdown or reload).
Throws:
java.io.IOException