fitter
1.0.0
Clojure 용 시스템 구성 요소 관리 라이브러리.
유사한 목적 라이브러리 :
최소 구성 요소는 다른 구성 요소 인스턴스의 시스템 "맵"을 수신 하고이 구성 요소 인스턴스를 반환하는 기능 일뿐입니다. 시스템 "맵"은 ILookup 인터페이스 만 지원합니다. 시스템 테스트를 참조하십시오. 모든 조회는 요청 된 구성 요소를 인스턴스화하고 구성 요소 간의 종속성을 동적으로 형성합니다. (!) 모든 구성 요소는 시스템 키 이름에 따라 엄격하게 결합됩니다.
완전한 구성 요소는 시작을 정의하고 중지 및 중단 행동을 정의합니다.
( ns readme.component
( :require [strojure.fitter.component :as component]))
( def function-component
" Simple function describes component start behaviour. "
( fn [{ :keys [another-component]}]
( comment " Use " another-component)
:instance ))
( def constant-component
" Just constant component. "
( constantly true ))
( def map-component
" Component described as hash map with required `::component/start` key. "
{ ::component/start ( constantly :instance )
::component/stop! ( fn stop! [instance]
( comment " Destroy " instance))
::component/suspend! ( fn suspend! [old-instance old-system]
( comment " Suspend " old-instance old-system)
( fn resume [new-system]
( comment " Resume " old-instance new-system)
:instance ))})
( def assembled-component
" Same map as above created using `component/of`. "
( component/of ( constantly :instance )
( fn stop! [instance]
( comment " Destroy " instance))
( fn suspend! [old-instance old-system]
( comment " Suspend " old-instance old-system)
( fn resume [new-system]
( comment " Resume " old-instance new-system)
:instance )))) 시스템 상태는 실행중인 구성 요소의 가변 보유 인스턴스입니다. 상태는 init 에 의해 초기화 된 다음 start! 그리고 stop! .
( ns readme.system-state
( :require [strojure.fitter.system :as system]))
( def ^:private registry
{ ::a ( constantly ::a )
::b ( fn [{ ::keys [a]}] { ::b a})})
; ; Initialize system state.
( defonce ^:private system!
( system/init { :registry registry}))
; ; Start all system keys.
( system/start! system!)
; ; Stop all running keys.
( system/stop! system!)
; ; The `start!`, `stop!` and `deref` return the actual system map.
( let [{ ::keys [a b]} ( system/start! system!)]
( comment " Work with " a b))
( let [_ ( system/start! system!)
{ ::keys [a b]} ( deref system!)]
( comment " Work with " a b))
; ; Start/stop only specific keys.
( system/start! system! { :filter-keys #{ ::a }})
( system/stop! system! { :filter-keys #{ ::a }})
; ; Start/stop system incrementally.
( doto system! ( system/start! { :filter-keys #{ :a }})
( system/start! { :filter-keys ( complement #{ :a })}))
( doto system! ( system/stop! { :filter-keys ( complement #{ :a })})
( system/stop! { :filter-keys #{ :a }}))
; ; Update registry on start.
( system/start! system! { :registry ( assoc registry ::c ( constantly ::c ))})
; ; Suspend suspendable components on stop and resume them on start.
( doto system! ( system/stop! { :suspend true })
( system/start! ))
; ; Execute components in parallel
( doto ( system/init { :parallel true }) ( system/start! )
( system/stop! ))
( system/start! system! { :parallel true })
( system/stop! system! { :parallel true })
; ; Use `with-open` to stop system automatically.
( with-open [s! ( system/init { :registry registry})]
( let [{ ::keys [a b]} ( system/start! s!)]
( comment " Work with " a b)))