Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

VaadinExecutorService.addInvokeLater(String key, Runnable runnable) for

invoking runnable only if another runnable with this key is not added
(and has not invoked at this time).
  • Loading branch information...
commit 3c5242e724df33f4546d9290b724d90be7be8874 1 parent 35d522f
@semanticsoft authored
View
2  org.semanticsoft.vaaclipse.api/src/org/semanticsoft/vaaclipse/api/VaadinExecutorService.java
@@ -10,6 +10,8 @@
public interface VaadinExecutorService
{
void invokeLater(Runnable runnable);
+ void invokeLater(Object key, Runnable runnable);
+ boolean containsKey(Object key);
void invokeLaterAlways(Runnable runnable);
void removeAlwaysRunnable(Runnable runnable);
}
View
36 org.semanticsoft.vaaclipse.app/src/org/semanticsoft/vaaclipse/app/VaadinOSGiCommunicationManager.java
@@ -11,12 +11,12 @@
package org.semanticsoft.vaaclipse.app;
-import java.util.ArrayList;
-import java.util.Iterator;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.LinkedList;
-import java.util.List;
import java.util.Map;
import java.util.Queue;
+import java.util.Set;
import org.semanticsoft.vaaclipse.api.VaadinExecutorService;
@@ -26,8 +26,10 @@
public class VaadinOSGiCommunicationManager extends CommunicationManager implements VaadinExecutorService
{
- Queue<Runnable> runnables = new LinkedList<>();
- Queue<Runnable> runnables2 = new LinkedList<>();
+ private Queue<Runnable> runnables = new LinkedList<>();
+ private Set<Object> keys = new HashSet<>();
+ private Map<Runnable, Object> runnable2Key = new HashMap<Runnable, Object>();
+ private Queue<Runnable> runnables2 = new LinkedList<>();
public VaadinOSGiCommunicationManager(Application application)
{
@@ -48,6 +50,8 @@ private synchronized void exec()
try
{
runnable.run();
+ Object key = runnable2Key.remove(runnable);
+ keys.remove(key);
}
catch (Throwable e)
{
@@ -66,6 +70,11 @@ private synchronized void exec()
e.printStackTrace();
}
}
+
+ //clean runnables that may added during runnables2 execution
+ runnables.clear();
+ runnable2Key.clear();
+ keys.clear();
}
public synchronized void invokeLater(Runnable runnable)
@@ -73,6 +82,23 @@ public synchronized void invokeLater(Runnable runnable)
this.runnables.add(runnable);
}
+ @Override
+ public void invokeLater(Object key, Runnable runnable)
+ {
+ if (!this.keys.contains(key))
+ {
+ this.keys.add(key);
+ this.runnable2Key.put(runnable, key);
+ this.runnables.add(runnable);
+ }
+ }
+
+ @Override
+ public boolean containsKey(Object key)
+ {
+ return this.keys.contains(key);
+ }
+
public synchronized void invokeLaterAlways(Runnable runnable)
{
this.runnables2.add(runnable);
Please sign in to comment.
Something went wrong with that request. Please try again.