日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

liferay调度器-定时任务

發布時間:2023/12/8 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 liferay调度器-定时任务 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

參考博客:(1)IT人生錄,網址:http://www.huqiwen.com/2012/10/22/liferay-6-1-development-study-11-use-scheduler/

???????? ? ? ? ?? (2)步行者,網址 http://blog.csdn.net/hantiannan/article/details/6739875


(1)在portlet中,自動添加監聽器

job任務系統中經常用到,liferay已經集成了Quartz,寫job很方便,只需繼承MessageListener接口即可。

public class MyMessageListener implements MessageListener{
?? ?@Override
?? ?public void receive(Message message) throws MessageListenerException {

?? ??? ? detailMethod(message);
?? ??? ?
?? ?}

?? ?//具體方法的實現
?? ?private void detailMethod(Message message) {
?? ????
?? ?}


在liferay-portlet.xml配置文件中設置啟動信息???


<scheduler-entry> <scheduler-event-listener-class> com.xxx.xxx.MyMessageListener </scheduler-event-listener-class><trigger><simple><simple-trigger-value>15</simple-trigger-value><time-unit>minute</time-unit></simple> <!-- <cron> <cron-trigger-value>0 0 12? * WED</cron-trigger-value> </cron>--></trigger> </scheduler-entry>


scheduler-event-listener-class:里面的類為第一步里面編寫的類

simple-trigger-value:里面為調度周期的數值,time-unit為調度周期的單位。上面的意思為每15分鐘執行一次

Time-unit:表示周期的周期可以為:day、hour、minute、second、week這幾個單位。


具體形如:

<portlet>
?? ??? ?<portlet-name>182</portlet-name>
?? ??? ?<icon>/html/icons/trash.png</icon>
?? ??? ?<struts-path>trash</struts-path>
?? ??? ?<indexer-class>com.liferay.portlet.trash.util.TrashIndexer</indexer-class>


?? ??? ?<scheduler-entry>
?? ??? ??? ?<scheduler-event-listener-class>com.liferay.mySupport.MyMessageListener1</scheduler-event-listener-class>
?? ??? ??? ?<trigger>
?? ??? ??? ??? ?<simple>
?? ??? ??? ??? ??? ?<property-key>mybatch.cron.test</property-key>
?? ??? ??? ??? ??? ?<time-unit>second</time-unit>
?? ??? ??? ??? ?</simple>
?? ??? ??? ?</trigger>
?? ??? ?</scheduler-entry>
?? ????
?? ??? ?<control-panel-entry-category>site_administration.content</control-panel-entry-category>
?? ??? ?<control-panel-entry-weight>30.0</control-panel-entry-weight>
?? ??? ?<control-panel-entry-class>com.liferay.portlet.trash.TrashControlPanelEntry</control-panel-entry-class>
?? ??? ?<preferences-owned-by-group>true</preferences-owned-by-group>
?? ??? ?<use-default-template>false</use-default-template>
?? ??? ?<scopeable>true</scopeable>
?? ??? ?<private-request-attributes>false</private-request-attributes>
?? ??? ?<private-session-attributes>false</private-session-attributes>
?? ??? ?<header-portlet-css>/html/portlet/document_library/css/main.css</header-portlet-css>
?? ??? ?<header-portlet-css>/html/portlet/message_boards/css/main.css</header-portlet-css>
?? ??? ?<header-portlet-css>/html/portlet/trash/css/main.css</header-portlet-css>
?? ??? ?<css-class-wrapper>portlet-trash</css-class-wrapper>
?? ?</portlet>

對于cron形式:

其中在portal-impl中的portal.properties中
??? mybatch.cron.test=3

0 0 12? * WED 為每個周二的12點。 seconds, minutes, hours, based on the days; months; on week days; year (optional)秒 分 時 天;月;周天;年

(2)直接后臺調用添加監聽器(重要)

? portal-impl/src/messaging-misc-spring.xml

中,添加對應的配置:

<?xml version="1.0"?>

<beans
?? ?default-destroy-method="destroy"
?? ?default-init-method="afterPropertiesSet"
?? ?xmlns="http://www.springframework.org/schema/beans"
?? ?xmlns:util="http://www.springframework.org/schema/util"
?? ?xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
?? ?xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"
>

?? ?<!-- Destinations? 當值為liferay/task時,目的值 destination.task-->

。。。。
? <!-- zhou add? -->
??? <bean id="destination.task" class="com.liferay.portal.kernel.messaging.SerialDestination">
??????? <property name="name" value="liferay/task" />
??? </bean>
。。。

?<!-- Listeners ? ? 監聽器id為messageListener.setup_listener時,類為,,, -->

?? <!-- zhou add? -->
<bean id="messageListener.setup_listener" class="com.liferay.mySupport.SetupMessagingImplTest" />
?? ?


???
?? ?<!-- Configurator -->

?? ?<bean id="messagingConfigurator.misc" class="com.liferay.portal.kernel.messaging.config.DefaultMessagingConfigurator">
?? ??? ?<property name="destinations">
?? ??? ??? ?<list>
......
?? ??? ??? ??? ?<!-- zhou add? -->
?? ??? ??? ??? ?<ref bean="destination.task" />
?? ??? ??? ?</list>
?? ??? ?</property>
?? ??? ?<property name="messageBus">
?? ??? ??? ?<ref bean="com.liferay.portal.kernel.messaging.MessageBus" />
?? ??? ?</property>
?? ??? ?<property name="messageListeners">
?? ??? ??? ?<map key-type="java.lang.String" value-type="java.util.List">
?? ??? ??? ??? 。。。。
?? ??? ??? ??? ?<!-- -zhou add -->
?? ??? ??? ??? ?<entry key="liferay/task">
?? ??? ??? ??? ??? ?<list value-type="com.liferay.portal.kernel.messaging.MessageListener">
?? ??? ??? ??? ??? ??? ?<ref bean="messageListener.setup_listener" />
?? ??? ??? ??? ??? ?</list>
?? ??? ??? ??? ?</entry>
?? ??? ??? ???? 。。。。

?? ??? ??? ?</map>
?? ??? ?</property>
?? ?</bean>
</beans>


觸發程序為:

??????? Message message = new Message();
?? ??? ?
?? ??? ?JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

?? ??? ?jsonObject.put("command", "success ----test command");

?? ??? ?message.setPayload(jsonObject.toString());

?? ??? ?//MessageBusUtil.sendMessage(DestinationNames.LIVE_USERS, message);

? // liferay/task可為portal-service com.liferay.portal.kernel.messaging中DestinationNames,具體為:public static final String LIVE_USERS = "liferay/live_users";?? ???? MessageBusUtil.sendMessage("liferay/task", message);

即可傳到SetupMessagingImplTest監聽器,其為:

import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.portal.kernel.messaging.BaseMessageListener;
import com.liferay.portal.kernel.messaging.Message;

public class SetupMessagingImplTest? extends BaseMessageListener {

?? ?@Override
?? ?protected void doReceive(Message message) throws Exception {
??
?? ??? ?String payload = (String)message.getPayload();

?? ??? ?JSONObject jsonObject = JSONFactoryUtil.createJSONObject(payload);

?? ??? ?String command = jsonObject.getString("command");
?? ???? System.out.println("message="+message);
?? ???? System.out.println("command="+command);
?? ??? ?
?? ?}
}





總結

以上是生活随笔為你收集整理的liferay调度器-定时任务的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。