@@ -38,8 +38,8 @@ module Control.Distributed.Process.Internal.Primitives
38 , unregister
38 , unregister
41− , registerRemote
41+ , registerRemoteAsync
42− , unregisterRemote
42+ , unregisterRemoteAsync
43 , whereisRemoteAsync
43 , whereisRemoteAsync
44 , nsendRemote
44 , nsendRemote
45 -- * Closures
45 -- * Closures
@@ -76,6 +76,7 @@ import Data.Time.Clock (getCurrentTime)
76import Data.Time.Format (formatTime)
76import Data.Time.Format (formatTime)
77import System.Locale (defaultTimeLocale)
77import System.Locale (defaultTimeLocale)
78import System.Timeout (timeout)
78import System.Timeout (timeout)
79+import Control.Monad (when)
79import Control.Monad.Reader (ask)
80import Control.Monad.Reader (ask)
80import Control.Monad.IO.Class (MonadIO, liftIO)
81import Control.Monad.IO.Class (MonadIO, liftIO)
81import Control.Applicative ((<$>))
82import Control.Applicative ((<$>))
@@ -127,6 +128,8 @@ import Control.Distributed.Process.Internal.Types
127 , DidUnlinkNode(..)
128 , DidUnlinkNode(..)
128 , DidUnlinkPort(..)
129 , DidUnlinkPort(..)
129 , WhereIsReply(..)
130 , WhereIsReply(..)
132+ , ProcessRegistrationException(..)
130 , createMessage
133 , createMessage
131 , runLocalProcess
134 , runLocalProcess
132 , ImplicitReconnect(WithImplicitReconnect, NoImplicitReconnect)
135 , ImplicitReconnect(WithImplicitReconnect, NoImplicitReconnect)
@@ -542,24 +545,44 @@ say string = do
543-- The process to be registered does not have to be local itself.
546-- The process to be registered does not have to be local itself.
544register :: String -> ProcessId -> Process ()
547register :: String -> ProcessId -> Process ()
545−register label pid =
548+register label pid = do
546 sendCtrlMsg Nothing (Register label (Just pid))
549 sendCtrlMsg Nothing (Register label (Just pid))
550+ receiveWait [ matchIf (\(RegisterReply label' _) -> label == label')
551+ (\(RegisterReply _ ok) -> handleRegistrationReply label ok)
548-- | Register a process with a remote registry (asynchronous).
554-- | Register a process with a remote registry (asynchronous).
550-- The process to be registered does not have to live on the same remote node.
556-- The process to be registered does not have to live on the same remote node.
557+-- Reply wil come in the form of a 'RegisterReply' message
559+-- See comments in 'whereisRemoteAsync'
551−registerRemote :: NodeId -> String -> ProcessId -> Process ()
560+registerRemoteAsync :: NodeId -> String -> ProcessId -> Process ()
552−registerRemote nid label pid =
561+registerRemoteAsync nid label pid =
553 sendCtrlMsg (Just nid) (Register label (Just pid))
562 sendCtrlMsg (Just nid) (Register label (Just pid))
555-- | Remove a process from the local registry (asynchronous).
564-- | Remove a process from the local registry (asynchronous).
556unregister :: String -> Process ()
565unregister :: String -> Process ()
557−unregister label =
566+unregister label = do
558 sendCtrlMsg Nothing (Register label Nothing)
567 sendCtrlMsg Nothing (Register label Nothing)
568+ receiveWait [ matchIf (\(RegisterReply label' _) -> label == label')
569+ (\(RegisterReply _ ok) -> handleRegistrationReply label ok)
572+-- | Deal with the result from an attempted registration or unregistration
573+-- by throwing an exception if necessary
574+handleRegistrationReply :: String -> Bool -> Process ()
575+handleRegistrationReply label ok =
577+ liftIO $ throwIO $ ProcessRegistrationException label
560-- | Remove a process from a remote registry (asynchronous).
579-- | Remove a process from a remote registry (asynchronous).
581+-- Reply wil come in the form of a 'RegisterReply' message
583+-- See comments in 'whereisRemoteAsync'
561−unregisterRemote :: NodeId -> String -> Process ()
584+unregisterRemoteAsync :: NodeId -> String -> Process ()
562−unregisterRemote nid label =
585+unregisterRemoteAsync nid label =
563 sendCtrlMsg (Just nid) (Register label Nothing)
586 sendCtrlMsg (Just nid) (Register label Nothing)
565-- | Query the local process registry
588-- | Query the local process registry