Gabriele Zigurella
2 anni fa
4 ha cambiato i file con 192 aggiunte e 0 eliminazioni
@ -0,0 +1,28 @@
|
||||
package portos.nextmind.quarkus.bridge.api; |
||||
|
||||
import com.liferay.portal.kernel.messaging.Message; |
||||
|
||||
public class QuarkusBridgeMessageFactoryUtil { |
||||
public static Message INSTANCE_READ(){ |
||||
Message INSTANCE_READ_MESSAGE = new Message(); |
||||
INSTANCE_READ_MESSAGE.setPayload("INSTANCE_READ"); |
||||
return INSTANCE_READ_MESSAGE; |
||||
} |
||||
|
||||
public static Message INSTANCE_WRITE(){ |
||||
Message INSTANCE_WRITE_MESSAGE = new Message(); |
||||
INSTANCE_WRITE_MESSAGE.setPayload("INSTANCE_WRITE"); |
||||
return INSTANCE_WRITE_MESSAGE; |
||||
} |
||||
|
||||
public static Message INSTANCE_DELETE(){ |
||||
Message INSTANCE_DELETE_MESSAGE = new Message(); |
||||
INSTANCE_DELETE_MESSAGE.setPayload("INSTANCE_DELETE"); |
||||
return INSTANCE_DELETE_MESSAGE; |
||||
} |
||||
|
||||
public static Message[] registerMessages(){ |
||||
Message[] messages = {INSTANCE_READ(), INSTANCE_WRITE(), INSTANCE_DELETE()}; |
||||
return messages; |
||||
} |
||||
} |
@ -0,0 +1,18 @@
|
||||
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.messaging.MessageListener; |
||||
import com.liferay.portal.kernel.messaging.MessageListenerException; |
||||
|
||||
public class QuarkusBridgeListener implements MessageListener { |
||||
|
||||
Log _log = LogFactoryUtil.getLog(QuarkusBridgeListener.class); |
||||
|
||||
@Override |
||||
public void receive(Message message) throws MessageListenerException { |
||||
_log.info("Miao!"); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,54 @@
|
||||
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"); |
||||
} |
||||
} |
@ -0,0 +1,92 @@
|
||||
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