View Javadoc

1   /*
2    * Copyright 2014 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. 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, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  
17  package org.jboss.netty.handler.ssl;
18  
19  import org.apache.tomcat.jni.SSLContext;
20  
21  /**
22   * Stats exposed by an OpenSSL session context.
23   *
24   * @see <a href="https://www.openssl.org/docs/ssl/SSL_CTX_sess_number.html"><code>SSL_CTX_sess_number</code></a>
25   */
26  public final class OpenSslSessionStats {
27  
28      private final long context;
29  
30      OpenSslSessionStats(long context) {
31          this.context = context;
32      }
33  
34      /**
35       * Returns the current number of sessions in the internal session cache.
36       */
37      public long number() {
38          return SSLContext.sessionNumber(context);
39      }
40  
41      /**
42       * Returns the number of started SSL/TLS handshakes in client mode.
43       */
44      public long connect() {
45          return SSLContext.sessionConnect(context);
46      }
47  
48      /**
49       * Returns the number of successfully established SSL/TLS sessions in client mode.
50       */
51      public long connectGood() {
52          return SSLContext.sessionConnectGood(context);
53      }
54  
55      /**
56       * Returns the number of start renegotiations in client mode.
57       */
58      public long connectRenegotiate() {
59          return SSLContext.sessionConnectRenegotiate(context);
60      }
61  
62      /**
63       * Returns the number of started SSL/TLS handshakes in server mode.
64       */
65      public long accept() {
66          return SSLContext.sessionAccept(context);
67      }
68  
69      /**
70       * Returns the number of successfully established SSL/TLS sessions in server mode.
71       */
72      public long acceptGood() {
73          return SSLContext.sessionAcceptGood(context);
74      }
75  
76      /**
77       * Returns the number of start renegotiations in server mode.
78       */
79      public long acceptRenegotiate() {
80          return SSLContext.sessionAcceptRenegotiate(context);
81      }
82  
83      /**
84       * Returns the number of successfully reused sessions. In client mode, a session set with {@code SSL_set_session}
85       * successfully reused is counted as a hit. In server mode, a session successfully retrieved from internal or
86       * external cache is counted as a hit.
87       */
88      public long hits() {
89          return SSLContext.sessionHits(context);
90      }
91  
92      /**
93       * Returns the number of successfully retrieved sessions from the external session cache in server mode.
94       */
95      public long cbHits() {
96          return SSLContext.sessionCbHits(context);
97      }
98  
99      /**
100      * Returns the number of sessions proposed by clients that were not found in the internal session cache
101      * in server mode.
102      */
103     public long misses() {
104         return SSLContext.sessionMisses(context);
105     }
106 
107     /**
108      * Returns the number of sessions proposed by clients and either found in the internal or external session cache
109      * in server mode, but that were invalid due to timeout. These sessions are not included in the {@link #hits()}
110      * count.
111      */
112     public long timeouts() {
113         return SSLContext.sessionTimeouts(context);
114     }
115 
116     /**
117      * Returns the number of sessions that were removed because the maximum session cache size was exceeded.
118      */
119     public long cacheFull() {
120         return SSLContext.sessionCacheFull(context);
121     }
122 }