JavaのWebアプリケーション開発フレームワークによる、Webサイト開発の顛末記です。

EclipseのMavenを使った、Spring-MVC、Thymeleaf、MyBatis 等のプログラミングテクニックを、
備忘録的に記録しています。実際に動くソースコードを多用して説明していますので、
これからEclipseや、Spring-MVCを始めたいと思っている人にとって、少しでも参考になれば幸いです。
Spring-MVCの散歩道 > 応用の森(総合テクニック編) > WebSocketを使った、リアルタイムCPU使用率推移グラフ

package jp.dip.arimodoki.common;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

import jp.dip.arimodoki.websocket.AccessHandler;
import jp.dip.arimodoki.websocket.CPUHandler;
import jp.dip.arimodoki.websocket.EchoHandler;

/**
 * WebSocketハンドラ登録
 */
@Configuration
@EnableWebSocket
public class ApplicationConfig implements WebSocketConfigurer {

        @Override  //registerWebSocketHandlersをオーバーライドします
        public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
            registry.addHandler(new CPUHandler(), "/wscpuused.xhtml");
            //他にもあれば必要なだけ羅列可能
           // registry.addHandler(new EchoHandler(), "/hoge.xhtml");

            // セッションごとにオブジェクトを分ける場合は以下のように書く
            //registry.addHandler(new PerConnectionWebSocketHandler(CPUHandler.class), "/wscpuused.xhtml");
        }
}