Commit 4f5121f5 authored by Bas Lijnse's avatar Bas Lijnse

Cleanup and small refactoring

git-svn-id: https://svn.cs.ru.nl/repos/iTask-system/trunk@1957 63da3aa8-80fd-4f01-9db8-e6ea747a3da2
parent 00b14b0a
......@@ -20,7 +20,6 @@ import Coffeemachine
import APIDocumentation
//import Newsgroups
import ChangeHandling
//import textEditor
import CoffeeTime
import Calculator
......@@ -28,9 +27,6 @@ import TableExamples
import GeoTracker
//import RPCExamples
//Change examples
import SimpleChanges
//Shared Value Examples
import SharedVariables
......@@ -58,9 +54,7 @@ where
, tableExamples
, geoTrackerExamples
//, newsgroupsExample
, exceptionHandlingExample
//, changeHandlingExample
, changeExamples
, exceptionHandlingExample
, sharedValueExamples
//, rpcExamples
//, ginExamples
......
......@@ -13,7 +13,6 @@ from SystemData import randomInt, topLevelTasks
from Map import qualified newMap
import CoreTasks, CoreCombinators, TuningCombinators, InteractionTasks
(>>*) infixl 1 :: !(Task a) ![TaskStep a b] -> Task b | iTask a & iTask b
(>>*) task steps = step task steps
......
......@@ -11,16 +11,28 @@ import iTaskClass
derive class iTask ParallelTaskMeta, ParallelControl, ParallelTaskType
/**
* Adds result transformation function to a task.
* Adds a result transformation function to a task.
* The resulting task is still considered a single step in the workflow.
*
* @param Function: The transformation function. It works on maybe's to also map over instable tasks.
* @param Task: The task to which the transformation function is added
*
* @return The transformed task
* @return The transformed task
*/
transform :: ((Maybe a) -> Maybe b) (Task a) -> Task b | iTask a & iTask b
/**
* Projects the result of a task in a share when its result changes.
* The resulting task is still considered a single step in the workflow.
*
* @param The projection function
* @param The share onto which the result should be projected
* @param The task that provides the result
* @return The modified task
*/
project :: ((Maybe a) r -> Maybe w) (ReadWriteShared r w) (Task a) -> Task a | iTask a
/**
* The generic sequential combinator.
* It does a task followed by one out of a given list of continuations.
......
......@@ -22,6 +22,9 @@ where
Nothing = (taskException "Task with permanent invalid result", iworld)
(TaskException e str, iworld) = (TaskException e str, iworld)
project :: ((Maybe a) r -> Maybe w) (ReadWriteShared r w) (Task a) -> Task a | iTask a
project projection share task = task //TODO
step :: (Task a) [TaskStep a b] -> Task b | iTask a & iTask b
step taska conts = mkTask (taskMeta taska) init edit eval
where
......
......@@ -11,7 +11,6 @@ from Task import :: Task, ::ChangeLifeTime, :: ChangeDyn, :: InteractionTermi
derive class iTask WorkOnProcessState
:: SharedStoreId :== String
/**
* Lifts a value to the task domain. The task finishes immediately and yields its parameter
......@@ -38,12 +37,6 @@ return :: !a -> Task a | iTask a
*/
throw :: !e -> Task a | iTask a & iTask, toString e
/*
* Creates a reference to a store identified by a string identifier.
* If no data is store the default value given as second argument is given as result.
*/
sharedStore :: !SharedStoreId !a -> Shared a | JSONEncode{|*|}, JSONDecode{|*|}, TC a
/**
* Reads shared data.
*
......@@ -130,19 +123,6 @@ interact :: !d !(l r Bool -> [InteractionPart l w]) l !(ReadWriteShared r w) ->
*/
workOn :: !ProcessId -> Task WorkOnProcessState
/**
* Administer a change to another (running) workflow process
*
* @param Process ID: A process id
* @param Change dynamic: The change
* @param Lifetime: The change's lifetime
*
* @return The task that will do the change
*
* @gin False
*/
applyChangeToProcess :: !ProcessId !ChangeDyn !ChangeLifeTime -> Task Void
/**
* Evaluate a "World" function that does not yield any result once.
*
......
......@@ -25,29 +25,13 @@ derive JSONDecode StoredPart, UpdateMask
JSONEncode{|StoredPutback|} _ _ p = [dynamicJSONEncode p]
JSONDecode{|StoredPutback|} _ _ [json:r] = (dynamicJSONDecode json,r)
JSONDecode{|StoredPutback|} _ _ c = (Nothing,c)
return :: !a -> (Task a) | iTask a
return a = mkInstantTask ("return", "Return a value") (\_ iworld -> (TaskStable a (NoRep,[]) TCEmpty, iworld))
throw :: !e -> Task a | iTask a & iTask, toString e
throw e = mkInstantTask ("throw", "Throw an exception") (\_ iworld -> (TaskException (dynamic e) (toString e), iworld))
sharedStore :: !SharedStoreId !a -> Shared a | JSONEncode{|*|}, JSONDecode{|*|}, TC a
sharedStore storeId defaultV = ReadWriteShared
["sharedStore_" +++ storeId]
(get (loadValue NS_APPLICATION_SHARES) defaultV)
write
(get (getStoreTimestamp NS_APPLICATION_SHARES) (Timestamp 0))
where
get f defaultV iworld
# (mbV,iworld) = f storeId iworld
# res = case mbV of
Nothing = Ok defaultV
Just v = Ok v
= (res,iworld)
write v iworld = (Ok Void,storeValue NS_APPLICATION_SHARES storeId v iworld)
get :: !(ReadWriteShared a w) -> Task a | iTask a
get shared = mkInstantTask ("Read shared", "Reads a shared value") eval
where
......@@ -377,18 +361,6 @@ getActionResult (Just (TaskEvent [] name)) actions
getActionResult _ actions
= Nothing
applyChangeToProcess :: !ProcessId !ChangeDyn !ChangeLifeTime -> Task Void
applyChangeToProcess pid change lifetime
= mkInstantTask ("Apply a change to a process", ("Apply a " +++ lt +++ " change to task " +++ toString pid)) eval
where
eval taskNr iworld = (TaskException (dynamic "TODO") "TODO", iworld)
//id (\tst -> (TaskStable Void, applyChangeToTaskTree pid (lifetime,change) tst))
//Interesting one, we need the tst somehow :)
lt = case lifetime of
CLTransient = "transient"
CLPersistent _ = "persistent"
appWorld :: !(*World -> *World) -> Task Void
appWorld fun = mkInstantTask ("Run world function", "Run a world function.") eval
where
......
......@@ -3,13 +3,23 @@ definition module SystemData
* This module provides access to the iTask framework data by means of
* a set of shared data structures.
*/
import Maybe
import Maybe, JSON
from SharedCombinators import :: ReadWriteShared, :: ReadOnlyShared, :: Shared
from SystemTypes import :: DateTime, :: Date, :: Time, :: User, :: Role, :: UserDetails, :: TaskList, :: Tree
from SystemTypes import :: ProcessId, :: TaskInstanceMeta, :: Config
from Void import :: Void
from FilePath import :: FilePath
//USER-DEFINED SHARES
/*
* Creates a reference to a store identified by a string identifier.
* If no data is store the default value given as second argument is given as result.
*/
sharedStore :: !String !a -> Shared a | JSONEncode{|*|}, JSONDecode{|*|}, TC a
//PREDEFINED SHARES
// Date & time
currentDateTime :: ReadOnlyShared DateTime
currentTime :: ReadOnlyShared Time
......@@ -25,15 +35,11 @@ processesForCurrentUser :: ReadOnlyShared [TaskInstanceMeta]
currentProcessId :: ReadOnlyShared ProcessId
currentUser :: ReadOnlyShared User
// Application name
applicationName :: ReadOnlyShared String
// Application build identifier
applicationBuild :: ReadOnlyShared String
// Direction in which the applicaton resides
applicationDirectory :: ReadOnlyShared FilePath
// Server config
applicationConfig :: ReadOnlyShared Config
// Application
applicationName :: ReadOnlyShared String // Application name
applicationBuild :: ReadOnlyShared String // Application build identifier
applicationDirectory :: ReadOnlyShared FilePath // Directory in which the applicaton resides
applicationConfig :: ReadOnlyShared Config // Server config
// Random source
randomInt :: ReadOnlyShared Int
......
......@@ -7,6 +7,22 @@ from StdFunc import o, seq
from IWorld import :: IWorld(..), :: Control
from Util import qualified currentDate, currentTime, currentDateTime, currentTimestamp
sharedStore :: !String !a -> Shared a | JSONEncode{|*|}, JSONDecode{|*|}, TC a
sharedStore storeId defaultV = ReadWriteShared
["sharedStore_" +++ storeId]
(get (loadValue NS_APPLICATION_SHARES) defaultV)
write
(get (getStoreTimestamp NS_APPLICATION_SHARES) (Timestamp 0))
where
get f defaultV iworld
# (mbV,iworld) = f storeId iworld
# res = case mbV of
Nothing = Ok defaultV
Just v = Ok v
= (res,iworld)
write v iworld = (Ok Void,storeValue NS_APPLICATION_SHARES storeId v iworld)
currentDateTime :: ReadOnlyShared DateTime
currentDateTime = makeReadOnlyShared "SystemData_currentDateTime" 'Util'.currentDateTime 'Util'.currentTimestamp
......@@ -43,9 +59,7 @@ where
find user procs
= flatten [if (p.managementMeta.worker === Just user || p.managementMeta.worker === Nothing) [{p & subInstances = find user p.subInstances}] (find user p.subInstances) \\ p <- procs]
//TODO: Figure out pattern match bug
currentProcessId :: ReadOnlyShared ProcessId
//currentProcessId = makeReadOnlyShared "SystemData_currentProcess" (\iworld=:{evalStack=[currentProcess:_]} -> (currentProcess, iworld)) ('ProcessDB'.lastChange)
currentProcessId = makeReadOnlyShared "SystemData_currentProcess" (\iworld=:{evalStack} -> (hd evalStack, iworld)) 'Util'.currentTimestamp
currentUser :: ReadOnlyShared User
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment