Foros de discusión

Liferay 7CE GA3 - Portlet runs even after delete the war from the osgi

Theja Babu, modificado hace 6 años.

Liferay 7CE GA3 - Portlet runs even after delete the war from the osgi

New Member Mensajes: 15 Fecha de incorporación: 2/06/17 Mensajes recientes
Hi All,

I'm developing a portlet application in spring portlets. I want to stop a portlet running with some spring schedulers. To do that I have open telnet and uninstall the portlet and I can see that portlet was resolved state. But in the log file the scheduler logs are logging. The same will happen even after I delete the war file from OSGI - war folder. To stop this I need to restart the server till then application will run and after it will stop running the war source code.

Can some one let me know the reason and how to solve this issue
thumbnail
Djamel TORCHE, modificado hace 6 años.

RE: Liferay 7CE GA3 - Portlet runs even after delete the war from the osgi

New Member Mensajes: 18 Fecha de incorporación: 21/10/14 Mensajes recientes
Hi,
Try to override the method "destroy" in your portlet and stop the scheduler in this method, this method will be called when portlet is un-deployed by portlet container.
If you do it with Liferay 7 manner for how to schedule Jobs (extending BaseSchedulerEntryMessageListener): you have activate and desactivate methods.

Note that adding and removing JARs must be done while the portal is shut down. Changes will take place the next time the portal is started.

Kind regards,
Djamel
Theja Babu, modificado hace 6 años.

RE: Liferay 7CE GA3 - Portlet runs even after delete the war from the osgi

New Member Mensajes: 15 Fecha de incorporación: 2/06/17 Mensajes recientes
Thanks for the replay Djamel TORCHE.

Just wanted to understand how the code will run after I uninstall a spring portlet war. Since there was no source in the OSGI ideally it should stop running the code. This was happening very rarely not regularly. If I delete of uninstalling war for 10 -20 tile this problem will come once or twice.

Is there any other place that OSGI will have a reference of any deployments that did in deploy folder like temp or work etc. So that I can clear that to stop this .
thumbnail
Olaf Kock, modificado hace 6 años.

RE: Liferay 7CE GA3 - Portlet runs even after delete the war from the osgi

Liferay Legend Mensajes: 6403 Fecha de incorporación: 23/09/08 Mensajes recientes
Theja Babu:
Just wanted to understand how the code will run after I uninstall a spring portlet war.


Not sure if I understand you correctly: When you remove a war file from the server's directory, the runtime will sense that you're about to uninstall this module, run all the shutdown code (even though the file is gone, the classes/resources are all loaded into memory) and only once this finished will release the memory, finally undeploying the plugin. E.g. the code is still there when the file has already been deleted.

What that what your question was about?
Theja Babu, modificado hace 6 años.

RE: Liferay 7CE GA3 - Portlet runs even after delete the war from the osgi

New Member Mensajes: 15 Fecha de incorporación: 2/06/17 Mensajes recientes
Hi Olaf,

I have a spring portlet(as war) and have some scheduler running in a class. I deleted from osgi-war folder and still I can see that scheduler is running and logs are printing. But this was not show in the lb command . Im surprised how the liferay is executing that scheduler related source code after undeployed the portlet.
thumbnail
Christoph Rabel, modificado hace 6 años.

RE: Liferay 7CE GA3 - Portlet runs even after delete the war from the osgi

Liferay Legend Mensajes: 1554 Fecha de incorporación: 24/09/09 Mensajes recientes
I noticed something like that too. When you register a component in the OSGI framework and don't unregister it, it will still work/will still be found.

I am not really familiar with spring portlets, but do you have an activator? If you register the job, you need to unregister it later:
e.g.:

	@Reference(unbind = "-")
	private volatile SchedulerEngineHelper _schedulerEngineHelper;

	@Activate
	@Modified
	protected void activate(Map<object, object> properties) throws ConfigurationException {
...	
			_schedulerEngineHelper.register(
				this, schedulerEntryImpl, DestinationNames.SCHEDULER_DISPATCH);
	}

// Do you deactivate it?
	@Deactivate
	protected void deactivate() {
        	_schedulerEngineHelper.unregister(this);
	}

</object,>
Theja Babu, modificado hace 6 años.

