• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Queueing of call in GWT

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way in GWT by which I can queue to service calls in FIFO.

my problem

I need to call two service
1. void updateModel(....)
2. refreshSomeView(....)

it is critical that refreshSomeView is called only after updateModel.

How can I ensure this
 
author
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by G M S:
Is there a way in GWT by which I can queue to service calls in FIFO.



No, not as a strict answer to your question. GWT has a concept of DeferredCommand which defers a particular command you have until after all the existing event handlers have executed, but is not necessarily what you are after, I feel.

my problem

I need to call two service
1. void updateModel(....)
2. refreshSomeView(....)

it is critical that refreshSomeView is called only after updateModel.

How can I ensure this



Your using standard Java so just make use of the Observer pattern.

Whilst you don't have the Java 1.4.2 java.util.Observer classes etc, they are trivial to implement yourself - I'll post the ones I use after this post.

To use create a class that represents your model and extends Observable; every change you make in the model call the notifyObservers() method. Your "view" would then implement the Observer interface that provides the update() method that updates your view.

When the model is updated, the view's update() method is automatically called, thus achieving what you are after.

(Of course some people could (would?) argue over my interpretation of the Observer pattern, but it works fine for me).

//Adam
 
Adam Tacy
author
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the Observer interface

public interface Observer {
public void update(Observable observable, Object arg);
}
 
Marshal
Posts: 67279
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Girish M S", you have previously been warned on one or more occasions regarding adjusting your display name to meet JavaRanch standards. This is not optional. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it prior to your next post.

Your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Be aware that accounts with invalid display names are disabled.

bear
JavaRanch Sheriff
 
Adam Tacy
author
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
..and the Observable class:

import java.util.Iterator;
import java.util.Vector;

public class Observable {

private boolean changed;
private Vector observers;

public void addObserver(Observer observer){
if (observer==null)
throw new RuntimeException();
observers.add(observer);
}

public void removeObserver(Observer observer){
observers.remove(observer);
}

public void removeObservers(){
observers.clear();
}

public void clearChanged(){
changed = false;
}

public void setChanged(){
changed = true;
}

public boolean hasChanged(){
return changed;
}

public void notifyObservers(){
notifyObservers(null);
}

public void notifyObservers(Object obj){
if(hasChanged()){
for (Iterator it = observers.iterator(); it.hasNext() {
Observer observer = (Observer) it.next();
observer.update(this,obj);
}
}
}

public Observable(){
// Create an empty list of observers.
observers = new Vector();
}
}
 
Let me tell you a story about a man named Jed. He made this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!