openwferu 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/README +47 -0
  2. data/lib/codec.rb +571 -0
  3. data/lib/controlclient.rb +115 -0
  4. data/lib/definitions.rb +112 -0
  5. data/lib/exception.rb +60 -0
  6. data/lib/flowexpressionid.rb +137 -0
  7. data/lib/openwferu.rb +43 -0
  8. data/lib/osocket.rb +138 -0
  9. data/lib/otime.rb +171 -0
  10. data/lib/restclient.rb +155 -0
  11. data/lib/ru/contextual.rb +63 -0
  12. data/lib/ru/dollar.rb +163 -0
  13. data/lib/ru/engine.rb +130 -0
  14. data/lib/ru/environment.rb +140 -0
  15. data/lib/ru/expressionmap.rb +120 -0
  16. data/lib/ru/expressionpool.rb +339 -0
  17. data/lib/ru/expressionstorage.rb +97 -0
  18. data/lib/ru/fe_base.rb +105 -0
  19. data/lib/ru/fe_concurrence.rb +122 -0
  20. data/lib/ru/fe_define.rb +101 -0
  21. data/lib/ru/fe_misc.rb +96 -0
  22. data/lib/ru/fe_participant.rb +75 -0
  23. data/lib/ru/fe_raw.rb +173 -0
  24. data/lib/ru/fe_subprocess.rb +84 -0
  25. data/lib/ru/fe_time.rb +135 -0
  26. data/lib/ru/fe_utils.rb +123 -0
  27. data/lib/ru/fe_value.rb +225 -0
  28. data/lib/ru/flowexpression.rb +250 -0
  29. data/lib/ru/logging.rb +85 -0
  30. data/lib/ru/participant.rb +67 -0
  31. data/lib/ru/participantmap.rb +93 -0
  32. data/lib/ru/participants.rb +74 -0
  33. data/lib/ru/rudefinitions.rb +70 -0
  34. data/lib/ru/ruutils.rb +68 -0
  35. data/lib/ru/scheduler.rb +478 -0
  36. data/lib/ru/schedulers.rb +63 -0
  37. data/lib/ru/service.rb +64 -0
  38. data/lib/test.rb +220 -0
  39. data/lib/utils.rb +94 -0
  40. data/lib/workitem.rb +250 -0
  41. data/lib/worklistclient.rb +276 -0
  42. data/test/dollartest.rb +79 -0
  43. data/test/feitest.rb +130 -0
  44. data/test/flowtestbase.rb +86 -0
  45. data/test/ft_0.rb +161 -0
  46. data/test/ft_1_unset.rb +152 -0
  47. data/test/ft_2_concurrence.rb +34 -0
  48. data/test/ft_3_equals.rb +84 -0
  49. data/test/ft_4_misc.rb +128 -0
  50. data/test/ft_5_time.rb +56 -0
  51. data/test/misctest.rb +46 -0
  52. data/test/runtest.rb +21 -0
  53. data/test/rutest_utils.rb +15 -0
  54. data/test/timetest.rb +111 -0
  55. metadata +100 -0
