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 io.netty.util.internal;
18  
19  import io.netty.util.concurrent.FastThreadLocal;
20  
21  import java.nio.charset.Charset;
22  import java.nio.charset.CharsetDecoder;
23  import java.nio.charset.CharsetEncoder;
24  import java.util.ArrayList;
25  import java.util.Map;
26  import java.util.concurrent.atomic.AtomicInteger;
27  
28  /**
29   * The internal data structure that stores the thread-local variables for Netty and all {@link FastThreadLocal}s.
30   * Note that this class is for internal use only and is subject to change at any time.  Use {@link FastThreadLocal}
31   * unless you know what you are doing.
32   */
33  class UnpaddedInternalThreadLocalMap {
34  
35      static final ThreadLocal<InternalThreadLocalMap> slowThreadLocalMap = new ThreadLocal<InternalThreadLocalMap>();
36      static final AtomicInteger nextIndex = new AtomicInteger();
37  
38      /** Used by {@link FastThreadLocal} */
39      Object[] indexedVariables;
40  
41      // Core thread-locals
42      int futureListenerStackDepth;
43      int localChannelReaderStackDepth;
44      Map<Class<?>, Boolean> handlerSharableCache;
45      IntegerHolder counterHashCode;
46      ThreadLocalRandom random;
47      Map<Class<?>, TypeParameterMatcher> typeParameterMatcherGetCache;
48      Map<Class<?>, Map<String, TypeParameterMatcher>> typeParameterMatcherFindCache;
49  
50      // String-related thread-locals
51      StringBuilder stringBuilder;
52      Map<Charset, CharsetEncoder> charsetEncoderCache;
53      Map<Charset, CharsetDecoder> charsetDecoderCache;
54  
55      // ArrayList-related thread-locals
56      ArrayList<Object> arrayList;
57  
58      UnpaddedInternalThreadLocalMap(Object[] indexedVariables) {
59          this.indexedVariables = indexedVariables;
60      }
61  }