From 19c27497cc88aca9bbbc7848efbc8a364baaf0b3 Mon Sep 17 00:00:00 2001 From: Gabriele Zigurella Date: Wed, 17 May 2023 17:21:47 +0200 Subject: [PATCH] minify footprint of scheduler --- .../docroot/WEB-INF/liferay-portlet.xml | 11 +-- ...tener.java => QuarkusBridgeScheduler.java} | 4 +- .../scheduler/QuarkusBridgeStartup.java | 54 ----------- .../bridge/scheduler/QuarkusScheduler.java | 92 ------------------- 4 files changed, 7 insertions(+), 154 deletions(-) rename liferay-plugins-sdk-6.2/portlets/schedulatore-portos-pratiche-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/scheduler/{QuarkusBridgeListener.java => QuarkusBridgeScheduler.java} (77%) delete mode 100644 liferay-plugins-sdk-6.2/portlets/schedulatore-portos-pratiche-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/scheduler/QuarkusBridgeStartup.java delete mode 100644 liferay-plugins-sdk-6.2/portlets/schedulatore-portos-pratiche-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/scheduler/QuarkusScheduler.java diff --git a/liferay-plugins-sdk-6.2/portlets/schedulatore-portos-pratiche-portlet/docroot/WEB-INF/liferay-portlet.xml b/liferay-plugins-sdk-6.2/portlets/schedulatore-portos-pratiche-portlet/docroot/WEB-INF/liferay-portlet.xml index d41a98de..7beb4bfc 100644 --- a/liferay-plugins-sdk-6.2/portlets/schedulatore-portos-pratiche-portlet/docroot/WEB-INF/liferay-portlet.xml +++ b/liferay-plugins-sdk-6.2/portlets/schedulatore-portos-pratiche-portlet/docroot/WEB-INF/liferay-portlet.xml @@ -7,13 +7,12 @@ schedulatore-portos-pratiche /icon.png - dati pratiche - integratore.IntegratoreSchedulato + quarkus bridge pratiche + portos.nextmind.quarkus.bridge.scheduler.QuarkusBridgeListener - - 30 - second - + + 0 */5 * ? * * + /css/main.css diff --git a/liferay-plugins-sdk-6.2/portlets/schedulatore-portos-pratiche-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/scheduler/QuarkusBridgeListener.java b/liferay-plugins-sdk-6.2/portlets/schedulatore-portos-pratiche-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/scheduler/QuarkusBridgeScheduler.java similarity index 77% rename from liferay-plugins-sdk-6.2/portlets/schedulatore-portos-pratiche-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/scheduler/QuarkusBridgeListener.java rename to liferay-plugins-sdk-6.2/portlets/schedulatore-portos-pratiche-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/scheduler/QuarkusBridgeScheduler.java index d1ad3bec..3f4cfb55 100644 --- a/liferay-plugins-sdk-6.2/portlets/schedulatore-portos-pratiche-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/scheduler/QuarkusBridgeListener.java +++ b/liferay-plugins-sdk-6.2/portlets/schedulatore-portos-pratiche-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/scheduler/QuarkusBridgeScheduler.java @@ -6,9 +6,9 @@ import com.liferay.portal.kernel.messaging.Message; import com.liferay.portal.kernel.messaging.MessageListener; import com.liferay.portal.kernel.messaging.MessageListenerException; -public class QuarkusBridgeListener implements MessageListener { +public class QuarkusBridgeScheduler implements MessageListener { - Log _log = LogFactoryUtil.getLog(QuarkusBridgeListener.class); + Log _log = LogFactoryUtil.getLog(QuarkusBridgeScheduler.class); @Override public void receive(Message message) throws MessageListenerException { diff --git a/liferay-plugins-sdk-6.2/portlets/schedulatore-portos-pratiche-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/scheduler/QuarkusBridgeStartup.java b/liferay-plugins-sdk-6.2/portlets/schedulatore-portos-pratiche-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/scheduler/QuarkusBridgeStartup.java deleted file mode 100644 index 43d5c953..00000000 --- a/liferay-plugins-sdk-6.2/portlets/schedulatore-portos-pratiche-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/scheduler/QuarkusBridgeStartup.java +++ /dev/null @@ -1,54 +0,0 @@ -package portos.nextmind.quarkus.bridge.scheduler; - -import com.liferay.portal.kernel.log.Log; -import com.liferay.portal.kernel.log.LogFactoryUtil; -import com.liferay.portal.kernel.messaging.Message; -import com.liferay.portal.kernel.scheduler.SchedulerEngineHelperUtil; -import com.liferay.portal.kernel.scheduler.SchedulerException; -import com.liferay.portal.kernel.scheduler.StorageType; -import com.liferay.portal.kernel.scheduler.Trigger; - -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import portos.nextmind.quarkus.bridge.api.QuarkusBridgeMessageFactoryUtil; - -public class QuarkusBridgeStartup implements ServletContextListener { - - Log _log = LogFactoryUtil.getLog(QuarkusBridgeStartup.class); - - @Override - public void contextInitialized(ServletContextEvent servletContextEvent) { - _log.info("### Registering Quarkus Bridge"); - QuarkusScheduler.registerScheduler(); - Trigger trigger = QuarkusScheduler.registerTrigger(); - String destinationName = QuarkusScheduler.getSchedulerendpoint(); - Message[] messageTypes = QuarkusBridgeMessageFactoryUtil.registerMessages(); - for(Message message : messageTypes){ - try { - SchedulerEngineHelperUtil.addJob(trigger, StorageType.MEMORY_CLUSTERED, - "Quarkus Bridge Scheduler", destinationName, message, - QuarkusBridgeListener.class.getName(), - null, Integer.MAX_VALUE); - } catch (SchedulerException e) { - _log.error(e ,e); - return; - } - } - _log.info("### Setup finished for Quarkus Bridge"); - } - - @Override - public void contextDestroyed(ServletContextEvent servletContextEvent) { - _log.info("### Uninstalling Quarkus Bridge"); - try { - QuarkusScheduler.deregisterScheduler(); - SchedulerEngineHelperUtil.delete(QuarkusScheduler.getTriggerJobName(), - QuarkusScheduler.getTriggerGroupName(), StorageType.MEMORY_CLUSTERED); - } catch (SchedulerException e) { - _log.error(e, e); - return; - } - _log.info("### Quarkus Bridge successfully removed"); - } -} diff --git a/liferay-plugins-sdk-6.2/portlets/schedulatore-portos-pratiche-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/scheduler/QuarkusScheduler.java b/liferay-plugins-sdk-6.2/portlets/schedulatore-portos-pratiche-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/scheduler/QuarkusScheduler.java deleted file mode 100644 index fd87dc11..00000000 --- a/liferay-plugins-sdk-6.2/portlets/schedulatore-portos-pratiche-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/scheduler/QuarkusScheduler.java +++ /dev/null @@ -1,92 +0,0 @@ -package portos.nextmind.quarkus.bridge.scheduler; - -import com.liferay.portal.kernel.log.Log; -import com.liferay.portal.kernel.log.LogFactoryUtil; -import com.liferay.portal.kernel.messaging.MessageBusUtil; -import com.liferay.portal.kernel.messaging.ParallelDestination; -import com.liferay.portal.kernel.scheduler.CronTrigger; -import com.liferay.portal.kernel.scheduler.SchedulerException; -import com.liferay.portal.kernel.scheduler.Trigger; -import com.liferay.portal.kernel.scheduler.TriggerFactoryUtil; -import com.liferay.portal.kernel.scheduler.TriggerType; - -public class QuarkusScheduler { - static Log _log = LogFactoryUtil.getLog(QuarkusScheduler.class); - private final static String SchedulerEndpoint = "portos_nextmind_quarkus_bridge_scheduler_REGISTRY"; - private final static String TriggerJobName = "portos_nextmind_quarkus_bridge_scheduler_T_JOB"; - private final static String TriggerGroupName = "portos_nextmind_quarkus_bridge_scheduler_T_GROUP"; - private static CronTrigger QuarkusSchedulerTrigger; - - public static CronTrigger getQuarkusSchedulerTrigger() { - if(QuarkusSchedulerTrigger == null){ - _log.warn("### Trying to access Quarkus Bridge Scheduler Trigger before it's registered!!"); - return null; - } - return QuarkusSchedulerTrigger; - } - - public static String getSchedulerendpoint() { - return SchedulerEndpoint; - } - - public static Boolean registerScheduler(){ - try{ - ParallelDestination destination = new ParallelDestination(); - destination.setName(SchedulerEndpoint); - if ( !MessageBusUtil.hasMessageListener(SchedulerEndpoint)){ - MessageBusUtil.addDestination(destination); - } - _log.debug("### Registering Quarkus Bridge Listener"); - MessageBusUtil.registerMessageListener(SchedulerEndpoint, new QuarkusBridgeListener()); - _log.debug("### Correctly Registered Quarkus Bridge Listener"); - } catch (RuntimeException r){ - _log.error(r ,r); - return false; - } - return true; - } - - public static Boolean deregisterScheduler(){ - try{ - if (MessageBusUtil.hasMessageListener(SchedulerEndpoint)){ - MessageBusUtil.removeDestination(SchedulerEndpoint); - } - _log.debug("### Removing Quarkus Bridge Listener"); - MessageBusUtil.unregisterMessageListener(SchedulerEndpoint, new QuarkusBridgeListener()); - _log.debug("### Correctly Removed Quarkus Bridge Listener"); - } catch (RuntimeException r){ - _log.error(r ,r); - return false; - } - return true; - } - - public static Trigger registerTrigger() { - final String cronExpression = "0 */5 * ? * *"; - try{ - _log.debug("### Creating Quarkus Bridge Scheduler Trigger"); - Trigger trigger = TriggerFactoryUtil.buildTrigger( - TriggerType.CRON, - TriggerJobName, TriggerGroupName, - null, null, cronExpression); - if(QuarkusSchedulerTrigger == null){ - QuarkusSchedulerTrigger = (CronTrigger) trigger; - } - _log.debug("### Correctly Created Quarkus Bridge Scheduler Trigger"); - }catch(RuntimeException r){ - _log.error(r, r); - }catch(SchedulerException s){ - _log.error(s, s); - } - return QuarkusSchedulerTrigger; - } - - public static String getTriggerJobName() { - return TriggerJobName; - } - - public static String getTriggerGroupName() { - return TriggerGroupName; - } - -}