Project

General

Profile

context_local_jmx.patch

Alexandru Lungu, 02/16/2023 05:28 AM

Download (6.55 KB)

View differences:

new/src/com/goldencode/p2j/jmx/NanoTimer.java 2023-02-16 10:23:10 +0000
109 109
   {
110 110
       start = System.nanoTime();
111 111
   }
112
   
112 113
   /** Stop operation and update counter */
113 114
   public void stop()
114 115
   {
......
158 159
           stop();
159 160
       }
160 161
   }
162

  
163
   /**
164
    * Execute operation and measure execution time
165
    * 
166
    * @param   <T> 
167
    *          The type of the return value for the operation to be executed.
168
    * @param   r
169
    *          operation to be executed
170
    *        
171
    * @return  The result of the operation to be executed
172
    */
173
   public <T> T timerWithReturn(ReturningOperation<T> r)
174
   {
175
       if (!enabled)
176
       {
177
           try
178
           {
179
              return r.exec();
180
           } 
181
           catch (RuntimeException re)
182
           {
183
              // unchecked exception propagate as is.  otherwise, we can't process ConditionException.
184
              throw re;
185
           }
186
           catch (Exception e)
187
           {
188
              throw new RuntimeException(e);
189
           }
190
       }
191
       start();
192
       try
193
       {
194
          return r.exec();
195
       }
196
       catch (RuntimeException re)
197
       {
198
          // unchecked exception propagate as is.  otherwise, we can't process ConditionException.
199
          throw re;
200
       }
201
       catch (Exception e)
202
       {
203
          throw new RuntimeException(e);
204
       }
205
       finally
206
       {
207
           stop();
208
       }
209
   }
161 210
}
new/src/com/goldencode/p2j/jmx/ReturningOperation.java 2023-02-16 10:24:40 +0000
1
/*
2
** Module   : ReturningOperation.java
3
** Abstract : Functional interface for operations which may throw exceptions and return a value
4
** ("Supplier with exceptions")  
5
**
6
** Copyright (c) 2023, Golden Code Development Corporation.
7
**
8
** -#- -I- --Date-- ---------------------------------Description----------------------------------
9
** 001 AL2 20220216 Created initial version.
10

  
11
*/ 
12

  
13
/*
14
** This program is free software: you can redistribute it and/or modify
15
** it under the terms of the GNU Affero General Public License as
16
** published by the Free Software Foundation, either version 3 of the
17
** License, or (at your option) any later version.
18
**
19
** This program is distributed in the hope that it will be useful,
20
** but WITHOUT ANY WARRANTY; without even the implied warranty of
21
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
** GNU Affero General Public License for more details.
23
**
24
** You may find a copy of the GNU Affero GPL version 3 at the following
25
** location: https://www.gnu.org/licenses/agpl-3.0.en.html
26
** 
27
** Additional terms under GNU Affero GPL version 3 section 7:
28
** 
29
**   Under Section 7 of the GNU Affero GPL version 3, the following additional
30
**   terms apply to the works covered under the License.  These additional terms
31
**   are non-permissive additional terms allowed under Section 7 of the GNU
32
**   Affero GPL version 3 and may not be removed by you.
33
** 
34
**   0. Attribution Requirement.
35
** 
36
**     You must preserve all legal notices or author attributions in the covered
37
**     work or Appropriate Legal Notices displayed by works containing the covered
38
**     work.  You may not remove from the covered work any author or developer
39
**     credit already included within the covered work.
40
** 
41
**   1. No License To Use Trademarks.
42
** 
43
**     This license does not grant any license or rights to use the trademarks
44
**     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
45
**     of Golden Code Development Corporation. You are not authorized to use the
46
**     name Golden Code, FWD, or the names of any author or contributor, for
47
**     publicity purposes without written authorization.
48
** 
49
**   2. No Misrepresentation of Affiliation.
50
** 
51
**     You may not represent yourself as Golden Code Development Corporation or FWD.
52
** 
53
**     You may not represent yourself for publicity purposes as associated with
54
**     Golden Code Development Corporation, FWD, or any author or contributor to
55
**     the covered work, without written authorization.
56
** 
57
**   3. No Misrepresentation of Source or Origin.
58
** 
59
**     You may not represent the covered work as solely your work.  All modified
60
**     versions of the covered work must be marked in a reasonable way to make it
61
**     clear that the modified work is not originating from Golden Code Development
62
**     Corporation or FWD.  All modified versions must contain the notices of
63
**     attribution required in this license.
64
*/
65

  
66
package com.goldencode.p2j.jmx;
67

  
68
/** 
69
 * Functional interface for operations which may throw exceptions and return a value 
70
 */
71
@FunctionalInterface
72
public interface ReturningOperation<T>
73
{
74
   /**
75
    * Execute operation
76
    * 
77
    * @return  The supplied value.
78
    * @throws  Exception
79
    */
80
   public T exec() 
81
   throws Exception;
82
}
new/src/com/goldencode/p2j/security/ContextLocal.java 2023-02-16 10:26:07 +0000
2 2
** Module   : ContextLocal.java
3 3
** Abstract : Container for a context local variable, using the ThreadLocal idiom
4 4
**
5
** Copyright (c) 2006-2022, Golden Code Development Corporation.
5
** Copyright (c) 2006-2023, Golden Code Development Corporation.
6 6
**
7 7
** -#- -I- --Date-- --JPRM-- ----------------------------------Description-----------------------------------
8 8
** 001 ECF 20060120   @24009 Created initial version. Contains a context
......
73 73
**                           an uninitialized thread-local variable. initialValue() is only invoked once for
74 74
**                           a thread-local, unless remove() is called.
75 75
**     CA  20221031          Added JMX instrumentation for the 'get()' method.
76
**     AL2 20230216          Avoid using an array to store the return value of the JMX instrumentation 
76 77
*/
77 78

  
78 79
/*
......
454 455
    * @return  Context local variable.
455 456
    */
456 457
   public final T get(boolean create)
457
   {
458
      Object[] res = new Object[1];
459
      
460
      GET.timer(() -> res[0] = getImpl(create));
461
      
462
      return (T) res[0];
458
   {      
459
      return GET.timerWithReturn(() -> getImpl(create));
463 460
   }
464 461
   
465 462
   /**