1 /**
2 * This file is part of Waarp Project.
3 *
4 * Copyright 2009, Frederic Bregier, and individual contributors by the @author tags. See the
5 * COPYRIGHT.txt in the distribution for a full listing of individual contributors.
6 *
7 * All Waarp Project is free software: you can redistribute it and/or modify it under the terms of
8 * the GNU General Public License as published by the Free Software Foundation, either version 3 of
9 * the License, or (at your option) any later version.
10 *
11 * Waarp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 * Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along with Waarp . If not, see
16 * <http://www.gnu.org/licenses/>.
17 */
18 package org.waarp.ftp.core.data.handler;
19
20 import io.netty.channel.Channel;
21 import org.waarp.ftp.core.session.FtpSession;
22
23 /**
24 * This class is to be implemented in order to allow Business actions according to FTP service
25 *
26 * @author Frederic Bregier
27 *
28 */
29 public abstract class DataBusinessHandler {
30 /**
31 * NettyHandler that holds this DataBusinessHandler
32 */
33 private DataNetworkHandler dataNetworkHandler = null;
34
35 /**
36 * Ftp SessionInterface
37 */
38 private FtpSession session = null;
39
40 /**
41 * Constructor with no argument (mandatory)
42 *
43 */
44 public DataBusinessHandler() {
45 // nothing to do
46 }
47
48 /**
49 * Call when the DataNetworkHandler is created
50 *
51 * @param dataNetworkHandler
52 * the dataNetworkHandler to set
53 */
54 public void setDataNetworkHandler(DataNetworkHandler dataNetworkHandler) {
55 this.dataNetworkHandler = dataNetworkHandler;
56 }
57
58 /**
59 * @return the dataNetworkHandler
60 */
61 public DataNetworkHandler getDataNetworkHandler() {
62 return dataNetworkHandler;
63 }
64
65 /**
66 * Called when the connection is opened
67 *
68 * @param session
69 * the session to set
70 */
71 public void setFtpSession(FtpSession session) {
72 this.session = session;
73 }
74
75 // Some helpful functions
76 /**
77 *
78 * @return the ftpSession
79 */
80 public FtpSession getFtpSession() {
81 return session;
82 }
83
84 /**
85 * Is executed when the channel is closed, just before the test on the finish status.
86 */
87 public abstract void executeChannelClosed();
88
89 /**
90 * To Clean the session attached objects for Data Network
91 */
92 protected abstract void cleanSession();
93
94 /**
95 * Clean the DataBusinessHandler
96 *
97 */
98 public void clear() {
99 cleanSession();
100 }
101
102 /**
103 * Is executed when the channel is connected after the handler is on, before answering OK or not
104 * on connection, except if the global service is going to shutdown.
105 *
106 * @param channel
107 */
108 public abstract void executeChannelConnected(Channel channel);
109
110 /**
111 * Run when an exception is get before the channel is closed.
112 *
113 * @param e
114 */
115 public abstract void exceptionLocalCaught(Throwable e);
116 }