Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Swing application being refreshed by server actions ?

 
Hatem Alimam
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeff Storey
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeff Storey
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic