掲示板

Method run in my app with key=application.startup.events is never invoked

7年前 に Roman S. によって更新されました。

Method run in my app with key=application.startup.events is never invoked

New Member 投稿: 6 参加年月日: 17/03/13 最新の投稿
I have a liferay bundle Liferay Community Edition Portal 7.0.3 GA4 (Wilberforce / Build 7003 / August 5, 2016) used along with my app that contains only one class CustomFieldsCreation defined as below.

Method run in my app with key=application.startup.events is never invoked.

I need an application that will create some custom expando columns for organization if they don't exist when my server starts.

My solution for that is the following class:

package mypackage.fields.creation;

@Component(
immediate = true,
property = {
"key=application.startup.events"
},
service = LifecycleAction.class
)

public class CustomFieldsCreation extends SimpleAction {

@Override
public void run(String[] ids) {
//Create expando fields
}
}

But my method run is never invoked.

Could anybody point me why this method is not invoked?

Any other solution to my original problem (create several custom expando columns for organization if missing on my server startup) would be very much appreciated.
thumbnail
7年前 に Olaf Kock によって更新されました。

RE: Method run in my app with key=application.startup.events is never invok

Liferay Legend 投稿: 6403 参加年月日: 08/09/23 最新の投稿
Without checking this in code - i.e. let me know if it does or doesn't work:
On reading https://github.com/liferay/liferay-blade-samples#user-content-logineventspre and the code for the sample mentioned in this paragraph: Try implementing LifecycleAction and override processLifecycleEvent.
7年前 に Roman S. によって更新されました。

RE: Method run in my app with key=application.startup.events is never invok

New Member 投稿: 6 参加年月日: 17/03/13 最新の投稿
Thank you for your interest to my problem.

I did an experiment and tried the code you mentioned, but it doesn't make any difference since SimpleAction is just a wrapper for LifecycleAction.

However, finally, I figured out the essence of my difficulties. I'll describe briefly what happened.

I use Eclipse. When I created the class mentioned in this thread I deployed it to my running server. Nothing happened. I thought that it should run on hot deploy as well, but now I understand I was wrong. Then I tried to restart the server, but nothing happened again. Then I tried everything I could imagine including implementing LifecycleAction interface directly, but it didn't work either. I was out of ideas.

What really happens here is that my app is deployed after server starts, but the method run is invoked during server startup process. So, to get it invoked I should've restarted my server twice and I would see the result. First restart - deployed, second - invoked.

I have one question left:

When my colleagues deploy my application to the production server, should they restart it twice? Is it how it is planned to be done?
thumbnail
7年前 に Olaf Kock によって更新されました。

RE: Method run in my app with key=application.startup.events is never invok

Liferay Legend 投稿: 6403 参加年月日: 08/09/23 最新の投稿
Good point.

So far (last time I've checked in 6.2) Application Startup Events were always executed when the plugin (e.g. hook) started - and that explicitly included deployment. If that behaviour changed (and I haven't checked it) something in this behavior seems to have changed.

My expectation would be that no restart is required. Notice the "expectation" and "would"...
7年前 に Roman S. によって更新されました。

RE: Method run in my app with key=application.startup.events is never invok

New Member 投稿: 6 参加年月日: 17/03/13 最新の投稿
The story has a continuation.

I have created another app that configures logger levels and attached it to the application.startup.events in the same way. After that liferay stopped invoking any of these two apps neither on server startup, nor on hot deploy.

I removed my new app, but the older one (configuring expando fields) didn't get being invoked again. I removed all code from it leaving just:

package mypackage.fields.creation;

@Component(
immediate = true,
property = {
"key=application.startup.events"
},
service = LifecycleAction.class
)

public class CustomFieldsCreation implements LifecycleAction {

@Override
public void processLifecycleEvent(LifecycleEvent lifecycleEvent) throws ActionException {
System.out.println("event=" + lifecycleEvent);
}
}

No luck with that. Changing key from application.startup.events to login.events.pre leads to invocation during logging in.

Am I missing something?
6年前 に Phill Pover によって更新されました。

RE: Method run in my app with key=application.startup.events is never invok

New Member 投稿: 16 参加年月日: 11/01/26 最新の投稿
Hi Roman,

I'm having the same issue with the startup event. Did you manage to figure it out?

-Phill
6年前 に Roman S. によって更新されました。

RE: Method run in my app with key=application.startup.events is never invok

New Member 投稿: 6 参加年月日: 17/03/13 最新の投稿
Hi Phil,

The only way I know for now how to start something for sure is to use constructor to invoke what I need:

@Component(
immediate = true,
property = {
"key=application.startup.events"
},
service = LifecycleAction.class
)

public class CustomFieldsCreation extends SimpleAction {

public CustomFieldsCreation() {
run(new String[] { Long.toString(PortalUtil.getDefaultCompanyId()) });
}

@Override
public void run(String[] ids) {
//My code
}
}
6年前 に Chad LaVigne によって更新されました。

RE: Method run in my app with key=application.startup.events is never invok

New Member 投稿: 10 参加年月日: 13/11/12 最新の投稿
I am also seeing this issue, Lifecycle event classes that use application.startup.events don't fire on start up consistently. Other actions such as login pre seem to work just fine. Does anyone have a solution to this other than call run the in the constructor? I need this to work with a company id other than the default.
6年前 に Chad LaVigne によって更新されました。

RE: Method run in my app with key=application.startup.events is never invok

New Member 投稿: 10 参加年月日: 13/11/12 最新の投稿
In case anyone else runs into this problem, it appears that application.startup.events will consistently fire if you set immediate = false on the @Component annotation. For example:


@Component(
	immediate = false,
	property = {
        "key=application.startup.events"
    },
    service = LifecycleAction.class
)
public class CustomFieldStartupAction implements LifecycleAction {
// rest of custom action class...


According to the Apache Felix documentation this field "Defines whether the component is to be instantiated immediately (true) or on-demand (false).", so perhaps a start up event needs to wait to be instantiated? If anyone could shed light on exactly why this works it would be greatly appreciated.