LoginSignup
1
0

More than 5 years have passed since last update.

Sparkの初期化処理

Posted at

ちょっとやりたいことがあったので、Sparkの初期化処理を調べてたのだけど、かなり複雑です。
忘れないようにシーケンス図を張っておきます。

シーケンス図

sequence.png

登場人物紹介。

Spark

Serviceインスタンスをsingletonで保持し、そのインスタンスのメソッドを呼び出すためのwrapperです。

Service

ルーティングの設定、Serverの初期化などを行います。

EmbeddedServers

組込サーバーのFactoryを管理します。何もしなければEmbeddedJettyFactoryが生成され、管理されます。

EmbeddedServerFactroy(EmbeddedJettyFactory)

EmbeddedServerのfactoryです。

EmbeddedServer(EmbeddedJettyServer)

Jettyなどが提供するServerのadaptorです。

JettyServerFactory(JettyServer)

JettyのServerインスタンスを生成するためのfactoryです。

拡張

事前にEmbeddedServersにEmbeddedServerFactoryを登録しておくことで、独自の処理に差し替えを行うことができます。


public static void main(String[] args) {

  EmbeddedServers.add(EmbeddedServers.Identifiers.JETTY, new MyEmbeddedServerFactory(new MyJettyServerFactory())); // 今のところキーを変更することはできないので、第一引数はEmbeddedServers.Identifiers.JETTYを指定する必要があります。

  get("/", (request, response) -> "Hello World")
}

Jettyの細かい設定を行う場合は、この辺のクラスを拡張して実装を行う必要があります。

参考
https://qiita.com/teekee/items/92ccfa892d6a9d02731c

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0