1/*
2 * Copyright 2007 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.mockftpserver.core.session;
17
18import java.net.InetAddress;
19import java.util.Set;
20
21/**
22 * Represents an FTP session state and behavior
23 *
24 * @version $Revision$ - $Date$
25 *
26 * @author Chris Mair
27 */
28public interface Session extends Runnable {
29
30    /**
31     * Close the session, closing the underlying sockets
32     */
33    public void close();
34
35    /**
36     * Send the specified reply code and text across the control connection.
37     *
38     * @param replyCode - the reply code
39     * @param replyText - the reply text to send; may be null
40     */
41    public void sendReply(int replyCode, String replyText);
42
43    /**
44     * Open the data connection, attaching to the predefined port number on the client
45     */
46    public void openDataConnection();
47
48    /**
49     * Close the data connection
50     */
51    public void closeDataConnection();
52
53    /**
54     * Switch to passive mode
55     * @return the local port to be connected to by clients for data transfers
56     */
57    public int switchToPassiveMode();
58
59    /**
60     * Write the specified data using the data connection
61     *
62     * @param data - the data to write
63     * @param numBytes - the number of bytes from data to send
64     */
65    public void sendData(byte[] data, int numBytes);
66
67    /**
68     * Read data from the client across the data connection
69     *
70     * @return the data that was read
71     */
72    public byte[] readData();
73
74    /**
75     * Return the InetAddress representing the client host for this session
76     * @return the client host
77     */
78    public InetAddress getClientHost();
79
80    /**
81     * Return the InetAddress representing the server host for this session
82     * @return the server host
83     */
84    public InetAddress getServerHost();
85
86    /**
87     * @param clientHost - the client host for the data connection
88     */
89    public void setClientDataHost(InetAddress clientHost);
90
91    /**
92     * @param clientDataPort - the port number on the client side for the data connection
93     */
94    public void setClientDataPort(int clientDataPort);
95
96    /**
97     * Return the attribute value for the specified name. Return null if no attribute value
98     * exists for that name or if the attribute value is null.
99     * @param name - the attribute name; may not be null
100     * @return the value of the attribute stored under name; may be null
101     * @throws AssertFailedException - if name is null
102     */
103    public Object getAttribute(String name);
104
105    /**
106     * Store the value under the specified attribute name.
107     * @param name - the attribute name; may not be null
108     * @param value - the attribute value; may be null
109     * @throws AssertFailedException - if name is null
110     */
111    public void setAttribute(String name, Object value);
112
113    /**
114     * Remove the attribute value for the specified name. Do nothing if no attribute
115     * value is stored for the specified name.
116     * @param name - the attribute name; may not be null
117     * @throws AssertFailedException - if name is null
118     */
119    public void removeAttribute(String name);
120
121    /**
122     * Return the Set of names under which attributes have been stored on this session.
123     * Returns an empty Set if no attribute values are stored.
124     * @return the Set of attribute names
125     */
126    public Set getAttributeNames();
127
128}