nekop's blog

OpenShift / JBoss / WildFly / Infinispanの中の人 http://twitter.com/nekop

WildFlyのリモーティング

JBoss / WildFly (全部俺) Advent Calendar 2013の20日目です。

WildFlyではEJBなどのリモートコールは全てWebSocketを利用するようになっています。それがどのように実装されているかを調べます。WildFlyのmasterをビルドしたもので確認しています。

wildfly/remoting/pom.xmlを見るとundertow-coreが依存として定義されています。undertowをimportしているものを探すとorg.jboss.as.remoting.RemotingHttpUpgradeServiceがundertowとjboss-remotingの橋渡しをしているクラスのようです。

以下のふたつがimportされています。

  • io.undertow.server.ListenerRegistry;
  • io.undertow.server.handlers.ChannelUpgradeHandler;

ListenerRegistryから取得できるListenerはメタデータの登録などに利用されているようです。実際のブリッジはChannelUpgradeHandlerにXNIOのChannelListenerを登録して、そのChannelListener内でjboss-remotingのEndpointにConnectedStreamChannelを渡すことによって連携しています。

EJBクライアントはポートを旧来のjboss-remotingの4447から8080に変更するだけで動作します。EJBクライアントのソースを見るとjboss-remotingに用意されているHttpUpgradeConnectionProviderFactoryを利用するようになっており、WebSocketで動作するようになっているようです。

コネクションオープン後に以下のUpgradeが行われて、あとは普通のjboss-remotingのペイロードにスイッチしています。

GET / HTTP/1.1
Sec-JbossRemoting-Key: oEKRMTn5e+qGoACK0Um0Yw==
Upgrade: jboss-remoting
Host: localhost
Connection: upgrade

HTTP/1.1 101 Switching Protocols
Connection: Upgrade
Upgrade: jboss-remoting
Content-Length: 0
Sec-JbossRemoting-Accept: FXGBl+OiN8bkZqTyzJ0DZKK9imA=