Skip to content

Commit 4cf78aa

Browse files
authored
Merge pull request #116 from Harshal-Rembhotkar/feature-dockerfile
2 parents dc3242a + 40124c3 commit 4cf78aa

3 files changed

Lines changed: 163 additions & 6 deletions

File tree

Dockerfile.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM openjdk:latest
2+
COPY . /src
3+
WORKDIR /src
4+

concore.hpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class Concore{
3838
char* sharedData_create;
3939
char* sharedData_get;
4040
// File sharing:- 0, Shared Memory:- 1
41-
int communication_iport = 0;
42-
int communication_oport = 0;
41+
int communication_iport = 0; // iport refers to input port
42+
int communication_oport = 0; // oport refers to input port
4343

4444
public:
4545
double delay = 1;
@@ -58,17 +58,22 @@ class Concore{
5858
oport = mapParser("concore.oport");
5959
std::map<std::string, int>::iterator it_iport = iport.begin();
6060
std::map<std::string, int>::iterator it_oport = oport.begin();
61-
int iport_number = ExtractNumeric(it_iport->first);
61+
int iport_number = ExtractNumeric(it_iport->first);
6262
int oport_number = ExtractNumeric(it_oport->first);
6363

64+
// if iport_number and oport_number is equal to -1 then it refers to File Method,
65+
// otherwise it refers to Shared Memory and the number represent the unique key.
66+
6467
if(oport_number != -1)
6568
{
69+
// oport_number is not equal to -1 so refers to SM and value is key.
6670
communication_oport = 1;
6771
this->createSharedMemory(oport_number);
6872
}
6973

7074
if(iport_number != -1)
7175
{
76+
// iport_number is not equal to -1 so refers to SM and value is key.
7277
communication_iport = 1;
7378
this->getSharedMemory(iport_number);
7479
}
@@ -112,6 +117,7 @@ class Concore{
112117

113118
if (numDigits == 1)
114119
{
120+
// this case is to avoid shared memory when there is just 0 or any negative value in front of edge.
115121
if (std::stoi(numberString) <= 0)
116122
{
117123
return -1;
@@ -348,7 +354,6 @@ class Concore{
348354
if (sharedData_get && sharedData_get[0] != '\0') {
349355
std::string message(sharedData_get, strnlen(sharedData_get, 256));
350356
ins = message;
351-
// std::cout << "Received message: " << message << " ins " << ins.length() << std::endl;
352357
}
353358
else
354359
{
@@ -367,7 +372,6 @@ class Concore{
367372
this_thread::sleep_for(timespan);
368373
try{
369374
if(shmId_get != -1) {
370-
std::cout << "in read while\n";
371375
std::string message(sharedData_get, strnlen(sharedData_get, 256));
372376
ins = message;
373377
retrycount++;
@@ -379,7 +383,7 @@ class Concore{
379383
}
380384
//observed retry count in C++ from various tests is approx 80.
381385
catch(...){
382-
cout<<"Read error";
386+
std::cout << "Read error" << std::endl;
383387
}
384388
}
385389
s += ins;

concoredocker.java

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
import java.io.IOException;
2+
import java.nio.file.Files;
3+
import java.nio.file.Paths;
4+
import java.util.HashMap;
5+
import java.util.Map;
6+
7+
public class concoredocker {
8+
private static Map<String, Object> iport = new HashMap<>();
9+
private static Map<String, Object> oport = new HashMap<>();
10+
private static String s = "";
11+
private static String olds = "";
12+
private static int delay = 1;
13+
private static int retrycount = 0;
14+
private static String inpath = "/in";
15+
private static String outpath = "/out";
16+
private static Map<String, Object> params = new HashMap<>();
17+
private static int maxtime;
18+
19+
public static void main(String[] args) {
20+
try {
21+
iport = parseFile("concore.iport");
22+
} catch (IOException e) {
23+
e.printStackTrace();
24+
}
25+
try {
26+
oport = parseFile("concore.oport");
27+
} catch (IOException e) {
28+
e.printStackTrace();
29+
}
30+
31+
try {
32+
String sparams = new String(Files.readAllBytes(Paths.get(inpath + "1/concore.params")));
33+
if (sparams.charAt(0) == '"') { // windows keeps "" need to remove
34+
sparams = sparams.substring(1);
35+
sparams = sparams.substring(0, sparams.indexOf('"'));
36+
}
37+
if (!sparams.equals("{")) {
38+
System.out.println("converting sparams: " + sparams);
39+
sparams = "{'" + sparams.replaceAll(",", ",'").replaceAll("=", "':").replaceAll(" ", "") + "}";
40+
System.out.println("converted sparams: " + sparams);
41+
}
42+
try {
43+
params = literalEval(sparams);
44+
} catch (Exception e) {
45+
System.out.println("bad params: " + sparams);
46+
}
47+
} catch (IOException e) {
48+
params = new HashMap<>();
49+
}
50+
51+
defaultMaxTime(100);
52+
}
53+
54+
private static Map<String, Object> parseFile(String filename) throws IOException {
55+
String content = new String(Files.readAllBytes(Paths.get(filename)));
56+
return literalEval(content);
57+
}
58+
59+
private static void defaultMaxTime(int defaultValue) {
60+
try {
61+
String content = new String(Files.readAllBytes(Paths.get(inpath + "1/concore.maxtime")));
62+
maxtime = literalEval(content).size();
63+
} catch (IOException e) {
64+
maxtime = defaultValue;
65+
}
66+
}
67+
68+
private static void unchanged() {
69+
if (olds.equals(s)) {
70+
s = "";
71+
} else {
72+
olds = s;
73+
}
74+
}
75+
76+
private static Object tryParam(String n, Object i) {
77+
if (params.containsKey(n)) {
78+
return params.get(n);
79+
} else {
80+
return i;
81+
}
82+
}
83+
84+
private static Object read(int port, String name, String initstr) {
85+
try {
86+
String ins = new String(Files.readAllBytes(Paths.get(inpath + port + "/" + name)));
87+
while (ins.length() == 0) {
88+
Thread.sleep(delay);
89+
ins = new String(Files.readAllBytes(Paths.get(inpath + port + "/" + name)));
90+
retrycount++;
91+
}
92+
s += ins;
93+
Object[] inval = new Map[] { literalEval(ins) };
94+
int simtime = Math.max((int) inval[0], 0); // assuming simtime is an integer
95+
return inval[1];
96+
} catch (IOException | InterruptedException e) {
97+
return initstr;
98+
}
99+
}
100+
101+
private static void write(int port, String name, Object val, int delta) {
102+
try {
103+
String path = outpath + port + "/" + name;
104+
StringBuilder content = new StringBuilder();
105+
if (val instanceof String) {
106+
Thread.sleep(2 * delay);
107+
} else if (!(val instanceof Object[])) {
108+
System.out.println("mywrite must have list or str");
109+
System.exit(1);
110+
}
111+
if (val instanceof Object[]) {
112+
Object[] arrayVal = (Object[]) val;
113+
content.append("[")
114+
.append(maxtime + delta)
115+
.append(",")
116+
.append(arrayVal[0]);
117+
for (int i = 1; i < arrayVal.length; i++) {
118+
content.append(",")
119+
.append(arrayVal[i]);
120+
}
121+
content.append("]");
122+
} else {
123+
content.append(val);
124+
}
125+
Files.write(Paths.get(path), content.toString().getBytes());
126+
} catch (IOException | InterruptedException e) {
127+
System.out.println("skipping" + outpath + port + "/" + name);
128+
}
129+
}
130+
131+
private static Object[] initVal(String simtimeVal) {
132+
int simtime = 0;
133+
Object[] val = new Object[] {};
134+
try {
135+
Object[] arrayVal = new Map[] { literalEval(simtimeVal) };
136+
simtime = (int) arrayVal[0]; // assuming simtime is an integer
137+
val = new Object[arrayVal.length - 1];
138+
System.arraycopy(arrayVal, 1, val, 0, val.length);
139+
} catch (Exception e) {
140+
e.printStackTrace();
141+
}
142+
return val;
143+
}
144+
145+
private static Map<String, Object> literalEval(String s) {
146+
147+
return new HashMap<>();
148+
}
149+
}

0 commit comments

Comments
 (0)