event · 观察者模式 · 事件监听
1.组合:事件集合
2.观察:onEvent驱动具体动作
public class ActiveInstallsInitializerListenerimplements EventListener
{
/**
* The events observed by this event listener.
*/
private static final ListEVENTS =new ArrayList<>(Arrays.asList(new ApplicationReadyEvent()));
/**
* Used to send the ping to the remote instance.
* <p>* Note that we use a Provider since the Observation Manager will register listeners very early in the
* initialization process and some of the components injected transitively by the {@link InstanceIdManager}
* implementation have initialization code that require an Execution Context to be available, which is not the case
* early on in XWiki's initialization since no HTTP request has been made yet...
*/
@Inject
private ProviderpingSenderProvider;
/**
* Used to display the remote URL being hit in the logs if the ping fails...
*/
@Inject
private ActiveInstallsConfigurationconfiguration;
@Override
public List getEvents()
{
return EVENTS;
}
@Override
public String getName()
{
return "ActiveInstallsInitializerListener";
}
@Override
public void onEvent(Event event, Object source, Object data)
{
// Start a thread to regularly send pings to the active installs server.
Thread pingThread =new Thread(new ActiveInstallsPingThread(this.configuration,this.pingSenderProvider.get()));
pingThread.setName("Active Installs Ping Thread");
pingThread.start();
}
}