chrismair | 00dc7bd | 2014-05-11 21:21:28 +0000 | [diff] [blame] | 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 | */
|
| 16 | package org.mockftpserver.core.session;
|
| 17 |
|
| 18 | import java.net.InetAddress;
|
| 19 | import java.util.Set;
|
| 20 |
|
| 21 | /**
|
| 22 | * Represents an FTP session state and behavior
|
| 23 | *
|
| 24 | * @version $Revision$ - $Date$
|
| 25 | *
|
| 26 | * @author Chris Mair
|
| 27 | */
|
| 28 | public 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 | * Read and return (up to) numBytes of data from the client across the data connection
|
| 76 | *
|
| 77 | * @return the data that was read; the byte[] will be up to numBytes bytes long
|
| 78 | */
|
| 79 | public byte[] readData(int numBytes);
|
| 80 |
|
| 81 | /**
|
| 82 | * Return the InetAddress representing the client host for this session
|
| 83 | * @return the client host
|
| 84 | */
|
| 85 | public InetAddress getClientHost();
|
| 86 |
|
| 87 | /**
|
| 88 | * Return the InetAddress representing the server host for this session
|
| 89 | * @return the server host
|
| 90 | */
|
| 91 | public InetAddress getServerHost();
|
| 92 |
|
| 93 | /**
|
| 94 | * @param clientHost - the client host for the data connection
|
| 95 | */
|
| 96 | public void setClientDataHost(InetAddress clientHost);
|
| 97 |
|
| 98 | /**
|
| 99 | * @param clientDataPort - the port number on the client side for the data connection
|
| 100 | */
|
| 101 | public void setClientDataPort(int clientDataPort);
|
| 102 |
|
| 103 | /**
|
| 104 | * Return the attribute value for the specified name. Return null if no attribute value
|
| 105 | * exists for that name or if the attribute value is null.
|
| 106 | * @param name - the attribute name; may not be null
|
| 107 | * @return the value of the attribute stored under name; may be null
|
| 108 | * @throws AssertFailedException - if name is null
|
| 109 | */
|
| 110 | public Object getAttribute(String name);
|
| 111 |
|
| 112 | /**
|
| 113 | * Store the value under the specified attribute name.
|
| 114 | * @param name - the attribute name; may not be null
|
| 115 | * @param value - the attribute value; may be null
|
| 116 | * @throws AssertFailedException - if name is null
|
| 117 | */
|
| 118 | public void setAttribute(String name, Object value);
|
| 119 |
|
| 120 | /**
|
| 121 | * Remove the attribute value for the specified name. Do nothing if no attribute
|
| 122 | * value is stored for the specified name.
|
| 123 | * @param name - the attribute name; may not be null
|
| 124 | * @throws AssertFailedException - if name is null
|
| 125 | */
|
| 126 | public void removeAttribute(String name);
|
| 127 |
|
| 128 | /**
|
| 129 | * Return the Set of names under which attributes have been stored on this session.
|
| 130 | * Returns an empty Set if no attribute values are stored.
|
| 131 | * @return the Set of attribute names
|
| 132 | */
|
| 133 | public Set getAttributeNames();
|
| 134 |
|
| 135 | } |