View Javadoc

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