µ±Ç°Î»Ö㺠´úÂëÃÔ >> WebÇ°¶Ë >> pushlet ֮ѶϢ֪ͨ
  Ïêϸ½â¾ö·½°¸

pushlet ֮ѶϢ֪ͨ

Èȶȣº598   ·¢²¼Ê±¼ä£º2012-08-24 10:00:21.0
pushlet Ö®ÏûϢ֪ͨ
×î½ü×öÍêÒ»¸öÓû§ÉÏ´«ÊÓƵÎļþ£¬ÔÚ·þÎñÆ÷Íê³ÉתÂëµÄ·þÎñ¡£¸ù¾ÝÐèÒªÉè¼ÆÁËÒ»¸ö¼òµ¥µÄÏûϢ֪ͨϵͳ£¬Ê¹ÓÃpushletʵÏÖ¡£ÈçÓдíÎ󣬻¶Ó­Ö¸Õý£¬·Ç³£¸Ðл¡£

[×ÊÔ´]
¹Ù·½ÍøÕ¾£ºhttp://www.pushlets.com/ ÏÂÔص½pushletµÄjar°ü£¬½âѹºó¿ÉÒÔ¿´µ½¹Ù·½µÄÀý×Ó¡£


ÔÚʵ¼ùÖвο¼ÁËpushlet-2.0.4\webapps\pushlet\examples\ajax\ajax-2.htmlµÄÀý×Ó

µÚÒ»²½

½«pushlet.jar·Åµ½¹¤³ÌµÄlibĿ¼ÖУ¬½«pushlet-2.0.4\webapps\pushlet\lib\js-pushlet-client.js·Åµ½ÍøÒ³ÄÜ·ÃÎʵÄĿ¼£¬½«pushlet-2.0.4\webapps\pushlet\WEB-INF\classes\pushlet.propertiesºÍpushlet-2.0.4\webapps\pushlet\WEB-INF\classes\sources.properties¿½±´µ½¹¤³ÌĿ¼µÄclassesĿ¼Ï¡£

µÚ¶þ²½

ʹÓÃpushletsÔÚÍøÒ³¿Í»§¶ËÖÐÅäÖ÷dz£¼òµ¥

ÔÚÍøÖÐÒ³ÃæÒýÓÃÈçÏ´úÂë
<script type="text/javascript" src="../../lib/ajax-pushlet-client.js">
</script>

<script type="text/javascript">
        //¿ÉÒÔÉèÖÃdebugΪtrue£¬»áÔÚбêÇ©Ò³ÖдòÓ¡debugÐÅÏ¢£¬µ÷ÊÔµÄʱºò·Ç³£ÓÐÓá£
	PL.setDebug(false);

	// Pushlet Event Callback from Server
        //»Øµ÷
	function onEvent(event) {
		pr(event.toString());
	}
       
        //¶©ÔÄtopic
	function joinListen() {
		pr('joinListen...');
		PL.joinListen('/pushlet/ping');
	}
        //È¡Ïû¶©ÔÄ
	function leave() {
		pr('leaving...');
		PL.leave();
	}

	// ´òÓ¡ÐÅÏ¢
	function pr(aString) {
		document.disp.event.value = aString;
	}

	//-->
	</script>



µÚÈý²½

ÔÚ¹¤³ÌµÄweb.xmlÖÐÌí¼ÓÅäÖÃÈçÏÂ

<!-- Define the pushlet servlet -->
	<servlet>
		<servlet-name>pushlet</servlet-name>
		<servlet-class>nl.justobjects.pushlet.servlet.Pushlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<!-- Define the Servlet Mappings. -->

	<!-- The pushlet -->
	<servlet-mapping>
		<servlet-name>pushlet</servlet-name>
		<url-pattern>/js/pushlet.srv</url-pattern>
	</servlet-mapping>

