Trigger an event when a download starts - java

Is there any way to listen for/capture the beginning of a download (not completing it, as I want the user to make a decision before the download begins)? The download will be user triggered (via browser or app, for example).

Related

Schedule JavaFX Application in Windows

I've GUI base JavaFX application. There are two buttons on it to perform specific functionality. One button used to send Inventory using HTTP Client to magento. I want to schedule this application on windows to run every 15mins. How to schedule it in way that when it runs, only 'Upload Inventory' button is clicked so that Inventory would be sent.
Scheduled tasks should run in the background and the most they should do on a UI is show a notification that "hey I'm active again". Certainly not show user windows (which is done typically to hand over control to the user) and then reclaim control from the user by automatically starting to click things on behalf of that user. Refactor your code to facilitate the function to run indepedently of the UI and schedule that.

Restart a GAE instance without re-deploying

I'm currently running a (free) Google App Engine instance which I need to restart manually.
However, in the 'instances' tab in my project it just gives me the options to 'view logs' or 'shutdown'.
Shutting down the instance is not an option because I do not want to manually re-deploy the application to google appspot. This is not an option because I need to do this from multiple locations (even on the road), and my project is located on a single desktop computer.
The reason I want to be able to restart the instance is because of the caching within my Java application. I cache certain users and data so that I only rarely have to call the datastore.
However, when I want to delete certain records from the datastore they still exist in the cache of my application. This means that the users can access data which was already deleted by hand.
I know it's possible to write a single-use admin application just to clear the cache, but that's not the way I wish to solve this problem. It should be easier than that.
Is there any way to restart a running instance, effectively rebooting my Java application, without re-deploying the entire application to google appspot?
Go to the Datastore viewer tab in your App Engine console. Click on "Flush memcache" button. Or, go to the Memcache viewer tab and click on "Flush cache" button.
If you want to restart your instance manually - shut it down. Then hit your website, and a new instance will be created automatically. There is no need to redeploy your app again.
The "Flush memcache" approach didn't work for me. I couldn't find where to shutdown a service either.
Instead, I found a way to delete the instance being served then hit the application's url. App engine would automatically create a new instance, which essentially would be a restart.
To delete an instance, do this:
From App engine dashboard, click "Instances" on the side menu. On the Instances page—below the graph—you would see a list of active instances, delete them, then hit your app's url.

Delay Java initialization until needed

I have a web page where sometimes I need to communicate with a device.
This device is accessed with sockets, so I have a jar file with the support libraries.
When you want to get data from the device, you press a button, and a javascript method fetches the data using the library (no java code here)
The presence of the jar makes the java machine to start as soon as you load the page.
Since there is a lot of users that don't use this option (usually they don't even have the device, to begin with), they see that as a nuisance.
Is there a posibility to delay the java loading until the button is pressed ?
I don't want to redirect them to another page, that should be done in the same page.
You can load the jar file into a seperate div created dynamically via javascript, at the time you need it.
If you want to consider loading your application with java-webstart-technology, you can implement a button similiar to what oracle has on their page here
Basically what the button does is download the required jars specified in a jnlp-file and launch it.

How to remove all file when app is removed by user?

I have blackberry app (java). My app stores some informations in files (file:///store/home/user/app_name/). When user removes app, these files don't delete.
I want to delete files when app is removed by user.
What is solution?
Don't store files this way - use Persistable for your app data instead: http://docs.blackberry.com/en/developers/deliverables/17952/Storing_objects_persistently_1219782_11.jsp
There are two "standard" ways to uninstall an application. The first, via Options - Applications menu. And the second, via javaloader -erase -f command.
Theoretically you can intercept the uninstall event for the first way (when you use "Options - Applications" menu), but you need additional application that receives this event and does the cleanup action.
To intercept and recognize an unknown event I do the following.
I write a simple BlackBerry app, that implements and uses GlobalEventListener and runs in background, and prints every intercepted global event guid to the system output and/or log with timestamps.
Now, uninstall your app from Options menu and inspect logged global event guids. After that install/uninstall another applications. And then inspect log/system output window to find out which events are related to uninstall action.
It does not guarantee 100% result, but at least you will get fun with coding, logging and exploring.

Access by one client at a time

My requirements are as follows.
I have a web application developed in java.
I have a link in the html page. When the first client clicks submit button in the html page the batch file should run.
Meanwhile when the other client clicks the submit button he should get message that the page is busy.
If the first client clicks release button then the other clients must be able to run the batch file.
How can I do that?
Set a flag when the submit button is clicked and clear it when the release button is clicked.
Depending on your architecture, the flag can be anything from a boolean variable in your code, a special entry somewhere in your database to a temporary file.
When the submit button is clicked, check whether the flag is already set. When it is, return an error message stating that the page is busy.
In pseudo code:
if (flagIsSet()) {
showPageIsBusy();
} else {
setFlag();
startBatchFile();
}
Remember to clear the flag when the batch file finishes or the release button is clicked and somewhere in a finally block.
You also have to make sure that only the client who started the batch file can release it and clear the flag.
As pointed out by Avi in the comments, you should also remember to synchronize access to the flag.
Pseudo algorithm:
Modify the batch file to run a servlet before and after batch operations.
Before running batch file, set a servlet or flag that will register a file or database or a session variable that I am being executed and at completion of batch file, set a servlet or flag that will register a file or database or a session variable that I am being released
When user clicks release button, run the same servlet which will relase the flag.
When User submits submit button, check for that flag whether it is executed or released, depending upon you alert your client.
you could use a field in servlet class (a big nono otherwise) for a flag.
If your application happens to run on multiple load-balanced servers, then you face the same problem I do :) I submitted a question earlier about it, but unfortunately I didn't get any response. In any case, you can see my solution for the problem as an answer to my question here.
That is a Singleton or better an Application-Bean. This Bean should kick of your long running background task and provide information about it, e.g. if it is running and maybe stuff like when did it start, who started it and if you could the progress, so you could display a progress bar as well.
If you would tell us, what web application framework you use, we could give better tips, I think.

Categories

Resources