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