ÆäÖÐurl-pattern¸úÇ°Ãæajax-pushlet-client.js·ÅÖõÄĿ¼Óйأ¬ÐèÒª¸ù¾Ý×Ô¼ºµÄÏîĿ·¾¶µ÷Õû¡£

µÚËIJ½
·þÎñÆ÷¶ËʵÏÖpushletsÓÐÁ½ÖÖ·½Ê½£¬µÚÒ»ÖÖʹÓÃeventpullsource£¬ÐèҪʵÏÖ°üº¬Ò»¸ö¼Ì³ÐÁËEventPullSourceµÄÄÚ²¿¾²Ì¬À࣬ÈçÏÂÃæ´úÂëÖеÄEncodeJobQuery¡£
public class EncodeJobQuery {

	public static class EncodeJobEventPullSource extends EventPullSource {
		Logger log = Logger.getLogger(getClass());
		@Autowired
		PvmsEncodeMessageManager encodeMessageManager;
		
		@Override
		protected long getSleepTime() {
			return 5000l;
		}

		@Override
		protected Event pullEvent() {
                        //²ÎÊýÊÇsubject£¬ÓëjsÖеÄsubjectÏàͬ
			Event event = Event.createDataEvent("/pushlet/ping");
			event.setField("msg", "encoding....");
			return event;
		}
	}
}

ͬʱҪÔÚclasses/sources.propertiesÎļþÖÐÔö¼ÓÒ»¸öÐС£
source7=cn.com.people.tv.pvms.encode.EncodeJobQuery$EncodeJobEventPullSource


µÚ¶þÖÖ·½·¨ÊÇÔÚ³ÌÐòÖе÷ÓÃDispatcher.getInstance().multicast(event)£¬³ýÁËmulticast»¹ÓÐÆäËûÁ½ÖÖ·½·¨ÓÃÀ´·¢ËÍÏûÏ¢¡£
String subject = "/pushlet/ping"
Event event = Event.createDataEvent(subject);
		event.setField("msg", "ping.....");
PvmsEncodeMessage.MSG_MESSAGE_COUNT);
		Dispatcher.getInstance().multicast(event);


×ܽ᣺
ÔÚʹÓõĹý³ÌÖÐÓöµ½ÁËÈô¸ÉÎÊÌâ

1.ÔõôʵÏÖ¸ù¾ÝÓû§À´ÍÆËÍÏûÏ¢
ÎÒÔÚʵÏÖµÄʱºòΪ²»Í¬µÄÓû§¶¨Ò岻ͬµÄtopic£¬¸ù¾ÝÓû§idÀ´Çø·Ö¡£¿´ÁËÎĵµ½éÉÜ£¬Ëµ¿ÉÒÔ°ó¶¨pushletµÄsession£¬Ã»Ñо¿Ã÷°×¾ßÌåÔõô²Ù×÷¡£ÎÒµÄʵÏÖ·½Ê½È±µãÊÇ£¬Èç¹û·þÎñÆ÷ÖØÆô»òÕßÏûÏ¢·¢ËÍʧ°Üµ¼ÖÂpushletµÄsession¹Ø±Õ£¬ÄÇôºóÐøµÄÏûÏ¢¾Íû°ì·¨·¢Ë͸øÓû§¡£

2.·¢ËÍÀëÏßÏûÏ¢
ÎÒ°ÑÏûÏ¢´æÔÚ·þÎñÆ÷£¬Ö»ÓÃpushletÀ´·¢Ë͵±Ç°µÄÏûÏ¢ÊýÁ¿¡£±ÈÈçÔÚÓû§µÇ¼ºó£¬·¢Ë͸øÓû§Ò»ÌõÏûÏ¢¸æËßÓû§ÓжàÉÙÌõδ¶ÁÏûÏ¢£¬Óû§¿ÉÒÔÊÖ¶¯±ê¼ÇÏûϢΪÒѶÁ»òÕßɾ³ýÏûÏ¢¡£