实时显示动态数据的架构

发布于 2024-09-18 15:33:59 字数 1615 浏览 2 评论 0 原文

执行摘要:使用 Swing 实时显示线程安全的动态数据有哪些合理的架构选择?

详细信息:我最近用 Java 编写了一个多线程、自动交易平台。我说“平台”是因为我通过对虚拟对象进行子类化,使实现新的和多个交易程序变得非常容易。我已经封装了交易代码,因此我可以在 Swing 应用程序、控制台应用程序或其他应用程序中使用它。目前我正在使用 Swing 前端运行它。

我想说我是 Swing 滥用者而不是用户。不是故意的。开发现代 GUI 并将其与我尚未学习的动态数据集成需要一种特殊的思维。我知道非常基础的知识,例如仅在事件调度线程中更新屏幕。以下是我显示消息的方式(来自我的 SingleFrameApplication 子类):

 private class PrintTraderMsgTask extends SwingWorker<Void, String>{
    @Override
    protected Void doInBackground() {
        String msg;
        while(!isCancelled()){

               msg = m_data.m_TraderMsgs.poll();
               if(msg!=null){
                  publish(msg);
               }
        }
        return null;
    }

    @Override
    protected void process(List<String> chunks) {
     for (String item: chunks){
         m_view.displayTraderString(item);
     }
    }
}

这里的数据元素正是

public ArrayBlockingQueue<String> m_TraderMsgs;

任意数量的“交易者”(单独的线程)可能随时粘贴消息的数据元素。我使用的另一种数据对象类型是ConcurrentHashMap。我在其中收集订单日志、交易记录、价格和其他类型的数据。因此,我试图在这里描绘的图片是大量与时间相关的数据,太多而无法一次显示全部。

我真正想做的是显示摘要信息并具有向下钻取的能力。现在,我在 JTextAreas 中显示消息,并在一些 JTextFields 中显示其他信息。我可以阅读 JCoolWhatever 并将数据填充到其中。但在开始这条路之前,我想了解其他架构选择。

方法 1:使用 SwingWorkers 获取数据并将其粘贴到位于我的 FrameView 子类中的 JWhatever 中。

方法2:???

...

我们想要:

(1)合理的模块化......足以添加/删除元素而不破坏我们晚上的

(2)交互能力,特别是向下钻取能力,因为有这么多数据

谢谢...实时显示一组复杂的动态数据是一个有趣的主题,我希望我们能够进行良好的讨论。

Executive summary: What kinds of sound architecture choices are there for displaying thread-safe, dynamic data in real time using Swing?

Details: I have recently completed writing a multi-threaded, automated trading platform in Java. I say "platform" because I have made it very easy to implement new and multiple trading programs by sub-classing virtual objects. I have encapsulated the trading code so I can use it in a Swing application, console application, or whatever. Currently I am running it with a Swing front-end.

I would say I am a Swing abuser rather than user. Not on purpose. It takes a special kind of thinking to develop a modern GUI and integrate it with dynamic data that I have yet to learn. I know the very basics, such as updating the screen only in the event dispatch thread. Here is how I display messages (from my SingleFrameApplication subclass):

 private class PrintTraderMsgTask extends SwingWorker<Void, String>{
    @Override
    protected Void doInBackground() {
        String msg;
        while(!isCancelled()){

               msg = m_data.m_TraderMsgs.poll();
               if(msg!=null){
                  publish(msg);
               }
        }
        return null;
    }

    @Override
    protected void process(List<String> chunks) {
     for (String item: chunks){
         m_view.displayTraderString(item);
     }
    }
}

The data element here is just

public ArrayBlockingQueue<String> m_TraderMsgs;

which any number of "Traders" (separate threads) might be sticking messages in at any time. The other type of data object I've used is a ConcurrentHashMap. I collect order logs, trade records, prices, and other sorts of data in these. So the picture I am trying to paint here is a large collection of time-dependent data, too much to display all at once.

What I would really like to do is display summary information and have the ability to drill down. Right now I am displaying messages in JTextAreas and other info in some JTextFields. I can read up on JCoolWhatever and stuff data in there. But before I start down that road I want to learn about other architecture choices.

Method 1: Use SwingWorkers to grab data and stick it in JWhatever which resides in my FrameView subclass.

Method 2: ???

...

We want:

(1) reasonable modularity.. enough to add/remove elements without ruining our evening

(2) interaction capability, specifically drill-down capability since there is so much data

Thanks... the real-time display of a complex set of dynamic data is an interesting subject and I hope we can get a good discussion going.

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

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

发布评论

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

评论(2

怂人 2024-09-25 15:33:59

管理分层数据复杂性的一种常见方法是可折叠树。在整个 NetBeans IDE 中使用, org.netbeans.swing.outline.Outline 是一个特别通用的实现。 NetBeans 在多个窗口中使用它,包括项目、导航器、文件、服务等。因为它派生自 javax.swing.JTable,所以通常的 javax.swing.JTable 派生的。 com/javase/tutorial/uiswing/components/table.html#editrender" rel="nofollow noreferrer">编辑器和渲染器机制可用。 宣布新的 Swing 树表一文展示了它是如何实现的用于对文件系统进行建模。尽管 org-netbeans-swing-outline.jar 包含在 IDE 中,但它可以单独使用。

附录:

“向下钻取”可能是点击交易程序,触发在另一个窗格中显示其所有交易。

JSplitPane在这种情况下很有用:一个窗格可能包含树,而另一个窗格则显示所选节点/行的扩展详细信息。

One common approach to managing the complexity of hierarchical data is a collapsible tree. Used throughout the NetBeans IDE, org.netbeans.swing.outline.Outline is a particularly versatile implementation. NetBeans uses it in several windows, including Projects, Navigator, File, Services, etc. Because is derives from javax.swing.JTable, the usual Editors and Renderers mechanism is available. The article Announcing the new Swing Tree Table shows how it is used to model a file system. Although org-netbeans-swing-outline.jar is included with the IDE, it may be used in isolation.

Addendum:

"Drill down" could be clicking on the trading program triggering the display of all its trades in another pane.

JSplitPane is useful in this context: one pane might hold the tree, while the other displays expanded details of the selected node/row.

娇女薄笑 2024-09-25 15:33:59

JIDE Grids 有多种类型的分层表。我只使用过树表。 “层次结构表(示例 1)”屏幕截图似乎非常接近您想要的:

alt text

JIDE Grids has several types of hierarchical tables. I've only used the tree table. The "Hierarchical Table (Example 1)" screenshot seems to be pretty close to what you want:

alt text

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