KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > coldcore > coloradoftp > command > impl > ftp > QuitCommand


1 /**
2  * Command QUIT.
3  * See FTP spec for details on the command.
4  */

5 package com.coldcore.coloradoftp.command.impl.ftp;
6
7 import com.coldcore.coloradoftp.command.Reply;
8 import com.coldcore.coloradoftp.command.impl.AbstractCommand;
9 import com.coldcore.coloradoftp.connection.DataConnection;
10 import com.coldcore.coloradoftp.connection.DataPortListener;
11 import com.coldcore.coloradoftp.connection.DataPortListenerSet;
12 import com.coldcore.coloradoftp.factory.ObjectFactory;
13 import com.coldcore.coloradoftp.factory.ObjectName;
14
15 public class QuitCommand extends AbstractCommand {
16
17   public Reply execute() {
18     Reply reply = getReply();
19     if (!testLogin()) return reply;
20
21     //Abort data connection initiator
22
controlConnection.getDataConnectionInitiator().abort();
23
24     //Abort data connection listeners
25
DataPortListenerSet listeners = (DataPortListenerSet) ObjectFactory.getObject(ObjectName.DATA_PORT_LISTENER_SET);
26     for (DataPortListener listener : listeners.list())
27       listener.removeConnection(controlConnection);
28
29     /* We must not clear login state of the user, instead we will poison his/her connection
30      * to make sure he/she cannot send any more commands in (except for special commands).
31      */

32     controlConnection.poison();
33
34     //Logout the user
35
logout();
36
37     DataConnection dataConnection = controlConnection.getDataConnection();
38     if (dataConnection != null) {
39       reply.setCode("221");
40       reply.setText("Logged out, closing control connection as soon as data transferred.");
41     } else {
42       reply.setCode("221");
43       reply.setText("Logged out, closing control connection.");
44     }
45     return reply;
46   }
47
48
49   public boolean processInInterruptState() {
50     return true;
51   }
52
53
54   /** Log out user.
55    * This implementation does nothing.
56    */

57   protected void logout() {
58   }
59 }
60
Popular Tags