Skip to content
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...
1 parent 35d522f commit 3c5242e724df33f4546d9290b724d90be7be8874 @semanticsoft committed Jan 9, 2013
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 ...soft.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,13 +70,35 @@ 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)
{
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);

0 comments on commit 3c5242e

Please sign in to comment.
Something went wrong with that request. Please try again.