package Ġorg . jetbrains . intellij . plugin Repository . internal . api Ċ Ċ import Ġcom . fasterxml . jackson . databind . Deserialization Feature Ċ import Ġcom . fasterxml . jackson . module . kotlin . jackson ObjectMapper Ċ import Ġokhttp 3 . Dispatcher Ċ import Ġokhttp 3 . Interceptor Ċ import Ġokhttp 3 . Ok HttpClient Ċ import Ġokhttp 3 . Response Ċ import Ġorg . jetbrains . intellij . plugin Repository .* Ċ import Ġorg . jetbrains . intellij . plugin Repository . internal . Messages Ċ import Ġorg . jetbrains . intellij . plugin Repository . internal . instances . Plugin Downloader Instance Ċ import Ġorg . jetbrains . intellij . plugin Repository . internal . instances . PluginManager Instance Ċ import Ġorg . jetbrains . intellij . plugin Repository . internal . instances . Plugin Update Manager Instance Ċ import Ġorg . jetbrains . intellij . plugin Repository . internal . instances . Plugin Uploader Instance Ċ import Ġorg . slf 4 j . Logger Ċ import Ġorg . slf 4 j . LoggerFactory Ċ import Ġretrofit 2 . Ret rofit Ċ import Ġretrofit 2 . converter . jackson . Jack son Converter Factory Ċ import Ġretrofit 2 . converter . jax b . Jax b Converter Factory Ċ import Ġjava . util . concurrent . Executors Ċ import Ġjava . util . concurrent . Thread Factory Ċ import Ġjava . util . concurrent . TimeUnit Ċ import Ġjava . util . concurrent . atomic . Atomic Long ĊĊ Ċ val ĠLOG : ĠLogger Ġ= ĠLoggerFactory . getLogger (" plugin - repository - rest - client ") Ċ Ċ internal Ġclass ĠPlugin Repository Instance < T Ġ: ĠPlugin Repository Service >( ĊĠ Ġsite Url : ĠString , ĊĠ Ġprivate Ġval Ġtoken : ĠString ? Ġ= Ġnull , ĊĠ Ġprivate Ġval Ġauth Scheme : ĠString , ĊĠ Ġservice Class : ĠClass < T >, Ċ ) Ġ: ĠPlugin Repository Ġ{ ĊĊĠ Ġprivate Ġval Ġmax Parallel Connection Ġ= ĠSystem . getProperty (" MARK ET PLACE _ MAX _ PAR ALLEL _ CONNECTION S ", Ġ" 1 6 "). toInt () ĊĊĠ Ġprivate Ġval ĠexecutorService Ġ= ĠExec utors . new Fixed ThreadPool ( max Parallel Connection , ĠDa emon Thread Factory (" ret rofit - thread ")) ĊĊĠ Ġprivate Ġval Ġdispatcher Ġ= ĠDispatcher ( executor Service ). apply Ġ{ ĊĠĠĠ Ġthis . max Requests Per Host Ġ= Ġmax Parallel Connection ĊĠĠĠ Ġthis . max Requests Ġ= Ġmax Parallel Connection ĊĠ Ġ} ĊĊĠ Ġprivate Ġval Ġok HttpClient Ġ= ĠOk HttpClient () ĊĠĠĠ Ġ. newBuilder () ĊĠĠĠ Ġ. dispatcher ( dispatcher ) ĊĠĠĠ Ġ. connect Timeout ( 5 , ĠTimeUnit . MIN UTES ) ĊĠĠĠ Ġ. read Timeout ( 5 , ĠTimeUnit . MIN UTES ) ĊĠĠĠ Ġ. write Timeout ( 5 , ĠTimeUnit . MIN UTES ) ĊĠĠĠ Ġ. add Interceptor ( object Ġ: ĠInter ceptor Ġ{ ĊĠĠĠĠĠ Ġoverride Ġfun Ġintercept ( chain : ĠInter ceptor . Chain ): ĠResponse Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= Ġif Ġ( token Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġchain . request (). newBuilder (). add Header (" Authorization ", Ġ"$ auth Scheme Ġ$ token "). build () ĊĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġchain . request () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġreturn Ġchain . proceed ( request ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ}) ĊĠĠĠ Ġ. build () ĊĊĠ Ġprivate Ġval Ġservice Ġ= ĠRet rofit . Builder () ĊĠĠĠ Ġ. baseUrl ( site Url ) ĊĠĠĠ Ġ. client ( ok HttpClient ) ĊĠĠĠ Ġ. add Converter Factory ( Jax b Converter Factory . create ()) ĊĠĠĠ Ġ. add Converter Factory ( Jack son Converter Factory . create ( ĊĠĠĠĠĠ Ġj ack son ObjectMapper () ĊĠĠĠĠĠĠĠ Ġ. configure ( ĊĠĠĠĠĠĠĠĠĠ ĠDeserial ization Feature . READ _ UNKNOWN _ ENUM _ VALUES _ AS _ NULL , Ġtrue ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ)) ĊĠĠĠ Ġ. build () ĊĠĠĠ Ġ. create ( service Class ) ĊĊĠ Ġinit Ġ{ ĊĠĠĠ ĠRuntime . get Runtime (). add Shutdown Hook ( Thread Ġ{ ĊĠĠĠĠĠ Ġdispatcher . executor Service . shutdown Now () ĊĠĠĠĠĠ Ġok HttpClient . connection Pool . ev ict All () ĊĠĠĠĠĠ Ġok HttpClient . cache ?. close () ĊĠĠĠ Ġ}) ĊĠ Ġ} ĊĊĠ Ġoverride Ġval Ġdown loader : ĠPlugin Downloader Ġ= ĠPlugin Downloader Instance ( service ) ĊĊĠ Ġoverride Ġval Ġup loader : ĠPlugin Uploader ĊĠĠĠ Ġget () Ġ{ ĊĠĠĠĠĠ Ġensure Credentials Are Set () ĊĠĠĠĠĠ Ġreturn ĠPlugin Uploader Instance ( service ) ĊĠĠĠ Ġ} ĊĠ Ġoverride Ġval Ġplugin Manager : ĠPlugin Manager Ġ= ĠPlugin Manager Instance ( service ) ĊĊĠ Ġoverride Ġval Ġplugin Update Manager : ĠPlugin Update Manager Ġ= ĠPlugin Update Manager Instance ( service ) ĊĊĠ Ġprivate Ġfun Ġensure Credentials Are Set () Ġ{ ĊĠĠĠ Ġif Ġ( token Ġ== Ġnull ) Ġthrow ĠRuntimeException ( Messages . getMessage (" missing . token ")) ĊĠ Ġ} ĊĊĠ Ġprivate Ġclass ĠDa emon Thread Factory ( private Ġval Ġthread Name Prefix : ĠString ) Ġ: ĠThread Factory Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġdefault Thread Factory Ġ= ĠExec utors . default Thread Factory () ĊĊĠĠĠ Ġprivate Ġval Ġname Count Ġ= ĠAtomic Long () ĊĊĠĠĠ Ġoverride Ġfun Ġnew Thread ( r : ĠRunnable ): ĠThread Ġ= Ġdefault Thread Factory . new Thread ( r ). apply Ġ{ ĊĠĠĠĠĠ Ġname Ġ= Ġ"$ thread Name Prefix -${ name Count . get And Increment () }" ĊĠĠĠĠĠ Ġis Daemon Ġ= Ġtrue ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ } Ċ