module Simulation.Aivika.Distributed.Optimistic.Internal.Message
(Message(..),
antiMessage,
antiMessages,
AcknowledgmentMessage(..),
acknowledgmentMessage,
LogicalProcessMessage(..),
TimeServerMessage(..),
InboxProcessMessage(..),
KeepAliveMessage(..)) where
import GHC.Generics
import Data.Typeable
import Data.Binary
import qualified Control.Distributed.Process as DP
import Control.Distributed.Process.Serializable
data Message =
Message { messageSequenceNo :: Int,
messageSendTime :: Double,
messageReceiveTime :: Double,
messageSenderId :: DP.ProcessId,
messageReceiverId :: DP.ProcessId,
messageAntiToggle :: Bool,
messageData :: DP.Message
} deriving (Show, Typeable, Generic)
instance Binary Message
antiMessage :: Message -> Message
antiMessage x = x { messageAntiToggle = not (messageAntiToggle x) }
antiMessages :: Message -> Message -> Bool
antiMessages x y =
(messageSequenceNo x == messageSequenceNo y) &&
(messageSendTime x == messageSendTime y) &&
(messageReceiveTime x == messageReceiveTime y) &&
(messageSenderId x == messageSenderId y) &&
(messageReceiverId x == messageReceiverId y) &&
(messageAntiToggle x /= messageAntiToggle y)
instance Eq Message where
x == y =
(messageSequenceNo x == messageSequenceNo y) &&
(messageSendTime x == messageSendTime y) &&
(messageReceiveTime x == messageReceiveTime y) &&
(messageSenderId x == messageSenderId y) &&
(messageReceiverId x == messageReceiverId y) &&
(messageAntiToggle x == messageAntiToggle y)
data AcknowledgmentMessage =
AcknowledgmentMessage { acknowledgmentSequenceNo :: Int,
acknowledgmentSendTime :: Double,
acknowledgmentReceiveTime :: Double,
acknowledgmentSenderId :: DP.ProcessId,
acknowledgmentReceiverId :: DP.ProcessId,
acknowledgmentAntiToggle :: Bool,
acknowledgmentMarked :: Bool
} deriving (Eq, Ord, Show, Typeable, Generic)
instance Binary AcknowledgmentMessage
acknowledgmentMessage :: Bool -> Message -> AcknowledgmentMessage
acknowledgmentMessage marked x =
AcknowledgmentMessage { acknowledgmentSequenceNo = messageSequenceNo x,
acknowledgmentSendTime = messageSendTime x,
acknowledgmentReceiveTime = messageReceiveTime x,
acknowledgmentSenderId = messageSenderId x,
acknowledgmentReceiverId = messageReceiverId x,
acknowledgmentAntiToggle = messageAntiToggle x,
acknowledgmentMarked = marked
}
data LogicalProcessMessage = QueueMessage Message
| QueueMessageBulk [Message]
| AcknowledgmentQueueMessage AcknowledgmentMessage
| AcknowledgmentQueueMessageBulk [AcknowledgmentMessage]
| ComputeLocalTimeMessage
| GlobalTimeMessage Double
| ProcessMonitorNotificationMessage DP.ProcessMonitorNotification
| ReconnectProcessMessage DP.ProcessId
| KeepAliveLogicalProcessMessage KeepAliveMessage
deriving (Show, Typeable, Generic)
instance Binary LogicalProcessMessage
data TimeServerMessage = RegisterLogicalProcessMessage DP.ProcessId
| UnregisterLogicalProcessMessage DP.ProcessId
| TerminateTimeServerMessage DP.ProcessId
| RequestGlobalTimeMessage DP.ProcessId
| LocalTimeMessage DP.ProcessId Double
| ReMonitorTimeServerMessage [DP.ProcessId]
deriving (Eq, Show, Typeable, Generic)
instance Binary TimeServerMessage
data InboxProcessMessage = MonitorProcessMessage DP.ProcessId
| ReMonitorProcessMessage [DP.ProcessId]
| TrySendKeepAliveMessage
| SendQueueMessage DP.ProcessId Message
| SendQueueMessageBulk DP.ProcessId [Message]
| SendAcknowledgmentQueueMessage DP.ProcessId AcknowledgmentMessage
| SendAcknowledgmentQueueMessageBulk DP.ProcessId [AcknowledgmentMessage]
| SendLocalTimeMessage DP.ProcessId DP.ProcessId Double
| SendRequestGlobalTimeMessage DP.ProcessId DP.ProcessId
| SendRegisterLogicalProcessMessage DP.ProcessId DP.ProcessId
| SendUnregisterLogicalProcessMessage DP.ProcessId DP.ProcessId
| SendTerminateTimeServerMessage DP.ProcessId DP.ProcessId
| RegisterLogicalProcessAcknowledgmentMessage DP.ProcessId
| UnregisterLogicalProcessAcknowledgmentMessage DP.ProcessId
| TerminateTimeServerAcknowledgmentMessage DP.ProcessId
| TerminateInboxProcessMessage
deriving (Eq, Show, Typeable, Generic)
instance Binary InboxProcessMessage
data KeepAliveMessage = KeepAliveMessage
deriving (Eq, Show, Typeable, Generic)
instance Binary KeepAliveMessage