org.curjent.example.agent.ftpxfer
Class FTPTransferTask
java.lang.Object
org.curjent.example.agent.ftpxfer.FTPTransferTask
class FTPTransferTask
- extends Object
FTP transfer task.
The agent's task defers most functionality to an instance of
FTPTransferClient. The client class is not thread safe, so each task has its
own instance. The starting method is annotated as a leading marker. This
ensures a directory's start message is logged before any of the files in the
directory. The finished method is annotated as a trailing marker. It does not
execute until all prior transfer calls have finished. This ensures the
finished message is logged after all file transfers for the directory are
done.
The FTPTransferTask class definition does not include an implements
FTPTransfer clause. This simplifies implementation of the task. The Java
compiler requires all methods to handle or declare checked exceptions,
including an IOException. This is a problem. We do not want to declare
exceptions in the FTPTransfer interface for asynchronous methods. The caller
can never receive an IOException when calling any of the agent's asynchronous
methods. Asynchronous methods are executed only within the context of an
agent's task's thread. By not implementing the agent interface directly, the
task can centralized asynchronous exception handling in the handler defined
by the agent's factory above. Otherwise, each method would have to catch and
individually deal with checked exceptions.
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ftp
private final FTPTransferClient ftp
logger
private static final Logger logger
FTPTransferTask
FTPTransferTask(String remote,
String local)
transfer
void transfer(String file)
throws IOException
- Throws:
IOException
starting
@Leading
void starting(String dir)
finished
@Marker
void finished(String dir)
disconnect
void disconnect()
throws IOException
- Throws:
IOException
Copyright 2009-2011 Tom Landon
Apache License 2.0