Minecraft Bukkit Plugin - Respond to Website - java

I was wondering if there was a way to make a plugin that has an event that's triggered when a user performs an action on my website. I would like to do this to make a custom store, since I don't like Enjin or Buycraft, since they are not very customizable.

You could have a php page that returns any tasks waiting to be done. Each task would have a unique id (maby mysql primary key?). Every 0.1-5 minutes (really any amount of time that is shortish) the plugin sends a http request to the page. The page would require either a get and/or post password to access, this prevents hackers/griefers/etc from gaining access to it. The plugin then does the tasks then sends another http request to another php file to mark the task as done (again with the password(s) for security), so it does not show up in future polls of new tasks (preventing it from being run again).

Related

Long running we request, UI gets timed out by the time response is ready

I have one angular app and one spring boot app, there is one request goes from UI to spring boot with some 100-200 objects even more, for each of these objects another back end system is called within a loop.
something like..
list.parallelStream().forEach(e->{
//code using rest template for backend.
// add the responses to an array list.
// i can send all these objects to backend at one shot because they have some limitations and dont support it currently.
});
This takes a lot of time to complete and by the time all the request is completed the UI gets timed out.
I tried using executer framework, forkjoin or parallel but this is not enough. because browser wait for 30-60 sec.
I want to switch to anyc process where i submit request to spring boot, from UI I should be able to check the status of the request after time interval. i tried concepts like DeferredResult, #Async, completeable future and StreamingResponseBody. is there any way to handle these long running request???
Some of these concepts works but when the input size increase they also fail to work properly. how do i manage to get the status of my request and use some progress bar etc to show even user.
or any better approch?
For me it sounds like you want to stream data.
Perhaps spring's reactive stack is something you want to look at:
Building a Reactive RESTful Web Service
Video Tutorial using Kotlin
With this your angular app should be able to display or react very finished processing of an individual item as they happen.
Hope that helps.

Send a message from Server to All Clients

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

Generating PDFs in multi-threaded environment

The goal is to make a pdf-generating service. The service is avaiable via simple servlet.
Assumptions made are such, that the service is supposed to be running on multiple load-balanced servers (e.g. Tomcat instances), with each server running its manually created threads, which generate PDFs. Each request has to be written to a database, and its pdf status has to be updated throughout the whole process, like:
QUEUED at first
IN PROGRESS when the pdf generation starts
PROCESSED after a pdf is created
Another assumption is that each Tomcat instance which got the request is responsible for generating the document. The whole solution must be persistent across restarts, so each server instance needs to store its task queue somehow (in a file for example?).
One might think that the whole process might be synchronized with the database, but IMHO polling a database for new PDF requests can be time-consuming.
Any ideas, hints?
Assumptions are flexible, so if anyone, who happens to come with some good out-of-assumptions solution, is kindly asked to share his/her ideas.
For queuing, use a message bus like RabbitMQ or ActiveMQ with persistent queues.
Provide a request servlet which puts a request on a message queue and sets a QUEUED status for the request in the database.
Use listeners (in the Tomcat servlet container or not) to listen for messages on the queue.
When the listeners detect a new message, they pull it off and start PDF generation, and set the IN PROGRESS status on the message.
When the listeners are done processing, they set PROCESSED status on the job, ACK the message to totally remove it from the queue, and move on to the next one.
If a listener dies before it is done processing the message, the message will be un-ACK'd and available for other listeners to process. Another listener will pick it up, set the status to IN PROGRESS again, and complete it.

server restart notify to clients

I am working on web based applications.
Server : Tomcat
Technology : Simple Jsp/Servlet/JQuery
I need to restart my server as an when new updates are there. And these changes are frequent almost every 1 or 2 day. I think to create some mechanism like I can say to every logged in user to save their changes and server will start in few minutes. (Timer will be there). Popup should be open though user is ideal.
Is there any direct way to do this so? Or I need to implement ajax call on every few seconds to server on every jsp page to check if any message is there on server???
Any idea will be appreciated.
Thanks in advance.
For the approach you are taking, I would suggest you to use Async Serlvets(Req. min Servlet API 3.0) or Apache Tomcat's comet technology(Kind of Async Servlet).
You will make ajax call on every page when it(page) loads(ajax onload() for eg.) to Async Servlet and will idle until response from server comes. This Async servlet should send Server Restart notification to all connected clients- whenever you trigger notification manually. Once ajax client gets notification, it will display the Warning(or user friendly message).
This will remove the need to make unnecessary polling to server after fixed internal - A big plus resource wise.
Personally I wont suggest this way, better get agreed on specific timeframe for deployment everyday(every two days) with clients and perform deployments in this time.
If you are from India- You must be aware about IRCTC website- Which is not available for train reservation every night for 1 hour.

detecting if a file is ready and serving it for download

I have a Spring MVC web application that is generating a report on the server, once the report is generated, I need to enable a button that allows the user to download it. I am not sure how to go about doing this.
I figured that I will have to spawn off a thread that will just keep checking for the existence of the file and use javascript (jQuery or prototype most likely) to handle the UI elements, but I'm just not sure how to tie these all together.
There are no threads in Javascript. Instead you'll set a timeout to do the polling. The polling would take the form of a URL that will respond with some sort of "ready" indicator when the file is ready. If the file is not ready, then the AJAX success handler will start another timeout. When the server says it's ready, your Javascript handler will make the button visible and no further polling will be necessary.
Check this example here http://forum.springsource.org/showthread.php?t=70489 and let know if it works
You could use some type of messaging on the server that tells the client when the file is ready e.g. we us a table for all report requests and the server writes the status into the table and the client is then asking for the status of the report job with an AJAX call every few seconds.

Categories

Resources