我可以使用 Flex 中的远程对象来轮询服务器上的 Java 类(Blazeds)吗?我想将实时信息返回到我的数据网格中

发布于 2024-10-07 00:33:21 字数 2250 浏览 5 评论 0原文

这是我到目前为止的代码:

Flex Code

<?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; 导入java.util.List; 导入 java.util.Random;

导入 org.springframework.flex.remoting.RemotingDestination; 导入 org.springframework.flex.remoting.RemotingIninclude; 导入 org.springframework.stereotype.Service;

导入supportingClasses.StockQuote;

@Service

@RemotingDestination

public class 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 秒轮询一次信息。这可以做到吗?

我需要更改我的设置吗?创建一些发布-订阅模式并使用流媒体通道?

谢谢

So here is the code I have so far:

Flex Code

<?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()"/>

And this is the java Class file. This returns and 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

public class 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;
}

}

At the minute a button needs to be pressed to refresh the data. I want to get rid of this and poll the information every x seconds. Can this be done?

Do I need to change my set-up? create some publish - subscribe pattern and use Streaming channels?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

内心旳酸楚 2024-10-14 00:33:21

如果您只想每 X 秒调用一次 getQuotes 方法,您可以在 Flex 中使用计时器,无需消息传递。如果您想在股票价值发生变化时收到通知,您可以在 Flex 端使用消费者,该消费者订阅了服务器添加消息的同一目的地。您可以在 traderdesktop 文件夹下的 BlazeDS 示例文件夹中找到执行此操作的示例。

If you just want to call the getQuotes method at every X seconds you can use a timer in Flex, no need for messaging. If you want to be notified when a stock value changed you can use a consumer on the flex side which is subscribed to the same destination where the server is adding messages. You can find a sample doing just that in the BlazeDS samples folder, under traderdesktop folder.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文