How do I create a snapshot of running java application in order to be able to load the same snapshot later to recreate exactly the same state of running application? How do I load this snapshot?
EDIT
Application uses Event Sourcing, we have event log which can be replayed to get to a particular application state, however we'd like to archive the log and only retain the latest application state in a snapshot which we'd like to load instead of replaying all of the events from event log.
I think you can serialize part of your data and deserialize it later on. Also, you need to think about common patterns (e.g. Command) and use them in your app. This will help you to do serialization of app's behavior or processing flow (even on half way of processing of data).
There is a great library from Martin Krasser which does exactly that - keeps state using event sourcing and also allows for event log snapshots: https://github.com/eligosource/eventsourced
Related
I'm having two main code design problems in my app.
My app mainly consists in sending ssh commands to a remote host.
Right now I have a separated thread (singleton) which gets messages through the handler which specifies which is the next command to be sent, or the username/password/ip (kind of messy but works...).
This approach works good for unidirectional commands, but I'm planning to make it bidirectional which I don't know how to implement. As far as I know Android doesn't allow to change UI elements by another thread so a listener pattern wouldn't be it.
Also, I just read that we shouldn't save things in the application object, which is also what I'm doing by saving whether my app is running full or lite mode... I don't know where should I save it in order to not make it obviously hackable (sqlite-SharedPrefs are easily editable...)
Only a general hint: There is Activity.runOnUiThread() to execute code (later) on main thread.
Say that we are writing a Java Swing application and we use Eclipse or MyEclipse to develop it. In web applications, you make code changes, you save and your ant deployment file takes care of the deployment of the changed files. Then you just refresh or hard refresh the web page and the changes appear there. Can we do the same thing for a Swing applications so that we don't have to close and open the program from the beginning every time we make a change?
I don't think so because you need hot code replacement ! Maybee using another framework.
You can't simply do that because once JVM is started, it loads the class files once and will not reload it untill next loading request. But you can use ClassLoader to load modified class files dynamically.
The following two articles may help:
IBM article on "hot class swap"
"Who Said Runtime Class Reloading Is Hard in Java?"
The first one is in Chinese, but you can look at the code and the result. I think the second article is more helpful for a GUI application.
In MyEclipse you can start your application in debug mode instead of run mode and changes you make will be pushed to the target VM; if changes you make cannot be replaced you'll see a dialog informing you the replace failed and you will need to restart your application. You don't need to place any breakpoints in the application, just starting in debug mode is sufficient.
As Guillaume states above, changes to the class structure will typically not be hot-synched, but changes within existing methods should be fine.
Obviously, how successfully hot-synched changes affect your running application would depend on your application design.
For my project I want to access the data from as many bug- and work-item repositories as possible (for development in Eclipse). Therefore I use the Mylyn plugin because it already provides a framework for efficient use of multiple sources.
If I found out right, the tasks are saved under .metadata\.mylyn\tasks.xml.zip\tasklist.xml and .metadata\.mylyn\tasks\<folder>\<id>.zip\data.xml. But I don't know how to access the data and get changes...
Is there a possibility to receive a notification if a task changes (e.g. if a work item status changes from CONFIRMED to SOLVED)?
Is it somehow possible to subscribe to the Mylyn event which shows a little notification if something changes? Or is there something like an eventlogger or resource change listener?
Thank you!
Mylyn has all of this data accessible by a variety of API's. You can use the ITaskDataManager API (accessible via TasksUi.getTaskDataManager()) to get the full task data for a given task. You can listen for changes to when the task data is updated (e.g. there was a change to a task) using the ITaskDataManagerListener and attaching your listener to the TaskDataManager, then you can look at the task data to get what the values of the fields that you are interested in are. To see how the notification popup uses this, you can look at the TaskListNotifier.
Feel free to email mylyn-integrators#eclipse.org if you have more questions.
I'm working on porting a desktop application (WinForm) to a web application (Java/Spring/JPA). The problems are many and I'm struggling a bit...
Now the problem is threading!
In the original application, that performs the export of certain data from the DB, there is a progress-bar indicating the progress of the process.
I want to port this progress-bar in the new web application. To do this I thought of using AJAX and use a separate thread to run the data export.
The main concerns are:
Am I following the right approach? Are there problems using multi-threading in web applications?
If during the export process F5 or refresh button are pressed what exactly happens? How can I stop the process?
How do I update the progress bar periodically? Do I have to make calls via ajax to the server?
I'm primarily an ASP.Net developer but from what I know of the HTTP protocol this just isn't the way to go about it. I've seen a lot of fairly clever solutions for this but in the end what becomes clear is that the HTTP protocol simply isn't designed to work like this.
Obviously you're aware that a flash or silverlight app would be able to do this but that comes with it's own set of issues.
Myself I prefer to keep all the weirdness on the server. In the past I've had to come up with a way to deliver several thousand emails through a web application and update the user on how it's coming along. I designed a set of tables to act as a queue. The web application would simply place any delivery requests in this queue and the progress bar would be determined by a request that checks the status of the items in the queue. Running in the background was a windows service which would also check this queue and was actually responsible for delivering the mail and setting the status of each item as it completed or failed.
It was a bit difficult to develop since windows services can be tricky but once it was up and running it was extremely smooth and reliable. Depending on your circumstances perhaps a simple scheduled task set to run every few minutes would do the trick for you.
I wouldn't necessarily jump straight to running a separate thread explicitly for the export. While it would be ideal to do this, the capability of the web container to do this is going to be a limiting factor. Your traditional Java EE app server generally discourages spawning threads for this (though you can hook up to a thread pool for this). Some containers are great at freeing up the threads from blocking until the work is done (Karaf with Jetty and Camel, for instance) so that they can service other web requests while the export is occurring. But my guess is that you're probably okay with the "start export" thread blocking until it receives a response.
How long does this export take? A couple of seconds, or are we talking closer to minutes here? If it's shorter, I'd think that just putting a little "Waiting" icon with the little circular spinner on it (using your favorite Ajax library, whatever that is) would be sufficient.
If you really want a true status bar that periodically refreshes itself, then yes you'd have to poll for it at some frequency. Presumably that could be a simple request that would load some kind of progress for the job from a database table for that job ID.
Find my answers Inline
I am following the right approach? Are there problem in using multi-threading in web applications?
-Yes you are on correct path. No there is no such problem in multi-threading in web application and its as easy as you do it in WinForm. Instead of using Dispatcher to update the UI, you would be making AJAX calls and with javascript DOM manipulation would take place.
If during the export process F5 or refresh button are pressed what exactly happens? How an I stop the process?
-Unfortunately there is no easy way. The standard way is, when such kind of processing is done and the user hits F5, you would show a dialog(with help of javascript) and inform user that the job is still running. If the user still wants to refresh then you have make another request to the server for cancelling the task.(You need to store thread id or cancellation token some where to cancel the task)
How do I update the progress bar periodically? Do I have to make calls via ajax to the server?
-The standard way is, generally you show show a loading image. IF you want to show a context senstive progress bar, it would mean you have to do polling. Here is an example by Dino Espito. Though its in ASP.NET, you could understand the underlying principle
Dino Espito
I am working with eclipse resources right now and interested whether it is possible to handle file read-only property change ? For example user changes file read-only property outside application and then I can handle this property change event in my application.
I don't think, it is possible to do it automatically, as Eclipse resources do not synchronize all the time with the file system. More specifically, file changes do not trigger events in the Eclipse resources directly. Files are refreshed only when the resources are read.
Maybe if you are refreshing continously, it would be possible, but that can have quite an overhead. After a refresh it is possible to listen to changes in resources - thats what Builders and resource listeners are for.
To be more precise than Zoltan's answer:
No, it is not possible to do this directly. However, it is possible to periodically refresh the workspace and look for changes that you are interested in.
Create and schedule a Job that runs every XXX seconds. This job will run IProject.refreshLocal(IResource.DEPTH_INFINITE, null). After running this operation, it will re-schedule itself to run in another XXX seconds.
Add an IResourceChangeListener that listens for the changes you are interested in.
Now, if the Read-only changes happen from inside the workspace, you will not have to do #1, and #2 (the resource change listener) will run automatically.