loader
Class WorkerClassServer

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--loader.WorkerClassServer

public class WorkerClassServer
extends java.lang.Thread

class which handles communication with NetworkClassLoader.

It waits for a class request (the name is a String).
The requested class is searched first in the cache (a byte array cache), and then in CLASSPATH of the server machine.

If the class is found it is loaded as a byte array.

To the client - NetworkClassLoader - a ClassPacket is sent with the byte array.

If the class is not found a ClassPacket with an error.

Version:
1.2 August 2000
Author:
Lorenzo Bettini - bettini@dsi.unifi.it, Donato Cappetta - cappetta@infomedia.it

Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
WorkerClassServer(java.net.Socket clientSocket, java.util.Hashtable classesCache)
          Constructor.
 
Method Summary
protected  byte[] getClassBytes(java.lang.String className)
          get the bytes for the requested class
protected  byte[] getResourceBytes(java.lang.String resourceName)
          get the bytes for the requested resource
protected  byte[] loadResource(java.io.InputStream is)
          read a file from a stream and returns a byte array.
 void run()
          A loop waiting for a class name.
protected  void sendPacket(byte[] bytes)
          send a byte array packet to the client
protected  void sendPacket(java.lang.String error)
          send an error packet to the client
protected  void writePacket(ResourcePacket packet)
          write a packet to the socket
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WorkerClassServer

public WorkerClassServer(java.net.Socket clientSocket,
                         java.util.Hashtable classesCache)
                  throws java.io.IOException
Constructor. Initializes the I/O streams associated to the socket of the client.
Parameters:
clientSocket - socket for the connection with the client.
classCahce - the cache of classes.
Throws:
java.io.IOException - I/O stream error.
Method Detail

run

public void run()
A loop waiting for a class name. It loads the class in a byte array which is sent to the client.
-1 is sent if the class is not found.
Overrides:
run in class java.lang.Thread

getResourceBytes

protected byte[] getResourceBytes(java.lang.String resourceName)
                           throws java.io.IOException
get the bytes for the requested resource
Parameters:
resourceName - the name of the resource
Returns:
the byte array for the resource or an exception is thrown
Throws:
java.io.IOException - file read error.

getClassBytes

protected byte[] getClassBytes(java.lang.String className)
                        throws java.io.IOException
get the bytes for the requested class
Parameters:
className - the name of the class
Returns:
the byte array for the class or an exception is thrown
Throws:
java.io.IOException - file read error.

loadResource

protected byte[] loadResource(java.io.InputStream is)
                       throws java.io.IOException
read a file from a stream and returns a byte array.
Parameters:
is - the InputStream to read from
Returns:
byte[] byte array: contents of the file
Throws:
java.io.FileNotFoundException - File .class not found in CLASSPATH.

sendPacket

protected void sendPacket(java.lang.String error)
                   throws java.io.IOException
send an error packet to the client
Throws:
java.io.IOException - file read error.

sendPacket

protected void sendPacket(byte[] bytes)
                   throws java.io.IOException
send a byte array packet to the client
Throws:
java.io.IOException - file read error.

writePacket

protected void writePacket(ResourcePacket packet)
                    throws java.io.IOException
write a packet to the socket
Throws:
java.io.IOException - file read error.