Subversion Repositories Programming Utils

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
86 rm5248 1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements.  See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership.  The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License.  You may obtain a copy of the License at
9
 *
10
 *   http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied.  See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 */
19
package org.apache.sshd.common.io;
20
 
21
import java.net.SocketAddress;
22
 
23
import org.apache.sshd.common.Closeable;
24
import org.apache.sshd.common.future.CloseFuture;
25
import org.apache.sshd.common.util.Buffer;
26
 
27
public interface IoSession extends Closeable {
28
 
29
    /**
30
     * Returns a unique identifier for this session.  Every session has its own
31
     * ID which is different from each other.
32
     */
33
    long getId();
34
 
35
    /**
36
     * Returns the value of the user-defined attribute of this session.
37
     *
38
     * @param key the key of the attribute
39
     * @return <tt>null</tt> if there is no attribute with the specified key
40
     */
41
    Object getAttribute(Object key);
42
 
43
    /**
44
     * Sets a user-defined attribute.
45
     *
46
     * @param key   the key of the attribute
47
     * @param value the value of the attribute
48
     * @return The old value of the attribute.  <tt>null</tt> if it is new.
49
     */
50
    Object setAttribute(Object key, Object value);
51
 
52
    /**
53
     * Returns the socket address of remote peer.
54
     */
55
    SocketAddress getRemoteAddress();
56
 
57
    /**
58
     * Returns the socket address of local machine which is associated with this
59
     * session.
60
     */
61
    SocketAddress getLocalAddress();
62
 
63
    /**
64
     * Write a packet on the socket.
65
     * Multiple writes can be issued concurrently and will be queued.
66
     */
67
    IoWriteFuture write(Buffer buffer);
68
 
69
 
70
    /**
71
     * Closes this session immediately or after all queued write requests
72
     * are flushed.  This operation is asynchronous.  Wait for the returned
73
     * {@link CloseFuture} if you want to wait for the session actually closed.
74
     *
75
     * @param immediately {@code true} to close this session immediately.
76
     *                    The pending write requests will simply be discarded.
77
     *                    {@code false} to close this session after all queued
78
     *                    write requests are flushed.
79
     */
80
    CloseFuture close(boolean immediately);
81
 
82
    /**
83
     * Returns the IoService that created this session.
84
     */
85
    IoService getService();
86
}