Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: src/org/adblockplus/libadblockplus/Disposer.java

Issue 5698450620416000: Replaced the Disposer (Closed)
Left Patch Set: Created April 30, 2014, 11:17 a.m.
Right Patch Set: Review issues fixed Created April 30, 2014, 3:44 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/org/adblockplus/libadblockplus/Disposable.java ('k') | src/org/adblockplus/libadblockplus/EventCallback.java » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 package org.adblockplus.libadblockplus; 18 package org.adblockplus.libadblockplus;
19 19
20 import java.lang.ref.ReferenceQueue; 20 import java.lang.ref.ReferenceQueue;
21 import java.lang.ref.WeakReference; 21 import java.lang.ref.WeakReference;
22 import java.util.HashSet; 22 import java.util.HashSet;
23 23
24 public final class Disposer extends WeakReference<Disposable> 24 public final class Disposer extends WeakReference<Disposable>
25 { 25 {
26 final static ReferenceQueue<Disposable> referenceQueue = new ReferenceQueue<Di sposable>(); 26 static final ReferenceQueue<Disposable> referenceQueue = new ReferenceQueue<Di sposable>();
27 final static HashSet<Disposer> disposerSet = new HashSet<Disposer>(); 27 private static final HashSet<Disposer> disposerSet = new HashSet<Disposer>();
Felix Dahlke 2014/04/30 15:34:08 Should be "static final".
René Jeschke 2014/04/30 15:43:16 Done.
28 private final Disposable disposable; 28 private final Disposable disposable;
29 private volatile boolean isDisposed = false; 29 private volatile boolean disposed = false;
Felix Dahlke 2014/04/30 15:34:08 Should be "disposed" according to the bean convent
René Jeschke 2014/04/30 15:43:16 Done.
30 30
31 static 31 static
32 { 32 {
33 final Thread thread = new Thread(new Cleaner()); 33 final Thread thread = new Thread(new Cleaner());
34 thread.setName(Cleaner.class.getCanonicalName()); 34 thread.setName(Cleaner.class.getCanonicalName());
35 thread.setDaemon(true); 35 thread.setDaemon(true);
36 thread.start(); 36 thread.start();
37 } 37 }
38 38
39 public Disposer(final Disposable referent, final Disposable disposable) 39 public Disposer(final Disposable referent, final Disposable disposable)
Felix Dahlke 2014/04/30 15:34:08 How about renaming "disposable" to "reference"? Th
René Jeschke 2014/04/30 15:43:16 'referent' is the reference that get stored in the
Felix Dahlke 2014/04/30 15:50:43 Isn't disposable the object that _gets_ disposed o
40 { 40 {
41 super(referent, referenceQueue); 41 super(referent, referenceQueue);
Felix Dahlke 2014/04/30 15:34:08 Shouldn't it be the referentQueue if it stores the
René Jeschke 2014/04/30 15:43:16 It stores the value from a local variable called '
42 this.disposable = disposable; 42 this.disposable = disposable;
43 43
44 synchronized (disposerSet) 44 synchronized (disposerSet)
45 { 45 {
46 disposerSet.add(this); 46 disposerSet.add(this);
47 } 47 }
48 } 48 }
49 49
50 public synchronized void dispose() 50 public synchronized void dispose()
51 { 51 {
52 if (!this.isDisposed) 52 if (!this.disposed)
53 { 53 {
54 try 54 try
55 { 55 {
56 this.disposable.dispose(); 56 this.disposable.dispose();
57 } 57 }
58 catch (final Throwable t) 58 catch (final Throwable t)
59 { 59 {
60 // catch to set state to 'disposed' on all circumstances 60 // catch to set state to 'disposed' on all circumstances
61 } 61 }
62 62
63 this.isDisposed = true; 63 this.disposed = true;
64 synchronized (disposerSet) 64 synchronized (disposerSet)
65 { 65 {
66 disposerSet.remove(this); 66 disposerSet.remove(this);
67 } 67 }
68 } 68 }
69 } 69 }
70 70
71 private static final class Cleaner implements Runnable 71 private static final class Cleaner implements Runnable
72 { 72 {
73 public Cleaner() 73 public Cleaner()
(...skipping 11 matching lines...) Expand all
85 ((Disposer) Disposer.referenceQueue.remove()).dispose(); 85 ((Disposer) Disposer.referenceQueue.remove()).dispose();
86 } 86 }
87 catch (final Throwable t) 87 catch (final Throwable t)
88 { 88 {
89 // ignored 89 // ignored
90 } 90 }
91 } 91 }
92 } 92 }
93 } 93 }
94 } 94 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld