summaryrefslogtreecommitdiff
path: root/gnu/java/util
diff options
context:
space:
mode:
authorMario Torre <neugens@limasoftware.net>2007-11-23 22:02:15 +0000
committerMario Torre <neugens@limasoftware.net>2007-11-23 22:02:15 +0000
commitcf5d4d7165840d9445ac4a263912731b98dd875f (patch)
tree6c210d269d4b1d434731de72de5d64180aacc72e /gnu/java/util
parent3eae71b2d5a285e973dbd882593a61c25a2598ea (diff)
downloadclasspath-cf5d4d7165840d9445ac4a263912731b98dd875f.tar.gz
2007-11-23 Mario Torre <neugens@limasoftware.net>
* gnu/java/util/prefs/EventDispatcher.java: class removed. * gnu/classpath/toolkit/DefaultDaemonThreadFactory.java: new file. * java/util/prefs/AbstractPreferences.java: (fire(PreferenceChangeEvent)): Use DefaultDaemonThreadFactory and Executors.newSingleThreadExecutor instead of EventDispatcher. Import statement refactored accordingly. Also refactored to use 1.5 enhanced for loop and generics. (fire(NodeChangeEvent, boolean)): likewise. * gnu/java/util/prefs/GConfBasedPreferences.java (childSpi): removed startWatchingNode call. * gnu/java/util/prefs/gconf/GConfNativePeer.java: (GConfNativePeer): removed use of semaphore. (gconf_all_nodes): method name shortened, renamed from gconf_client_all_nodes (removed client_ from method signature) and declared synchronized. (gconf_suggest_sync): likewise. (gconf_get_string): likewise. (gconf_unescape_key): likewise. (gconf_set_string): likewise. (gconf_escape_key): likewise. (gconf_all_keys): likewise. (gconf_dir_exists): likewise. (getKeys): refactored to use new native method name. (getKey): likewise. (setString): likewise. (getChildrenNodes): likewise. (unset): likewise. (suggestSync): likewise. (finalize): likewise. (nodeExist): likewise. (gconf_client_add_dir): removed, not needed anymore. (gconf_client_remove_dir): likewise. (startWatchingNode): likewise. (stopWatchingNode): likewise. * native/jni/conf-peer/GConfNativePeer.c: All native methods renamed to match changes in GConfNativePeer.java Now use GConfEngine instead of GConfClient. Removed gdk_thread_enter/leave locking from all methods. (Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1add_1dir): removed. (Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1dir_1exists): likewise. * include/gnu_java_util_prefs_gconf_GConfNativePeer.h: regenerated.
Diffstat (limited to 'gnu/java/util')
-rw-r--r--gnu/java/util/prefs/EventDispatcher.java113
-rw-r--r--gnu/java/util/prefs/GConfBasedPreferences.java4
-rw-r--r--gnu/java/util/prefs/gconf/GConfNativePeer.java99
3 files changed, 25 insertions, 191 deletions
diff --git a/gnu/java/util/prefs/EventDispatcher.java b/gnu/java/util/prefs/EventDispatcher.java
deleted file mode 100644
index f73c3e703..000000000
--- a/gnu/java/util/prefs/EventDispatcher.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/* EventDispatcher.java -- Dispatch events for prefs
- Copyright (C) 2006 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package gnu.java.util.prefs;
-
-import java.util.ArrayList;
-
-/**
- * This is a helper class used for dispatching events for
- * the prefs package.
- */
-public class EventDispatcher extends Thread
-{
- // This is a singleton class. We dispatch all events via a
- // new Thread which is created on demand.
- private static final Thread dispatchThread = new EventDispatcher();
-
- // This is a queue of events to dispatch. This thread waits on
- // the queue and when notified will remove events until the queue
- // is empty.
- private static final ArrayList<Runnable> queue = new ArrayList<Runnable>();
-
- // FIXME: this thread probably ought to go in some classpath-internal
- // ThreadGroup. But we don't have that yet.
- private EventDispatcher()
- {
- setDaemon(true);
- start();
- }
-
- public void run()
- {
- while (true)
- {
- Runnable r;
- synchronized (queue)
- {
- while (queue.size() == 0)
- {
- try
- {
- queue.wait();
- }
- catch (InterruptedException _)
- {
- // Ignore.
- }
- }
- r = queue.remove(0);
- }
- // Invoke outside the synchronization, so that
- // we aren't blocking other threads from posting events.
- try
- {
- r.run();
- }
- catch (Throwable _)
- {
- // Ignore.
- }
- }
- }
-
- /**
- * Add a new runnable to the event dispatch queue. The
- * runnable will be invoked in the event dispatch queue
- * without any locks held.
- * @param runner the Runnable to dispatch
- */
- public static void dispatch(Runnable runner)
- {
- synchronized (queue)
- {
- queue.add(runner);
- queue.notify();
- }
- }
-}
diff --git a/gnu/java/util/prefs/GConfBasedPreferences.java b/gnu/java/util/prefs/GConfBasedPreferences.java
index 0fd4df366..8d1d84f5e 100644
--- a/gnu/java/util/prefs/GConfBasedPreferences.java
+++ b/gnu/java/util/prefs/GConfBasedPreferences.java
@@ -166,10 +166,6 @@ public class GConfBasedPreferences
GConfBasedPreferences preferenceNode
= new GConfBasedPreferences(this, name, this.isUser);
- // register the node for to GConf so that it can listen
- // events outside the scope of the application
- backend.startWatchingNode(this.node);
-
return preferenceNode;
}
diff --git a/gnu/java/util/prefs/gconf/GConfNativePeer.java b/gnu/java/util/prefs/gconf/GConfNativePeer.java
index 5e12c718b..3c0291959 100644
--- a/gnu/java/util/prefs/gconf/GConfNativePeer.java
+++ b/gnu/java/util/prefs/gconf/GConfNativePeer.java
@@ -49,19 +49,11 @@ import java.util.prefs.BackingStoreException;
public final class GConfNativePeer
{
/**
- * Object to achieve locks for methods that need to be synchronized.
- */
- private static final Object[] semaphore = new Object[0];
-
- /**
* Creates a new instance of GConfNativePeer
*/
public GConfNativePeer()
{
- synchronized (semaphore)
- {
- init_class();
- }
+ init_class();
}
/**
@@ -72,31 +64,7 @@ public final class GConfNativePeer
*/
public boolean nodeExist(String node)
{
- return gconf_client_dir_exists(node);
- }
-
- /**
- * Add the node <code>node</code> to the list of nodes the GConf will watch.
- * An event is raised everytime this node is changed. You can add a node
- * multiple times.
- *
- * @param node the node to track.
- */
- public void startWatchingNode(String node)
- {
- gconf_client_add_dir(node);
- }
-
- /**
- * Remove the node <code>node</code> to the list of nodes the GConf is
- * watching. Note that if a node has been added multiple times, you must
- * remove it the same number of times before the remove takes effect.
- *
- * @param node the node you don't want to track anymore.
- */
- public void stopWatchingNode(String node)
- {
- gconf_client_remove_dir(node);
+ return gconf_dir_exists(node);
}
/**
@@ -111,7 +79,7 @@ public final class GConfNativePeer
*/
public boolean setString(String key, String value)
{
- return gconf_client_set_string(key, value);
+ return gconf_set_string(key, value);
}
/**
@@ -124,7 +92,7 @@ public final class GConfNativePeer
*/
public boolean unset(String key)
{
- return gconf_client_unset(key);
+ return gconf_unset(key);
}
/**
@@ -135,7 +103,7 @@ public final class GConfNativePeer
*/
public String getKey(String key)
{
- return gconf_client_get_string(key);
+ return gconf_get_string(key);
}
/**
@@ -149,7 +117,7 @@ public final class GConfNativePeer
*/
public List<String> getKeys(String node) throws BackingStoreException
{
- return gconf_client_all_keys(node);
+ return gconf_all_keys(node);
}
/**
@@ -161,7 +129,7 @@ public final class GConfNativePeer
*/
public List<String> getChildrenNodes(String node) throws BackingStoreException
{
- return gconf_client_all_nodes(node);
+ return gconf_all_nodes(node);
}
/**
@@ -185,17 +153,14 @@ public final class GConfNativePeer
*/
public void suggestSync() throws BackingStoreException
{
- gconf_client_suggest_sync();
+ gconf_suggest_sync();
}
protected void finalize() throws Throwable
{
try
{
- synchronized (semaphore)
- {
- finalize_class();
- }
+ finalize_class();
}
finally
{
@@ -215,18 +180,18 @@ public final class GConfNativePeer
* Initialize the GConf native peer and enable the object cache.
* It is meant to be used by the static initializer.
*/
- native static final private void init_id_cache();
+ native synchronized static final private void init_id_cache();
/**
* Initialize the GConf native peer. This is meant to be used by the
* class constructor.
*/
- native static final private void init_class();
+ native synchronized static final private void init_class();
/**
* Class finalizer.
*/
- native static final private void finalize_class();
+ native synchronized static final private void finalize_class();
/**
* Queries the GConf database to see if the given node exists, returning
@@ -235,23 +200,8 @@ public final class GConfNativePeer
* @param node the node to query for existence.
* @return true if the node exist, false otherwise.
*/
- native static final protected boolean gconf_client_dir_exists(String node);
-
- /**
- * Adds the given node to the list of nodes that GConf watches for
- * changes.
- *
- * @param node the node to watch for changes.
- */
- native static final protected void gconf_client_add_dir(String node);
-
- /**
- * Removes the given node from the list of nodes that GConf watches for
- * changes.
- *
- * @param node the node to remove from from the list of watched nodes.
- */
- native static final protected void gconf_client_remove_dir(String node);
+ native synchronized
+ static final protected boolean gconf_dir_exists(String node);
/**
* Sets the given key/value pair into the GConf database.
@@ -261,8 +211,8 @@ public final class GConfNativePeer
* @param value the value to associate to the given key.
* @return true if the change has effect, false otherwise.
*/
- native static final protected boolean gconf_client_set_string(String key,
- String value);
+ native synchronized
+ static final protected boolean gconf_set_string(String key, String value);
/**
* Returns the key associated to the given key. Null is returned if the
@@ -271,7 +221,8 @@ public final class GConfNativePeer
* @param key the key to return the value of.
* @return The value associated to the given key, or null.
*/
- native static final protected String gconf_client_get_string(String key);
+ native synchronized
+ static final protected String gconf_get_string(String key);
/**
* Usets the given key, removing the key from the database.
@@ -279,13 +230,13 @@ public final class GConfNativePeer
* @param key the key to remove.
* @return true if the operation success, false otherwise.
*/
- native static final protected boolean gconf_client_unset(String key);
+ native synchronized static final protected boolean gconf_unset(String key);
/**
* Suggest to the GConf native peer a sync with the database.
*
*/
- native static final protected void gconf_client_suggest_sync()
+ native synchronized static final protected void gconf_suggest_sync()
throws BackingStoreException;
/**
@@ -295,7 +246,7 @@ public final class GConfNativePeer
* @return A list of nodes under the given source node.
*/
native
- static final protected List<String> gconf_client_all_nodes(String node)
+ static synchronized final protected List<String> gconf_all_nodes(String node)
throws BackingStoreException;
/**
@@ -304,8 +255,8 @@ public final class GConfNativePeer
* @param node the source node.
* @return A list of all keys stored in the given node.
*/
- native
- static final protected List<String> gconf_client_all_keys(String node)
+ native synchronized
+ static final protected List<String> gconf_all_keys(String node)
throws BackingStoreException;
/**
@@ -314,7 +265,7 @@ public final class GConfNativePeer
* @param plain the String to escape.
* @return An escaped String for use with GConf.
*/
- native
+ native synchronized
static final protected String gconf_escape_key(String plain);
/**
@@ -324,7 +275,7 @@ public final class GConfNativePeer
* @param escaped key as returned by gconf_escape_key
* @return An unescaped key.
*/
- native
+ native synchronized
static final protected String gconf_unescape_key(String escaped);
static