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.server.session;
20
 
21
import org.apache.sshd.common.Session;
22
import org.apache.sshd.common.SessionListener;
23
import org.slf4j.Logger;
24
import org.slf4j.LoggerFactory;
25
 
26
import java.util.Set;
27
import java.util.concurrent.CopyOnWriteArraySet;
28
 
29
/**
30
 * Task that iterates over all currently open {@link ServerSession}s and checks each of them for timeouts. If
31
 * the {@link ServerSession} has timed out (either auth or idle timeout), the session will be disconnected.
32
 *
33
 * @see org.apache.sshd.server.session.ServerSession#checkForTimeouts()
34
 */
35
public class ServerSessionTimeoutListener implements SessionListener, Runnable {
36
 
37
    private final Logger log = LoggerFactory.getLogger(ServerSessionTimeoutListener.class);
38
 
39
    private final Set<ServerSession> sessions = new CopyOnWriteArraySet<ServerSession>();
40
 
41
    public void sessionCreated(Session session) {
42
        if (session instanceof ServerSession) {
43
            sessions.add((ServerSession) session);
44
        }
45
    }
46
 
47
    public void sessionEvent(Session session, Event event) {
48
    }
49
 
50
    public void sessionClosed(Session s) {
51
        sessions.remove(s);
52
    }
53
 
54
    public void run() {
55
        for (ServerSession session : sessions) {
56
            try {
57
                session.checkForTimeouts();
58
            } catch (Exception e) {
59
                log.warn("An error occurred while checking session timeouts", e);
60
            }
61
        }
62
    }
63
}