Topic: 基于XML的应用程序组件消息传递架构,不知是否可行? |
Print this page |
1.基于XML的应用程序组件消息传递架构,不知是否可行? | Copy to clipboard |
Posted by: rego Posted on: 2003-01-23 22:04 基本思路为: 应用程序的各个需要接受消息的组件都实现XML ContentHandler Interface,然后统一subscribe到系统的MessageBus;需要发布消息的组件通过MessageBus的publish方法向PipedWriter写入XML格式的Message。 同时MessageBus通过一个独立的Thread来Parse从PipedReader中得到的XML Message,根据Parse过程中的Event调用各个已经subscribe组件的ContentHandler CallBack。 实现过程中出现以下异常: java.io.IOException: Write end dead at java.io.PipedReader.ready(PipedReader.java:286) at java.io.BufferedReader.read(BufferedReader.java:263) 各位觉得以上设想可行吗,对于PipedReader和PipedWriter我有许多地方不明白,还请指教。 以下是MessageBus代码: import org.apache.log4j.BasicConfigurator; import org.apache.log4j.Category; import org.apache.xerces.parsers.SAXParser; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import java.io.*; public class MessageBus { static Category cat = Category.getInstance(MessageBus.class.getName()); static PipedReader mReader; static PipedWriter mWriter; static PrintWriter out; static InputSource is; static SAXParser parser; static Subscriber subscription_list = null; public static void subscribe(Subscriber subscriber) { subscription_list = Multicaster.add(subscription_list, subscriber); } public static void unsubscribe(Subscriber subscriber) { subscription_list = Multicaster.remove(subscription_list, subscriber); } static { BasicConfigurator.configure(); mWriter = new PipedWriter(); out = new PrintWriter(mWriter); try { mReader = new PipedReader(mWriter); } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use Options | File Templates. } is = new InputSource(new BufferedReader(mReader)); parser = new SAXParser(); new Thread() { public void run() { parser.setContentHandler(subscription_list); try { cat.info("Start parsing."); parser.parse(is); } catch (SAXException e) { e.printStackTrace(); //To change body of catch statement use Options | File Templates. } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use Options | File Templates. } } }.start(); } public static void publish(String message) { out.write(message); } |
2.Re:基于XML的应用程序组件消息传递架构,不知是否可行? [Re: rego] | Copy to clipboard |
Posted by: 烂泥 Posted on: 2003-01-24 10:40 可行 |
3.Re:基于XML的应用程序组件消息传递架构,不知是否可行? [Re: rego] | Copy to clipboard |
Posted by: rego Posted on: 2003-01-26 00:17 但实现过程中PipedReader出错,是哪里出了问题了呢? |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |