Develop Log - Print Service (Part I)

Architecture Background

Problem Background

企业intranet内的各种应用均可能需要作打印动作,包括标签的打印,表单的打印,等等。考虑提供这样一套组件 ,为需要打印的系统提供远程的或是本地的打印服务,以减小各系统的实现的复杂度及困难度,并可能对网络内的打印作统一控管。组件叫做PrintService。

System Overview

PrintService 的作用,就是给客户系统提供打印服务。如下图示:










Driving Requirements

Functional Requirements

打印内容

    PrinvService应提供标签跟表单的打印实现。支援目前客户系统所出的各式标签样式及表单样式。

使用方式

    PrintService应有2种使用方式,即Server ModeLirary Mode

Server Mode:

该模式下 PrintService 为客户系统提供远程打印服务:独立启动 PrintService 后,接收远端 message 作分发打印。

Library Mode:

该模式下PrintService为客户系统提供本地打印服务。本地叫用时传入messagePrintService 叫用MsgParser生成PrintRequest,而后

PrintService 直接将 PrintRequest 交由 PrintMsgHandler 作本地打印。
PrintService 再将 PrintRequest 转换为 XML 格式返回,由 Client 自行选择处理方式。

Quantity Requirement

PrintService应具有以下特性:

Platform Independent -- PrintService运行环境不局限于Windows平台。可以migrate到UNIX/Linux平台,以利用该系列平台的诸多优势。

High Availability -- PrintService应满足高可用性,适时响应客户系统的打印需求。

High Reliability -- PrintService应满足高可靠性,降低类似因网络丢包而打印失败状况的几率。

High Performance -- PrintService应满足高效能,能同时处理若干客户系统的打印请求。

Architectural Approaches

Local Cache

相较于客户系统的打印请求提交速率, PrintService 对于打印请求的处理速率始终是一瓶颈。为避免因客户系统提交的请求过多造成网络拥塞而致使应用崩溃,考虑在 PrintService 端提供本地缓存。即尽快将网络中存在的消息取至本地,然后再行处理。另外由于本地缓存的引入势必会给 PrintService 的运行造成额外的负担,其机制也应作为运行时的可选项为宜。

Server Mode vs. Library Mode

考虑为 PrintService 2 种使用方式( Server Mode Library Mode )分别交付对应的 Package 。其中 Server Mode 下的 Package 应是完整模式的 PrintService ,包括其所有的组件,发布后单独启动,响应客户系统的远程打印需求。而 Library Mode 下的 Package 则是部分模式的 PrintService ,仅包括其作为 Library 使用的部分组件,发布后接收客户系统的本地叫用。


因为 Local Cache 的引入,完整模式下的 PrintService 的运作模式可分为 Direct Mode Data Cache Mode 2 种。

Direct Mode

该模式下 PrintService 接收到 message 后,直接作转派打印动作。





Data Cached Mode

该模式下, PrintListener 收到 message 后只需把 message 存入 embeded DB ,而后由 CachedMsgHandler 负责分批取出作打印。



ps: PrintServiceException 需在界线两边分别 throw catch


Mapping Requirements to Architecture

The following use case diagram depicts the high-level system functional requirements:


Views (core部分)

Module Views

High Level Module View

Primary Presentation

总体来看,PrintService Server Mode 运作时的架构 如下:

Element Catalog
PrintService

PrintService 为程序入口, PrintService 启动时,则会将相关 PrintListener 叫起以备接收 message

PrintListener

PrintListener 收到 message 后,或是直接将 message 交由 PrintMsgHandler 处理,或是将 message 交由 DBCache 缓存起来然后由 CachedMsgHandler 分批取出再交给 PrintMsgHandler 处理。

PrintMsgHandler

PrintMsgHandler 被叫用时,使用 PrintMsgParser message 转换得到 PrintRequest ,然后交由 PrintServer 处理。


以上各类实际运作时多以线程方式存在,相互配合以实现打印服务。

Variability Guide

定义接口PrintListener,以针对不同的网络侦听方式。如MQ, Mail, RMI, WS, etc.

定义接口PrintMsgParser,以针对不同的打印样式请求。如shipping label, carton label, stock in sheet, etc.

定义接口 PrintServer ,以针对不同的打印模式,如标签打印,表单打印,等等。

Related Views

Initialization Module

Message Receiving Module

Message Handling Module

Initialazation Module

Primary Presentation


Element Catalog

作初始化时, PrintService 通过 PrintServiceConfig 读取配置文件 printservice-config.xml 并缓存配置信息。然后根据配置要求启动相应服务。

Message Receiving Module

Primary Presentation


Element Catalog
MQPrintListner

目前接口 PrintListner 仅有 1 个实现即 MQPrintListner MQPrintListner 可以接收 MQ Message ,收到后交由 PrintMsgHandler 处理,或是通过 DBCache 暂存。

DBCache

DBCache 是一个工具类,封装了对于 javaDB 的操作。

CachedMsgHandler

CachedMsgHandler 则通过 DBCache 分批取出暂存于 javaDB message ,转而交由 PrintMsgHandler 处理。

Related Views

Message Handling Module

 

Message Handling Module

Primary Presentation


Element Catalog
PrintMsgHandler

处理打印 message 直至提交打印请求的类。

PrintMsgParser

PrintMsgHandler 通过 PrintMsgParserFactory 创建对应的 PrintMsgParser ,然后由 PrintMsgParser 解析 message 生成 PrintRequest

PrintServer

PrintMsgHandler 通过 PrintServerFactory 创建对应的 PrintServer ,然后将 PrintRequest 交由 PrintServer 实现打印。

Printer

Printer 在此仅是一个工具类。以其属性 isBlocked 表征 PrintServer 当前使用的 Printer 的状态。目的是为了避免不同 PrintServer 同时要向一个 Printer 打印而可能造成的冲突。打印的代码实现事实上放在 PrintServer 里面。

Variability Guide

PrintMsgParser部分的设计考虑需要支援足够的可扩展性,未来即可依此架构开发各种PrintMsgParser来解析各式各样的message以生成对应的PrintRequest

目前实现的 PrintServer SheetPrintServer, LabelPrintServer ,未来还可以此架构开发其它 PrintServer 来作不同目的的打印。

Related Views

Message Receiving Module




--END
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值