0Pricing
Erlang OTP: Distributed & Fault-Tolerant Systems Programming · レッスン

スーパーバイザーブリッジと混在プロセス階層

supervisor_bridgeを使ってOTP以外のプロセスや外部サブシステムを監視ツリーに統合し、フォールトトレランスを維持します。

「スーパーバイザーブリッジと混在プロセス階層」はCoddyKit上の無料Erlang OTP: Distributed & Fault-Tolerant Systems Programmingレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはErlang OTP: Distributed & Fault-Tolerant Systems Programming学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Erlang OTP: Distributed & Fault-Tolerant Systems Programmingコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Why a Supervisor Bridge?

Not every process you depend on is a clean OTP gen_server. Sometimes you must supervise a plain Erlang process, a port, or a third-party subsystem. The supervisor_bridge behaviour lets such a process appear as a normal child in a supervision tree.

The Problem It Solves

A standard supervisor only knows how to start, stop and restart OTP-compliant children. A raw process started with spawn_link does not respond to OTP shutdown protocols. The bridge translates between the two worlds.

Behaviour Callbacks

A supervisor_bridge module implements two callbacks:

  • init/1 starts the real subsystem and returns its pid
  • terminate/2 cleanly shuts the subsystem down

Skeleton Module

The bridge is started like a supervisor but behaves like a worker to its parent.

-module(legacy_bridge).
-behaviour(supervisor_bridge).
-export([start_link/0, init/1, terminate/2]).

start_link() ->
    supervisor_bridge:start_link({local, ?MODULE}, ?MODULE, []).

Implementing init/1

init/1 must start and link the external process, then return {ok, Pid, State}. If start fails, return {error, Reason}.

init([]) ->
    case legacy_server:start() of
        {ok, Pid} -> {ok, Pid, Pid};
        Error -> Error
    end.

Implementing terminate/2

When the bridge is asked to shut down, it calls terminate/2 so you can stop the subsystem gracefully.

terminate(_Reason, Pid) ->
    legacy_server:stop(Pid),
    ok.

Placing the Bridge in a Tree

To its parent supervisor, the bridge is just another child spec with type => worker.

ChildSpec = #{id => legacy,
              start => {legacy_bridge, start_link, []},
              restart => permanent,
              type => worker}.

Failure Propagation

Because the bridge links to the external process, a crash there exits the bridge, which the parent supervisor sees as a normal worker crash and restarts according to its strategy.

Mixed Hierarchies

A real system mixes gen_server workers, sub-supervisors, and bridges. The bridge lets legacy or foreign code participate without weakening the OTP guarantees of the rest of the tree.

When NOT to Use a Bridge

If you can wrap the subsystem in a proper gen_server, prefer that — it gives you full OTP introspection. Reserve the bridge for code you cannot rewrite or that has its own process lifecycle.

Debugging Bridged Subsystems

Because the inner process is not OTP, tools like sys:get_state/1 will not reach it. Add logging inside the subsystem and rely on the bridge state to track the inner pid.

Quick Check

Test your understanding of supervisor bridges.

Recap

You learned to integrate foreign processes into supervision trees:

  • supervisor_bridge wraps non-OTP subsystems
  • init/1 starts and links the subsystem; terminate/2 stops it
  • It appears as a worker child to its parent supervisor
  • Crashes propagate so normal restart strategies apply
  • Prefer a real gen_server when you control the code

よくある質問

「スーパーバイザーブリッジと混在プロセス階層」レッスンは無料ですか?

はい。「スーパーバイザーブリッジと混在プロセス階層」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Erlang OTP: Distributed & Fault-Tolerant Systems Programmingコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Erlang OTP: Distributed & Fault-Tolerant Systems Programmingコースには全4レッスンが含まれています。

「スーパーバイザーブリッジと混在プロセス階層」で何を学びますか?

supervisor_bridgeを使ってOTP以外のプロセスや外部サブシステムを監視ツリーに統合し、フォールトトレランスを維持します。 ブラウザで直接実行するハンズオンコードでErlang OTP: Distributed & Fault-Tolerant Systems Programmingを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Erlang OTP: Distributed & Fault-Tolerant Systems Programmingを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのErlang OTP: Distributed & Fault-Tolerant Systems Programmingは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「スーパーバイザーブリッジと混在プロセス階層」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このErlang OTP: Distributed & Fault-Tolerant Systems Programmingレッスンでコードを書いて実行できますか?

はい。すべてのErlang OTP: Distributed & Fault-Tolerant Systems Programmingレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. 複雑なSupervisorツリー
  2. 動的なプロセス管理
  3. 高度な再起動戦略
  4. スーパーバイザーブリッジと混在プロセス階層
← Erlang OTP: Distributed & Fault-Tolerant Systems Programmingに戻る