Subject | Hash | Author | Date (UTC) |
---|---|---|---|
hallo dit is kapot maar het werkt woehoe | 4475c2633e962688c71634d633ac8789524f16cf | XCBouke | 2017-11-22 13:58:54 |
It's actually working now! With a gameloop and new icons :D | 0b65d450fea6d9f679029f2d6765c7e2d1126cdd | Jan Allersma | 2017-11-20 22:02:23 |
Something... Works?? | 9a6afe028642b571483fccd6d6bdab10dee68e9c | Jan Allersma | 2017-11-20 15:14:07 |
User input for sending msg. | cdd1c17cfe8cc73985945aad5878e4891e92eab1 | Jan Allersma | 2017-11-14 23:05:53 |
prutsen veel prusten | f37cf730ff7a0ad2e08cd769da5f488051ac6dd4 | XCBouke | 2017-11-09 21:32:15 |
uglyJsonCode created online with Bitbucket | ed6c9c541947ec64827b6e80ed959feb1b0f9b85 | XCBouke | 2017-11-09 14:29:36 |
Connectie created online with Bitbucket (send en recieve in 1) | b484aff52014ff8d1dbaf8387cf1479cf236f33a | XCBouke | 2017-11-09 14:28:29 |
Ready for test case 3. Also BIG cleanup. | bda906e19e3b82fb91df53eb2208e8def822c6b5 | Jan Allersma | 2017-11-05 21:38:16 |
test case 2 fix(?) | dd86d637d166707a31b644dad711c7a9e39dbc8d | Jan Allersma | 2017-11-04 10:55:03 |
Test case 2 | 9ea6eadbd85dde0e9522068718092b1f0e9b49f0 | Jan Allersma | 2017-10-29 22:37:57 |
Added threading. | 4540fe1669c9e145e613edf2459031e7bec500ea | Jan Allersma | 2017-10-29 20:47:49 |
Code for testing 16/10/17. Use simulatie/rabbit/combination.py mainly. | c5e87d7fe5abbcd3316b1538a0d647fd23faa59f | Jan Allersma | 2017-10-15 19:13:23 |
Added more paths. Some of them are WIP. | 03ad1039e22bd1ebd301bda99e78f38239a15077 | Jan Allersma | 2017-09-21 14:40:44 |
Added paths... | 5561d21918f048a40ca9686112638a48805917e3 | Jan Allersma | 2017-09-21 13:06:43 |
Added first paths of crossroad. Also added reference of crossroad. | 43a5ddf291e38b47bad02a92af58839d86f9d449 | Jan Allersma | 2017-09-21 12:21:53 |
Added first paths of crossroad. Also added reference of crossroad. | bb687a8152231d0c89fed827baefcfbf067be90c | Jan Allersma | 2017-09-21 12:21:11 |
Fixed typo. | db82c84f8d834e62cb37333ff973ddc54af5372f | Jan Allersma | 2017-09-20 20:51:15 |
RabbitMQ test.First attempt. | 876d29c668f5e027a820f3ff48a6ca080fc530c2 | Jan Allersma | 2017-09-19 13:47:31 |
Initial commit | 6a565c61a3337232d0e7a136ffb2f49b431c2a40 | Jan Allersma | 2017-09-11 06:52:38 |
File Controller/RabbitMq2/build/built-jar.properties changed (mode: 100644) (index 882ef85..41fbadd) | |||
1 | #Thu, 09 Nov 2017 22:30:55 +0100 | ||
1 | #Sat, 18 Nov 2017 22:28:37 +0100 | ||
2 | 2 | ||
3 | 3 | ||
4 | 4 | C\:\\Users\\bouke\\Documents\\software-development\\Controller\\RabbitMq2= | C\:\\Users\\bouke\\Documents\\software-development\\Controller\\RabbitMq2= |
File Controller/RabbitMq2/build/classes/rabbitmq2/Checker.class added (mode: 100644) (index 0000000..0ce6a2b) |
File Controller/RabbitMq2/build/classes/rabbitmq2/Connectie$1.class changed (mode: 100644) (index cc859d2..a37918d) |
File Controller/RabbitMq2/build/classes/rabbitmq2/Connectie.class changed (mode: 100644) (index f9c8e5c..7f00e7e) |
File Controller/RabbitMq2/build/classes/rabbitmq2/CreateJsonObj.class changed (mode: 100644) (index 44fcd5c..998e285) |
File Controller/RabbitMq2/build/classes/rabbitmq2/CreateJsonObj2.class copied from file Controller/RabbitMq2/build/classes/rabbitmq2/CreateJsonObj.class (similarity 65%) (mode: 100644) (index 44fcd5c..41b62ce) |
File Controller/RabbitMq2/build/classes/rabbitmq2/MisschienNogGebruiken.class added (mode: 100644) (index 0000000..60b9948) |
File Controller/RabbitMq2/build/classes/rabbitmq2/RandomUselessSend.class added (mode: 100644) (index 0000000..e440581) |
File Controller/RabbitMq2/build/classes/rabbitmq2/TrafficLight.class deleted (index 89df1be..0000000) |
File Controller/RabbitMq2/build/classes/rabbitmq2/TrafficParse.class added (mode: 100644) (index 0000000..fc828b4) |
File Controller/RabbitMq2/build/classes/rabbitmq2/Update.class deleted (index a4a7096..0000000) |
File Controller/RabbitMq2/build/classes/rabbitmq2/UpdateStatus.class added (mode: 100644) (index 0000000..cd17cb4) |
File Controller/RabbitMq2/dist/RabbitMq2.jar changed (mode: 100644) (index 839fcdb..fbd2388) |
File Controller/RabbitMq2/src/rabbitmq2/Checker.java added (mode: 100644) (index 0000000..e223f29) | |||
1 | /* | ||
2 | * To change this license header, choose License Headers in Project Properties. | ||
3 | * To change this template file, choose Tools | Templates | ||
4 | * and open the template in the editor. | ||
5 | */ | ||
6 | package rabbitmq2; | ||
7 | |||
8 | import org.json.JSONObject; | ||
9 | |||
10 | /** | ||
11 | * | ||
12 | * @author bouke | ||
13 | */ | ||
14 | public class Checker { | ||
15 | |||
16 | boolean Check = false; | ||
17 | |||
18 | public void Check(Integer Id, JSONObject obj){ | ||
19 | //ugly ugly code yeah | ||
20 | /* | ||
21 | if(Id == 104) | ||
22 | { | ||
23 | Check = true; | ||
24 | } | ||
25 | else | ||
26 | Check = false; | ||
27 | */ | ||
28 | Check = true; | ||
29 | } | ||
30 | |||
31 | public boolean getCheck(){ | ||
32 | return Check; | ||
33 | } | ||
34 | } |
File Controller/RabbitMq2/src/rabbitmq2/Connectie.java changed (mode: 100644) (index c978a5a..a4c8070) | |||
4 | 4 | * and open the template in the editor. | * and open the template in the editor. |
5 | 5 | */ | */ |
6 | 6 | package rabbitmq2; | package rabbitmq2; |
7 | |||
7 | 8 | import com.rabbitmq.client.*; | import com.rabbitmq.client.*; |
8 | 9 | import java.io.IOException; | import java.io.IOException; |
10 | import java.io.UnsupportedEncodingException; | ||
9 | 11 | import java.util.concurrent.TimeoutException; | import java.util.concurrent.TimeoutException; |
10 | 12 | import java.util.logging.Level; | import java.util.logging.Level; |
11 | 13 | import java.util.logging.Logger; | import java.util.logging.Logger; |
12 | import org.json.JSONArray; | ||
13 | |||
14 | 14 | import org.json.JSONException; | import org.json.JSONException; |
15 | 15 | import org.json.JSONObject; | import org.json.JSONObject; |
16 | import rabbitmq2.CreateJsonObj; | ||
17 | import rabbitmq2.TrafficLight; | ||
16 | import java.util.*; | ||
17 | import org.json.JSONArray; | ||
18 | 18 | ||
19 | 19 | /** | /** |
20 | 20 | * | * |
21 | 21 | * @author bouke | * @author bouke |
22 | 22 | */ | */ |
23 | 23 | public class Connectie { | public class Connectie { |
24 | private final static String QUEUE_NAME = "hello"; | ||
25 | private static ConnectionFactory factory = new ConnectionFactory(); | ||
24 | |||
25 | private final static String QUEUE_NAME = "controller"; | ||
26 | private static final ConnectionFactory factory = new ConnectionFactory(); | ||
26 | 27 | private static Connection connection = null; | private static Connection connection = null; |
27 | 28 | private static Channel channel; | private static Channel channel; |
28 | 29 | private static Connectie p; | private static Connectie p; |
29 | private final static String host = "localhost"; | ||
30 | private final CreateJsonObj CJO = new CreateJsonObj();; | ||
31 | private Update U = new Update(); | ||
32 | private TrafficLight T = new TrafficLight(); | ||
33 | |||
34 | public static Connectie instance() | ||
35 | { | ||
30 | private static Checker C = new Checker(); | ||
31 | private final static String host = "localhost";//"141.252.237.90"; | ||
32 | private final static String vhost = "/8"; | ||
33 | private final CreateJsonObj CJO = new CreateJsonObj(); | ||
34 | private final CreateJsonObj2 CJO2 = new CreateJsonObj2(); | ||
35 | private UpdateStatus U = new UpdateStatus(); | ||
36 | private TrafficParse T = new TrafficParse(); | ||
37 | private int Count = 0; | ||
38 | private final RandomUselessSend RUS = new RandomUselessSend(); | ||
39 | private final List<Integer> Ids = new ArrayList<>(); | ||
40 | |||
41 | public static Connectie instance() { | ||
36 | 42 | return p; | return p; |
37 | 43 | } | } |
38 | |||
39 | public Connectie() throws IOException, JSONException | ||
40 | { | ||
44 | |||
45 | public Connectie() throws JSONException, IOException { | ||
41 | 46 | channel = connection.createChannel(); | channel = connection.createChannel(); |
42 | channel.queueDeclare(QUEUE_NAME, false,false,false,null); | ||
47 | |||
48 | Map<String, Object> args = new HashMap<String, Object>(); | ||
49 | args.put("x-message-ttl", 10000); | ||
50 | channel.queueDeclare(QUEUE_NAME, false, false, false, args); | ||
43 | 51 | channel.basicQos(1); | channel.basicQos(1); |
44 | |||
52 | |||
45 | 53 | Consumer consumer; | Consumer consumer; |
54 | |||
46 | 55 | consumer = new DefaultConsumer(channel) { | consumer = new DefaultConsumer(channel) { |
47 | |||
56 | |||
48 | 57 | @Override | @Override |
49 | public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException | ||
50 | { | ||
58 | public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { | ||
59 | |||
51 | 60 | String message = new String(body, "UTF-8"); | String message = new String(body, "UTF-8"); |
52 | |||
61 | Boolean check = false; | ||
53 | 62 | System.out.println(" [x] Received '" + message + "'"); | System.out.println(" [x] Received '" + message + "'"); |
54 | 63 | try { | try { |
55 | T.TrafficLight(message); | ||
64 | //parsed message in 3 variables Id,Count,DirectionRequests | ||
65 | T.TrafficParse(message); | ||
56 | 66 | } catch (JSONException ex) { | } catch (JSONException ex) { |
57 | 67 | Logger.getLogger(Connectie.class.getName()).log(Level.SEVERE, null, ex); | Logger.getLogger(Connectie.class.getName()).log(Level.SEVERE, null, ex); |
58 | 68 | } | } |
59 | |||
69 | //C.Check(); | ||
60 | 70 | try { | try { |
61 | U.Update(instance().CJO.JSONobj, T.LightId,T.Count,T.DirectionRequest); | ||
71 | if (T.getAllowed() == true) { | ||
72 | if (Count == 0) { | ||
73 | //update de JSONObject met de binnen gekomen message | ||
74 | check = true; | ||
75 | U.UpdateStatus(CJO.getJSONobj(), T.getLightId(), T.getCount(), T.getDirectionRequests(), check, CJO2.getJSONobj()); | ||
76 | Count++; | ||
77 | } else { | ||
78 | //update de JSONObject met ouwe waardes met de nieuwe | ||
79 | check = true; | ||
80 | Update(); | ||
81 | |||
82 | } | ||
83 | } | ||
62 | 84 | } catch (JSONException ex) { | } catch (JSONException ex) { |
63 | 85 | Logger.getLogger(Connectie.class.getName()).log(Level.SEVERE, null, ex); | Logger.getLogger(Connectie.class.getName()).log(Level.SEVERE, null, ex); |
64 | 86 | } | } |
65 | 87 | ||
66 | 88 | } | } |
67 | |||
68 | 89 | }; | }; |
69 | channel.basicConsume(QUEUE_NAME, false, consumer); | ||
90 | channel.basicConsume(QUEUE_NAME, false, consumer); | ||
91 | |||
70 | 92 | } | } |
71 | public static void main(String[] args) throws IOException, TimeoutException { | ||
72 | |||
93 | |||
94 | public void Update() throws JSONException { | ||
95 | |||
96 | C.Check(T.getLightId(),U.getFinal()); | ||
97 | |||
98 | if (C.getCheck() == true) { | ||
99 | U.UpdateStatus(U.getFinal(), T.getLightId(), T.getCount(), T.getDirectionRequests(), true, U.getSecond()); | ||
100 | |||
101 | } else { | ||
102 | Ids.add(T.getLightId()); | ||
103 | } | ||
104 | |||
105 | } | ||
106 | |||
107 | public void CheckLoop() throws JSONException{ | ||
108 | if(!Ids.isEmpty()); | ||
109 | { | ||
110 | for (int i = 0; i < Ids.size(); i++) { | ||
111 | |||
112 | |||
113 | Integer Id = Ids.get(i); | ||
114 | C.Check(Id, U.getFinal()); | ||
115 | if (C.getCheck() == true) { | ||
116 | U.UpdateStatus(U.getFinal(), Id, T.getCount(), T.getDirectionRequests(), true, U.getSecond()); | ||
117 | Ids.remove(i); | ||
118 | } | ||
119 | } | ||
120 | } | ||
121 | } | ||
122 | |||
123 | public void Loop() throws IOException, JSONException, InterruptedException { | ||
124 | JSONObject obj = CJO.getJSONobj(); | ||
125 | JSONObject obj2 = RUS.test2; | ||
126 | Channel testChannel = connection.createChannel(); | ||
127 | |||
73 | 128 | ||
129 | Map<String, Object> hallo = new HashMap<String, Object>(); | ||
130 | hallo.put("x-message-ttl", 10000); | ||
131 | channel.queueDeclare(QUEUE_NAME, false,false,false,hallo); | ||
132 | |||
133 | |||
134 | //stuurt steeds per seconde de momentele Status naar simulator | ||
135 | while (true) { | ||
136 | if (U.getFinal() == null) { | ||
137 | testChannel.basicPublish("", QUEUE_NAME, null, obj2.toString().getBytes("UTF-8")); | ||
138 | System.out.println(" [x] Sent1 '" + obj.toString() + "'"); | ||
139 | //testChannel.queueDelete(QUEUE_NAME); | ||
140 | |||
141 | } else { | ||
142 | |||
143 | testChannel.basicPublish("", QUEUE_NAME, null, U.getSecond().toString().getBytes("UTF-8")); | ||
144 | System.out.println(" [x] Sent2 '" + U.getSecond().toString() + "'"); | ||
145 | //testChannel.queueDelete(QUEUE_NAME); | ||
146 | U.UpdateStatus(U.getFinal(), T.getLightId(), T.getCount(), T.getDirectionRequests(), U.check, U.getSecond()); | ||
147 | CheckLoop(); | ||
148 | //System.out.println(U.getFinal()); | ||
149 | } | ||
150 | Thread.sleep(1000); | ||
151 | |||
152 | } | ||
153 | } | ||
154 | |||
155 | |||
156 | |||
157 | |||
158 | public static void main(String[] args) throws IOException, TimeoutException, JSONException, InterruptedException { | ||
159 | //host connectie info | ||
74 | 160 | factory.setHost(host); | factory.setHost(host); |
75 | try | ||
76 | { | ||
161 | /* | ||
162 | factory.setVirtualHost(vhost); | ||
163 | factory.setUsername("softdev"); | ||
164 | factory.setPassword("softdev"); | ||
165 | */ | ||
166 | try { | ||
167 | //roept reciever class en loop class aan | ||
77 | 168 | connection = factory.newConnection(); | connection = factory.newConnection(); |
78 | 169 | p = new Connectie(); | p = new Connectie(); |
79 | 170 | ||
80 | |||
81 | } | ||
82 | catch (Exception ex) | ||
83 | { | ||
171 | } catch (Exception ex) { | ||
84 | 172 | ex.printStackTrace(); | ex.printStackTrace(); |
85 | 173 | System.exit(1); | System.exit(1); |
86 | 174 | } | } |
87 | |||
88 | //System.out.println(instance().CJO.JSONobj); | ||
89 | JSONObject obj = instance().CJO.JSONobj; | ||
90 | |||
91 | try | ||
92 | { | ||
93 | Channel testChannel = connection.createChannel(); | ||
94 | testChannel.basicPublish("", QUEUE_NAME, null, obj.toString().getBytes("UTF-8")); | ||
95 | System.out.println(" [x] Sent '" + obj.toString() + "'"); | ||
96 | testChannel.queueDelete(QUEUE_NAME); | ||
175 | try{ | ||
176 | instance().Loop(); | ||
97 | 177 | } | } |
98 | catch(IOException ex) | ||
99 | { | ||
178 | catch (Exception ex) { | ||
100 | 179 | ex.printStackTrace(); | ex.printStackTrace(); |
180 | System.exit(1); | ||
101 | 181 | } | } |
102 | 182 | ||
103 | |||
104 | |||
105 | |||
106 | |||
107 | 183 | } | } |
108 | |||
109 | |||
110 | 184 | } | } |
File Controller/RabbitMq2/src/rabbitmq2/CreateJsonObj.java changed (mode: 100644) (index c04dcee..29857c8) | |||
... | ... | import org.json.JSONObject; | |
15 | 15 | * @author bouke | * @author bouke |
16 | 16 | */ | */ |
17 | 17 | public class CreateJsonObj { | public class CreateJsonObj { |
18 | JSONArray obj = new JSONArray(); | ||
19 | JSONObject JSONobj = new JSONObject(); | ||
20 | HashMap rows = new HashMap(); | ||
18 | private JSONArray obj = new JSONArray(); | ||
19 | private JSONObject JSONobj = new JSONObject(); | ||
20 | private HashMap rows = new HashMap(); | ||
21 | 21 | ||
22 | 22 | public CreateJsonObj() throws JSONException{ | public CreateJsonObj() throws JSONException{ |
23 | 23 | rows.put("Id",101); | rows.put("Id",101); |
24 | rows.put("Status", 2); | ||
24 | rows.put("Status", 0); | ||
25 | 25 | rows.put("Time", -1 ); | rows.put("Time", -1 ); |
26 | 26 | obj.put(rows); | obj.put(rows); |
27 | 27 | JSONobj.put("Lights",obj); | JSONobj.put("Lights",obj); |
28 | 28 | ||
29 | 29 | rows = new HashMap(); | rows = new HashMap(); |
30 | 30 | rows.put("Id",102); | rows.put("Id",102); |
31 | rows.put("Status", 2); | ||
31 | rows.put("Status", 0); | ||
32 | 32 | rows.put("Time", -1); | rows.put("Time", -1); |
33 | 33 | obj.put(rows); | obj.put(rows); |
34 | 34 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
35 | 35 | ||
36 | 36 | rows = new HashMap(); | rows = new HashMap(); |
37 | 37 | rows.put("Id",103); | rows.put("Id",103); |
38 | rows.put("Status", 2); | ||
38 | rows.put("Status", 0); | ||
39 | 39 | rows.put("Time", -1); | rows.put("Time", -1); |
40 | 40 | obj.put(rows); | obj.put(rows); |
41 | 41 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
42 | 42 | ||
43 | 43 | rows = new HashMap(); | rows = new HashMap(); |
44 | 44 | rows.put("Id",104); | rows.put("Id",104); |
45 | rows.put("Status", 2); | ||
45 | rows.put("Status", 0); | ||
46 | 46 | rows.put("Time", -1); | rows.put("Time", -1); |
47 | 47 | obj.put(rows); | obj.put(rows); |
48 | 48 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
49 | 49 | ||
50 | 50 | rows = new HashMap(); | rows = new HashMap(); |
51 | 51 | rows.put("Id",105); | rows.put("Id",105); |
52 | rows.put("Status", 2); | ||
52 | rows.put("Status", 0); | ||
53 | 53 | rows.put("Time", -1); | rows.put("Time", -1); |
54 | 54 | obj.put(rows); | obj.put(rows); |
55 | 55 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
56 | 56 | ||
57 | 57 | rows = new HashMap(); | rows = new HashMap(); |
58 | 58 | rows.put("Id",106); | rows.put("Id",106); |
59 | rows.put("Status", 2); | ||
59 | rows.put("Status", 0); | ||
60 | 60 | rows.put("Time", -1); | rows.put("Time", -1); |
61 | 61 | obj.put(rows); | obj.put(rows); |
62 | 62 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
63 | 63 | ||
64 | 64 | rows = new HashMap(); | rows = new HashMap(); |
65 | 65 | rows.put("Id",107); | rows.put("Id",107); |
66 | rows.put("Status", 2); | ||
66 | rows.put("Status", 0); | ||
67 | 67 | rows.put("Time", -1); | rows.put("Time", -1); |
68 | 68 | obj.put(rows); | obj.put(rows); |
69 | 69 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
70 | 70 | ||
71 | 71 | rows = new HashMap(); | rows = new HashMap(); |
72 | 72 | rows.put("Id",108); | rows.put("Id",108); |
73 | rows.put("Status", 2); | ||
73 | rows.put("Status", 0); | ||
74 | 74 | rows.put("Time", -1); | rows.put("Time", -1); |
75 | 75 | obj.put(rows); | obj.put(rows); |
76 | 76 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
77 | 77 | ||
78 | 78 | rows = new HashMap(); | rows = new HashMap(); |
79 | 79 | rows.put("Id",109); | rows.put("Id",109); |
80 | rows.put("Status", 2); | ||
80 | rows.put("Status", 0); | ||
81 | 81 | rows.put("Time", -1); | rows.put("Time", -1); |
82 | 82 | obj.put(rows); | obj.put(rows); |
83 | 83 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
84 | 84 | ||
85 | 85 | rows = new HashMap(); | rows = new HashMap(); |
86 | 86 | rows.put("Id",110); | rows.put("Id",110); |
87 | rows.put("Status", 2); | ||
87 | rows.put("Status", 0); | ||
88 | 88 | rows.put("Time", -1); | rows.put("Time", -1); |
89 | 89 | obj.put(rows); | obj.put(rows); |
90 | 90 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
91 | 91 | ||
92 | 92 | rows = new HashMap(); | rows = new HashMap(); |
93 | 93 | rows.put("Id",201); | rows.put("Id",201); |
94 | rows.put("Status", 2); | ||
94 | rows.put("Status", 0); | ||
95 | 95 | rows.put("Time", -1); | rows.put("Time", -1); |
96 | 96 | obj.put(rows); | obj.put(rows); |
97 | 97 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
98 | 98 | ||
99 | 99 | rows = new HashMap(); | rows = new HashMap(); |
100 | 100 | rows.put("Id",301); | rows.put("Id",301); |
101 | rows.put("Status", 2); | ||
101 | rows.put("Status", 0); | ||
102 | 102 | rows.put("Time", -1); | rows.put("Time", -1); |
103 | 103 | obj.put(rows); | obj.put(rows); |
104 | 104 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
105 | 105 | ||
106 | 106 | rows = new HashMap(); | rows = new HashMap(); |
107 | 107 | rows.put("Id",302); | rows.put("Id",302); |
108 | rows.put("Status", 2); | ||
108 | rows.put("Status", 0); | ||
109 | 109 | rows.put("Time", -1); | rows.put("Time", -1); |
110 | 110 | obj.put(rows); | obj.put(rows); |
111 | 111 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
112 | 112 | ||
113 | 113 | rows = new HashMap(); | rows = new HashMap(); |
114 | 114 | rows.put("Id",303); | rows.put("Id",303); |
115 | rows.put("Status", 2); | ||
115 | rows.put("Status", 0); | ||
116 | 116 | rows.put("Time", -1); | rows.put("Time", -1); |
117 | 117 | obj.put(rows); | obj.put(rows); |
118 | 118 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
119 | 119 | ||
120 | 120 | rows = new HashMap(); | rows = new HashMap(); |
121 | 121 | rows.put("Id",304); | rows.put("Id",304); |
122 | rows.put("Status", 2); | ||
122 | rows.put("Status", 0); | ||
123 | 123 | rows.put("Time", -1); | rows.put("Time", -1); |
124 | 124 | obj.put(rows); | obj.put(rows); |
125 | 125 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
126 | 126 | ||
127 | 127 | rows = new HashMap(); | rows = new HashMap(); |
128 | 128 | rows.put("Id",305); | rows.put("Id",305); |
129 | rows.put("Status", 2); | ||
129 | rows.put("Status", 0); | ||
130 | 130 | rows.put("Time", -1); | rows.put("Time", -1); |
131 | 131 | obj.put(rows); | obj.put(rows); |
132 | 132 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
133 | 133 | ||
134 | 134 | rows = new HashMap(); | rows = new HashMap(); |
135 | 135 | rows.put("Id",401); | rows.put("Id",401); |
136 | rows.put("Status", 2); | ||
136 | rows.put("Status", 0); | ||
137 | 137 | rows.put("Time", -1); | rows.put("Time", -1); |
138 | 138 | obj.put(rows); | obj.put(rows); |
139 | 139 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
140 | 140 | ||
141 | 141 | rows = new HashMap(); | rows = new HashMap(); |
142 | 142 | rows.put("Id",402); | rows.put("Id",402); |
143 | rows.put("Status", 2); | ||
143 | rows.put("Status", 0); | ||
144 | 144 | rows.put("Time", -1); | rows.put("Time", -1); |
145 | 145 | obj.put(rows); | obj.put(rows); |
146 | 146 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
147 | 147 | ||
148 | 148 | rows = new HashMap(); | rows = new HashMap(); |
149 | 149 | rows.put("Id",403); | rows.put("Id",403); |
150 | rows.put("Status", 2); | ||
150 | rows.put("Status", 0); | ||
151 | 151 | rows.put("Time", -1); | rows.put("Time", -1); |
152 | 152 | obj.put(rows); | obj.put(rows); |
153 | 153 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
154 | 154 | ||
155 | 155 | rows = new HashMap(); | rows = new HashMap(); |
156 | 156 | rows.put("Id",404); | rows.put("Id",404); |
157 | rows.put("Status", 2); | ||
157 | rows.put("Status", 0); | ||
158 | 158 | rows.put("Time", -1); | rows.put("Time", -1); |
159 | 159 | obj.put(rows); | obj.put(rows); |
160 | 160 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
161 | 161 | ||
162 | 162 | rows = new HashMap(); | rows = new HashMap(); |
163 | 163 | rows.put("Id",405); | rows.put("Id",405); |
164 | rows.put("Status", 2); | ||
164 | rows.put("Status", 0); | ||
165 | 165 | rows.put("Time", -1); | rows.put("Time", -1); |
166 | 166 | obj.put(rows); | obj.put(rows); |
167 | 167 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
168 | 168 | ||
169 | 169 | rows = new HashMap(); | rows = new HashMap(); |
170 | 170 | rows.put("Id",406); | rows.put("Id",406); |
171 | rows.put("Status", 2); | ||
171 | rows.put("Status", 0); | ||
172 | 172 | rows.put("Time", -1); | rows.put("Time", -1); |
173 | 173 | obj.put(rows); | obj.put(rows); |
174 | 174 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
175 | 175 | ||
176 | 176 | rows = new HashMap(); | rows = new HashMap(); |
177 | 177 | rows.put("Id",501); | rows.put("Id",501); |
178 | rows.put("Status", 2); | ||
178 | rows.put("Status", 0); | ||
179 | 179 | rows.put("Time", -1); | rows.put("Time", -1); |
180 | 180 | obj.put(rows); | obj.put(rows); |
181 | 181 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
182 | 182 | ||
183 | 183 | rows = new HashMap(); | rows = new HashMap(); |
184 | 184 | rows.put("Id",601); | rows.put("Id",601); |
185 | rows.put("Status", 2); | ||
185 | rows.put("Status", 0); | ||
186 | 186 | rows.put("Time", -1); | rows.put("Time", -1); |
187 | 187 | obj.put(rows); | obj.put(rows); |
188 | 188 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
... | ... | public class CreateJsonObj { | |
190 | 190 | ||
191 | 191 | ||
192 | 192 | } | } |
193 | |||
193 | public JSONObject getJSONobj(){ | ||
194 | return JSONobj; | ||
195 | } | ||
194 | 196 | ||
195 | 197 | } | } |
File Controller/RabbitMq2/src/rabbitmq2/CreateJsonObj2.java copied from file Controller/RabbitMq2/src/rabbitmq2/CreateJsonObj.java (similarity 79%) (mode: 100644) (index c04dcee..e9c6707) | |||
... | ... | import org.json.JSONObject; | |
14 | 14 | * | * |
15 | 15 | * @author bouke | * @author bouke |
16 | 16 | */ | */ |
17 | public class CreateJsonObj { | ||
18 | JSONArray obj = new JSONArray(); | ||
19 | JSONObject JSONobj = new JSONObject(); | ||
20 | HashMap rows = new HashMap(); | ||
17 | public class CreateJsonObj2 { | ||
18 | private JSONArray obj = new JSONArray(); | ||
19 | private JSONObject JSONobj = new JSONObject(); | ||
20 | private HashMap rows = new HashMap(); | ||
21 | 21 | ||
22 | public CreateJsonObj() throws JSONException{ | ||
22 | public CreateJsonObj2() throws JSONException{ | ||
23 | 23 | rows.put("Id",101); | rows.put("Id",101); |
24 | rows.put("Status", 2); | ||
24 | rows.put("Status", 0); | ||
25 | 25 | rows.put("Time", -1 ); | rows.put("Time", -1 ); |
26 | 26 | obj.put(rows); | obj.put(rows); |
27 | 27 | JSONobj.put("Lights",obj); | JSONobj.put("Lights",obj); |
28 | 28 | ||
29 | 29 | rows = new HashMap(); | rows = new HashMap(); |
30 | 30 | rows.put("Id",102); | rows.put("Id",102); |
31 | rows.put("Status", 2); | ||
31 | rows.put("Status", 0); | ||
32 | 32 | rows.put("Time", -1); | rows.put("Time", -1); |
33 | 33 | obj.put(rows); | obj.put(rows); |
34 | 34 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
35 | 35 | ||
36 | 36 | rows = new HashMap(); | rows = new HashMap(); |
37 | 37 | rows.put("Id",103); | rows.put("Id",103); |
38 | rows.put("Status", 2); | ||
38 | rows.put("Status", 0); | ||
39 | 39 | rows.put("Time", -1); | rows.put("Time", -1); |
40 | 40 | obj.put(rows); | obj.put(rows); |
41 | 41 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
42 | 42 | ||
43 | 43 | rows = new HashMap(); | rows = new HashMap(); |
44 | 44 | rows.put("Id",104); | rows.put("Id",104); |
45 | rows.put("Status", 2); | ||
45 | rows.put("Status", 0); | ||
46 | 46 | rows.put("Time", -1); | rows.put("Time", -1); |
47 | 47 | obj.put(rows); | obj.put(rows); |
48 | 48 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
49 | 49 | ||
50 | 50 | rows = new HashMap(); | rows = new HashMap(); |
51 | 51 | rows.put("Id",105); | rows.put("Id",105); |
52 | rows.put("Status", 2); | ||
52 | rows.put("Status", 0); | ||
53 | 53 | rows.put("Time", -1); | rows.put("Time", -1); |
54 | 54 | obj.put(rows); | obj.put(rows); |
55 | 55 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
56 | 56 | ||
57 | 57 | rows = new HashMap(); | rows = new HashMap(); |
58 | 58 | rows.put("Id",106); | rows.put("Id",106); |
59 | rows.put("Status", 2); | ||
59 | rows.put("Status", 0); | ||
60 | 60 | rows.put("Time", -1); | rows.put("Time", -1); |
61 | 61 | obj.put(rows); | obj.put(rows); |
62 | 62 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
63 | 63 | ||
64 | 64 | rows = new HashMap(); | rows = new HashMap(); |
65 | 65 | rows.put("Id",107); | rows.put("Id",107); |
66 | rows.put("Status", 2); | ||
66 | rows.put("Status", 0); | ||
67 | 67 | rows.put("Time", -1); | rows.put("Time", -1); |
68 | 68 | obj.put(rows); | obj.put(rows); |
69 | 69 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
70 | 70 | ||
71 | 71 | rows = new HashMap(); | rows = new HashMap(); |
72 | 72 | rows.put("Id",108); | rows.put("Id",108); |
73 | rows.put("Status", 2); | ||
73 | rows.put("Status", 0); | ||
74 | 74 | rows.put("Time", -1); | rows.put("Time", -1); |
75 | 75 | obj.put(rows); | obj.put(rows); |
76 | 76 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
77 | 77 | ||
78 | 78 | rows = new HashMap(); | rows = new HashMap(); |
79 | 79 | rows.put("Id",109); | rows.put("Id",109); |
80 | rows.put("Status", 2); | ||
80 | rows.put("Status", 0); | ||
81 | 81 | rows.put("Time", -1); | rows.put("Time", -1); |
82 | 82 | obj.put(rows); | obj.put(rows); |
83 | 83 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
84 | 84 | ||
85 | 85 | rows = new HashMap(); | rows = new HashMap(); |
86 | 86 | rows.put("Id",110); | rows.put("Id",110); |
87 | rows.put("Status", 2); | ||
87 | rows.put("Status", 0); | ||
88 | 88 | rows.put("Time", -1); | rows.put("Time", -1); |
89 | 89 | obj.put(rows); | obj.put(rows); |
90 | 90 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
91 | 91 | ||
92 | 92 | rows = new HashMap(); | rows = new HashMap(); |
93 | 93 | rows.put("Id",201); | rows.put("Id",201); |
94 | rows.put("Status", 2); | ||
94 | rows.put("Status", 0); | ||
95 | 95 | rows.put("Time", -1); | rows.put("Time", -1); |
96 | 96 | obj.put(rows); | obj.put(rows); |
97 | 97 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
98 | 98 | ||
99 | 99 | rows = new HashMap(); | rows = new HashMap(); |
100 | 100 | rows.put("Id",301); | rows.put("Id",301); |
101 | rows.put("Status", 2); | ||
101 | rows.put("Status", 0); | ||
102 | 102 | rows.put("Time", -1); | rows.put("Time", -1); |
103 | 103 | obj.put(rows); | obj.put(rows); |
104 | 104 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
105 | 105 | ||
106 | 106 | rows = new HashMap(); | rows = new HashMap(); |
107 | 107 | rows.put("Id",302); | rows.put("Id",302); |
108 | rows.put("Status", 2); | ||
108 | rows.put("Status", 0); | ||
109 | 109 | rows.put("Time", -1); | rows.put("Time", -1); |
110 | 110 | obj.put(rows); | obj.put(rows); |
111 | 111 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
112 | 112 | ||
113 | 113 | rows = new HashMap(); | rows = new HashMap(); |
114 | 114 | rows.put("Id",303); | rows.put("Id",303); |
115 | rows.put("Status", 2); | ||
115 | rows.put("Status", 0); | ||
116 | 116 | rows.put("Time", -1); | rows.put("Time", -1); |
117 | 117 | obj.put(rows); | obj.put(rows); |
118 | 118 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
119 | 119 | ||
120 | 120 | rows = new HashMap(); | rows = new HashMap(); |
121 | 121 | rows.put("Id",304); | rows.put("Id",304); |
122 | rows.put("Status", 2); | ||
122 | rows.put("Status", 0); | ||
123 | 123 | rows.put("Time", -1); | rows.put("Time", -1); |
124 | 124 | obj.put(rows); | obj.put(rows); |
125 | 125 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
126 | 126 | ||
127 | 127 | rows = new HashMap(); | rows = new HashMap(); |
128 | 128 | rows.put("Id",305); | rows.put("Id",305); |
129 | rows.put("Status", 2); | ||
129 | rows.put("Status", 0); | ||
130 | 130 | rows.put("Time", -1); | rows.put("Time", -1); |
131 | 131 | obj.put(rows); | obj.put(rows); |
132 | 132 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
133 | 133 | ||
134 | 134 | rows = new HashMap(); | rows = new HashMap(); |
135 | 135 | rows.put("Id",401); | rows.put("Id",401); |
136 | rows.put("Status", 2); | ||
136 | rows.put("Status", 0); | ||
137 | 137 | rows.put("Time", -1); | rows.put("Time", -1); |
138 | 138 | obj.put(rows); | obj.put(rows); |
139 | 139 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
140 | 140 | ||
141 | 141 | rows = new HashMap(); | rows = new HashMap(); |
142 | 142 | rows.put("Id",402); | rows.put("Id",402); |
143 | rows.put("Status", 2); | ||
143 | rows.put("Status", 0); | ||
144 | 144 | rows.put("Time", -1); | rows.put("Time", -1); |
145 | 145 | obj.put(rows); | obj.put(rows); |
146 | 146 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
147 | 147 | ||
148 | 148 | rows = new HashMap(); | rows = new HashMap(); |
149 | 149 | rows.put("Id",403); | rows.put("Id",403); |
150 | rows.put("Status", 2); | ||
150 | rows.put("Status", 0); | ||
151 | 151 | rows.put("Time", -1); | rows.put("Time", -1); |
152 | 152 | obj.put(rows); | obj.put(rows); |
153 | 153 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
154 | 154 | ||
155 | 155 | rows = new HashMap(); | rows = new HashMap(); |
156 | 156 | rows.put("Id",404); | rows.put("Id",404); |
157 | rows.put("Status", 2); | ||
157 | rows.put("Status", 0); | ||
158 | 158 | rows.put("Time", -1); | rows.put("Time", -1); |
159 | 159 | obj.put(rows); | obj.put(rows); |
160 | 160 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
161 | 161 | ||
162 | 162 | rows = new HashMap(); | rows = new HashMap(); |
163 | 163 | rows.put("Id",405); | rows.put("Id",405); |
164 | rows.put("Status", 2); | ||
164 | rows.put("Status", 0); | ||
165 | 165 | rows.put("Time", -1); | rows.put("Time", -1); |
166 | 166 | obj.put(rows); | obj.put(rows); |
167 | 167 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
168 | 168 | ||
169 | 169 | rows = new HashMap(); | rows = new HashMap(); |
170 | 170 | rows.put("Id",406); | rows.put("Id",406); |
171 | rows.put("Status", 2); | ||
171 | rows.put("Status", 0); | ||
172 | 172 | rows.put("Time", -1); | rows.put("Time", -1); |
173 | 173 | obj.put(rows); | obj.put(rows); |
174 | 174 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
175 | 175 | ||
176 | 176 | rows = new HashMap(); | rows = new HashMap(); |
177 | 177 | rows.put("Id",501); | rows.put("Id",501); |
178 | rows.put("Status", 2); | ||
178 | rows.put("Status", 0); | ||
179 | 179 | rows.put("Time", -1); | rows.put("Time", -1); |
180 | 180 | obj.put(rows); | obj.put(rows); |
181 | 181 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
182 | 182 | ||
183 | 183 | rows = new HashMap(); | rows = new HashMap(); |
184 | 184 | rows.put("Id",601); | rows.put("Id",601); |
185 | rows.put("Status", 2); | ||
185 | rows.put("Status", 0); | ||
186 | 186 | rows.put("Time", -1); | rows.put("Time", -1); |
187 | 187 | obj.put(rows); | obj.put(rows); |
188 | 188 | JSONobj.put("Lights", obj); | JSONobj.put("Lights", obj); |
... | ... | public class CreateJsonObj { | |
190 | 190 | ||
191 | 191 | ||
192 | 192 | } | } |
193 | |||
194 | |||
195 | } | ||
193 | public JSONObject getJSONobj(){ | ||
194 | return JSONobj; | ||
195 | } | ||
196 | } |
File Controller/RabbitMq2/src/rabbitmq2/MisschienNogGebruiken.java added (mode: 100644) (index 0000000..f0323b9) | |||
1 | /* | ||
2 | * To change this license header, choose License Headers in Project Properties. | ||
3 | * To change this template file, choose Tools | Templates | ||
4 | * and open the template in the editor. | ||
5 | */ | ||
6 | package rabbitmq2; | ||
7 | |||
8 | /** | ||
9 | * | ||
10 | * @author bouke | ||
11 | */ | ||
12 | public class MisschienNogGebruiken { | ||
13 | |||
14 | |||
15 | |||
16 | |||
17 | /* | ||
18 | while (true) { | ||
19 | |||
20 | |||
21 | |||
22 | if (Checker == true) { | ||
23 | try { | ||
24 | if (Count == 0) { | ||
25 | //update de JSONObject met de binnen gekomen message | ||
26 | U.UpdateStatus(instance().CJO.JSONobj, T.LightId, T.Count, T.DirectionRequests); | ||
27 | Count++; | ||
28 | } else { | ||
29 | U.UpdateStatus(instance().U.Final, T.LightId, T.Count, T.DirectionRequests); | ||
30 | } | ||
31 | } catch (JSONException ex) { | ||
32 | Logger.getLogger(Connectie.class.getName()).log(Level.SEVERE, null, ex); | ||
33 | } | ||
34 | break; | ||
35 | } | ||
36 | else{ | ||
37 | |||
38 | } | ||
39 | } | ||
40 | |||
41 | |||
42 | try { | ||
43 | Thread.sleep(5000); | ||
44 | U.UpdateStatus(instance().U.Final, T.LightId,T.Count,T.DirectionRequests); | ||
45 | Thread.sleep(5000); | ||
46 | U.UpdateStatus(instance().U.Final, T.LightId,T.Count,T.DirectionRequests); | ||
47 | } catch (InterruptedException | JSONException ex) { | ||
48 | Logger.getLogger(Connectie.class.getName()).log(Level.SEVERE, null, ex); | ||
49 | } | ||
50 | |||
51 | |||
52 | |||
53 | JSONObject obj = instance().U.Final; | ||
54 | //System.out.println(obj); | ||
55 | |||
56 | try | ||
57 | { | ||
58 | Channel testChannel = connection.createChannel(); | ||
59 | Map<String, Object> args = new HashMap<String, Object>(); | ||
60 | args.put("x-message-ttl", 10000); | ||
61 | channel.queueDeclare("simulator", false,false,true,args); | ||
62 | testChannel.basicPublish("", QUEUE_NAME, null, obj.toString().getBytes("UTF-8")); | ||
63 | System.out.println(" [x] Sent '" + obj.toString() + "'"); | ||
64 | testChannel.queueDelete(QUEUE_NAME); | ||
65 | } | ||
66 | catch(IOException ex) | ||
67 | { | ||
68 | ex.printStackTrace(); | ||
69 | } | ||
70 | */ | ||
71 | |||
72 | } |
File Controller/RabbitMq2/src/rabbitmq2/RandomUselessSend.java added (mode: 100644) (index 0000000..dd96367) | |||
1 | /* | ||
2 | * To change this license header, choose License Headers in Project Properties. | ||
3 | * To change this template file, choose Tools | Templates | ||
4 | * and open the template in the editor. | ||
5 | */ | ||
6 | package rabbitmq2; | ||
7 | |||
8 | import org.json.JSONArray; | ||
9 | import org.json.JSONException; | ||
10 | import org.json.JSONObject; | ||
11 | |||
12 | /** | ||
13 | * | ||
14 | * @author bouke | ||
15 | */ | ||
16 | public class RandomUselessSend { | ||
17 | public JSONObject test2; | ||
18 | public RandomUselessSend() throws JSONException{ | ||
19 | |||
20 | JSONObject test1 = new JSONObject(); | ||
21 | JSONObject test2 = new JSONObject(); | ||
22 | JSONObject test3 = new JSONObject(); | ||
23 | |||
24 | |||
25 | test1.put("LightId",104); | ||
26 | test1.put("Count", 3); | ||
27 | int[] hoi = {2}; | ||
28 | test1.put("DirectionRequests", test3.NULL); //test3.NULL); | ||
29 | test2.put("TrafficUpdate", test1); | ||
30 | |||
31 | |||
32 | //test2.put("speed", 10); | ||
33 | |||
34 | this.test2 = test2; | ||
35 | } | ||
36 | } |
File Controller/RabbitMq2/src/rabbitmq2/TrafficLight.java deleted (index 37b02a3..0000000) | |||
1 | /* | ||
2 | * To change this license header, choose License Headers in Project Properties. | ||
3 | * To change this template file, choose Tools | Templates | ||
4 | * and open the template in the editor. | ||
5 | */ | ||
6 | package rabbitmq2; | ||
7 | |||
8 | import org.json.JSONArray; | ||
9 | import org.json.JSONException; | ||
10 | import org.json.JSONObject; | ||
11 | |||
12 | /** | ||
13 | * | ||
14 | * @author bouke | ||
15 | */ | ||
16 | public class TrafficLight { | ||
17 | |||
18 | |||
19 | |||
20 | public Integer LightId; | ||
21 | public Integer Count; | ||
22 | public JSONArray DirectionRequest; | ||
23 | |||
24 | public void TrafficLight(String message) throws JSONException | ||
25 | { | ||
26 | JSONObject json = new JSONObject(message); | ||
27 | JSONObject first = json.getJSONObject("TrafficUpdate"); | ||
28 | Integer LightId = first.getInt("LightId"); | ||
29 | Integer Count = first.getInt("Count"); | ||
30 | JSONArray DirectionRequest = first.getJSONArray("DirectionRequest"); | ||
31 | |||
32 | System.out.println(LightId); | ||
33 | System.out.println(Count); | ||
34 | System.out.println(DirectionRequest); | ||
35 | |||
36 | this.LightId = LightId; | ||
37 | this.Count = Count; | ||
38 | this.DirectionRequest = DirectionRequest; | ||
39 | |||
40 | |||
41 | |||
42 | } | ||
43 | } |
File Controller/RabbitMq2/src/rabbitmq2/TrafficParse.java added (mode: 100644) (index 0000000..2e7d0db) | |||
1 | /* | ||
2 | * To change this license header, choose License Headers in Project Properties. | ||
3 | * To change this template file, choose Tools | Templates | ||
4 | * and open the template in the editor. | ||
5 | */ | ||
6 | package rabbitmq2; | ||
7 | |||
8 | import java.util.Arrays; | ||
9 | import org.json.JSONArray; | ||
10 | import org.json.JSONException; | ||
11 | import org.json.JSONObject; | ||
12 | |||
13 | /** | ||
14 | * | ||
15 | * @author bouke | ||
16 | */ | ||
17 | public class TrafficParse { | ||
18 | |||
19 | private Integer LightId; | ||
20 | private Integer Count; | ||
21 | private JSONArray DirectionRequests; | ||
22 | private boolean Allowed; | ||
23 | |||
24 | public void TrafficParse(String message) throws JSONException { | ||
25 | Allowed = false; | ||
26 | |||
27 | JSONObject json = new JSONObject(message); | ||
28 | if (json.has("speed")) { | ||
29 | Allowed = false; | ||
30 | } else { | ||
31 | JSONObject first = json.getJSONObject("TrafficUpdate"); | ||
32 | Integer LightId = first.getInt("LightId"); | ||
33 | Integer Count = first.getInt("Count"); | ||
34 | Object fckyou = null; | ||
35 | if (first.has("DirectionRequests") && !first.get("DirectionRequests").equals(fckyou)) { | ||
36 | System.out.println("hoi ik kom hier"); | ||
37 | //System.out.println(first.get("DirectionRequests")); | ||
38 | DirectionRequests = first.getJSONArray("DirectionRequests"); | ||
39 | //System.out.println(DirectionRequests.get(0)); | ||
40 | } else { | ||
41 | System.out.println("DirectionRequests is null"); | ||
42 | DirectionRequests = null; | ||
43 | } | ||
44 | |||
45 | System.out.println(LightId); | ||
46 | System.out.println(Count); | ||
47 | System.out.println(DirectionRequests); | ||
48 | |||
49 | this.LightId = LightId; | ||
50 | this.Count = Count; | ||
51 | this.DirectionRequests = DirectionRequests; | ||
52 | Allowed = true; | ||
53 | } | ||
54 | } | ||
55 | |||
56 | public Integer getLightId(){ | ||
57 | return LightId; | ||
58 | } | ||
59 | |||
60 | public Integer getCount() | ||
61 | { | ||
62 | return Count; | ||
63 | } | ||
64 | public JSONArray getDirectionRequests() | ||
65 | { | ||
66 | return DirectionRequests; | ||
67 | } | ||
68 | public boolean getAllowed(){ | ||
69 | return Allowed; | ||
70 | } | ||
71 | } |
File Controller/RabbitMq2/src/rabbitmq2/Update.java deleted (index 6f62156..0000000) | |||
1 | /* | ||
2 | * To change this license header, choose License Headers in Project Properties. | ||
3 | * To change this template file, choose Tools | Templates | ||
4 | * and open the template in the editor. | ||
5 | */ | ||
6 | package rabbitmq2; | ||
7 | import org.json.JSONArray; | ||
8 | import org.json.JSONException; | ||
9 | import org.json.JSONObject; | ||
10 | import rabbitmq2.TrafficLight; | ||
11 | import rabbitmq2.Connectie; | ||
12 | |||
13 | |||
14 | /** | ||
15 | * | ||
16 | * @author bouke | ||
17 | */ | ||
18 | public class Update { | ||
19 | private JSONObject Final; | ||
20 | public void Update(JSONObject obj, Integer LightId, Integer Count, JSONArray DirectionRequest) throws JSONException | ||
21 | { | ||
22 | JSONObject json = new JSONObject(obj); | ||
23 | JSONArray first = json.getJSONArray("TrafficUpdate"); | ||
24 | |||
25 | for (int i = 0; i < first.length(); i++) | ||
26 | { | ||
27 | JSONObject itemArr = (JSONObject)first.get(i); | ||
28 | if (itemArr.get("LightId").equals(LightId) && itemArr.get("Status").equals(0)) | ||
29 | { | ||
30 | itemArr.put("Status", 2); | ||
31 | } | ||
32 | else if (itemArr.get("Id").equals(LightId) && itemArr.get("Status").equals(2)) | ||
33 | { | ||
34 | itemArr.put("Status", 1); | ||
35 | } | ||
36 | else if (itemArr.get("Id").equals(LightId) && itemArr.get("Status").equals(1)) | ||
37 | { | ||
38 | itemArr.put("Status", 0); | ||
39 | } | ||
40 | } | ||
41 | /* | ||
42 | het versturen van constante berichten | ||
43 | uitbreiden van update met alles | ||
44 | treinen fietser voetgangers | ||
45 | dit is nog basic | ||
46 | |||
47 | */ | ||
48 | |||
49 | this.Final.put("Lights", first); | ||
50 | |||
51 | } | ||
52 | } |
File Controller/RabbitMq2/src/rabbitmq2/UpdateStatus.java added (mode: 100644) (index 0000000..95c9440) | |||
1 | /* | ||
2 | * To change this license header, choose License Headers in Project Properties. | ||
3 | * To change this template file, choose Tools | Templates | ||
4 | * and open the template in the editor. | ||
5 | */ | ||
6 | package rabbitmq2; | ||
7 | import org.json.JSONArray; | ||
8 | import org.json.JSONException; | ||
9 | import org.json.JSONObject; | ||
10 | |||
11 | |||
12 | /** | ||
13 | * | ||
14 | * @author bouke | ||
15 | */ | ||
16 | public class UpdateStatus { | ||
17 | |||
18 | private JSONObject Final; | ||
19 | private JSONObject Second; | ||
20 | public boolean check; | ||
21 | |||
22 | public void UpdateStatus(JSONObject obj, Integer LightId, Integer Count, Object DirectionRequests, Boolean check, JSONObject obj2) throws JSONException { | ||
23 | JSONArray first = obj.getJSONArray("Lights"); | ||
24 | JSONArray second = obj2.getJSONArray("Lights"); | ||
25 | //JSONArray second = obj2.getJSONArray("Lights"); | ||
26 | //System.out.println(Count2); | ||
27 | //Count2+=1; | ||
28 | |||
29 | for (int i = 0; i < first.length(); i++) { | ||
30 | JSONObject itemArr = first.getJSONObject(i); | ||
31 | JSONObject itemArr2 = second.getJSONObject(i); | ||
32 | Integer Time = first.getJSONObject(i).getInt("Time"); | ||
33 | Time = Time + 1; | ||
34 | itemArr.put("Time", Time); | ||
35 | if (itemArr.get("Id").equals(LightId) && itemArr.get("Status").equals(0) && check == true) { | ||
36 | |||
37 | itemArr.put("Status", 2); | ||
38 | itemArr2.put("Status", 2); | ||
39 | itemArr.put("Time", 0); | ||
40 | check = false; | ||
41 | |||
42 | } else if (itemArr.get("Time").equals(10) && itemArr.get("Status").equals(2)) { | ||
43 | itemArr.put("Status", 1); | ||
44 | itemArr2.put("Status", 1); | ||
45 | } else if (itemArr.get("Time").equals(15) && itemArr.get("Status").equals(1)) { | ||
46 | itemArr.put("Status", 0); | ||
47 | itemArr2.put("Status", 0); | ||
48 | } | ||
49 | |||
50 | } | ||
51 | |||
52 | Final = new JSONObject(); | ||
53 | Second = new JSONObject(); | ||
54 | this.Final.put("Lights", first); | ||
55 | this.Second.put("Lights", second); | ||
56 | this.check = check; | ||
57 | |||
58 | } | ||
59 | |||
60 | public JSONObject getFinal() { | ||
61 | |||
62 | return Final; | ||
63 | |||
64 | } | ||
65 | |||
66 | public JSONObject getSecond() { | ||
67 | return Second; | ||
68 | } | ||
69 | } |
File jar/amqp-client-4.0.2.jar copied from file Controller/RabbitMq2/dist/lib/amqp-client-4.0.2.jar (similarity 100%) |
File jar/java-json.jar copied from file Controller/RabbitMq2/dist/lib/java-json.jar (similarity 100%) |
File jar/slf4j-api-1.7.21.jar copied from file Controller/RabbitMq2/dist/lib/slf4j-api-1.7.21.jar (similarity 100%) |
File jar/slf4j-simple-1.7.22.jar copied from file Controller/RabbitMq2/dist/lib/slf4j-simple-1.7.22.jar (similarity 100%) |
File simulatie/auto.png changed (mode: 100644) (index 15cfc2e..36962c7) |