jdk/src/java.base/share/classes/sun/misc/Signal.java
author lana
Thu, 07 Apr 2016 10:07:01 -0700
changeset 36987 7c3239397d1b
parent 36009 2dbdf909ac81
permissions -rw-r--r--
Added tag jdk-9+113 for changeset b54f0a474ea2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
36009
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
     2
 * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.misc;
36009
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
    27
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
    28
import java.util.Objects;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * This class provides ANSI/ISO C signal support. A Java program can register
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * signal handlers for the current process. There are two restrictions:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Java code cannot register a handler for signals that are already used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * by the Java VM implementation. The <code>Signal.handle</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * function raises an <code>IllegalArgumentException</code> if such an attempt
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * is made.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * When <code>Signal.handle</code> is called, the VM internally registers a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * special C signal handler. There is no way to force the Java signal handler
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * to run synchronously before the C signal handler returns. Instead, when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * VM receives a signal, the special C signal handler creates a new thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * (at priority <code>Thread.MAX_PRIORITY</code>) to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * run the registered Java signal handler. The C signal handler immediately
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * returns. Note that because the Java signal handler runs in a newly created
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * thread, it may not actually be executed until some time after the C signal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * handler returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * Signal objects are created based on their names. For example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * new Signal("INT");
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 29919
diff changeset
    54
 * </pre></blockquote>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * constructs a signal object corresponding to <code>SIGINT</code>, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * typically produced when the user presses <code>Ctrl-C</code> at the command line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * The <code>Signal</code> constructor throws <code>IllegalArgumentException</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * when it is passed an unknown signal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * This is an example of how Java code handles <code>SIGINT</code>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * SignalHandler handler = new SignalHandler () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *     public void handle(Signal sig) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *       ... // handle SIGINT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * Signal.handle(new Signal("INT"), handler);
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 29919
diff changeset
    68
 * </pre></blockquote>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * @author   Sheng Liang
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * @author   Bill Shannon
36009
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
    72
 * @see     sun.misc.SignalHandler
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * @since    1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
public final class Signal {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
36009
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
    77
    // Delegate to jdk.internal.misc.Signal.
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
    78
    private final jdk.internal.misc.Signal iSignal;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /* Returns the signal number */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public int getNumber() {
36009
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
    82
        return iSignal.getNumber();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Returns the signal name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @return the name of the signal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @see sun.misc.Signal#Signal(String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public String getName() {
36009
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
    92
        return iSignal.getName();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Compares the equality of two <code>Signal</code> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @param other the object to compare with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @return whether two <code>Signal</code> objects are equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public boolean equals(Object other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        if (this == other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        if (other == null || !(other instanceof Signal)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        Signal other1 = (Signal)other;
36009
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   109
        return iSignal.equals(other1.iSignal);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Returns a hashcode for this Signal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @return  a hash code value for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public int hashCode() {
36009
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   118
        return getNumber();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Returns a string representation of this signal. For example, "SIGINT"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * for an object constructed using <code>new Signal ("INT")</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @return a string representation of the signal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public String toString() {
36009
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   128
        return iSignal.toString();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * Constructs a signal from its name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @param name the name of the signal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @exception IllegalArgumentException unknown signal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @see sun.misc.Signal#getName()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public Signal(String name) {
36009
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   139
        iSignal = new jdk.internal.misc.Signal(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * Registers a signal handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @param sig a signal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @param handler the handler to be registered with the given signal.
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 29919
diff changeset
   147
     * @return the old handler
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @exception IllegalArgumentException the signal is in use by the VM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @see sun.misc.Signal#raise(Signal sig)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @see sun.misc.SignalHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @see sun.misc.SignalHandler#SIG_DFL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @see sun.misc.SignalHandler#SIG_IGN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public static synchronized SignalHandler handle(Signal sig,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                                                    SignalHandler handler)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        throws IllegalArgumentException {
36009
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   157
        jdk.internal.misc.Signal.Handler oldHandler = jdk.internal.misc.Signal.handle(sig.iSignal,
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   158
                InternalMiscHandler.of(sig, handler));
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   159
        return SunMiscHandler.of(sig.iSignal, oldHandler);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * Raises a signal in the current process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @param sig a signal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @see sun.misc.Signal#handle(Signal sig, SignalHandler handler)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public static void raise(Signal sig) throws IllegalArgumentException {
36009
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   169
        jdk.internal.misc.Signal.raise(sig.iSignal);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
36009
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   172
    /*
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   173
     * Wrapper class to proxy a SignalHandler to a jdk.internal.misc.Signal.Handler.
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   174
     */
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   175
    static final class InternalMiscHandler implements jdk.internal.misc.Signal.Handler {
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   176
        private final SignalHandler handler;
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   177
        private final Signal signal;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
36009
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   179
        static jdk.internal.misc.Signal.Handler of(Signal signal, SignalHandler handler) {
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   180
            if (handler == SignalHandler.SIG_DFL) {
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   181
                return jdk.internal.misc.Signal.Handler.SIG_DFL;
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   182
            } else if (handler == SignalHandler.SIG_IGN) {
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   183
                return jdk.internal.misc.Signal.Handler.SIG_IGN;
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   184
            } else if (handler instanceof SunMiscHandler) {
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   185
                return ((SunMiscHandler)handler).iHandler;
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   186
            } else {
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   187
                return new InternalMiscHandler(signal, handler);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            }
36009
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   189
        }
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   190
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   191
        private InternalMiscHandler(Signal signal, SignalHandler handler) {
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   192
            this.handler = handler;
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   193
            this.signal = signal;
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   194
        }
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   195
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   196
        @Override
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   197
        public void handle(jdk.internal.misc.Signal ignore) {
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   198
            handler.handle(signal);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
36009
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   202
    /*
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   203
     * Wrapper class to proxy a jdk.internal.misc.Signal.Handler to a SignalHandler.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     */
36009
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   205
    static final class SunMiscHandler implements SignalHandler {
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   206
        private final jdk.internal.misc.Signal iSignal;
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   207
        private final jdk.internal.misc.Signal.Handler iHandler;
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   208
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   209
        static SignalHandler of(jdk.internal.misc.Signal signal, jdk.internal.misc.Signal.Handler handler) {
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   210
            if (handler == jdk.internal.misc.Signal.Handler.SIG_DFL) {
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   211
                return SignalHandler.SIG_DFL;
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   212
            } else if (handler == jdk.internal.misc.Signal.Handler.SIG_IGN) {
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   213
                return SignalHandler.SIG_IGN;
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   214
            } else if (handler instanceof InternalMiscHandler) {
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   215
                return ((InternalMiscHandler) handler).handler;
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   216
            } else {
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   217
                return new SunMiscHandler(signal, handler);
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   218
            }
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   219
        }
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   220
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   221
        SunMiscHandler(jdk.internal.misc.Signal iSignal, jdk.internal.misc.Signal.Handler iHandler) {
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   222
            this.iSignal = iSignal;
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   223
            this.iHandler = iHandler;
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   224
        }
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   225
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   226
        @Override
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   227
        public void handle(Signal sig) {
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   228
            iHandler.handle(iSignal);
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   229
        }
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   230
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   231
        public String toString() {
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   232
            return iHandler.toString();
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   233
        }
2dbdf909ac81 8149750: Decouple sun.misc.Signal from the base module
rriggs
parents: 34716
diff changeset
   234
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
}