RE: Liferay 7CE GA3 - Portlet runs even after delete the war from the osgi

New Member Mensajes: 15 Fecha de incorporación: 2/06/17 Mensajes recientes
Hello Rabel,

In spring we have an annotation called @Schedule this will have a pattern at what time the method has to execute. This is what i was using to schedule a task. The problem is even though I undeploy the portlet I can see the method is executing.
thumbnail
Christoph Rabel, modificado hace 6 años.

RE: Liferay 7CE GA3 - Portlet runs even after delete the war from the osgi

Liferay Legend Mensajes: 1554 Fecha de incorporación: 24/09/09 Mensajes recientes
Maybe somebody else with more spring knowledge can give you a better answer, but it seems those "@Scheduled" jobs are not meant to be stopped. But "something" needs to stop the job when the module is deactivated. If something in Spring doesn't do it, it keeps running.

I googled "osgi stop spring scheduler" and this came up:
https://stackoverflow.com/questions/42715336/stopping-spring-task-scheduler-at-runtime-by-removing-the-bean-definition-from-c

Maybe you could use something like that to stop your scheduler. Another thing I found is that you could create your scheduler yourself and then stop it later with the returned ScheduledFuture object. You basically would do the same thing I did in the code I posted. Start the scheduler in the activate method, store that ScheduledFuture object and stop it in the deactivate method.
Theja Babu, modificado hace 6 años.

RE: Liferay 7CE GA3 - Portlet runs even after delete the war from the osgi

New Member Mensajes: 15 Fecha de incorporación: 2/06/17 Mensajes recientes
Hi Rabel,

As per my understanding, the code snippet what you share is from liferay library. But we are completely developing the portlet in spring library and at this point, we can not move to liferay implementation. Is there any simple solution.
I had good experience in spring j2ee application. I have used @Scheduler in my prior applications. When i remove the war from any of the server it will stop executing the schedule job but this did not happen within the liferay server. I doubt there was some other place that code referece would be there which liferay pointing and running the job even though I deleted or undeployed portlet from deploy folder under osgi.
thumbnail
Christoph Rabel, modificado hace 6 años.

RE: Liferay 7CE GA3 - Portlet runs even after delete the war from the osgi

Liferay Legend Mensajes: 1554 Fecha de incorporación: 24/09/09 Mensajes recientes
Well, I am only a dabbler in the arts of OSGI. So, I am not sure if OSGI or Spring is responsible.

My guess is: Spring must unregister the scheduler. I think that, because when you undeploy a J2EE application, the whole application is removed and the scheduler simply killed. So Spring can just start it and forget about it. In OSGI, the container stays active. It can't simply nuke a single reference. It has to stay there, till it is removed.

Not sure what you mean with "we are completely developing the portlet in spring library and at this point, we can not move to liferay implementation". You obviously deploy a portlet in Liferay, so why can't you write an activator? The activators stop method would have to destroy the scheduler. Maybe you won't be able to use the annotation and write some code to start the scheduler yourself.

You could also ask in a spring forum, maybe open a bug there. As I said: I think, Spring needs to stop the scheduler.
thumbnail
Olaf Kock, modificado hace 6 años.

RE: Liferay 7CE GA3 - Portlet runs even after delete the war from the osgi

Liferay Legend Mensajes: 6403 Fecha de incorporación: 23/09/08 Mensajes recientes
Confirmed: When any component starts a thread or some background operation, it's responsible to clean up after itself.

If you do something in any Activation (or just within a regular service), make sure it's undone on undeployment. While OSGi will happily remove any references from its ServiceRegistry that it can, and no longer have anything at hand to reach your code, the classloader might still have a hold of your classes from a top level thread that you started. This results in an undeployed module that still has code running: The classloader (well: garbage collector) will only clean up when there are no more references to your code.

How to fix this with spring is another thing - so far this is just an explanation why undeployed code can still run. It will happen naturally.
Aayush Bhalla, modificado hace 6 años.

RE: Liferay 7CE GA3 - Portlet runs even after delete the war from the osgi

New Member Mensajes: 8 Fecha de incorporación: 7/06/17 Mensajes recientes
Hi,
Try opening the telnet localhost 11311 and stop the service and then uninstall the service and reload the webpage. I hope your problem will be resolved.