-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathCspFactory.java
More file actions
157 lines (141 loc) · 4.59 KB
/
Copy pathCspFactory.java
File metadata and controls
157 lines (141 loc) · 4.59 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package JyCSP.util;
import org.python.core.PyObject;
import org.python.core.PyString;
import org.python.core.PyInteger;
import org.python.core.PyType;
import org.python.util.PythonInterpreter;
import JyCSP.JavaCspProcess;
import JyCSP.Interfaces.JavaCspProcessInterface;
import JyCSP.Interfaces.JyCspAltInterface;
import JyCSP.Interfaces.JyCspChannelInterface;
import JyCSP.Interfaces.JyCspParInterface;
import JyCSP.Interfaces.JyCspProcessInterface;
import JyCSP.Interfaces.JyCspSeqInterface;
import JyCSP.Interfaces.JyCspSkipGuardInterface;
import JyCSP.Interfaces.JyCspTimerGuardInterface;
public class CspFactory {
/**
* Handle on the Python Interpreter
*/
static PythonInterpreter interpreter = new PythonInterpreter();
/**
* Flag if the class should print Debug information
* Default False
*/
static boolean debug = false;
/**
* static Constructor
* Make a call to the interpreter to import Javacspthread
*/
static {
String cmd = "from Javacspthread import *";
interpreter.exec(cmd);
}
/**
* Gets a handle to a Jython JCSPProcess object
*
* @param i Class which implements the JavaCspProcessInterface,
* Similar to the Runnable interface.
*
* If the user is extending JavaCspProcess this call is made
* by the constructor of the JavaCspProcess.
*
* If the user is implementing the JavaCspProcessInterface
* this method is analogous to Runnable interface, used with
* native java threads.
*
* @return JyCspProcessInterface
*/
public static JyCspProcessInterface createJavaCspProcess(
JavaCspProcessInterface i) {
PyObject jyJCSPClass;
jyJCSPClass = interpreter.get("JCSPProcess");
PyObject JCSPObj = jyJCSPClass.__call__((PyObject)i);
return (JyCspProcessInterface) JCSPObj
.__tojava__(JyCspProcessInterface.class);
}
/**
* Gets a handle to a Jython Par Object
*
* @param args List of JavaCspProcesses which should be run in parallel
*
* Users should avoid using this method, instead use
* the Java Par Class which makes a call to this
* @return JyCspParInterface
*/
public static JyCspParInterface createJavaCspPar(JavaCspProcess... args) {
PyObject jyJCSPParClass;
jyJCSPParClass = interpreter.get("ParFactory");
PyObject JCSPObj = jyJCSPParClass.__call__((PyObject[])args);
return (JyCspParInterface) JCSPObj
.__tojava__(JyCspParInterface.class);
}
/**
* Gets a handle to a Jython Seq Object
*
* @param args List of JavaCspProcesses which should be run in sequence
*
* Users should avoid using this method, instead use
* the Java Seq Class which makes a call to this
* @return JyCspSeqInterface
*/
public static JyCspSeqInterface createJavaCspSeq(JavaCspProcess... args) {
PyObject jyJCSPSeqClass;
jyJCSPSeqClass = interpreter.get("SeqFactory");
PyObject JCSPObj = jyJCSPSeqClass.__call__((PyObject[])args);
return (JyCspSeqInterface) JCSPObj
.__tojava__(JyCspSeqInterface.class);
}
/**
* Gets a handle to a Jython Alt Object
*
* @param args List of Channels for the Alt to select from
*
* Users should avoid using this method, instead use
* the Java Alt Class which makes a call to this
* @return JyCspAltInterface
*/
public static JyCspAltInterface createJavaCspAlt(PyObject... args) {
PyObject jyJCSPAltClass;
jyJCSPAltClass = interpreter.get("AltFactory");
PyObject JCSPObj = jyJCSPAltClass.__call__((PyObject[])args);
return (JyCspAltInterface) JCSPObj
.__tojava__(JyCspAltInterface.class);
}
/**
* Gets a handle to a Jython Channel Object
*
* @return JyCspChannelInterface
*/
public static JyCspChannelInterface createJavaCspChannel(){
PyObject jyJCSPChannel;
jyJCSPChannel = interpreter.get("Channel");
PyObject JCSPObj = jyJCSPChannel.__call__();
return (JyCspChannelInterface) JCSPObj
.__tojava__(JyCspChannelInterface.class);
}
/**
* Gets a handle to a Jython TimerGuard Object
*
* @return JyCspChannelInterface
*/
public static JyCspTimerGuardInterface createJavaCspTimerGuard(){
PyObject jyCspTimerGuard;
jyCspTimerGuard = interpreter.get("TimerGuard");
PyObject JCSPObj = jyCspTimerGuard.__call__();
return (JyCspTimerGuardInterface) JCSPObj
.__tojava__(JyCspTimerGuardInterface.class);
}
/**
* Gets a handle to a Jython SkipGuard Object
*
* @return JyCspChannelInterface
*/
public static JyCspSkipGuardInterface createJavaCspSkipGuard(){
PyObject jyCspSkipGuard;
jyCspSkipGuard = interpreter.get("Skip");
PyObject JCSPObj = jyCspSkipGuard.__call__();
return (JyCspSkipGuardInterface) JCSPObj
.__tojava__(JyCspSkipGuardInterface.class);
}
}