Starting OSGI Declarative Services causing thread error - eclipse

I have an RCP 3.7 application that requires two database connections, the code for each database is in a separate bundle. Previously the database startup was done in the Activator.start() methods. I have heavily refactored the code to move the database startup into two Declarative Services. This achieved the goal of breaking the tight coupling and excessive package exposure across bundles (almost everything was exported).
The challenge I have now is that the two Services do not start quickly enough, the workbench loads and I'm getting thread violations. I have both services set immediate=true. The bundle start order is eclipse.osgi at -1 (default), equinox.ds and equinox.common at 2, core.runtime at default. I have tried adding start levels for my bundles but it did not help so removed them.
Any thoughts or suggestions on how to ensure the database starts before the service returns?

It looks like you are accessing SWT from within the DS activation thread. Please use Display.asyncExec to access SWT code from other threads. See PlatformUI.getWorkbench for accessing the Display.

Related

Perl Catalyst: possibility to share .so files between child server processes

I have a catalyst web server. I can see every child server process load a lot of same .so files individually, which take a lot of memory.
Is there any possible Catalyst preload all .so file once for all child processes?
The specific behavior you are describing is a feature of mod_perl rather than Catalyst itself. But you can of course run your Catalyst application under a mod_perl environment.
Under mod_perl there can only load shared library files once and it is not possible to have different versions. Aside from the saving of loading for multiple children this would actually work over different applications on the same server. So two different web applications using the mod_perl interpreter would actually share a loaded instance of a lirbrary that they both used.
For this reason, most people generally prefer to not use mod_perl as a means of serving their application, because they actually want to maintain different library versions per application. For the reasons described above this would not be possible in this environment.
But if that is something that you believe suits your needs, then mod_perl may be the environment for you.
Support for mod_perl with Catalyst is in a slight state of flux. The generally preferred method is to use the Plack::Handler methods to bootstrap Catalyst as a PSGI application to the mod_perl environment. There are some additional notes on configuration here.
I don't know what options are available in built-in Catalyst server, but looking at the documentation for Starman shows this option:
--preload-app
This option lets Starman preload the specified PSGI application in the
master parent process before preforking children. This allows memory
savings with copy-on-write memory management. When not set (default),
forked children loads the application in the initialization hook.
Enabling this option can cause bad things happen when resources like
sockets or database connections are opened at load time by the master
process and shared by multiple children.
Since Starman 0.2000, this option defaults to false, and you should
explicitly set this option to preload the application in the master
process.
Alternatively, you can use -M command line option (plackup's common
option) to preload the modules rather than the
itself.starman -MCatalyst -MDBIx::Class myapp.psgi
will load the modules in the master process for memory savings with
CoW, but the actual loading of myapp.psgi is done per children,
allowing resource managements such as database connection safer.
If you enable this option, sending HUP signal to the master process
will not pick up any code changes you make. See "SIGNALS" for details.

reconstructing drools StatefulKnowledgeSession after server restart

Assume I created a StatefulKnowledgeSession from a given knowledgebase.
The JBPM process in this session can last for multiple days so we need to persist the session between invocations.
Now the knowledge resouces (JBPM Process definitions (BPMN files)) may change while a given process instance is running.
Upon server restart, I will need to reconstruct the correct knowledgebase in order to load the session.
But how do I know which resources to use to rebuild the knowledgebase?
Does a session keep track of the resources which were used to start it?
Do I need to build and manage knowledgebaseconfigurations?
Any help would be greatly appreciated!
Michiel
Typically your application would recreate the kbase the same way it was created the first time. So depending on how you create your kbase, this will involve simply loading the necessary processes again from classpath, from filesystem or from guvnor repository for example.
The session itself doesn't keep track of the kbase (so it can recreate it).
Kris

java Web Start is running slower than normal application running

I'm having trouble with Web Start.
There is no problem if I start the application from IntelliJ.
With Web Start it's working ok most of the time but at a point I'm loading 10000 records from database and there it's getting very slow.
What can I do?
Thanks,
It is possible that running as a WebStart application, your application has diferent memory settings. You should attempt to tweak those (as described here) and see if that makes a difference with application performance.
Other than that, you should profile your application to see where the delays occur (which parts of the application, what kind of operations, constantly or intermittently etc.)

Jboss Service / Managed Bean Question

I have a managed bean / service running inside of JBOSS. I then have a quartz job that will occasionally wake up and call a method of the managed bean. This method is sometimes long and drawn out, and since I don't want the quartz job to time out, I have implemented a thread within the managed bean to perform the processing. When the thread is finished I need to update a database table with the results. This is a very serial process and it needs to be based upon some business rules, etc.
My main question is that I can use an EntityManager within the service without a problem however I can not use it from within the thread, I get a NullPointerException. What would be the best way to address this?
Thanks,
Scott
As creating threads in appservers is discouraged, I'd modify the setup a bit.
I'd move the core of processing to a message driven bean, and have the Quartz job just send a message to the queue on which the MDB is listening. The MDB in turn can call your EJB, and like this everything remains within what's allowed by the standard.
As per the documentation and specification the Entity Manager is not thread safe and can not be used across different child threads as I had originally had in mind. I ended up going back to the original design similar to the one provided by fvu, however I found some annotations that would allow me to modify the been timeout period and allow the long running process to work properly. Here's the annotation that I used:
#PoolClass(value=org.jboss.ejb3.StrictMaxPool.class, timeout=360000000L)

Is there any way to Hibernate an Application?

(I am not talking about Hibernate or NHibernate ORM )
Windows OS (and some linux version) have 'Hibernate' option to save the state and shutdown the Machine. And Later when we restart we can resume from previous stored state.
Is there any way to Hibernate an application alone ? I mean i want to close the application by saving its state and later when i start the application, it should resume from the previous stored state.
Is there any third party tools available, Or Can i add the feature to my application by using third party libraries ?
Edit: I have a .Net WinForm application with tabbed interface and more than 50 input controls . I need a solution to shutdown the application , and restart later with same values on textboxes. I can write a routine to store and restore all textbox values. But i am looking for some generic method, which can work for any application.
You could bundle your application with its OS as an "appliance" and use something like VMWare to hibernate the whole virtual machine.
Or you could use Smalltalk.
(Both approaches are not something you can easily plug into an existing application, but hey, what you are asking for does seem to call for "platform-level support").
Microsoft MED-V Application virtualization might be able to do such thing, would be nice to have more app virtualization features in the OS itself in the future
Objects containing memory that you own are not too difficult. The problem comes with resources owned by the OS (windows, threads, semaphores etc). You could write something that saved/restored the state of these OS-owned resource but you still need to destroy/recreate them.
What are your goals for doing this?
There isn't a framework for this. The simplist way to achieve this, as you suggested, is to store your data in serializable objects and serialize them out into a file and then serialize them back in later.
That's not difficult, and gets you most of the way. It's also fairly generic-- you only need to write a few lines to serialize any amount of serializeable data in and out.
For more complex things, state like where the cursor was previously etc, should be pushed into a serializable object when the user attempts to close the app and manually pushed back when they load the app.
... but chances are your users aren't going to care about stuff like that, they probably just care that there data is back to how it was.