Java Reference
In-Depth Information
L ISTING 6.7 Continued
} catch (Exception exce) {
System.out.println(“BankClient- executing transaction: “+exce);
}
System.out.println(“BankClient- Client Log out.”);
}
private void executeTransaction() throws Exception{
System.out.println(“BankClient- BankClient Executing.”);
InputStream is =
getClass().getClassLoader().getResourceAsStream(“test.txt”);
int c;
while((c = is.read())!=-1 )
System.out.print((char)c);
Class.forName(“Clazz”);
manager.post(“all OK.”);
}
}
The method executeTransaction (lines 29-40 in Listing 6.7) loads a resource (in this case, a
text file) from its classloader, printing out as a proof the file content. If this class is created by
the ApplicationHelper (as it is supposed to be), the BankClientLoader will take charge of
downloading the file if it is not present in cache. The same is true for the dynamic creation of a
class, at line 37.
Running the Example
Having seen all the pieces separately, we will study a client-server session in which classes and
resources are deployed transparently to the executing application and to the end-user.
C AUTION
When executing the ApplicationHelper configured to launch the BankClient appli-
cation, be careful to not include the example class at line 37 in Listing 6.7 in your
client classpath (this is possible especially if you use an IDE). In this case, the file
Clazz.class ” won't appear in the client cache at the end of execution, indicating
that the class was loaded by the super classloader instead. Just compile the class sepa-
rately, and put the obtained file in the serverdir directory, from where the
BankServer takes files for replying to clients.
Search WWH ::




Custom Search