For a school project, I need to write a simple Java server that constantly listens on the incoming directory and moves files from this directory to another location. The server needs to log information and error messages, so I decided to use a proxy template for this. So I created the following ServerInterface:
public interface ServerInterface extends Runnable {
public void initialize(String repPath, ExecutorInterface executor, File propertiesFile) throws ServerInitException;
public void run();
public void terminate();
public void updateHTML();
public File[] scanIncomingDir();
public List<DatasetAttributes> moveIncomingFilesIfComplete(File[] incomingFiles);
}
Then I created an implementation Serverrepresenting the real object and a class ProxyServerrepresenting the proxy. It also Serverhas a factory method that creates an object ProxyServer, but returns it as ServerInterface.
The method runin the proxy object is as follows:
@Override
public void run(){
log(LogLevels.INFO, "server is running ...");
while( !stopped ){
try {
File[] incomingContent = scanIncomingDir();
moveIncomingFilesIfComplete(incomingContent);
updateHTML();
pause();
} catch (Exception e) {
logger.logException(e, new Timestamp(timestampProvider.getTimestamp()));
pause();
}
}
log(LogLevels.INFO, "server stopped");
}
, try, -, . . , run -, run , , ( , terminate).
, : ? -?
, , "" "" -behaviour... "" while, -, ? , :
run , - , while. - , , - .
, Proxy-Server Runnable, run terminate , .
? , ?