File: RemoteClient.hs

package info (click to toggle)
haskell-acid-state 0.16.1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 932 kB
  • sloc: haskell: 3,692; makefile: 2
file content (44 lines) | stat: -rw-r--r-- 1,675 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
module RemoteClient (main) where

import           Control.Monad
import           Data.Acid
import           Data.Acid.Advanced
import           Data.Acid.Remote
import           Network.Socket (SockAddr(..))
import           RemoteCommon
import           System.Environment
import           System.IO

------------------------------------------------------
-- This is how AcidState is used:

open :: IO (AcidState StressState)
open = openRemoteState skipAuthenticationPerform "localhost" 8080
-- on Unixy systems we could use a Unix Domain Socket
-- open = openRemoteStateSockAddr skipAuthenticationPerform (SockAddrUnix "remote.socket")

main :: IO ()
main = do args <- getArgs
          case args of
            ["checkpoint"]
              -> do acid <- open
                    createCheckpoint acid
            ["query"]
              -> do acid <- open
                    n <- query acid QueryState
                    putStrLn $ "State value: " ++ show n
            ["poke"]
              -> do acid <- open
                    putStr "Issuing 100k transactions... "
                    hFlush stdout
                    replicateM_ (100000-1) (scheduleUpdate acid PokeState)
                    update acid PokeState
                    putStrLn "Done"
            ["clear"]
              -> do acid <- open
                    update acid ClearState
                    createCheckpoint acid
            _ -> do putStrLn "Commands:"
                    putStrLn "  query            Prints out the current state."
                    putStrLn "  poke             Spawn 100k transactions."
                    putStrLn "  checkpoint       Create a new checkpoint."