SF.net SVN: jython:[7195] trunk/jython/src/org/python/core
[email protected] Tue, 08 Feb 2011 01:16:54 +0000
| Newsgroups | gmane.comp.lang.jython.cvs |
|---|---|
| Message-ID | <[email protected]> |
Revision: 7195
http://jython.svn.sourceforge.net/jython/?rev=7195&view=rev
Author: pjenvey
Date: 2011-02-08 01:16:53 +0000 (Tue, 08 Feb 2011)
Log Message:
-----------
cleanup generics around PySystemStateCloser, PySystemState.unregisterCloser
doesn't need synchronization
Modified Paths:
--------------
trunk/jython/src/org/python/core/PyFile.java
trunk/jython/src/org/python/core/PySystemState.java
Modified: trunk/jython/src/org/python/core/PyFile.java
===================================================================
--- trunk/jython/src/org/python/core/PyFile.java 2011-02-05 01:23:12 UTC (rev 7194)
+++ trunk/jython/src/org/python/core/PyFile.java 2011-02-08 01:16:53 UTC (rev 7195)
@@ -574,7 +574,7 @@
* be called during shutdown, so we can't use it. It's vital that this Closer has no
* reference to the PyFile it's closing so the PyFile remains garbage collectable.
*/
- private static class Closer implements Callable {
+ private static class Closer implements Callable<Void> {
/**
* The underlying file
@@ -588,8 +588,7 @@
sys.registerCloser(this);
}
- // For closing directly
-
+ /** For closing directly */
public void close() {
if (sys.unregisterCloser(this)) {
file.close();
@@ -597,9 +596,8 @@
sys = null;
}
- // For closing as part of a shutdown process
-
- public Object call() {
+ /** For closing as part of a shutdown process */
+ public Void call() {
file.close();
sys = null;
return null;
Modified: trunk/jython/src/org/python/core/PySystemState.java
===================================================================
--- trunk/jython/src/org/python/core/PySystemState.java 2011-02-05 01:23:12 UTC (rev 7194)
+++ trunk/jython/src/org/python/core/PySystemState.java 2011-02-08 01:16:53 UTC (rev 7195)
@@ -155,8 +155,10 @@
// Automatically close resources associated with a PySystemState when they get GCed
private final PySystemStateCloser closer;
- private static final ReferenceQueue systemStateQueue = new ReferenceQueue<PySystemState>();
- private static final ConcurrentMap<WeakReference<PySystemState>, PySystemStateCloser> sysClosers = Generic.concurrentMap();
+ private static final ReferenceQueue<PySystemState> systemStateQueue =
+ new ReferenceQueue<PySystemState>();
+ private static final ConcurrentMap<WeakReference<PySystemState>,
+ PySystemStateCloser> sysClosers = Generic.concurrentMap();
public PySystemState() {
initialize();
@@ -1286,11 +1288,11 @@
return f;
}
- public void registerCloser(Callable resourceCloser) {
+ public void registerCloser(Callable<Void> resourceCloser) {
closer.registerCloser(resourceCloser);
}
- public synchronized boolean unregisterCloser(Callable resourceCloser) {
+ public boolean unregisterCloser(Callable<Void> resourceCloser) {
return closer.unregisterCloser(resourceCloser);
}
@@ -1300,32 +1302,33 @@
private static class PySystemStateCloser {
- private final Set<Callable> resourceClosers = new LinkedHashSet<Callable>();
+ private final Set<Callable<Void>> resourceClosers = new LinkedHashSet<Callable<Void>>();
private volatile boolean isCleanup = false;
private final Thread shutdownHook;
private PySystemStateCloser(PySystemState sys) {
shutdownHook = initShutdownCloser();
- WeakReference<PySystemState> ref = new WeakReference(sys, systemStateQueue);
+ WeakReference<PySystemState> ref =
+ new WeakReference<PySystemState>(sys, systemStateQueue);
sysClosers.put(ref, this);
cleanupOtherClosers();
}
private static void cleanupOtherClosers() {
- Reference<PySystemStateCloser> ref;
+ Reference<? extends PySystemState> ref;
while ((ref = systemStateQueue.poll()) != null) {
PySystemStateCloser closer = sysClosers.get(ref);
closer.cleanup();
}
}
- private synchronized void registerCloser(Callable closer) {
+ private synchronized void registerCloser(Callable<Void> closer) {
if (!isCleanup) {
resourceClosers.add(closer);
}
}
- private synchronized boolean unregisterCloser(Callable closer) {
+ private synchronized boolean unregisterCloser(Callable<Void> closer) {
return resourceClosers.remove(closer);
}
@@ -1335,7 +1338,8 @@
}
isCleanup = true;
- // close this thread so we can unload any associated classloaders in cycle with this instance
+ // close this thread so we can unload any associated classloaders in cycle
+ // with this instance
if (shutdownHook != null) {
try {
Runtime.getRuntime().removeShutdownHook(shutdownHook);
@@ -1344,7 +1348,7 @@
}
}
- for (Callable callable : resourceClosers) {
+ for (Callable<Void> callable : resourceClosers) {
try {
callable.call();
} catch (Exception e) {
@@ -1378,7 +1382,7 @@
// resourceClosers can be null in some strange cases
return;
}
- for (Callable callable : resourceClosers) {
+ for (Callable<Void> callable : resourceClosers) {
try {
callable.call(); // side effect of being removed from this set
} catch (Exception e) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb