1 /*
2 * Copyright (c) 2000, 2015, 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
23 * questions.
24 */
25
26 package java.util.prefs;
27
28 import java.util.*;
29 import java.io.*;
30 import java.security.AccessController;
31 import java.security.PrivilegedAction;
32 import sun.misc.ManagedLocalsThread;
33 // These imports needed only as a workaround for a JavaDoc bug
34 import java.lang.Integer;
35 import java.lang.Long;
36 import java.lang.Float;
37 import java.lang.Double;
38
39 /**
40 * This class provides a skeletal implementation of the {@link Preferences}
41 * class, greatly easing the task of implementing it.
42 *
43 * <p><strong>This class is for {@code Preferences} implementers only.
44 * Normal users of the {@code Preferences} facility should have no need to
45 * consult this documentation. The {@link Preferences} documentation
46 * should suffice.</strong>
47 *
48 * <p>Implementors must override the nine abstract service-provider interface
49 * (SPI) methods: {@link #getSpi(String)}, {@link #putSpi(String,String)},
50 * {@link #removeSpi(String)}, {@link #childSpi(String)}, {@link
51 * #removeNodeSpi()}, {@link #keysSpi()}, {@link #childrenNamesSpi()}, {@link
52 * #syncSpi()} and {@link #flushSpi()}. All of the concrete methods specify
1498 * eventQueue so the event dispatch thread knows whether to call
1499 * childAdded or childRemoved.
1500 */
1501 private class NodeAddedEvent extends NodeChangeEvent {
1502 private static final long serialVersionUID = -6743557530157328528L;
1503 NodeAddedEvent(Preferences parent, Preferences child) {
1504 super(parent, child);
1505 }
1506 }
1507 private class NodeRemovedEvent extends NodeChangeEvent {
1508 private static final long serialVersionUID = 8735497392918824837L;
1509 NodeRemovedEvent(Preferences parent, Preferences child) {
1510 super(parent, child);
1511 }
1512 }
1513
1514 /**
1515 * A single background thread ("the event notification thread") monitors
1516 * the event queue and delivers events that are placed on the queue.
1517 */
1518 private static class EventDispatchThread extends ManagedLocalsThread {
1519 public void run() {
1520 while(true) {
1521 // Wait on eventQueue till an event is present
1522 EventObject event = null;
1523 synchronized(eventQueue) {
1524 try {
1525 while (eventQueue.isEmpty())
1526 eventQueue.wait();
1527 event = eventQueue.remove(0);
1528 } catch (InterruptedException e) {
1529 // XXX Log "Event dispatch thread interrupted. Exiting"
1530 return;
1531 }
1532 }
1533
1534 // Now we have event & hold no locks; deliver evt to listeners
1535 AbstractPreferences src=(AbstractPreferences)event.getSource();
1536 if (event instanceof PreferenceChangeEvent) {
1537 PreferenceChangeEvent pce = (PreferenceChangeEvent)event;
1538 PreferenceChangeListener[] listeners = src.prefListeners();
|
1 /*
2 * Copyright (c) 2000, 2016, 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
23 * questions.
24 */
25
26 package java.util.prefs;
27
28 import java.util.*;
29 import java.io.*;
30 import java.security.AccessController;
31 import java.security.PrivilegedAction;
32 // These imports needed only as a workaround for a JavaDoc bug
33 import java.lang.Integer;
34 import java.lang.Long;
35 import java.lang.Float;
36 import java.lang.Double;
37
38 /**
39 * This class provides a skeletal implementation of the {@link Preferences}
40 * class, greatly easing the task of implementing it.
41 *
42 * <p><strong>This class is for {@code Preferences} implementers only.
43 * Normal users of the {@code Preferences} facility should have no need to
44 * consult this documentation. The {@link Preferences} documentation
45 * should suffice.</strong>
46 *
47 * <p>Implementors must override the nine abstract service-provider interface
48 * (SPI) methods: {@link #getSpi(String)}, {@link #putSpi(String,String)},
49 * {@link #removeSpi(String)}, {@link #childSpi(String)}, {@link
50 * #removeNodeSpi()}, {@link #keysSpi()}, {@link #childrenNamesSpi()}, {@link
51 * #syncSpi()} and {@link #flushSpi()}. All of the concrete methods specify
1497 * eventQueue so the event dispatch thread knows whether to call
1498 * childAdded or childRemoved.
1499 */
1500 private class NodeAddedEvent extends NodeChangeEvent {
1501 private static final long serialVersionUID = -6743557530157328528L;
1502 NodeAddedEvent(Preferences parent, Preferences child) {
1503 super(parent, child);
1504 }
1505 }
1506 private class NodeRemovedEvent extends NodeChangeEvent {
1507 private static final long serialVersionUID = 8735497392918824837L;
1508 NodeRemovedEvent(Preferences parent, Preferences child) {
1509 super(parent, child);
1510 }
1511 }
1512
1513 /**
1514 * A single background thread ("the event notification thread") monitors
1515 * the event queue and delivers events that are placed on the queue.
1516 */
1517 private static class EventDispatchThread extends Thread {
1518 private EventDispatchThread() {
1519 super(null, null, "Event Dispatch Thread", 0, false);
1520 }
1521
1522 public void run() {
1523 while(true) {
1524 // Wait on eventQueue till an event is present
1525 EventObject event = null;
1526 synchronized(eventQueue) {
1527 try {
1528 while (eventQueue.isEmpty())
1529 eventQueue.wait();
1530 event = eventQueue.remove(0);
1531 } catch (InterruptedException e) {
1532 // XXX Log "Event dispatch thread interrupted. Exiting"
1533 return;
1534 }
1535 }
1536
1537 // Now we have event & hold no locks; deliver evt to listeners
1538 AbstractPreferences src=(AbstractPreferences)event.getSource();
1539 if (event instanceof PreferenceChangeEvent) {
1540 PreferenceChangeEvent pce = (PreferenceChangeEvent)event;
1541 PreferenceChangeListener[] listeners = src.prefListeners();
|