所以这是我到目前为止的代码:
Flex代码
<?xml version="1.0" encoding="utf-8"?>
<fx:Declarations>
<s:RemoteObject id="getStockPrices" result="result(event)" destination="blazeDsService"
endpoint="http://localhost:8400/flexspring/messagebroker/streamingamf"/>
</fx:Declarations>
<mx:DataGrid x="10" y="295" width="910" height="211" creationComplete="getStockPrices.getQuotes();"
dataProvider="{getStockPrices.getQuotes.lastResult}" >
<mx:columns>
<mx:DataGridColumn headerText="Stock Ticker" dataField="name" />
<mx:DataGridColumn headerText="Price" dataField="price"/>
<mx:DataGridColumn headerText="Hi" dataField="col3"/>
<mx:DataGridColumn headerText="Low" dataField="col4"/>
<!--<mx:DataGridColumn headerText="Adverage" dataField="col5"/>
<mx:DataGridColumn headerText="Graph" dataField="col6"/>-->
</mx:columns>
</mx:DataGrid>
<mx:Button label="Retrieve Stocks" click="retrieveStocks()"/>
这是java类文件。这将返回和arraylist:
package flex;
import java.util.ArrayList; import java.util.List; import java.util.Random;
import org.springframework.flex.remoting.RemotingDestination; import org.springframework.flex.remoting.RemotingInclude; import org.springframework.stereotype.Service;
import supportingClasses.StockQuote;
@Service
@RemotingDestination
公共类BlazeDsService {
private static final String[] MASTER_LIST = {"C", "FNM", "FRE", "F", "GOOG", "AIG", "CSCO", "MSFT", "AAPL", "YHOO", "BSX", "PORT","F", "TNT", "ESP", "RET", "VBN", "EES"};
@RemotingInclude
public List<StockQuote> getQuotes(){
List<StockQuote> list = new ArrayList<StockQuote>();
Random r = new Random();
for (String s:MASTER_LIST){
StockQuote sq = new StockQuote();
sq.setName(s);
sq.setPrice(r.nextInt(50));
list.add(sq);
}
return list;
}
}
此时需要按一个按钮刷新数据。我想摆脱这个并每隔x秒轮询一次信息。可以这样做吗?
我需要更改设置吗?创建一些发布 - 订阅模式并使用流媒体渠道?
由于
答案 0 :(得分:1)
如果您只想每隔X秒调用一次getQuotes方法,就可以在Flex中使用计时器,无需进行消息传递。如果您希望在库存值更改时收到通知,则可以使用Flex订阅服务器正在添加消息的同一目标的消费者。你可以在traderdesktop文件夹下的BlazeDS samples文件夹中找到一个样本。