module Database.CQL.IO.Cluster.Host where
import Control.Lens ((^.), Lens')
import Data.ByteString.Lazy.Char8 (unpack)
import Data.Text (Text)
import Database.CQL.IO.Types (InetAddr)
import System.Logger.Message
data HostEvent
= HostNew !Host
| HostGone !InetAddr
| HostUp !InetAddr
| HostDown !InetAddr
data Host = Host
{ _hostAddr :: !InetAddr
, _dataCentre :: !Text
, _rack :: !Text
} deriving (Eq, Ord)
hostAddr :: Lens' Host InetAddr
hostAddr f ~(Host a c r) = fmap (\x -> Host x c r) (f a)
dataCentre :: Lens' Host Text
dataCentre f ~(Host a c r) = fmap (\x -> Host a x r) (f c)
rack :: Lens' Host Text
rack f ~(Host a c r) = fmap (\x -> Host a c x) (f r)
instance Show Host where
show = unpack . eval . bytes
instance ToBytes Host where
bytes h = h^.dataCentre +++ val ":" +++ h^.rack +++ val ":" +++ h^.hostAddr