I'm new in this area and a little bit confused about my current thoughts on a web-service implementation for my application. I want to synchronize all connected clients with the current data on a MySQL DB. I came up to use web-services as for coordination purposes, but I got stuck.
The way I tried to implement it is...
The web-service is running a deamon to check/listen on CRUD operations affecting DB data. Once an CRUD operation has been occured it undetakes to notify all the connected clients and each client in turn refreshes the JTable with current DB data and informs the user with the change that took place on the DB.
This is where I'm stuck...
The way I'm thinking it's (maybe?) wrong, since conceptually web-services are awaiting for client requests and then send him the corresponding response. But here, there is no client requests. The web-service just sends a response (noification), which must multicast since it's unaware of a "calling" client -there's no request.
Therefore, in order a client to send a request it must "cron" all the time the web-service if a change on the DB has been occured. Then the web-service responts as true or false with the CRUD details (CRUDEventFired(event_type, event_details)). But, this is not optimal as it will create big and (much of time) useless traffic especially when there is no CRUD operation occured. Also, there will be two different deamons (one in web-service and the other in client-app) that check/listen for the same type of event and that's redundant.
Also, with that implementation it seems that there's no need for a web-service at all and the code to check the DB for changes could be implemented in the client. On the other hand setting the client responsible for the DB changes would require to code the same functions in different platforms (desktop, ios, android, etc), while setting the web-service as the coordinator for data synchronization between clients would require to code only once the appropriate function and each client simply implement its own NotificationListener().
Is it wrong the way I'm thinking using web-services? How it should be changed? Do I even need to use web-services?
John Astralidis wrote:Could you please anyone give me any advice?
I would rely upon a MOM software instead of using webservices. This way all clients may be asynchronously notified when a remote event happened, instead of continuously polling remote server. When an update event occurs, receiver client should invalidate its own copy of the data, and eventually reload data from mysql. I wonder if this approach may work on a medium-sized scale, though.
posted 5 years ago
Thank you very much for your reply, but let me ask you what do you mean? To use/buy a ready-made software? If so, this is not the case I want.
If not, are there any example codes for reference as a starting point?
Well, in real-world projects is generally preferable to adopt one well consolidated, production ready framework instead of re inventing the wheel. In your case, if of a self-educating project, you are free to experiment any approach you want, experience difficulties , try to solve or bypass them, and learn a lot from your mistakes. First, I would have a look of what are well known, widely adopted approaches for solving yor application scenario's problems. Architectural patterns -books, articles and so on -are my opinion a good starting point. Before coding, I'd prefer studying -having the chance and the time - what is already known in patterns literature. I would try to understand why things are done in a certain way, before trying to code.