1 /*
2 * Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
985 private final BooleanProperty running = new SimpleBooleanProperty(this, "running", false);
986 private void setRunning(boolean value) { checkThread(); running.set(value); }
987 @Override public final boolean isRunning() { checkThread(); return running.get(); }
988 @Override public final ReadOnlyBooleanProperty runningProperty() { checkThread(); return running; }
989
990 private final StringProperty message = new SimpleStringProperty(this, "message", "");
991 @Override public final String getMessage() { checkThread(); return message.get(); }
992 @Override public final ReadOnlyStringProperty messageProperty() { checkThread(); return message; }
993
994 private final StringProperty title = new SimpleStringProperty(this, "title", "");
995 @Override public final String getTitle() { checkThread(); return title.get(); }
996 @Override public final ReadOnlyStringProperty titleProperty() { checkThread(); return title; }
997
998 @Override public final boolean cancel() {
999 return cancel(true);
1000 }
1001
1002 // Need to assert the modifyThread permission so an app can cancel
1003 // a task that it created (the default executor for the service runs in
1004 // its own thread group)
1005 // Note that this is needed when running as an applet or a web start app.
1006 private static final Permission modifyThreadPerm = new RuntimePermission("modifyThread");
1007
1008 @Override public boolean cancel(boolean mayInterruptIfRunning) {
1009 // Delegate to the super implementation to actually attempt to cancel this thing
1010 // Assert the modifyThread permission
1011 boolean flag = AccessController.doPrivileged(
1012 (PrivilegedAction<Boolean>) () -> super.cancel(mayInterruptIfRunning),
1013 null,
1014 modifyThreadPerm);
1015
1016 // If cancel succeeded (according to the semantics of the Future cancel method),
1017 // then we need to make sure the State flag is set appropriately
1018 if (flag) {
1019 // If this method was called on the FX application thread, then we can
1020 // just update the state directly and this will make sure that after
1021 // the cancel method was called, the state will be set correctly
1022 // (otherwise it would be indeterminate). However if the cancel method was
1023 // called off the FX app thread, then we must use runLater, and the
1024 // state flag will not be readable immediately after this call. However,
1025 // that would be the case anyway since these properties are not thread-safe.
|
1 /*
2 * Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
985 private final BooleanProperty running = new SimpleBooleanProperty(this, "running", false);
986 private void setRunning(boolean value) { checkThread(); running.set(value); }
987 @Override public final boolean isRunning() { checkThread(); return running.get(); }
988 @Override public final ReadOnlyBooleanProperty runningProperty() { checkThread(); return running; }
989
990 private final StringProperty message = new SimpleStringProperty(this, "message", "");
991 @Override public final String getMessage() { checkThread(); return message.get(); }
992 @Override public final ReadOnlyStringProperty messageProperty() { checkThread(); return message; }
993
994 private final StringProperty title = new SimpleStringProperty(this, "title", "");
995 @Override public final String getTitle() { checkThread(); return title.get(); }
996 @Override public final ReadOnlyStringProperty titleProperty() { checkThread(); return title; }
997
998 @Override public final boolean cancel() {
999 return cancel(true);
1000 }
1001
1002 // Need to assert the modifyThread permission so an app can cancel
1003 // a task that it created (the default executor for the service runs in
1004 // its own thread group)
1005 // Note that this is needed when running with a security manager.
1006 private static final Permission modifyThreadPerm = new RuntimePermission("modifyThread");
1007
1008 @Override public boolean cancel(boolean mayInterruptIfRunning) {
1009 // Delegate to the super implementation to actually attempt to cancel this thing
1010 // Assert the modifyThread permission
1011 boolean flag = AccessController.doPrivileged(
1012 (PrivilegedAction<Boolean>) () -> super.cancel(mayInterruptIfRunning),
1013 null,
1014 modifyThreadPerm);
1015
1016 // If cancel succeeded (according to the semantics of the Future cancel method),
1017 // then we need to make sure the State flag is set appropriately
1018 if (flag) {
1019 // If this method was called on the FX application thread, then we can
1020 // just update the state directly and this will make sure that after
1021 // the cancel method was called, the state will be set correctly
1022 // (otherwise it would be indeterminate). However if the cancel method was
1023 // called off the FX app thread, then we must use runLater, and the
1024 // state flag will not be readable immediately after this call. However,
1025 // that would be the case anyway since these properties are not thread-safe.
|