Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-132542

WebFragment Bundle Watcher refresh fragmentHost multiple times

    Details

      Description

      As you know web-fragment bundles could have dependencies to other bundles.

      When a dependency bundle is removed (typically because you need to install a more up-to-date version) the web-fragment bundle switches from Resolved to Installed state and
      stay in it state.

      To return in Resolved state the FragmentHost bundle has to be refreshed. And this is exactly what "portal-fragment-bundle-watcher" does.

      Unfortunately it fires a refresh multiple times. Depending on the relation between your custom bundles it could force a refresh 5-10-20 times.

      Let me explain it better. Suppose you have the following modules

      name description
      it.smc.sample.commons.api.jar it is a simple api module with constants and interfaces
      it.smc.sample.commons.impl.jar it implements some API as OSGi components. It depends on "it.smc.sample.commons.api.jar"
      it.smc.sample.feature.dummy01.impl.jar it implements some other API as OSGi components. It depends on "it.smc.sample.commons.api.jar"
      it.smc.sample.hook.portal.instances.web.hook.jar it "override" an MVCRenderCommand of "com.liferay.portal.instances.web" and depends also on "it.smc.sample.commons.api.jar"
      it.smc.sample.hook.portal.instances.web.fragment.jar it override a jsp of "com.liferay.portal.instances.web" and uses code from "it.smc.sample.commons.api.jar". It depends also on "it.smc.sample.hook.portal.instances.web.hook.jar"

      On a fresh Liferay installation I've extended "com.liferay.portal.fragment.bundle.watcher.internal.PortalFragmentBundleWatcher" to add some log info.

      Step 1

      Install all custom bundles except the web fragment.

      2021-05-19 18:59:23.796 INFO  [com.liferay.portal.kernel.deploy.auto.AutoDeployScanner][AutoDeployDir:272] Processing it.smc.sample.commons.api-1.0.0.jar
      2021-05-19 18:59:23.835 INFO  [com.liferay.portal.kernel.deploy.auto.AutoDeployScanner][AutoDeployDir:272] Processing it.smc.sample.hook.portal.instances.web.hook-1.0.0.jar
      2021-05-19 18:59:23.835 INFO  [com.liferay.portal.kernel.deploy.auto.AutoDeployScanner][AutoDeployDir:272] Processing it.smc.sample.feature.dummy01.impl-1.0.0.jar
      2021-05-19 18:59:23.836 INFO  [com.liferay.portal.kernel.deploy.auto.AutoDeployScanner][AutoDeployDir:272] Processing it.smc.sample.commons.impl-1.0.0.jar
      it.smc.sample.commons.api_1.0.0 [1205] no installedFragmentBundles
      it.smc.sample.commons.impl_1.0.0 [1206] no installedFragmentBundles
      it.smc.sample.feature.dummy01.impl_1.0.0 [1207] no installedFragmentBundles
      it.smc.sample.hook.portal.instances.web.hook_1.0.0 [1208] no installedFragmentBundles
      2021-05-19 18:59:32.772 INFO  [fileinstall-directory-watcher][BundleStartStopLogger:46] STARTED it.smc.sample.commons.impl_1.0.0 [1206]
      2021-05-19 18:59:32.778 INFO  [fileinstall-directory-watcher][BundleStartStopLogger:46] STARTED it.smc.sample.feature.dummy01.impl_1.0.0 [1207]
      2021-05-19 18:59:32.779 INFO  [fileinstall-directory-watcher][BundleStartStopLogger:46] STARTED it.smc.sample.commons.api_1.0.0 [1205]
      2021-05-19 18:59:32.782 INFO  [fileinstall-directory-watcher][BundleStartStopLogger:46] STARTED it.smc.sample.hook.portal.instances.web.hook_1.0.0 [1208]
      
      

      As you could see the Watcher detect bundle installation but do nothing because there are no web-fragment installed.

      Step 2

      Install the web-fragment

      2021-05-19 19:00:32.840 INFO  [com.liferay.portal.kernel.deploy.auto.AutoDeployScanner][AutoDeployDir:272] Processing it.smc.sample.hook.portal.instances.web.fragment-1.0.0.jar
      it.smc.sample.hook.portal.instances.web.fragment_1.0.0 [1209] refresh com.liferay.portal.instances.web
      2021-05-19 19:00:38.548 INFO  [Refresh Thread: Equinox Container: 0ec57281-225f-424d-9453-e28b175f9256][BundleStartStopLogger:49] STOPPED com.liferay.portal.instances.web_5.0.5 [234]
      com.liferay.portal.instances.web_5.0.5 [234] no refresh
      it.smc.sample.hook.portal.instances.web.fragment_1.0.0 [1209] no installedFragmentBundles
      2021-05-19 19:00:38.774 INFO  [Refresh Thread: Equinox Container: 0ec57281-225f-424d-9453-e28b175f9256][BundleStartStopLogger:46] STARTED com.liferay.portal.instances.web_5.0.5 [234]
      2021-05-19 19:00:38.815 INFO  [Refresh Thread: Equinox Container: 0ec57281-225f-424d-9453-e28b175f9256][BundleStartStopLogger:49] STOPPED com.liferay.portal.instances.web_5.0.5 [234]
      com.liferay.portal.instances.web_5.0.5 [234] no refresh
      it.smc.sample.hook.portal.instances.web.fragment_1.0.0 [1209] no installedFragmentBundles
      2021-05-19 19:00:39.006 INFO  [Refresh Thread: Equinox Container: 0ec57281-225f-424d-9453-e28b175f9256][BundleStartStopLogger:46] STARTED com.liferay.portal.instances.web_5.0.5 [234]
      
      

      The watcher detects the web-fragment and fire a refresh of the FragmentHost (this refresh is queued by the OSGi engine).

      Then FragmentHost (com.liferay.portal.instances.web_5.0.5) is reloaded 2 times:

      • the first one is the standard behaviour
      • the second one is the refresh fired by the Watcher

      On refresh no other refresh is queued because it.smc.sample.hook.portal.instances.web.fragment_1.0.0 is in Resolved state.

      Step 3

      Delete module "it.smc.sample.commons.api-1.0.0.jar" from "osgi/modules"

      2021-05-19 19:19:17.918 INFO  [fileinstall-directory-watcher][BundleStartStopLogger:49] STOPPED it.smc.sample.commons.api_1.0.0 [1205]
      2021-05-19 19:19:18.042 INFO  [Refresh Thread: Equinox Container: 0ec57281-225f-424d-9453-e28b175f9256][BundleStartStopLogger:49] STOPPED it.smc.sample.hook.portal.instances.web.hook_1.0.0 [1208]
      2021-05-19 19:19:18.083 INFO  [Refresh Thread: Equinox Container: 0ec57281-225f-424d-9453-e28b175f9256][BundleStartStopLogger:49] STOPPED it.smc.sample.feature.dummy01.impl_1.0.0 [1207]
      2021-05-19 19:19:18.086 INFO  [Refresh Thread: Equinox Container: 0ec57281-225f-424d-9453-e28b175f9256][BundleStartStopLogger:49] STOPPED it.smc.sample.commons.impl_1.0.0 [1206]
      2021-05-19 19:19:18.297 INFO  [Refresh Thread: Equinox Container: 0ec57281-225f-424d-9453-e28b175f9256][BundleStartStopLogger:49] STOPPED com.liferay.portal.instances.web_5.0.5 [234]
      com.liferay.portal.instances.web_5.0.5 [234] no refresh
      2021-05-19 19:19:22.594 INFO  [Refresh Thread: Equinox Container: 0ec57281-225f-424d-9453-e28b175f9256][BundleStartStopLogger:46] STARTED com.liferay.portal.instances.web_5.0.5 [234]
      
      

      FragmentHost is reloaded because it.smc.sample.hook.portal.instances.web.fragment_1.0.0 switches in Installed state, as reported by gogo shell

       1206|Installed  |   15|SMC Commons Impl (1.0.0)|1.0.0
       1207|Installed  |   15|SMC Dummy Feature 01 Impl (1.0.0)|1.0.0
       1208|Installed  |   15|SMC Portal Instances Web Hook (1.0.0)|1.0.0
       1209|Installed  |   15|SMC Portal Instances Web Fragment (1.0.0)|1.0.0
      
      

      Step 4

      Install module "it.smc.sample.commons.api-1.0.1.jar"

      2021-05-19 19:42:42.287 INFO  [com.liferay.portal.kernel.deploy.auto.AutoDeployScanner][AutoDeployDir:272] Processing it.smc.sample.commons.api-1.0.1.jar
      it.smc.sample.commons.impl_1.0.0 [1206] refresh com.liferay.portal.instances.web 
      it.smc.sample.feature.dummy01.impl_1.0.0 [1207] refresh com.liferay.portal.instances.web 
      it.smc.sample.hook.portal.instances.web.hook_1.0.0 [1208] refresh com.liferay.portal.instances.web 
      it.smc.sample.commons.api_1.0.0 [1210] refresh com.liferay.portal.instances.web 
      2021-05-19 19:42:47.914 INFO  [Refresh Thread: Equinox Container: 0ec57281-225f-424d-9453-e28b175f9256][BundleStartStopLogger:46] STARTED it.smc.sample.commons.impl_1.0.0 [1206]
      2021-05-19 19:42:47.917 INFO  [Refresh Thread: Equinox Container: 0ec57281-225f-424d-9453-e28b175f9256][BundleStartStopLogger:46] STARTED it.smc.sample.feature.dummy01.impl_1.0.0 [1207]
      2021-05-19 19:42:47.920 INFO  [Refresh Thread: Equinox Container: 0ec57281-225f-424d-9453-e28b175f9256][BundleStartStopLogger:46] STARTED it.smc.sample.hook.portal.instances.web.hook_1.0.0 [1208]
      2021-05-19 19:42:47.922 INFO  [fileinstall-directory-watcher][BundleStartStopLogger:46] STARTED it.smc.sample.commons.api_1.0.0 [1210]
      2021-05-19 19:42:47.950 INFO  [Refresh Thread: Equinox Container: 0ec57281-225f-424d-9453-e28b175f9256][BundleStartStopLogger:49] STOPPED com.liferay.portal.instances.web_5.0.5 [234]
      com.liferay.portal.instances.web_5.0.5 [234] no refresh 
      it.smc.sample.hook.portal.instances.web.fragment_1.0.0 [1209] no installedFragmentBundles
      2021-05-19 19:42:48.139 INFO  [Refresh Thread: Equinox Container: 0ec57281-225f-424d-9453-e28b175f9256][BundleStartStopLogger:46] STARTED com.liferay.portal.instances.web_5.0.5 [234]
      2021-05-19 19:42:48.168 INFO  [Refresh Thread: Equinox Container: 0ec57281-225f-424d-9453-e28b175f9256][BundleStartStopLogger:49] STOPPED com.liferay.portal.instances.web_5.0.5 [234]
      com.liferay.portal.instances.web_5.0.5 [234] no refresh 
      it.smc.sample.hook.portal.instances.web.fragment_1.0.0 [1209] no installedFragmentBundles
      2021-05-19 19:42:48.325 INFO  [Refresh Thread: Equinox Container: 0ec57281-225f-424d-9453-e28b175f9256][BundleStartStopLogger:46] STARTED com.liferay.portal.instances.web_5.0.5 [234]
      2021-05-19 19:42:48.344 INFO  [Refresh Thread: Equinox Container: 0ec57281-225f-424d-9453-e28b175f9256][BundleStartStopLogger:49] STOPPED com.liferay.portal.instances.web_5.0.5 [234]
      com.liferay.portal.instances.web_5.0.5 [234] no refresh 
      it.smc.sample.hook.portal.instances.web.fragment_1.0.0 [1209] no installedFragmentBundles
      2021-05-19 19:42:48.515 INFO  [Refresh Thread: Equinox Container: 0ec57281-225f-424d-9453-e28b175f9256][BundleStartStopLogger:46] STARTED com.liferay.portal.instances.web_5.0.5 [234]
      2021-05-19 19:42:48.545 INFO  [Refresh Thread: Equinox Container: 0ec57281-225f-424d-9453-e28b175f9256][BundleStartStopLogger:49] STOPPED com.liferay.portal.instances.web_5.0.5 [234]
      com.liferay.portal.instances.web_5.0.5 [234] no refresh 
      it.smc.sample.hook.portal.instances.web.fragment_1.0.0 [1209] no installedFragmentBundles
      2021-05-19 19:42:48.708 INFO  [Refresh Thread: Equinox Container: 0ec57281-225f-424d-9453-e28b175f9256][BundleStartStopLogger:46] STARTED com.liferay.portal.instances.web_5.0.5 [234]
      
      

      Installing api module the other modules switches in Active state. For every module Watcher queue a refresh of the FragmentHost bundle "com.liferay.portal.instances.web"
      So we have 4 refresh of the same bundle.

      Consideration

      If you have 20 custom modules depending on "it.smc.sample.commons.api" when you update it the PortalFragmentBundleWatcher queued 20 refresh of "com.liferay.portal.instances.web"
      If you have more web-fragment with common dependencies these refresh explodes and you have to wait minutes for it to complete. And this, sometimes, couses problems on npm subsystem.

       

      My suggestion is to implement, into PortalFragmentBundleWatcher, a sort of buffer.

       

      Instead of fire a refresh immediately, collect it in Buffer. The buffer will be executed when the oldest element is older than x seconds (15?, 30?).

      With this approach we have a delay between dependency deployment and FragmentHost reactivation; but for sure we refresh the FragmentHost less times

       

       

        Attachments

          Activity

            People

            Assignee:
            support-lep@liferay.com SE Support
            Reporter:
            maumar Mauro Mariuzzo
            Participants of an Issue:
            Recent user:
            Mauro Mariuzzo
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Days since last comment:
              35 weeks, 5 days ago

                Packages

                Version Package