<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>lizongbo at 618119.com &#187; URLStreamHandlerFactory</title>
	<atom:link href="http://618119.com/tag/urlstreamhandlerfactory/feed" rel="self" type="application/rss+xml" />
	<link>http://618119.com</link>
	<description>工作,生活,Android,前端,Linode,Ubuntu,nginx,java,apache,tomcat,Resin,mina,Hessian,XMPP,RPC</description>
	<lastBuildDate>Tue, 31 Jan 2012 14:25:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>扩展java.net.URL支持自定义协议来优化hessian的调用</title>
		<link>http://618119.com/archives/2009/01/11/126.html</link>
		<comments>http://618119.com/archives/2009/01/11/126.html#comments</comments>
		<pubDate>Sun, 11 Jan 2009 14:51:17 +0000</pubDate>
		<dc:creator>lizongbo</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Hessian]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[https]]></category>
		<category><![CDATA[RPC]]></category>
		<category><![CDATA[URL]]></category>
		<category><![CDATA[URLStreamHandler]]></category>
		<category><![CDATA[URLStreamHandlerFactory]]></category>

		<guid isPermaLink="false">http://618119.com/?p=126</guid>
		<description><![CDATA[扩展java.net.URL支持自定义协议来优化hessian调用 hessian是个高性能的java RPC调用协议，但是官方默认只提供了基于http和https两种方式的远程调用。 虽然每天使用http方式调用上千万次也没出现性能问题，(有jdk一份功劳，jdk1.5及以上版本支持了http.KeepAlive， 默认设置为： http.KeepAlive.remainingData=512 http.KeepAlive.queuedConnections=10) 但是如果能够改成tcp纯socket长连接池方式，性能是还可以优化的，因为把http的header头信息给省了七七八八。 由于hessian使用的URL和URLConnection来发送hessian请求和应答的，而URL的协议处理是可以扩展的, 因此可以通过扩展URL支持自定义协议来灵活切换hessian使用http或者tcp或者udp方式进行请求发送和接收应答。 查找相关资料后整理了三种扩展方法： 1.通过用户指定的package名称的最后一位作为协议名称（包名要是小写的）。 例如我自定义了三个协议,hessiantcp,hessianudp,hessiantcpudp； 则需要建立三个继承java.net.URLStreamHandler的Handler类(实现类的名字必须是Handler). 即： com.lizongbo.hessian.protocol.hessiantcp.Handler.java com.lizongbo.hessian.protocol.hessianudp.Handler.java com.lizongbo.hessian.protocol.hessiantcpudp.Handler.java 在运行时，还要指定系统属性java.protocol.handler.pkgs 或者在java命令行里增加启动参数： -Djava.protocol.handler.pkgs=com.lizongbo.hessian.protocol（多个包名之间用竖线隔开，例如: -Djava.protocol.handler.pkgs=com.lizongbo.hessian.protocola&#124;com.lizongbo.hessian.protocolb） 或者在代码里调用创建URL之前，先执行： [code] System.setProperty("java.protocol.handler.pkgs","com.lizongbo.hessian.protocol"); URL serviceUrl = new URL("hessiantcp://618119.com/blog/hessian/service"); [/code] 这样，用户便能够通过URL对象处理hessiantcp://这样的协议了， 否则，使用hessiantcp://这样的协议会导致异常。 参考：http://www.tuscany.org.cn/index.php/Tuscany与JBoss集成中遇到的问题及排除 和http://java.sun.com/developer/onlineTraining/protocolhandlers/ 2.设置指定的URLStreamHandlerFactory也可以扩展自定义的协议。 [code] package com.lizongbo.hessian.protocol; import java.net.*; import java.util.Hashtable; class HessianURLStreamHandlerFactory implements URLStreamHandlerFactory { private String packagePrefix = "com.lizongbo.hessian.protocol"; protected static [...]]]></description>
		<wfw:commentRss>http://618119.com/archives/2009/01/11/126.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

