Results 1 to 6 of 6
Thread: Animation Synchronization
- 08-07-2008, 06:41 PM #1
Member
- Join Date
- Aug 2008
- Posts
- 3
- Rep Power
- 0
Animation Synchronization
Hi all.
I have a server/client online app/applet development.
To simplify my problem, the client get 2 commands from the server, one right after the other.
The 1st one is dispatched to a Timer to do a particular animation. The next is handled on the EDT.
Because the animation takes longer than the time difference between getting the 1st and 2nd commands, the 2nd command gets done way before the animation is over. However, I want the response from the 2nd command to begin ONLY when the animation is over.
I tried synchronizing the Timer but of course it only atomizes each call, in between which, the EDT does stuff from the 1st command response anyway. (I could be wrong about this).
I prefer not to use delays as it would differ between machines.
I don't want to have the server wait till it gets an "endAnimation" signal from the client because EACH CLIENT MAY END AT A DIFFERENT TIME.
So it must be handled within each client independently.
Actually, there are many commands that the server sends right after the "doAnimation" one. By the time the animation is done, all the other command have already been done and were never seen, or they all appear at their end stages (the server uses delays to space the sending of the commands after the animation command to slow down the appearance of these onscreen objects on the client-side. This is nullified as they all happen in the background while the animation was doing its thing).
I realize that this all sounds very complicated and that I may not be explaining myself properly.
So in a nutshell:
- [SERVER]->doAnimation_________[CLIENT] startAnimation
- [SERVER]->showScreenWidget1___[CLIENT] still doing animation
- [SERVER]Pause_________________[CLIENT] still doing animation
- [SERVER]->showScreenWidget2___[CLIENT] still doing animation
- [SERVER]Pause_________________[CLIENT] still doing animation
- [SERVER]->showScreenWidget3___[CLIENT] still doing animation
[CLIENT] done doing animation
[CLIENT] show all screen widgets at once
I realize also as I write this that whatever solution I use, the delays on the server side would become mute points so I'll have to find another way to pause between screen widgets. The priority, however, is to have the rest of the screen updates wait till the animation is over.
Any help would be appreciated.
Thank you.
- 08-07-2008, 07:40 PM #2
Have the client queue the show requests until the animation is done and then do them? Can the client detect that the animation is inprogress to know that it must queue the show request until completion?
Can you show what you'd like to happen in the same format as your "in a nutshell:" form?
Why doesn't the server send all the info to the client in one go and let the client do the displays? If there is no feedback from the client while it is showing the animation, why have the server send multiple responses to the client if all the responses can be determined for the first response.
- 08-07-2008, 11:03 PM #3
Member
- Join Date
- Aug 2008
- Posts
- 3
- Rep Power
- 0
If I use the Swing Timer, then everything it does is on the EDT. What happens in between timer calls? Does the EDT do other stuff?
How can I ensure that until the Timer is destroyed (marking the end of the animation), that nothing else gets done?
I can't very well put a wait on the EDT as that's the very same thread I need for the animation. EVEN if I use the java.utils.Timer/TimerTask combo. I would still have to spin the GUI stuff off onto the EDT anyway.
I understand the queue list concept but how would that work when its not just a single event but many as my animation is?
I even thought of sending the pause command TO the client as a call to a pause method but that still wouldn't work because as soon as the animation command is sent and the 1st Timer call is done, while waiting for the Timer to fire off the next event, the pause routine would run prematurely. This means that it will pause the animation.
Thanks for reply anyway
- 08-08-2008, 12:34 AM #4
By using different threads, you can leave the EDT to do the animation and have other threads monitor the input, queue it, monitor the animation and start the next task after the animation is done. Its a scheduling job, keeping track of what to do when.Can you show what you'd like to happen in the same format as your "in a nutshell:" form?
- 08-08-2008, 01:31 AM #5
Member
- Join Date
- Aug 2008
- Posts
- 3
- Rep Power
- 0
Thanks Norm.
I had a friend construct the remoting for me. That's the model I am using.
This way I can call methods as if they were on the same machine. Acoording to you, I would have to alter that model.
Part of the code is below. As you can see, it's already in queue mode.
Maybe I would have to send methods that need to wait on an animation, to an intermediate method that monitors the animation and has its own queue list? The rest being sent normally?
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.LinkedList;
import java.util.List;
import java.util.ArrayList;
/**
*/
public class RemoteEventListenerList<T extends RemoteEventListener> implements
InvocationHandler {
private List<T> list = new LinkedList<T>();
private List<T> toAdd = new ArrayList<T>();
private final Class<T> type;
private T proxy;
private List<T> toRemove = new ArrayList<T>();
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
updateList();
dispatchList(list, method, args);
while (moreAdded()) {
final List<T> temp = new ArrayList<T>(toAdd);
updateList();
dispatchList(temp, method, args);
}
return null;
}
private void updateList() {
doRemove();
doAdd();
}
private boolean moreAdded() {
return !toAdd.isEmpty();
}
private void dispatchList(List<T> list, Method method, Object[] args)
throws IllegalAccessException {
for (Object t : list.toArray()) {
dispatch(method, type.cast(t), args);
}
}
private void doRemove() {
list.removeAll(toRemove);
toRemove.clear();
}
private void doAdd() {
list.addAll(toAdd);
toAdd.clear();
}
private void dispatch(Method method, T t, Object[] args)
throws IllegalAccessException {
try {
method.invoke(t, args);
} catch (InvocationTargetException e) {
if (!(e.getTargetException() instanceof DisconnectedException)) {
e.getTargetException().printStackTrace();
remove(t);
} else {
e.printStackTrace();
}
} catch (RuntimeException e) {
e.printStackTrace();
}
}
public RemoteEventListenerList(Class<T> type) {
this.type = type;
}
public T getProxy() {
if (proxy == null) {
proxy = type.cast(Proxy
.newProxyInstance(type.getClassLoader(), new Class[]{type}, this)
);
}
return proxy;
}
public void add(T t) {
toAdd.add(t);
}
public void remove(T t) {
toRemove.add(t);
}
}
- 08-08-2008, 02:56 AM #6
Why doesn't the server send all the info to the client in one go and let the client do the displays serially as it wants?
The Proxy code above implies a different design then I was working towards. How much communication does the applet do with the server?
The Proxy code would be to allow the applet to call methods on the server without having to worry about where the methods were located.
That seems like a lot more complicated than you have described.Last edited by Norm; 08-08-2008 at 04:05 PM.
Similar Threads
-
synchronization question
By oguz in forum Threads and SynchronizationReplies: 2Last Post: 07-22-2008, 08:56 AM -
Synchronization Doesn't seem to work
By sherinpearl in forum Threads and SynchronizationReplies: 1Last Post: 04-23-2008, 06:30 PM -
is synchronization on method passing local variables as parameters needed
By reddzer in forum Java ServletReplies: 0Last Post: 11-10-2007, 04:47 PM -
Synchronization problems
By Jack in forum Advanced JavaReplies: 2Last Post: 07-02-2007, 01:17 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks