module Holumbus.FileSystem.Controller.ControllerPort
(
ControllerPort
, newControllerPort
, newControllerPortFromServerPort
)
where
import Holumbus.Common.Debug
import Holumbus.Network.Communication
import Holumbus.FileSystem.Messages
import Holumbus.FileSystem.Controller
data ControllerPort = ControllerPort ServerPort
deriving (Show)
newControllerPort :: StreamName -> Maybe SocketId -> IO ControllerPort
newControllerPort sn soid
= do
sp <- newServerPort sn soid
return (ControllerPort sp)
newControllerPortFromServerPort :: ServerPort -> ControllerPort
newControllerPortFromServerPort sp = ControllerPort sp
instance ControllerClass ControllerPort where
closeController _ = return ()
getFileSites f (ControllerPort p)
= do
sendRequestToServer p time30 (CReqGetFileSites f) $
\rsp ->
do
case rsp of
(CRspGetFileSites set) -> return (Just set)
_ -> return Nothing
containsFile f (ControllerPort p)
= do
sendRequestToServer p time30 (CReqContains f) $
\rsp ->
do
case rsp of
(CRspContains b) -> return (Just b)
_ -> return Nothing
getNearestNodePortWithFile f sid (ControllerPort p)
= do
sendRequestToServer p time30 (CReqGetNearestNodePortWithFile f sid) $
\rsp ->
do
case rsp of
(CRspGetNearestNodePortWithFile po) -> return (Just po)
_ -> return Nothing
getNearestNodePortWithFiles l sid (ControllerPort p)
= do
sendRequestToServer p time30 (CReqGetNearestNodePortWithFiles l sid) $
\rsp ->
do
case rsp of
(CRspGetNearestNodePortWithFiles portmap) -> return (Just portmap)
_ -> return Nothing
getNearestNodePortForFile f l sid (ControllerPort p)
= do
sendRequestToServer p time30 (CReqGetNearestNodePortForFile f l sid) $
\rsp ->
do
case rsp of
(CRspGetNearestNodePortForFile po) -> return (Just po)
_ -> return Nothing
getNearestNodePortForFiles l sid (ControllerPort p)
= do
sendRequestToServer p time30 (CReqGetNearestNodePortForFiles l sid) $
\rsp ->
do
case rsp of
(CRspGetNearestNodePortForFiles portlist) -> return (Just portlist)
_ -> return Nothing
createFile f nid (ControllerPort p)
= do
sendRequestToServer p time30 (CReqCreate f nid) $
\rsp ->
do
case rsp of
(CRspSuccess) -> return (Just $ ())
_ -> return Nothing
createFiles l (ControllerPort p)
= do
sendRequestToServer p time30 (CReqCreateS l) $
\rsp ->
do
case rsp of
(CRspSuccess) -> return (Just $ ())
_ -> return Nothing
appendFile f nid (ControllerPort p)
= do
sendRequestToServer p time30 (CReqAppend f nid) $
\rsp ->
do
case rsp of
(CRspSuccess) -> return (Just $ ())
_ -> return Nothing
deleteFile f nid (ControllerPort p)
= do
sendRequestToServer p time30 (CReqDelete f nid) $
\rsp ->
do
case rsp of
(CRspSuccess) -> return (Just $ ())
_ -> return Nothing
instance Debug ControllerPort where
printDebug (ControllerPort p)
= do
putStrLn "ControllerPort:"
putStrLn $ show p
getDebug (ControllerPort p)
= return ("ControllerPort:\n"++show p++"\n")