`
lch_2010
  • 浏览: 35159 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

flex 消息推送

    博客分类:
  • java
阅读更多

messaging-config.xml 文件

     <destination id="simple-feed">
		<properties>
			<server>
				<allow-subtopics>true</allow-subtopics>
				<subtopic-separator>.</subtopic-separator>
			</server>
		</properties>
	</destination>

applicationContext.xml 文件

 

	<flex:message-broker>
		<flex:message-service
			default-channels="my-streaming-amf,my-longpolling-amf,my-polling-amf" />
	</flex:message-broker>

		<!-- MessageTemplate makes it easy to publish messages -->
	<bean id="defaultMessageTemplate" class="org.springframework.flex.messaging.MessageTemplate" />
	
	<bean id="simpleFeedStarter" class="com.team.gis.service.SimpleFeed">  
   	 	<constructor-arg ref="defaultMessageTemplate" />  
    	<flex:remoting-destination /> 
    	<property name="stationMapper" ref="stationMapper" />
	</bean> 
 

 

flex  文件:

		<mx:ChannelSet id="cs">  
			<mx:AMFChannel url="http://localhost:8080/pipe/messagebroker/amflongpolling"/>  
			<mx:AMFChannel url="http://localhost:8080/pipe/messagebroker/amfpolling"/>  
		</mx:ChannelSet>  
		
		<mx:Consumer id="consumer" destination="simple-feed" channelSet="{cs}"   
					 message="messageHandler(event.message)"/>  
		

 as文件:

 

	consumer.subscribe(); 

 

private function messageHandler(message:IMessage):void  
{  
	var siteInfo:ArrayCollection = message.body as ArrayCollection;
	var sites:ArrayCollection = siteInfo.getItemAt(0) as ArrayCollection;
	/**清空图层数据*/
	var keySets :Array = GlobeConfig.getInstance().graphicsLayerHashTable.getKeySet();
	for(var k:int =0 ; k < keySets.length ; k++){
		var templayer:GraphicsLayer = GlobeConfig.getInstance().graphicsLayerHashTable..find(keySets[k]);
		templayer.clear();
	}
	GlobeConfig.getInstance().graphicHashTable.clear();
	for(var a :int = 0 ; a<sites.length ; a++){
		var gisLocation:GisLocation = sites.getItemAt(a) as GisLocation;
		var g:Graphic = new Graphic();
		g.geometry = new MapPoint(Number(gisLocation.x),Number(gisLocation.y));
		g.symbol = new MonitorSymbol(gisLocation.alias,gisLocation.symbol,gisLocation.items);
		g.attributes = gisLocation;
		g.toolTip = gisLocation.alias;
		g.addEventListener(MouseEvent.CLICK,graphicClickHandler);
		var layerHashTable:HashTable = GlobeConfig.getInstance().graphicsLayerHashTable;
		var layer:GraphicsLayer = layerHashTable.find(gisLocation.layerid);
		if(gisLocation == null){
			continue;
		}
		if(layer != null){
			layer.add(g);
			GlobeConfig.getInstance().graphicHashTable.add(gisLocation.id,g);
		}
	}
	AppEventDispatcher.getInstance().dispatchEvent(new AppEvent(ArcgisEventConst.REFRESH_GIS_LOCATION_EVENT));
} 
 

java代码:

package com.team.gis.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.flex.messaging.MessageTemplate;

import com.team.gis.domain.GisLocation;
import com.team.gis.domain.MonitorItem;
import com.team.gis.persistence.StationMapper;

public class SimpleFeed {

    private final MessageTemplate template;
    
    private StationMapper stationMapper;

    public SimpleFeed(MessageTemplate template) {
        this.template = template;
    }
    
    public void pushSiteInfo(){
    	List<GisLocation> locations = stationMapper.searchGisLocation();
		List<MonitorItem> items = stationMapper.searchMonitorItems();
		List<MonitorItem> aitems = null;
		for(GisLocation gisLocation : locations){
			if(gisLocation.getMonitor() != null){
				String[] ms = gisLocation.getMonitor().split(",");
				aitems = new ArrayList<MonitorItem>();
				for(MonitorItem m : items){
					for(String mi : ms){
						if(m.getId() == Integer.valueOf(mi)){
							m.setAvailable(true);
							aitems.add(m);
						}
					}
				}
				gisLocation.setItems(aitems);
			}
		}
		List<List<?>> siteInfo = new ArrayList<List<?>>(); 
		siteInfo.add(locations);
		siteInfo.add(items);
    	template.send("simple-feed",siteInfo);
    }

	public StationMapper getStationMapper() {
		return stationMapper;
	}

	public void setStationMapper(StationMapper stationMapper) {
		this.stationMapper = stationMapper;
	}
   
}
 

 

分享到:
评论
2 楼 chensong215 2013-05-29  
有什么办法解决?
1 楼 d8txc 2012-09-26  
楼主 请教个问题,按您说的这种方式有没有尝试过 启动tomcat 启动一个线程长时间推送后观察发现 内存溢出问题,在我的使用出现了这样的问题
msgBroker.routeMessageToService(msg, null); 关键就在这里 造成一直不回收 老年代最后耗完了整个堆 就溢出了,我是4秒溢出推送大概700多条数据
Thread.sleep(4000);

相关推荐

Global site tag (gtag.js) - Google Analytics