I want the user to be informed that database is updated. I'm using PHP and mysql. There is a process behind which updates information in database. Once the process (java application) updates the database, how can I tell user the that they can view the processed information?
I don't have any idea at this moment how to do it or even is this possible?
You will have to check some script periodically (assuming your endclient is an webapp - probably using javascript) and raise an alert once the script returns the DB has been updated. Have a look on jQuery polling.
you could trigger ajax requests to poll information from the server, or you can try to use websockets to let the server
I've not fully understood your question.
If I've understood, you have a job that updates tables in the db.
While the job is running the user is not aware that the data are being updated and when the job has ended the user is not informed about.
I don't know if you can handle the tables, what kind of data are there, and if you can manage/control the java app...
If data and tables (and java app) are under my control, I will do the following:
create a table called job_in_progress, with some fields like running as boolean, started_at as timestamp.
modify the java app to update that table writing true in the running field when started, and writing false when ended.
when the user goes to your PHP page, you check the job_in_progress table, and if the running field is true, it means that the java app is still running.
Another way: send an e-mail to the user when the java has ended (if the update process is heavy).
Related
I know I don't have any code to show you guys, I am stuck at some point and I dont know where to start. I hope someone will help me.
I am developing a Spring MVC application, and I need to send a message to all active session users to execute a script which is available to all the clients as it is defined in a js file and included for every user.
I have looked around and found some frameworks which offers these type of functionalities like Atmosphere but I don't think it should be used in my situation as it is a big framework and the functionality required is very little. I have also gone thorough WebSockets but I cant find anything which would help me in invoking the script on client side for all the clients.
If someone can help me go to a right path or direct me to a similar example. I will be grateful
****Update****
I can also use polling if there is way that: if the controller gets a request the session should be considered idle during that, for instance, there is controller which is called every 5 minutes and in the session out time is 30 minutes. The session won't expire in this time if the controller used for polling is called every 5 minutes, I need to exclude the particular controller from calculating the idle time
No Polling Solution:
From what I gather, you need a Remote Procedure Call mechanism.
I would go with https://github.com/eriksank/rpc-websocket.
The general idea:
Your clients register themselves to your server process as "consumers".
When a message is ready, your server then goes through every registered "consumer" and sends the message which rpc-websocket can handle .
Polling Solution:
Here is a general idea, works if you have registered, logged on users.
Have a database table that stores messages, lets call it "messages".
Have a database table that keeps track of messages and users, lets call it "message_tracker". if a user has seen a message, there will be a row in this table for the messageId and UserID.
Have a javascript script poll a server url for new messages. What is a new message can be decided based on the database tables above.
If a new message is found, process it and then call another server url which inserts into the message_tracker database table
I am using this code:
my code
to output my table. My question is how is possible to updating it in the page without reloading?
Thank you
Either use AJAX requests or if you feel good, try HTML5 websockets : add a trigger to the table UPDATE / INSERT / DELETE, and keep your clients up-to-date.
AJAX means you'll be doing a request from client to server every few seconds, to check if anything have changed and if so, you'll download the new data (usually devs use JSON), and update your table using javascript with this data.
With websockets, the event starts server side : whenever the db table is updated, you send a request from the server to the clients to tell them to update the table with the new data.
You'll find plenty of examples on the web, searching either for AJAX or websockets.
If you don't know what they are, I'd recommend you to go for AJAX, as setting-up a websockets server with PHP might be tricky.
I need load 10.000 rows in my database google cloud sql using AppEngine with Java. For this case, i use a proccess using backend, but i want advertise to user, how rows was wrong load? But, i don't know as send a message from my backend proccess to my front to show a message to screen.
Regards.
Maybe you don't need to send callback (from backend to front-end). Maybe you should make the front-end poll to see when these results are ready at the back-end side. Maybe through some JS/Ajax code which keeps polling on the background and once the results are ready, pulls them and displays them in the designated area of the page. I assume your front-end is a web page.
I am developing a java web application using JSF and I will like to find out if it is possible for me to hold (and save) user information in an different location, say a file, and then when the user confirm their email before the date is save to the database.
I don't yet understand certain thing. What I intend to know is if it is possible to use serialization for this problem.
You need to persist the user on the database before it has confirmed its email.
You need to set him a status NOT_CONFIRMED which can be transformed to CONFIRMED.
Until he has confirmed, you should not allow the application login for users which are found, but having an illegal status like NOT_CONFIRMED.
There's no benefit in saving the user data somewhere else for most usecases.
HTML5 proposes the local storage API which permits storing data in the browser of your client. Since the user is not logged, you'll be unable to recognize him from another computer, so it's fair that the data will be available only on the browser he wrote it in.
You can then transfer the data to your server once the user is connected (htis feature is used by Google documents, offline gmail etc...). If you're using GWT, a java API is available to access the native browser API, otherwise, you'll need some js coding
Best Regards,
Zied Hamdi
http://1vu.fr
Environment: The application is using Spring Framework 2.5.6.SEC01 and iBatis 2.3.4.726. It is MVC design.
Here's the scenario:
Input/update data from the client
Press Update button to submit
Process the data and execute DML (insert, update, delete)
Back the result to client and display the data
However, upon the page loaded, I need to call the API via Javascript (i have no control with the API, just need to pass the required parameter and check the result if SUCCESS or ERROR)
If API returns SUCCESS, nothing to do. But it returns ERROR, I give alert message to inform the user.
I have View(client), Service and Data Access Layers. When the client do the submit (scenario #2), it enters the Service to process the data and automatically start Transaction (scenario #3). Automatically execute the commit upon exit to Service and back to client to show the data (scenario #4).
Problem: How can I suspend the transaction not to execute the commit, then back to client to call API via Javascript. When API returns SUCCESS, execute commit via Ajax (or other way) or in the other hand, rollback it.
Any guidance on the right direction is appreciated.
If I understand correctly, you want to start a database transaction, insert data (without comitting), keeping the connection and the transaction open, return to the client, and based on some javascript result, do a commit.
This feels like a strange design where the client can actually keep a connection open, making your application extremely vulnerable for (D)DOS attacks or client problems in general.
I would try really hard to remodel it as follows:
Upon submit, call the javascript you need to confirm the commit/save action
When the javascript succeeds, do the submit to your own server
Do normal Connection/Transaction handling within the DAO, not exposing transactions to the client.
This is quicker, more robust and also probably less code.