Java Spring Boot - enable button when server says

Viewed 172

I have a task to create a button which execute initialization of server on demand. I have successfully implemented the part where the customer pushes a button and a remote server is created. While the button is pressed, the application will redirect to another page this is where I want a button which will be disabled as long as the server is not created. After clinking on it I want to enable it and redirect to new server.

Any thoughs how to eneble this button from backend?
I am new to web development and will be thankfull for any suggestions.

1 Answers

I assume your backend server is not the same server you are creating on a button click.

There's 2 obvious approaches here.

(1) HTTP polling

Frequently make HTTP requests to the server (every 5 secs or so) - to see if the new server is ready. The server response should contain JSON with a boolean value to say if it is ready or not. When it is ready stop polling and enable the button.

(2) Websockets

When the server is ready, the server will emit to the client letting the client know that the server is ready. This is the beauty of websockets, the server can talk to the client unlike HTTP where the client can request from the server and the server can respond but the server can only respond to a client request.

Related