3030@ InterfaceAudience .Private
3131public class SignalUtil {
3232
33- static final Class <?> jdkSignalClazz =
33+ static final Class <?> JDK_SIGNAL_CLAZZ =
3434 BindingUtils .loadClassSafely ("sun.misc.Signal" );
35- static final Class <?> jdkSignalHandlerClazz =
35+ static final Class <?> JDK_SIGNAL_HANDLER_CLAZZ =
3636 BindingUtils .loadClassSafely ("sun.misc.SignalHandler" );
3737
38- static DynConstructors .Ctor <?> jdkSignalCtor =
38+ static final DynConstructors .Ctor <?> JDK_SIGNAL_CTOR =
3939 new DynConstructors .Builder ()
40- .impl (jdkSignalClazz , String .class )
40+ .impl (JDK_SIGNAL_CLAZZ , String .class )
4141 .build ();
4242
43- static DynMethods .StaticMethod jdkSignalHandleStaticMethod =
43+ static final DynMethods .StaticMethod JDK_SIGNAL_HANDLE_STATIC_METHOD =
4444 new DynMethods .Builder ("handle" )
45- .impl (jdkSignalClazz , jdkSignalClazz , jdkSignalHandlerClazz )
45+ .impl (JDK_SIGNAL_CLAZZ , JDK_SIGNAL_CLAZZ , JDK_SIGNAL_HANDLER_CLAZZ )
4646 .buildStatic ();
4747
48- static DynMethods .StaticMethod jdkSignalRaiseStaticMethod =
48+ static final DynMethods .StaticMethod JDK_SIGNAL_RAISE_STATIC_METHOD =
4949 new DynMethods .Builder ("raise" )
50- .impl (jdkSignalClazz , jdkSignalClazz )
50+ .impl (JDK_SIGNAL_CLAZZ , JDK_SIGNAL_CLAZZ )
5151 .buildStatic ();
5252
53- static DynMethods .UnboundMethod jdkSignalHandlerHandleUnboundMethod =
53+ static final DynMethods .UnboundMethod JDK_SIGNAL_HANDLER_HANDLE_UNBOUND_METHOD =
5454 new DynMethods .Builder ("handle" )
55- .impl (jdkSignalHandlerClazz , jdkSignalClazz )
55+ .impl (JDK_SIGNAL_HANDLER_CLAZZ , JDK_SIGNAL_CLAZZ )
5656 .build ();
5757
5858 @ InterfaceAudience .Private
5959 public static class Signal {
60- private static final DynMethods .UnboundMethod getNumberUnboundMethod =
61- new DynMethods .Builder ("getNumber" ).impl (jdkSignalClazz ).build ();
60+ private static final DynMethods .UnboundMethod GET_NUMBER_UNBOUND_METHOD =
61+ new DynMethods .Builder ("getNumber" ).impl (JDK_SIGNAL_CLAZZ ).build ();
6262
63- private static final DynMethods .UnboundMethod getNameUnboundMethod =
64- new DynMethods .Builder ("getName" ).impl (jdkSignalClazz ).build ();
63+ private static final DynMethods .UnboundMethod GET_NAME_UNBOUND_METHOD =
64+ new DynMethods .Builder ("getName" ).impl (JDK_SIGNAL_CLAZZ ).build ();
6565
6666 private final Object delegate ;
6767 private final DynMethods .BoundMethod getNumberMethod ;
6868 private final DynMethods .BoundMethod getNameMethod ;
6969
7070 public Signal (String name ) {
7171 Preconditions .checkNotNull (name );
72- this .delegate = jdkSignalCtor .newInstance (name );
73- this .getNumberMethod = getNumberUnboundMethod .bind (delegate );
74- this .getNameMethod = getNameUnboundMethod .bind (delegate );
72+ this .delegate = JDK_SIGNAL_CTOR .newInstance (name );
73+ this .getNumberMethod = GET_NUMBER_UNBOUND_METHOD .bind (delegate );
74+ this .getNameMethod = GET_NAME_UNBOUND_METHOD .bind (delegate );
7575 }
7676
7777 public Signal (Object delegate ) {
78- Preconditions .checkArgument (jdkSignalClazz .isInstance (delegate ),
78+ Preconditions .checkArgument (JDK_SIGNAL_CLAZZ .isInstance (delegate ),
7979 String .format ("Expected class is '%s', but actual class is '%s'" ,
80- jdkSignalClazz .getName (), delegate .getClass ().getName ()));
80+ JDK_SIGNAL_CLAZZ .getName (), delegate .getClass ().getName ()));
8181 this .delegate = delegate ;
82- this .getNumberMethod = getNumberUnboundMethod .bind (delegate );
83- this .getNameMethod = getNameUnboundMethod .bind (delegate );
82+ this .getNumberMethod = GET_NUMBER_UNBOUND_METHOD .bind (delegate );
83+ this .getNameMethod = GET_NAME_UNBOUND_METHOD .bind (delegate );
8484 }
8585
8686 public int getNumber () {
@@ -123,26 +123,28 @@ static class JdkSignalHandlerImpl implements Handler {
123123 JdkSignalHandlerImpl (Handler handler ) {
124124 this .delegate = Proxy .newProxyInstance (
125125 getClass ().getClassLoader (),
126- new Class <?>[] { jdkSignalHandlerClazz },
126+ new Class <?>[] {JDK_SIGNAL_HANDLER_CLAZZ },
127127 (proxyObj , method , args ) -> {
128- if ("handle" .equals (method .getName ()) && args .length == 1 && jdkSignalClazz .isInstance (args [0 ])) {
128+ if ("handle" .equals (method .getName ()) && args .length == 1
129+ && JDK_SIGNAL_CLAZZ .isInstance (args [0 ])) {
129130 handler .handle (new Signal (args [0 ]));
130131 return null ;
131132 } else {
132- Method delegateMethod = Handler .class .getMethod (method .getName (), method .getParameterTypes ());
133+ Method delegateMethod = Handler .class .getMethod (
134+ method .getName (), method .getParameterTypes ());
133135 return delegateMethod .invoke (handler , args );
134136 }
135137 }
136138 );
137- this .jdkSignalHandlerHandleMethod = jdkSignalHandlerHandleUnboundMethod .bind (delegate );
139+ this .jdkSignalHandlerHandleMethod = JDK_SIGNAL_HANDLER_HANDLE_UNBOUND_METHOD .bind (delegate );
138140 }
139141
140142 JdkSignalHandlerImpl (Object delegate ) {
141- Preconditions .checkArgument (jdkSignalHandlerClazz .isInstance (delegate ),
143+ Preconditions .checkArgument (JDK_SIGNAL_HANDLER_CLAZZ .isInstance (delegate ),
142144 String .format ("Expected class is '%s', but actual class is '%s'" ,
143- jdkSignalHandlerClazz .getName (), delegate .getClass ().getName ()));
145+ JDK_SIGNAL_HANDLER_CLAZZ .getName (), delegate .getClass ().getName ()));
144146 this .delegate = delegate ;
145- this .jdkSignalHandlerHandleMethod = jdkSignalHandlerHandleUnboundMethod .bind (delegate );
147+ this .jdkSignalHandlerHandleMethod = JDK_SIGNAL_HANDLER_HANDLE_UNBOUND_METHOD .bind (delegate );
146148 }
147149
148150 @ Override
@@ -152,12 +154,12 @@ public void handle(Signal sig) {
152154 }
153155
154156 public static Handler handle (Signal sig , Handler handler ) {
155- Object preHandle = jdkSignalHandleStaticMethod .invoke (
157+ Object preHandle = JDK_SIGNAL_HANDLE_STATIC_METHOD .invoke (
156158 sig .delegate , new JdkSignalHandlerImpl (handler ).delegate );
157159 return new JdkSignalHandlerImpl (preHandle );
158160 }
159161
160162 public static void raise (Signal sig ) throws IllegalArgumentException {
161- jdkSignalRaiseStaticMethod .invoke (sig .delegate );
163+ JDK_SIGNAL_RAISE_STATIC_METHOD .invoke (sig .delegate );
162164 }
163165}
0 commit comments