1 /*
2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26
27 package sun.security.ssl;
28
29 import java.util.Enumeration;
30 import java.util.Vector;
31 import java.util.Locale;
32
33 import javax.net.ssl.SSLSession;
34 import javax.net.ssl.SSLSessionContext;
35
36 import sun.security.util.Cache;
37
38
39 final class SSLSessionContextImpl implements SSLSessionContext {
40 private Cache<SessionId, SSLSessionImpl> sessionCache;
41 // session cache, session id as key
42 private Cache<String, SSLSessionImpl> sessionHostPortCache;
43 // session cache, "host:port" as key
44 private int cacheLimit; // the max cache size
45 private int timeout; // timeout in seconds
46
47 // package private
48 SSLSessionContextImpl() {
49 cacheLimit = getDefaultCacheLimit(); // default cache size
50 timeout = 86400; // default, 24 hours
51
52 // use soft reference
53 sessionCache = Cache.newSoftMemoryCache(cacheLimit, timeout);
54 sessionHostPortCache = Cache.newSoftMemoryCache(cacheLimit, timeout);
55 }
233 Vector<byte[]> ids = null;
234
235 // public void visit(java.util.Map<K,V> map) {}
236 @Override
237 public void visit(java.util.Map<SessionId, SSLSessionImpl> map) {
238 ids = new Vector<>(map.size());
239
240 for (SessionId key : map.keySet()) {
241 SSLSessionImpl value = map.get(key);
242 if (!isTimedout(value)) {
243 ids.addElement(key.getId());
244 }
245 }
246 }
247
248 public Enumeration<byte[]> getSessionIds() {
249 return ids != null ? ids.elements() :
250 new Vector<byte[]>().elements();
251 }
252 }
253
254 }
|
1 /*
2 * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.security.ssl;
27
28 import java.util.Enumeration;
29 import java.util.Locale;
30 import java.util.Vector;
31 import javax.net.ssl.SSLSession;
32 import javax.net.ssl.SSLSessionContext;
33 import sun.security.util.Cache;
34
35
36 final class SSLSessionContextImpl implements SSLSessionContext {
37 private Cache<SessionId, SSLSessionImpl> sessionCache;
38 // session cache, session id as key
39 private Cache<String, SSLSessionImpl> sessionHostPortCache;
40 // session cache, "host:port" as key
41 private int cacheLimit; // the max cache size
42 private int timeout; // timeout in seconds
43
44 // package private
45 SSLSessionContextImpl() {
46 cacheLimit = getDefaultCacheLimit(); // default cache size
47 timeout = 86400; // default, 24 hours
48
49 // use soft reference
50 sessionCache = Cache.newSoftMemoryCache(cacheLimit, timeout);
51 sessionHostPortCache = Cache.newSoftMemoryCache(cacheLimit, timeout);
52 }
230 Vector<byte[]> ids = null;
231
232 // public void visit(java.util.Map<K,V> map) {}
233 @Override
234 public void visit(java.util.Map<SessionId, SSLSessionImpl> map) {
235 ids = new Vector<>(map.size());
236
237 for (SessionId key : map.keySet()) {
238 SSLSessionImpl value = map.get(key);
239 if (!isTimedout(value)) {
240 ids.addElement(key.getId());
241 }
242 }
243 }
244
245 public Enumeration<byte[]> getSessionIds() {
246 return ids != null ? ids.elements() :
247 new Vector<byte[]>().elements();
248 }
249 }
250 }
|