Index: remoting/android/java/src/org/chromium/chromoting/Event.java |
diff --git a/remoting/android/java/src/org/chromium/chromoting/Event.java b/remoting/android/java/src/org/chromium/chromoting/Event.java |
index 5a0e75be7b41729684fff45aac9aea03fa8fa962..be27831f4887ca5a4a08f2068a64a681d37a5354 100644 |
--- a/remoting/android/java/src/org/chromium/chromoting/Event.java |
+++ b/remoting/android/java/src/org/chromium/chromoting/Event.java |
@@ -8,7 +8,7 @@ import java.util.HashSet; |
/** |
* A thread-safe event queue which provides both {@link #add} and {@link #remove} functions with |
- * O(log(n)) time complexity, and a {@link raise} function in the derived class |
+ * O(log(n)) time complexity, and a {@link #raise} function in the derived class |
* {@link Event.Raisable} to execute all queued callbacks. |
* |
* @param <ParamT> The parameter used in {@link ParameterRunnable} callback. |
@@ -25,11 +25,11 @@ public class Event<ParamT> { |
} |
/** |
- * An event provider version of {@link Event} implementation, provides {@link raise} function to |
- * execute appended {@link ParameterRunnable}, and {@link clear} function to clear all appended |
- * callbacks. |
+ * An event provider version of {@link Event} implementation, provides {@link #raise} function |
+ * to execute appended {@link ParameterRunnable}, and {@link clear} function to clear all |
+ * appended callbacks. |
*/ |
- public static final class Raisable<ParamT> extends Event<ParamT> { |
+ public static class Raisable<ParamT> extends Event<ParamT> { |
/** Clears all appended callbacks */ |
public void clear() { |
synchronized (mSet) { |
@@ -64,6 +64,44 @@ public class Event<ParamT> { |
} |
/** |
+ * An {@link Raisable} which always executes the newly added {@link ParameterRunnable} with the |
Lambros
2016/10/05 19:30:04
s/An/A/
Hzj_jie
2016/10/06 00:08:09
Done.
|
+ * parameter sent to the last {@link #raise} function call. If the event has not been raised, |
+ * this class has a consistent behavior as {@link Raisable}. |
Lambros
2016/10/05 19:30:03
..has consistent behavior with..
or
..behaves the
Hzj_jie
2016/10/06 00:08:09
Done.
|
+ * <p> This class is useful for some one-time events, such as RenderStub.onClientSizeChanged(). |
Lambros
2016/10/05 19:30:04
I might be mistaken, but is it common style to use
Hzj_jie
2016/10/06 00:08:09
AFAICT, without <p> or <br>, the newline character
|
+ * A later attached runnable will never be able to get the event. |
+ * <p> The {@link ParameterRunnable} will be executed in the thread which {@link #add} function |
Lambros
2016/10/05 19:30:04
..thread which calls {@link #add}..
or
..thread in
Yuwei
2016/10/05 20:50:34
I think to be consistent it could be better to run
Hzj_jie
2016/10/06 00:08:09
Done.
Hzj_jie
2016/10/06 00:08:09
Yes, but I would prefer to remove all the synchron
Yuwei
2016/10/06 01:32:24
Acknowledged.
|
+ * is called if the event has been raised before. |
Lambros
2016/10/05 19:30:04
You're saying that the implementation will call th
joedow
2016/10/05 19:46:43
Agreed, I've used events which can either fire syn
Yuwei
2016/10/05 20:50:34
Yep. Running the callbacks in current task will ha
Hzj_jie
2016/10/06 00:08:09
This should not happen, raise is only called from
Yuwei
2016/10/06 01:32:24
Well, you code doesn't disallow circular event dep
Hzj_jie
2016/10/06 19:01:34
I think that's a totally incorrect pattern. It loo
|
+ * <p> The {@link ParameterRunnable} may be executed twice on different threads with exactly |
Lambros
2016/10/05 19:30:04
Personally, I wouldn't make this a separate paragr
Hzj_jie
2016/10/06 00:08:09
Done.
|
+ * same parameter. Usually this is not an issue, but consumers need to aware. |
Lambros
2016/10/05 19:30:04
..to be aware.
But you can remove this anyway.
Hzj_jie
2016/10/06 00:08:09
Done.
|
+ */ |
+ public static final class ReproducibleRaisable<ParamT> extends Raisable<ParamT> { |
joedow
2016/10/05 19:46:43
The name ReproducibleRaisable doesn't tell me that
Hzj_jie
2016/10/06 00:08:09
Changed to PromisedRaisable.
|
+ private boolean mRaised; |
+ private ParamT mLastParameter; |
+ |
+ @Override |
+ public Object add(ParameterRunnable<ParamT> runnable) { |
+ Object result = super.add(runnable); |
+ if (result != null) { |
+ synchronized (mSet) { |
+ if (mRaised) { |
Yuwei
2016/10/05 20:50:34
Could you do the check without the boolean, say ch
Hzj_jie
2016/10/06 00:08:09
No, not a good idea, we cannot ensure a null-able
Yuwei
2016/10/06 01:32:24
Ah. I think you are right.
|
+ runnable.run(mLastParameter); |
+ } |
+ } |
+ } |
+ return result; |
+ } |
+ |
+ @Override |
+ public int raise(ParamT parameter) { |
+ synchronized (mSet) { |
+ mRaised = true; |
+ mLastParameter = parameter; |
+ } |
+ return super.raise(parameter); |
+ } |
+ } |
+ |
+ /** |
* A self removable {@link ParameterRunner}, uses a boolean {@link ParameterCallback} to decide |
* whether removes self from {@link Event} or not. |
*/ |