Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 基于XML的应用程序组件消息传递架构,不知是否可行?
rego





发贴: 26
积分: 10
于 2003-01-23 22:04 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
基本思路为:
应用程序的各个需要接受消息的组件都实现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);
}


rego edited on 2003-01-23 22:06


菜鸟请教,基本程序调试不通,急急急急急急!!!

话题树型展开
人气 标题 作者 字数 发贴时间
6089 基于XML的应用程序组件消息传递架构,不知是否可行? rego 2466 2003-01-23 22:04
4305 Re:基于XML的应用程序组件消息传递架构,不知是否可行? 烂泥 2 2003-01-24 10:40
4660 Re:基于XML的应用程序组件消息传递架构,不知是否可行? rego 30 2003-01-26 00:17

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   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