Gabriele Zigurella
2 anni fa
4 ha cambiato i file con 7 aggiunte e 154 eliminazioni
4
liferay-plugins-sdk-6.2/portlets/schedulatore-portos-pratiche-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/scheduler/QuarkusBridgeListener.java → liferay-plugins-sdk-6.2/portlets/schedulatore-portos-pratiche-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/scheduler/QuarkusBridgeScheduler.java
4
liferay-plugins-sdk-6.2/portlets/schedulatore-portos-pratiche-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/scheduler/QuarkusBridgeListener.java → liferay-plugins-sdk-6.2/portlets/schedulatore-portos-pratiche-portlet/docroot/WEB-INF/src/portos/nextmind/quarkus/bridge/scheduler/QuarkusBridgeScheduler.java
@ -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"); |
|
||||||
} |
|
||||||
} |
|
@ -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; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
Caricamento…
Reference in new issue