Package com.streamconverter.command.rule
Class MdcPropagatingRule
java.lang.Object
com.streamconverter.command.rule.MdcPropagatingRule
- All Implemented Interfaces:
IRule
変換結果をMDC共有値として伝搬するルール。
ストリームデータから抽出された値を、パイプライン内の全コマンドのログ出力に 自動反映するために使用する。値はパススルーされ、変換は行わない。
MDC.put だけのルールとの違い:
- 後続コマンドへの伝搬 — 値を
PipelineContextの共有値として格納し、PipelineContextTurboFilterが他コマンドのログ出力直前にsyncToMDC()で自動反映する。MDC.putだけでは呼び出しスレッド内しか効かない。 - 実行タイミング非依存 — 子スレッド起動後に値を書いても
PipelineContext経由ならTurboFilterが毎ログ前に同期するため順序非依存。 - スレッドからのコンテキスト切り離し —
PipelineContext.clear()により、このスレッドとの関連付けを解除できる。
使用例:
// XMLの orderId を抽出してMDCに伝搬
XmlNavigateCommand command = XmlNavigateCommand.create(
TreePath.fromXPath("/order/@id"),
MdcPropagatingRule.create("orderId")
);
-
Method Summary
-
Method Details
-
create
指定されたキーにストリーム値を伝搬するルールを作成します。使用例:
XmlNavigateCommand.create( TreePath.fromXml("request/userId"), MdcPropagatingRule.create("userId"));- Parameters:
mdcKey- MDC/PipelineContext に格納するキー名- Returns:
- 伝搬ルールのインスタンス
- Throws:
IllegalArgumentException- mdcKey が null または空の場合
-
apply
入力値をMDC共有値として設定し、そのまま返す。- Specified by:
applyin interfaceIRule- Parameters:
input- 変換対象の文字列- Returns:
- 入力値をそのまま返す
- Throws:
IllegalArgumentException- inputがnullの場合
-
toString
-
equals
-
hashCode
-