Java Reference
In-Depth Information
it needs are downloaded just in time from the server if not present locally (this happens only
the first time, anyway). In fact, thanks to the classloader mechanism of the J2SE platform, the
needed classes are loaded by the same classloader that loaded the invoking class, if not other-
wise explicitly specified (as it is done at line 240 of Listing 6.2). Hence, all classes used by the
main class are loaded by our custom class loader as the classes needed by those classes, and so
Another important part of our architecture is the server class, shown in Listing 6.4. It is a sim-
ple, multithreaded, socket-based server. For simplicity, we kept the deployment server (essen-
tially the method implementing the CHECK command and the management of the
downloadPolicy properties) and the so-called business server (the other protocol commands)
together in one class. That is to say, there are always two server threads for each client process.
One server instance works conceptually as a deployment server, providing classes and other
files to the client application helper, whereas the other server thread assists the business appli-
cation independently from the other instance.
L ISTING 6.4 The BankServer Class
import java.util.*;
* Chapter 6 - The Bank Server
* @author Mauro Marinilli
* @version 1.0
public class BankServer implements Runnable {
public final static char QUIT_COMMAND = 'q';
public final static char GET_COMMAND = 'g';
public final static char POST_COMMAND = 'p';
public final static char CHECK_COMMAND = 'c';
public final static String SERVER_DIR = “serverdir/”;
private DataOutputStream out;
private DataInputStream in;
private Properties downloadPolicy;
private String header;
private Socket clientSocket;
private final static String PROPS_FILE_NAME = “”;
Search WWH ::

Custom Search