org.curjent.example.agent.ftpxfer
Class FTPTransferTask

java.lang.Object
  extended by 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.


Field Summary
private  FTPTransferClient ftp
           
private static Logger logger
           
 
Constructor Summary
FTPTransferTask(String remote, String local)
           
 
Method Summary
(package private)  void disconnect()
           
(package private)  void finished(String dir)
           
(package private)  void starting(String dir)
           
(package private)  void transfer(String file)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ftp

private final FTPTransferClient ftp

logger

private static final Logger logger
Constructor Detail

FTPTransferTask

FTPTransferTask(String remote,
                String local)
Method Detail

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