@@ -0,0 +1,115 @@
1
+ #
2
+ # Copyright (c) 2005-2006, John Mettraux, OpenWFE.org
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # . Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # . Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # . Neither the name of the "OpenWFE" nor the names of its contributors may be
16
+ # used to endorse or promote products derived from this software without
17
+ # specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ # POSSIBILITY OF SUCH DAMAGE.
30
+ #
31
+ # $Id: controlclient.rb 3454 2006-10-08 16:51:00Z jmettraux $
32
+ #
33
+
34
+ #
35
+ # "hecho en Costa Rica"
36
+ #
37
+
38
+ require 'definitions'
39
+ require 'restclient'
40
+ require 'codec'
41
+
42
+
43
+ module OpenWFE
44
+
45
+
46
+ class ControlClient < RestClient
47
+
48
+ def initialize (server, port, username, password)
49
+
50
+ super('http://'+server+':'+port.to_s(), username, password)
51
+ end
52
+
53
+ def initialize (url, username, password)
54
+
55
+ super(url, username, password)
56
+ end
57
+
58
+ #
59
+ # Returns the list of controlable expressions
60
+ #
61
+ def listExpressions ()
62
+
63
+ r = self.get('listexpressions', nil, nil)
64
+ return decode(r)
65
+ end
66
+
67
+ #
68
+ # Cancels a given expression (and potentially its whole subtree)
69
+ #
70
+ def cancelExpression (flowExpressionId)
71
+
72
+ fei = OpenWFE.encode(flowExpressionId)
73
+
74
+ params = {}
75
+
76
+ return decode(self.post('cancelexpression', nil, params, fei))
77
+ end
78
+
79
+ #
80
+ # Freezes an expression (and potentially its whole subtree)
81
+ #
82
+ def freezeExpression (flowExpressionId)
83
+
84
+ fei = OpenWFE.encode(flowExpressionId)
85
+
86
+ params = {}
87
+
88
+ return decode(self.post('freezeexpression', nil, params, fei))
89
+ end
90
+
91
+ #
92
+ # Unfreezes an expression (and potentially its whole subtree)
93
+ #
94
+ def unfreezeExpression (flowExpressionId)
95
+
96
+ fei = OpenWFE.encode(flowExpressionId)
97
+
98
+ params = {}
99
+
100
+ return decode(self.post('unfreezeexpression', nil, params, fei))
101
+ end
102
+
103
+
104
+ protected
105
+
106
+ def decode (reply)
107
+
108
+ xml = REXML::Document.new(reply.body)
109
+ return OpenWFE.decode(xml.root)
110
+ end
111
+
112
+ end
113
+
114
+ end
115
+
@@ -0,0 +1,112 @@
1
+ #
2
+ # Copyright (c) 2005-2006, John Mettraux, OpenWFE.org
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # . Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # . Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # . Neither the name of the "OpenWFE" nor the names of its contributors may be
16
+ # used to endorse or promote products derived from this software without
17
+ # specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ # POSSIBILITY OF SUCH DAMAGE.
30
+ #
31
+ # $Id: definitions.rb 3454 2006-10-08 16:51:00Z jmettraux $
32
+ #
33
+
34
+ #
35
+ # "hecho en Costa Rica"
36
+ #
37
+
38
+ module OpenWFE
39
+
40
+ NAME = 'name'
41
+ STORE = 'store'
42
+ STORES = 'stores'
43
+ WORKITEM_COUNT = 'workitem-count'
44
+ PERMISSIONS = 'permissions'
45
+ HEADER = 'header'
46
+ HEADERS = 'headers'
47
+ A_LAST_MODIFIED = 'last-modified'
48
+ A_LOCKED = 'locked'
49
+ FLOW_EXPRESSION_ID = 'flow-expression-id'
50
+ ATTRIBUTES = 'attributes'
51
+
52
+ OWFE_VERSION = 'owfe-version'
53
+ ENGINE_ID = 'engine-id'
54
+ INITIAL_ENGINE_ID = 'initial-engine-id'
55
+ WORKFLOW_DEFINITION_URL = 'workflow-definition-url'
56
+ WORKFLOW_DEFINITION_NAME = 'workflow-definition-name'
57
+ WORKFLOW_DEFINITION_REVISION = 'workflow-definition-revision'
58
+ WORKFLOW_INSTANCE_ID = 'workflow-instance-id'
59
+ EXPRESSION_NAME = 'expression-name'
60
+ EXPRESSION_ID = 'expression-id'
61
+
62
+ E_STRING = 'string'
63
+ E_INTEGER = 'integer'
64
+ E_BOOLEAN = 'boolean'
65
+ E_LONG = 'long'
66
+ E_DOUBLE = 'double'
67
+
68
+ E_XML = 'raw-xml'
69
+ E_BASE64 = 'base64'
70
+
71
+ E_LIST = 'list'
72
+ E_MAP = 'map'
73
+ E_SMAP = 'smap'
74
+
75
+ M_ENTRY = 'entry'
76
+ M_KEY = 'key'
77
+ M_VALUE = 'value'
78
+
79
+ MAP_TYPE = '___map_type'
80
+
81
+ FLOW_EXPRESSION_IDS = 'flow-expression-ids'
82
+
83
+ E_LAUNCHITEM = 'launchitem'
84
+ ENGINEID = "engineid"
85
+ OK = "ok"
86
+ A_FLOW_ID = "flow-id"
87
+
88
+ IN_FLOW_WORKITEM = 'workitem'
89
+ A_DISPATCH_TIME = 'dispatch-time'
90
+ A_PARTICIPANT_NAME = 'participant-name'
91
+ E_LAST_EXPRESSION_ID = 'last-expression-id'
92
+
93
+ LAUNCHABLES = 'launchables'
94
+ LAUNCHABLE = 'launchable'
95
+ URL = 'url'
96
+
97
+ TARGETSTORE = 'targetstore'
98
+
99
+ EXPRESSIONS = 'expressions'
100
+ EXPRESSION = 'expression'
101
+ APPLY_TIME = 'apply-time'
102
+ STATE = 'state'
103
+ STATE_SINCE = 'state-since'
104
+
105
+ HISTORY = 'history'
106
+ HISTORY_ITEM = 'history-item'
107
+ A_AUTHOR = 'author'
108
+ A_DATE = 'date'
109
+ A_HOST = 'host'
110
+
111
+ end
112
+
data/lib/exception.rb ADDED
@@ -0,0 +1,60 @@
1
+ #
2
+ # Copyright (c) 2005-2006, John Mettraux, OpenWFE.org
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # . Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # . Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # . Neither the name of the "OpenWFE" nor the names of its contributors may be
16
+ # used to endorse or promote products derived from this software without
17
+ # specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ # POSSIBILITY OF SUCH DAMAGE.
30
+ #
31
+ # $Id: exception.rb 3454 2006-10-08 16:51:00Z jmettraux $
32
+ #
33
+
34
+ #
35
+ # "hecho en Costa Rica"
36
+ #
37
+ # john.mettraux@openwfe.org
38
+ #
39
+
40
+
41
+ module OpenWFE
42
+
43
+ #
44
+ # EXCEPTION(S)
45
+ #
46
+
47
+ class OwfeException < RuntimeError
48
+
49
+ def initialize ()
50
+ super.initialize()
51
+ end
52
+
53
+ def initialize (message)
54
+ super.initialize(message)
55
+ end
56
+
57
+ end
58
+
59
+ end
60
+
@@ -0,0 +1,137 @@
1
+ #
2
+ # Copyright (c) 2005-2006, John Mettraux, OpenWFE.org
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # . Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # . Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # . Neither the name of the "OpenWFE" nor the names of its contributors may be
16
+ # used to endorse or promote products derived from this software without
17
+ # specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ # POSSIBILITY OF SUCH DAMAGE.
30
+ #
31
+ # $Id: workitem.rb 3555 2006-11-13 00:47:53Z jmettraux $
32
+ #
33
+
34
+ #
35
+ # "hecho en Costa Rica"
36
+ # enhanced in Japan
37
+ #
38
+ # john.mettraux@openwfe.org
39
+ #
40
+
41
+ require 'base64'
42
+
43
+ require 'definitions'
44
+
45
+
46
+ module OpenWFE
47
+
48
+ #
49
+ # FlowExpressionId
50
+ #
51
+ class FlowExpressionId
52
+
53
+ attr_accessor \
54
+ :owfeVersion, \
55
+ :engineId, \
56
+ :initialEngineId, \
57
+ :workflowDefinitionUrl, \
58
+ :workflowDefinitionName, \
59
+ :workflowDefinitionRevision, \
60
+ :workflowInstanceId, \
61
+ :expressionName, \
62
+ :expressionId
63
+
64
+ #
65
+ # overrides the classical to_s()
66
+ #
67
+ def to_s ()
68
+ return "(fei #{@owfeVersion} #{@engineId}/#{@initialEngineId} #{@workflowDefinitionUrl} #{@workflowDefinitionName} #{@workflowDefinitionRevision} #{@workflowInstanceId} #{@expressionName} #{@expressionId} )"
69
+ end
70
+
71
+ #
72
+ # This class method parses a string into a FlowExpressionId instance
73
+ #
74
+ def FlowExpressionId.strToFei (string)
75
+
76
+ fei = FlowExpressionId.new()
77
+
78
+ ss = string.split(" ")
79
+
80
+ fei.owfeVersion = ss[2]
81
+
82
+ ssRawEngineId = ss[3].split("/")
83
+ fei.engineId= ssRawEngineId[0]
84
+ fei.initialEngineId= ssRawEngineId[1]
85
+
86
+ fei.workflowDefinitionUrl = ss[4]
87
+ fei.workflowDefinitionName = ss[5]
88
+ fei.workflowDefinitionRevision = ss[6]
89
+ fei.workflowInstanceId = ss[7]
90
+ fei.expressionName = ss[8]
91
+ fei.expressionId = ss[9]
92
+
93
+ return fei
94
+ end
95
+
96
+ def hash ()
97
+ return to_s().hash()
98
+ end
99
+
100
+ def == (other)
101
+ return false if not other.kind_of?(FlowExpressionId)
102
+
103
+ @owfeVersion == other.owfeVersion and
104
+ @engineId == other.engineId and
105
+ @initialEngineId == other.initialEngineId and
106
+ @workflowDefinitionUrl == other.workflowDefinitionUrl and
107
+ @workflowDefinitionName == other.workflowDefinitionName and
108
+ @workflowDefinitionRevision == other.workflowDefinitionRevision and
109
+ @workflowInstanceId == other.workflowInstanceId and
110
+ @expressionName == other.expressionName and
111
+ @expressionId == other.expressionId
112
+ end
113
+
114
+ def dup
115
+ n = FlowExpressionId.new
116
+ n.owfeVersion = @owfeVersion.dup
117
+ n.engineId = @engineId.dup
118
+ n.initialEngineId = @initialEngineId.dup
119
+ n.workflowDefinitionUrl = @workflowDefinitionUrl.dup
120
+ n.workflowDefinitionName = @workflowDefinitionName.dup
121
+ n.workflowDefinitionRevision = @workflowDefinitionRevision.dup
122
+ n.workflowInstanceId = @workflowInstanceId.dup
123
+ n.expressionName = @expressionName.dup
124
+ n.expressionId = @expressionId.dup
125
+ return n
126
+ end
127
+
128
+ alias eql? ==
129
+
130
+ #alias to_debug_s to_s
131
+ def to_debug_s
132
+ "#{to_s} (h#{hash}) (i#{object_id})"
133
+ end
134
+ end
135
+
136
+ end
137
+
data/lib/openwferu.rb ADDED
@@ -0,0 +1,43 @@
1
+ #
2
+ # Copyright (c) 2005-2006, John Mettraux, OpenWFE.org
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # . Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # . Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # . Neither the name of the "OpenWFE" nor the names of its contributors may be
16
+ # used to endorse or promote products derived from this software without
17
+ # specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ # POSSIBILITY OF SUCH DAMAGE.
30
+ #
31
+ #++
32
+ #
33
+ # = openwferu -- Open Workflow Engine in Ruby
34
+ #
35
+ # This is the main file for the openwferu engine. It is normally
36
+ # referenced as a library via a require statement.
37
+ #
38
+
39
+ require 'workitem'
40
+ require 'ru/engine'
41
+ require 'ru/rudefinitions'
42
+ require 'ru/participants'
43
+
data/lib/osocket.rb ADDED
@@ -0,0 +1,138 @@
1
+ #
2
+ # Copyright (c) 2006, John Mettraux, OpenWFE.org
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # . Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # . Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # . Neither the name of the "OpenWFE" nor the names of its contributors may be
16
+ # used to endorse or promote products derived from this software without
17
+ # specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ # POSSIBILITY OF SUCH DAMAGE.
30
+ #
31
+ # $Id: codec.rb 2515 2006-04-26 18:38:39Z jmettraux $
32
+ #
33
+
34
+ require 'socket'
35
+ require 'codec'
36
+
37
+ module OpenWFE
38
+
39
+ class SocketListener < TCPServer
40
+
41
+ #
42
+ # starts to listen on a given interface (IP) and port
43
+ #
44
+ def initialize (iface, port)
45
+ super(iface, port)
46
+ end
47
+
48
+ def listen ()
49
+ while (session = accept())
50
+ s = session.gets
51
+
52
+ if s[0..8] != 'xmlCoder '
53
+ session.close
54
+ break
55
+ end
56
+
57
+ l = s[9..-1].to_i
58
+
59
+ s = session.gets
60
+ #
61
+ # skipping the empty line between the
62
+ # header and the actual workitem
63
+
64
+ sXml = ''
65
+
66
+ while sXml.length < l
67
+ s = session.gets
68
+ sXml = "#{sXml}#{s}"
69
+ end
70
+
71
+ session.print "<ok-reply/>"
72
+ session.close
73
+
74
+ #yield sXml
75
+
76
+ xml = REXML::Document.new(sXml)
77
+ yield OpenWFE.decode(xml.root)
78
+ end
79
+ end
80
+ end
81
+
82
+ #
83
+ # dispatches a workitem over TCP
84
+ #
85
+ def OpenWFE.dispatchWorkitem (host, port, workitem)
86
+
87
+ sXml = OpenWFE.encode(workitem)
88
+ socket = TCPSocket.new(host, port)
89
+ socket.puts "xmlCoder #{sXml.length}"
90
+ socket.puts
91
+ socket.puts sXml
92
+ socket.puts
93
+
94
+ reply = socket.gets
95
+ reply = reply + socket.gets
96
+ #
97
+ # a bit ridiculous, but it works
98
+
99
+ socket.close
100
+
101
+ #puts "dispatch() reply is >#{reply}<"
102
+ end
103
+
104
+ class OwfeHook
105
+ end
106
+
107
+ end
108
+
109
+
110
+ #
111
+ # some test code
112
+
113
+ sl = OpenWFE::SocketListener.new('127.0.0.1', 7010)
114
+
115
+ puts "..ready.."
116
+
117
+ sl.listen do |workitem|
118
+
119
+ #puts workitem
120
+ #next
121
+
122
+ puts workitem.flowExpressionId
123
+ puts "...history length : #{workitem.history.length}"
124
+
125
+ #puts workitem.history
126
+ workitem.history.each do |hi|
127
+ puts ".....hi = '#{hi.text}' #{hi.date}"
128
+ end
129
+
130
+ #hi = OpenWFE::HistoryItem.new
131
+ #hi.author = 'osocket.rb'
132
+ #workitem.history.push(hi)
133
+
134
+ workitem.attributes['ruby?'] = 'yes'
135
+
136
+ OpenWFE.dispatchWorkitem('127.0.0.1', 7007, workitem)
137
+ end
138
+