简体   繁体   English

OOP设计用于从不同来源读取数据并将其发送到不同目的地的系统

[英]OOP Design for a system for reading data from different sources and send it to different destinations

I am working on programming a java software that will be like a middleware for gathering data from different sources then process the data and send it to different destinations. 我正在编写一个java软件,它将像一个中间件,用于从不同的源收集数据,然后处理数据并将其发送到不同的目的地。

The data sources and destinations includes: files, database, TCP, HTTP. 数据源和目标包括:文件,数据库,TCP,HTTP。

The user will be able to create a channels, each channel will have one data source (file reader, database reader, tcp listener) and one or many data destinations (file writer, database writer, tcp sender). 用户将能够创建一个通道,每个通道将有一个数据源(文件读取器,数据库读取器,tcp监听器)和一个或多个数据目标(文件编写器,数据库写入器,tcp发送器)。

通道图

The application will work as following: 该应用程序将如下工作:

  1. Read Channels from database. 从数据库中读取通道。
  2. For each channel create the data source and its destinations. 对于每个通道,创建数据源及其目标。
  3. Start the data sources to read data. 启动数据源以读取数据。

What comes in my mind is: 我想到的是:

  • Sources and destinations are represented as following: 来源和目的地表示如下: 在此输入图像描述
  • The channel is a container which will be injected by a source and a list of destinations. 通道是一个容器,它将由一个源和一个目的地列表注入。 So the channel is like a facade pattern 所以这个频道就像一个立面图案
  • The data processor in the channel will be connected to the destinations using observer pattern 通道中的数据处理器将使用观察者模式连接到目的地
  • At run time, when the application will load the channel list from the database, i will use the factory pattern to create the sources and destinations. 在运行时,当应用程序将从数据库加载通道列表时,我将使用工厂模式来创建源和目标。

So, is this the best way to represents the channels, sources and destinations? 那么,这是表示频道,来源和目的地的最佳方式吗? I think sources and destinations have a similarities, for example, FileReader and FileWriter classes will be the same except that one will be for reading and the other for writing, is it good to represent each of them as a separate class? 我认为源和目的地有相似之处,例如,FileReader和FileWriter类将是相同的,除了一个用于阅读而另一个用于写入,将它们作为一个单独的类表示是否很好?

That look ok. 那看起来不错。 If you look at some integration frameworks like Camel or Spring Integration, they have something very similar. 如果你看一些像Camel或Spring Integration这样的集成框架,它们会有类似的东西。 They also have different types of channels (p2p async, p2p sync and pub-sub) and transformers. 它们还有不同类型的通道(p2p async,p2p sync和pub-sub)和变换器。 I mention this 2 very mature frameworks in case you want to use them rather than to write your own (I strongly suggest you to take look at Camel, as that might provide exactly what you want). 我提到了这两个非常成熟的框架,以防你想要使用它们而不是自己编写(我强烈建议你看看Camel,因为它可能提供你想要的)。

About the question of Readers/Writers, I think it's definitely better to keep them as separate classes, as otherwise it might create confusion (is this class being used as a reader or writer?) and can prevent errors (someone configuring a reader, but injecting it as a writer). 关于读者/作者的问题,我认为最好将它们作为单独的类保留,否则它可能会造成混淆(这个类是用作读者还是作者?)并且可以防止错误(有人配置读者,但是把它作为一个作家注入)。

You might want to use a utility class shared between the reader and writer (or a delegate) to avoid duplicating code. 您可能希望使用读取器和编写器(或委托)之间共享的实用程序类来避免重复代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用于使用来自不同数据源的大量数据的架构设计 - Architectural design for consuming big volume of data from different data sources 设计模式可从不同来源访问相同数据 - Design Pattern to access same data from different sources 使用Java从不同源(Oracle,平面文件)加载数据的设计方法 - design approach for loading data from different sources (Oracle, flat files) using Java 在 OOP 中,我应该为表的写入和读取定义不同的对象吗? - In OOP, should I define different objects for writing to and reading from a table? JSF 数据表,包含来自两个不同来源的数据 - JSF datatable with data from two different sources 测试和运行时从不同来源获取数据 - Test and Runtime getting data from different sources 在apache spark中组合来自不同来源的数据 - combining data from different sources in apache spark 从不同的远程源中读取:如何优化线程? - Reading from different remote sources: how to optimize threads? QuickFIX-接收和发送来自不同算法的订单(源) - QuickFIX - Receive and send orders from different algorithms (sources) 从两个不同的数据源中选择排序的数据 - Selecting sorted data from two different data sources
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM