aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Swing application being refreshed by server actions ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Swing application being refreshed by server actions ?" Watch "Swing application being refreshed by server actions ?" New topic
Author

Swing application being refreshed by server actions ?

Hatem Alimam
Ranch Hand

Joined: Dec 14, 2008
Posts: 30
Hi guys

I have a little project (a thin client) .

The main function of this swing application is to notify a user of an action happened in the server side ( DB Changes ).

What is the pattern to make the server refresh the client or notify it without any action from the client side ?

What do I have to do ? put a checker in client side which checks every 2 seconds on any changes !!! .... so here I am causing a network traffic .
please any idea on how to solve this issue.

Best regards.


SCJP 5.0, SCWCD 1.4, SCBCD 3.0 with 100 score
Jeff Storey
Ranch Hand

Joined: Apr 07, 2007
Posts: 230
Hi Hatem,

There are a couple of ways to handle this. The way you suggested about the checking every 2 seconds is known as "polling" or a "pull" system, where the client asks the server what has changed. As you said, this can lead to extra network traffic. Another simple way to accomplish this is using the Observer pattern (a "push" system). The client tells the server that it wants to be notified whenever something changes. One example can be found here. http://www.javaworld.com/javaworld/javaqa/2001-05/04-qa-0525-observer.html.

Jeff


Jeff Storey
Software Developer
[url]http://jeffastorey.blogspot.com[/url]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42292
    
  64
I'm not convinced that there's a really a problem with client pull. Sure, it's network traffic, but how many clients are we talking about? If it' just 10 I wouldn't worry about it; if it's potentially 1000, then I'd worry. And maybe a check every 10 or 30 seconds would be sufficient?

What's more, server push has its own problems. You could keep a socket to the server open, but then you're using up server resources permanently although nothing much happens, and socket connection can go stale (so you'd need to send an occasional ping over them just to be sure they're still open).

The server opening a connection to the client (after the client has initially notified the server that it wishes to receive updates) is also problematic, as many desktops machines may not accept arbitrary socket connections without firewall changes.


Ping & DNS - my free Android networking tools app
Jeff Storey
Ranch Hand

Joined: Apr 07, 2007
Posts: 230
Ulf,

I agree, it may not be a problem. It's also dependent on the context of the application. If it's a time critical application where data might be too stale after 30 seconds, then I'd definitely recommend the push, but for a smaller app with a single (or a few) clients, the pull system would work fine too.
Hatem Alimam
Ranch Hand

Joined: Dec 14, 2008
Posts: 30
Hi ,

it's seems to be a great solution.

Thank you Jeff , And Ulf .

Hay Hay Java Coders.

Heres a good place to start .

Applied Java Pattrens
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Swing application being refreshed by server actions ?