package Ġcom . kas per sky . test _ server . implementation Ċ Ċ import Ġcom . k asp res ky . test _ server . log . Logger Ċ Ċ /** Ċ Ġ* ĠThe Ġhelper Ġto Ġestablish Ġa Ġconnection Ġcorrectly Ġaccording Ġto Ġall Ġpossible Ġstates Ġand Ġmult ith read 's Ġenvironment Ċ Ġ*/ Ċ internal Ġclass ĠConnection Maker ( ĊĠĠĠ Ġprivate Ġval Ġlogger : ĠLogger Ċ ) Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġtag Ġ= Ġjava Class . simple Name ĊĠĠĠ Ġ@ Volatile ĊĠĠĠ Ġprivate Ġvar Ġconnection State : ĠConnection State Ġ= ĠConnection State . DIS CONNECTED ĊĊĠĠĠ Ġ@ Synchron ized ĊĠĠĠ Ġfun Ġconnect ( connect Action : Ġ() Ġ-> ĠUnit , Ġsuccess Connect Action : Ġ() Ġ-> ĠUnit ) Ġ{ ĊĠĠĠĠĠĠĠ Ġlogger . i ( tag , Ġ" connect ", Ġ" start ") ĊĠĠĠĠĠĠĠ Ġlogger . i ( tag , Ġ" connect ", Ġ" current Ġstate =$ connection State ") ĊĠĠĠĠĠĠĠ Ġif Ġ( connection State Ġ== ĠConnection State . CONNECT ING Ġ|| Ġconnection State Ġ== ĠConnection State . DIS CONNECT ING ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlogger . i ( tag , Ġ" connect ", Ġ" Unexpected Ġconnection Ġstate Ġappeared Ġduring Ġconnect ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġif Ġ( connection State Ġ== ĠConnection State . CONNECTED ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġconnection State Ġ= ĠConnection State . CONNECT ING ĊĠĠĠĠĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġconnect Action . invoke () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġconnection State Ġ= ĠConnection State . CONNECTED ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlogger . i ( tag , Ġ" connect ", Ġ" updated Ġstate =$ connection State ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsuccess Connect Action . invoke () ĊĠĠĠĠĠĠĠ Ġ} Ġcatch Ġ( exception : ĠException ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlogger . e ( tag , Ġ" connect ", Ġexception ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġconnection State Ġ= ĠConnection State . DIS CONNECTED ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Synchron ized ĊĠĠĠ Ġfun Ġdisconnect ( connect Action : Ġ() Ġ-> ĠUnit ) Ġ{ ĊĠĠĠĠĠĠĠ Ġlogger . i ( tag , Ġ" disconnect ", Ġ" start ") ĊĠĠĠĠĠĠĠ Ġlogger . i ( tag , Ġ" disconnect ", Ġ" current Ġstate =$ connection State ") ĊĠĠĠĠĠĠĠ Ġif Ġ( connection State Ġ== ĠConnection State . CONNECT ING Ġ|| Ġconnection State Ġ== ĠConnection State . DIS CONNECT ING ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlogger . i ( tag , Ġ" disconnect ", Ġ" Unexpected Ġconnection Ġstate Ġappeared Ġduring Ġdisconnect ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġif Ġ( connection State Ġ== ĠConnection State . DIS CONNECTED ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġconnection State Ġ= ĠConnection State . DIS CONNECT ING ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlogger . i ( tag , Ġ" disconnect ", Ġ" updated Ġstate =$ connection State ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġconnect Action . invoke () ĊĠĠĠĠĠĠĠ Ġ} Ġfinally Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġconnection State Ġ= ĠConnection State . DIS CONNECTED ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlogger . i ( tag , Ġ" disconnect ", Ġ" updated Ġstate =$ connection State ") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġis Connected (): ĠBoolean Ġ= ĊĠĠĠĠĠĠĠ Ġconnection State Ġ== ĠConnection State . CONNECTED ĊĊĠĠĠ Ġprivate Ġenum Ġclass ĠConnection State Ġ{ ĊĠĠĠĠĠĠĠ ĠCONNECT ING , ĊĠĠĠĠĠĠĠ ĠCONNECT ED , ĊĠĠĠĠĠĠĠ ĠDIS CONNECT ING , ĊĠĠĠĠĠĠĠ ĠDIS CONNECTED ĊĠĠĠ Ġ} Ċ } Ċ