-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlogic_worker.erl
115 lines (81 loc) · 3.1 KB
/
logic_worker.erl
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
%% -*- erlang -*-
%%
%% CRE: common runtime environment for distributed programming languages
%%
%% Copyright 2015 Jörgen Brandt <[email protected]>
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%
%% -------------------------------------------------------------------
%% @author Jörgen Brandt <[email protected]>
%% @copyright 2015
%%
%%
%%
%%
%%
%% @end
%% -------------------------------------------------------------------
-module(logic_worker).
-behaviour(cre_worker).
%%====================================================================
%% Exports
%%====================================================================
-export([init/1,
prepare_case/2,
stagein_lst/2,
do_stagein/3,
run/2,
stageout_lst/3,
do_stageout/3,
error_to_expr/3,
cleanup_case/3]).
-export([start_link/0, start_link/1, start_link/2, stop/1]).
%%====================================================================
%% API functions
%%====================================================================
start_link() ->
{ok, CreName} = cre:pid(),
start_link(CreName).
start_link(CreName) ->
cre_worker:start_link(CreName, ?MODULE, []).
start_link(WrkName, CreName) ->
cre_worker:start_link(WrkName, CreName, ?MODULE, []).
stop(WrkName) ->
cre_worker:stop(WrkName).
%%====================================================================
%% CRE worker callback functions
%%====================================================================
-spec init(WrkArg :: _) -> UsrInfo :: _.
init(_WrkArg) -> [].
-spec prepare_case(A :: _, UsrInfo :: _) -> ok.
prepare_case(_A, _UsrInfo) -> ok.
-spec stagein_lst(A :: _, UsrInfo :: _) -> [F :: _].
stagein_lst(_A, _UsrInfo) -> [].
-spec do_stagein(A :: _, F :: _, UsrInfo :: _) -> ok | {error, enoent}.
do_stagein(_A, _F, _UsrInfo) -> error(unused).
-spec run(A :: _, UsrInfo :: _) -> {ok, R :: _} | {error, Reason :: _}.
run({'not', X}, _) -> {ok, not X};
run({'and', X1, X2}, _) -> {ok, X1 andalso X2};
run({'or', X1, X2}, _) -> {ok, X1 orelse X2}.
-spec stageout_lst(A :: _, R :: _, UsrInfo :: _) -> [F :: _].
stageout_lst(_A, _R, _UsrInfo) -> [].
-spec do_stageout(A :: _, F :: _, UsrInfo :: _) -> ok | {error, enoent}.
do_stageout(_A, _F, _UsrInfo) -> error(unused).
-spec error_to_expr(A, Reason, UsrInfo) -> _
when A :: _,
Reason :: {stagein | stageout, [_]} | {run, _},
UsrInfo :: _.
error_to_expr(_A, _Reason, _UsrInfo) -> error(unused).
-spec cleanup_case(A :: _, R :: _, UsrInfo :: _) -> R1 :: _.
cleanup_case(_A, R, _UsrInfo) -> R.