+ querying for supply implemented.

pull/1/head
Ivan Olexyn 5 years ago
parent 55abcbbba1
commit d519725651

@ -1,6 +1,6 @@
package com.olexyn.misp.embedded; package com.olexyn.misp.embedded;
import com.olexyn.misp.reverse.ReverseApp; import com.olexyn.misp.reverse.Reverse;
public class RunAll { public class RunAll {
@ -12,7 +12,7 @@ public class RunAll {
Thread.sleep(2000); Thread.sleep(2000);
Thread reverseT = new Thread(new ReverseApp()); Thread reverseT = new Thread(new Reverse());
reverseT.start(); reverseT.start();
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 42 KiB

@ -4,46 +4,21 @@
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>1210</x> <x>1250</x>
<y>480</y> <y>410</y>
<w>90</w> <w>90</w>
<h>30</h>
</coordinates>
<panel_attributes>inet
lt=-</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>810</x>
<y>480</y>
<w>120</w>
<h>70</h> <h>70</h>
</coordinates> </coordinates>
<panel_attributes> <panel_attributes>
mobile inet
modem</panel_attributes> lt=-</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>980</x>
<y>480</y>
<w>100</w>
<h>30</h>
</coordinates>
<panel_attributes>webhost
lt=-
layer=-1</panel_attributes>
<additional_attributes/> <additional_attributes/>
</element> </element>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>1210</x> <x>1250</x>
<y>520</y> <y>750</y>
<w>90</w> <w>90</w>
<h>30</h> <h>30</h>
</coordinates> </coordinates>
@ -54,8 +29,8 @@ bg=#90CAF9</panel_attributes>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>980</x> <x>1020</x>
<y>520</y> <y>750</y>
<w>100</w> <w>100</w>
<h>30</h> <h>30</h>
</coordinates> </coordinates>
@ -67,8 +42,8 @@ layer=-1</panel_attributes>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>730</x> <x>770</x>
<y>570</y> <y>820</y>
<w>280</w> <w>280</w>
<h>50</h> <h>50</h>
</coordinates> </coordinates>
@ -80,8 +55,8 @@ Generated by Loop</panel_attributes>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>1060</x> <x>1100</x>
<y>610</y> <y>860</y>
<w>200</w> <w>200</w>
<h>40</h> <h>40</h>
</coordinates> </coordinates>
@ -93,8 +68,8 @@ fg=#1E88E5</panel_attributes>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>650</x> <x>690</x>
<y>520</y> <y>750</y>
<w>100</w> <w>100</w>
<h>30</h> <h>30</h>
</coordinates> </coordinates>
@ -106,21 +81,21 @@ layer=-1</panel_attributes>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>730</x> <x>770</x>
<y>720</y> <y>970</y>
<w>280</w> <w>280</w>
<h>50</h> <h>50</h>
</coordinates> </coordinates>
<panel_attributes>lt=&lt;&lt;&lt;- <panel_attributes>lt=&lt;&lt;&lt;-
GET (Ride)(Request) POST (Ride)(Request)
(Data)</panel_attributes> (Data)</panel_attributes>
<additional_attributes>260.0;20.0;10.0;20.0</additional_attributes> <additional_attributes>260.0;20.0;10.0;20.0</additional_attributes>
</element> </element>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>1060</x> <x>1100</x>
<y>740</y> <y>990</y>
<w>200</w> <w>200</w>
<h>40</h> <h>40</h>
</coordinates> </coordinates>
@ -132,8 +107,8 @@ fg=#1E88E5</panel_attributes>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>730</x> <x>770</x>
<y>780</y> <y>1030</y>
<w>280</w> <w>280</w>
<h>40</h> <h>40</h>
</coordinates> </coordinates>
@ -144,8 +119,8 @@ OK (Ride)</panel_attributes>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>450</x> <x>490</x>
<y>520</y> <y>750</y>
<w>80</w> <w>80</w>
<h>30</h> <h>30</h>
</coordinates> </coordinates>
@ -156,8 +131,8 @@ bg=#90CAF9</panel_attributes>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>490</x> <x>530</x>
<y>650</y> <y>900</y>
<w>190</w> <w>190</w>
<h>40</h> <h>40</h>
</coordinates> </coordinates>
@ -169,8 +144,8 @@ fg=#1E88E5</panel_attributes>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>490</x> <x>530</x>
<y>700</y> <y>950</y>
<w>190</w> <w>190</w>
<h>40</h> <h>40</h>
</coordinates> </coordinates>
@ -182,8 +157,8 @@ fg=#1E88E5</panel_attributes>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>730</x> <x>770</x>
<y>630</y> <y>880</y>
<w>280</w> <w>280</w>
<h>40</h> <h>40</h>
</coordinates> </coordinates>
@ -194,22 +169,23 @@ OK (Ride)(Request)</panel_attributes>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>450</x> <x>490</x>
<y>480</y> <y>410</y>
<w>300</w> <w>300</w>
<h>30</h> <h>70</h>
</coordinates> </coordinates>
<panel_attributes>localhost <panel_attributes>
localhost
lt=-</panel_attributes> lt=-</panel_attributes>
<additional_attributes/> <additional_attributes/>
</element> </element>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>420</x> <x>460</x>
<y>450</y> <y>810</y>
<w>910</w> <w>910</w>
<h>400</h> <h>280</h>
</coordinates> </coordinates>
<panel_attributes> <panel_attributes>
lt=.. lt=..
@ -219,8 +195,8 @@ layer=-10</panel_attributes>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>990</x> <x>1030</x>
<y>590</y> <y>840</y>
<w>80</w> <w>80</w>
<h>40</h> <h>40</h>
</coordinates> </coordinates>
@ -233,13 +209,13 @@ transparency=0</panel_attributes>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>660</x> <x>700</x>
<y>590</y> <y>840</y>
<w>80</w> <w>80</w>
<h>60</h> <h>210</h>
</coordinates> </coordinates>
<panel_attributes>Available <panel_attributes>
Rides Ride
bg=#FFF59D bg=#FFF59D
transparency=0</panel_attributes> transparency=0</panel_attributes>
<additional_attributes/> <additional_attributes/>
@ -247,8 +223,8 @@ transparency=0</panel_attributes>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>990</x> <x>1030</x>
<y>630</y> <y>880</y>
<w>80</w> <w>80</w>
<h>110</h> <h>110</h>
</coordinates> </coordinates>
@ -262,36 +238,8 @@ layer=1</panel_attributes>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>660</x> <x>1030</x>
<y>650</y> <y>990</y>
<w>80</w>
<h>70</h>
</coordinates>
<panel_attributes>Booked
Rides
bg=#E6EE9C
transparency=0</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>660</x>
<y>720</y>
<w>80</w>
<h>80</h>
</coordinates>
<panel_attributes>Loaded
Rides
bg=#A5D6A7
transparency=0</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>990</x>
<y>740</y>
<w>80</w> <w>80</w>
<h>60</h> <h>60</h>
</coordinates> </coordinates>
@ -304,32 +252,32 @@ transparency=0</panel_attributes>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>1240</x> <x>1280</x>
<y>540</y> <y>770</y>
<w>30</w> <w>30</w>
<h>310</h> <h>320</h>
</coordinates> </coordinates>
<panel_attributes>lt=- <panel_attributes>lt=-
fg=#1E88E5</panel_attributes> fg=#1E88E5</panel_attributes>
<additional_attributes>10.0;10.0;10.0;290.0</additional_attributes> <additional_attributes>10.0;10.0;10.0;300.0</additional_attributes>
</element> </element>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>480</x> <x>520</x>
<y>540</y> <y>770</y>
<w>30</w> <w>30</w>
<h>310</h> <h>320</h>
</coordinates> </coordinates>
<panel_attributes>lt=- <panel_attributes>lt=-
fg=#1E88E5</panel_attributes> fg=#1E88E5</panel_attributes>
<additional_attributes>10.0;10.0;10.0;290.0</additional_attributes> <additional_attributes>10.0;10.0;10.0;300.0</additional_attributes>
</element> </element>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>1240</x> <x>1280</x>
<y>630</y> <y>880</y>
<w>20</w> <w>20</w>
<h>130</h> <h>130</h>
</coordinates> </coordinates>
@ -342,8 +290,8 @@ layer=4</panel_attributes>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>480</x> <x>520</x>
<y>670</y> <y>920</y>
<w>20</w> <w>20</w>
<h>50</h> <h>50</h>
</coordinates> </coordinates>
@ -356,27 +304,171 @@ layer=4</panel_attributes>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>1020</x> <x>1060</x>
<y>540</y> <y>770</y>
<w>30</w> <w>30</w>
<h>310</h> <h>320</h>
</coordinates> </coordinates>
<panel_attributes>lt=- <panel_attributes>lt=-
fg=#5E35B1 fg=#5E35B1
layer=-4</panel_attributes> layer=-4</panel_attributes>
<additional_attributes>10.0;10.0;10.0;290.0</additional_attributes> <additional_attributes>10.0;10.0;10.0;300.0</additional_attributes>
</element> </element>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates>
<x>730</x>
<y>770</y>
<w>30</w>
<h>320</h>
</coordinates>
<panel_attributes>lt=-
fg=#5E35B1
layer=-4</panel_attributes>
<additional_attributes>10.0;10.0;10.0;300.0</additional_attributes>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>700</x>
<y>590</y>
<w>80</w>
<h>50</h>
</coordinates>
<panel_attributes>Check
Supply
bg=#FFF59D
transparency=0</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>850</x>
<y>410</y>
<w>120</w>
<h>70</h>
</coordinates>
<panel_attributes>
mobile
modem</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>1020</x>
<y>410</y>
<w>100</w>
<h>70</h>
</coordinates>
<panel_attributes>
webhost
lt=-
layer=-1</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>1020</x>
<y>510</y>
<w>100</w>
<h>30</h>
</coordinates>
<panel_attributes>forward
bg=#B39DDB
layer=-1</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates> <coordinates>
<x>690</x> <x>690</x>
<y>540</y> <y>510</y>
<w>100</w>
<h>30</h>
</coordinates>
<panel_attributes>reverse
bg=#B39DDB
layer=-1</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>460</x>
<y>570</y>
<w>910</w>
<h>110</h>
</coordinates>
<panel_attributes>
lt=..
layer=-10</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>UMLClass</id>
<coordinates>
<x>1030</x>
<y>590</y>
<w>80</w>
<h>50</h>
</coordinates>
<panel_attributes>Available
Rides
bg=#FFF59D
transparency=0</panel_attributes>
<additional_attributes/>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>1060</x>
<y>530</y>
<w>30</w>
<h>150</h>
</coordinates>
<panel_attributes>lt=-
fg=#5E35B1
layer=-4</panel_attributes>
<additional_attributes>10.0;10.0;10.0;130.0</additional_attributes>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>730</x>
<y>530</y>
<w>30</w> <w>30</w>
<h>310</h> <h>150</h>
</coordinates> </coordinates>
<panel_attributes>lt=- <panel_attributes>lt=-
fg=#5E35B1 fg=#5E35B1
layer=-4</panel_attributes> layer=-4</panel_attributes>
<additional_attributes>10.0;10.0;10.0;290.0</additional_attributes> <additional_attributes>10.0;10.0;10.0;130.0</additional_attributes>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>770</x>
<y>580</y>
<w>280</w>
<h>40</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;-
POST (Available)</panel_attributes>
<additional_attributes>260.0;20.0;10.0;20.0</additional_attributes>
</element>
<element>
<id>Relation</id>
<coordinates>
<x>770</x>
<y>610</y>
<w>280</w>
<h>40</h>
</coordinates>
<panel_attributes>lt=&lt;&lt;&lt;.
OK (# Available)</panel_attributes>
<additional_attributes>10.0;20.0;260.0;20.0</additional_attributes>
</element> </element>
</diagram> </diagram>

@ -0,0 +1,39 @@
package com.olexyn.misp.reverse;
import org.json.JSONObject;
public class CheckSuppyR implements Runnable {
private int available;
public int CHECK_SUPPLY_INTERVAL = 100;
private Reverse reverse;
public CheckSuppyR(Reverse reverse) {
this.reverse = reverse;
}
@Override
public void run() {
while (true) {
JSONObject obj = new JSONObject().put("available", 0);
try {
String result = Tools.send("POST", reverse.FORWARD_URL, obj.toString());
JSONObject resultObj = new JSONObject(result);
available = resultObj.getInt("available");
Thread.sleep(CHECK_SUPPLY_INTERVAL);
} catch (Exception ignored) { }
}
}
public int getAvailable() { return available; }
}

@ -0,0 +1,36 @@
package com.olexyn.misp.reverse;
public class JourneyGenerator implements Runnable {
public int OVERHEAD = 8;
public int CHECK_DEPLETION_INTERVAL = 500;
public int START_NEW_JOURNEY_INTERVAL = 100;
private Reverse reverse;
private CheckSuppyR checkSuppyR;
public JourneyGenerator(Reverse reverse , CheckSuppyR checkSuppyR) {
this.reverse = reverse;
this.checkSuppyR = checkSuppyR;
}
@Override
public void run() {
while (true) {
try {
Thread journeyT = new Thread(new JourneyR(reverse));
journeyT.setName("journeyT");
journeyT.start();
while (checkSuppyR.getAvailable() > OVERHEAD) { Thread.sleep(CHECK_DEPLETION_INTERVAL); }
Thread.sleep(START_NEW_JOURNEY_INTERVAL);
} catch (Exception ignored) { }
}
}
}

@ -0,0 +1,53 @@
package com.olexyn.misp.reverse;
import com.olexyn.misp.helper.Ride;
import java.io.IOException;
public class JourneyR implements Runnable {
private Reverse reverse;
public JourneyR(Reverse reverse) {
this.reverse = reverse;
}
@Override
public void run() {
try {
Ride _ride = sendPostRide();
_ride = sendGetRequest(_ride);
sendPostRideRequestData(_ride);
} catch (Exception ignored) { }
}
Ride sendPostRide() throws IOException {
final Ride ride = new Ride();
final String result = Tools.send("POST", reverse.FORWARD_URL, ride.json());
String _req = new Ride(result).getRequest();
String request = (_req == null) ? "" : _req;
ride.setRequest(request);
return ride;
}
Ride sendGetRequest(Ride ride) throws IOException {
final String result = Tools.send("GET", reverse.APP_URL, ride.getRequest());
ride.setData(result);
return ride;
}
void sendPostRideRequestData(Ride ride) throws IOException {
Tools.send("POST", reverse.FORWARD_URL, ride.json());
}
}

@ -1,3 +1,16 @@
* Run from `ReverseApp` : #### Overview
* `Reverse`
* Core
* Starts Threads
* Coordinates
* Launch from here
* as `main()` * as `main()`
* or as `Runnable` from somewhere else. * or as `Runnable` from somewhere else.
* `CheckSupply`
* Runnable
* Asks *forward* about supply.
* `Journey`
* Runnable
* Journey fo a `Ride` through the App.
* `Tools`
* Performs the actual request.

@ -1,117 +1,31 @@
package com.olexyn.misp.reverse; package com.olexyn.misp.reverse;
import com.olexyn.misp.helper.Ride; public class Reverse implements Runnable {
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class Reverse {
private int available;
public String FORWARD_URL = "http://localhost:8090/forward"; public String FORWARD_URL = "http://localhost:8090/forward";
public String APP_URL = "http://localhost:8090/app"; public String APP_URL = "http://localhost:8090/app";
public void start() throws IOException { public void start() {
sendPostAvailable();
sendPostRide();
}
void sendPostRide() throws IOException {
final Ride ride = new Ride();
final String result = send("POST", FORWARD_URL, ride.json());
String _req = new Ride(result).getRequest();
String request = (_req == null) ? "" : _req;
ride.setRequest(request);
sendGetRequest(ride);
}
void sendGetRequest(Ride ride) throws IOException {
final String result = send("GET", APP_URL, ride.getRequest());
ride.setData(result);
sendPostRideRequestData(ride);
}
void sendPostRideRequestData(Ride ride) throws IOException {
send("POST", FORWARD_URL, ride.json());
//sendPostRide();
}
CheckSuppyR checkSuppyR = new CheckSuppyR(this);
void sendPostAvailable() throws IOException { Thread checkSupplyT = new Thread(checkSuppyR);
JSONObject obj = new JSONObject(); checkSupplyT.setName("checkSupplyT");
obj.put("available", 0); checkSupplyT.start();
String result = send("POST", FORWARD_URL, obj.toString());
JSONObject resultObj = new JSONObject(result);
available = resultObj.getInt("available");
Thread journeyGeneratorT = new Thread(new JourneyGenerator(this, checkSuppyR));
journeyGeneratorT.setName("journeyGeneratorT");
journeyGeneratorT.start();
} }
public static void main(String... args) { new Reverse().start(); }
private String send(String method, String urlString, String body) throws IOException { @Override
public void run() { start(); }
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod(method);
boolean getToForward = method.equals("GET") && urlString.contains("forward");
if (method.equals("POST") || getToForward) {
connection.setDoOutput(true);
DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
if (body != null) {
outputStream.writeBytes(body);
}
outputStream.flush();
outputStream.close();
}
int i = connection.getResponseCode();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String out;
StringBuilder sb = new StringBuilder();
while ((out = in.readLine()) != null) { sb.append(out); }
in.close();
return sb.toString();
}
} }

@ -1,35 +0,0 @@
package com.olexyn.misp.reverse;
import java.io.IOException;
public class ReverseApp implements Runnable {
public static void main(String... args) throws IOException {
new ReverseApp().doRun();
}
@Override
public void run() {
try {
doRun();
} catch (IOException e) {
e.printStackTrace();
}
}
private void doRun() throws IOException {
Reverse reverse = new Reverse();
reverse.FORWARD_URL = "http://localhost:8090/forward";
reverse.APP_URL = "http://localhost:8090/app";
reverse.start();
}
}

@ -0,0 +1,46 @@
package com.olexyn.misp.reverse;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class Tools {
static String send(String method, String urlString, String body) throws IOException {
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod(method);
boolean getToForward = method.equals("GET") && urlString.contains("forward");
if (method.equals("POST") || getToForward) {
connection.setDoOutput(true);
DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
if (body != null) {
outputStream.writeBytes(body);
}
outputStream.flush();
outputStream.close();
}
int i = connection.getResponseCode();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String out;
StringBuilder sb = new StringBuilder();
while ((out = in.readLine()) != null) { sb.append(out); }
in.close();
return sb.toString();
}
}
Loading…
Cancel
Save