Begin gemaakt met devices die events kunnen sturen naar applications via main opdat actions worden uitgevoerd.
This commit is contained in:
@@ -1,27 +1,45 @@
|
||||
package pm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
import pm.applicatie.voorbeeld.Voorbeeld;
|
||||
import pm.application.Application;
|
||||
import pm.device.Device;
|
||||
import pm.device.Features;
|
||||
import pm.device.exampledevice.ExampleDevice;
|
||||
import pm.device.example.Example;
|
||||
import pm.event.Event;
|
||||
|
||||
public class Main {
|
||||
ArrayList<Application> applicationList;
|
||||
ArrayList<Device> deviceList;
|
||||
Queue<Event> eventQueue;
|
||||
|
||||
public Main() {
|
||||
applicationList = new ArrayList<Application>();
|
||||
deviceList = new ArrayList<Device>();
|
||||
eventQueue = new ConcurrentLinkedQueue<Event>();
|
||||
}
|
||||
|
||||
public void addApplication(Application application) {
|
||||
applicationList.add(application);
|
||||
}
|
||||
|
||||
public boolean removeApplication(Application application) {
|
||||
return applicationList.remove(application);
|
||||
}
|
||||
|
||||
public void addDevice(Device device) {
|
||||
deviceList.add(device);
|
||||
if (device.hasFeature(Features.RESTART)) {
|
||||
device.start();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean removeDevie(Device device) {
|
||||
return deviceList.remove(device);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
addDevice(new ExampleDevice());
|
||||
addDevice(new Example(eventQueue));
|
||||
addApplication(new Voorbeeld());
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
5
java/src/pm/action/Action.java
Normal file
5
java/src/pm/action/Action.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package pm.action;
|
||||
|
||||
public enum Action {
|
||||
START
|
||||
}
|
||||
9
java/src/pm/applicatie/voorbeeld/Voorbeeld.java
Normal file
9
java/src/pm/applicatie/voorbeeld/Voorbeeld.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package pm.applicatie.voorbeeld;
|
||||
|
||||
import pm.application.Application;
|
||||
|
||||
public class Voorbeeld extends Application {
|
||||
protected void start() {
|
||||
System.out.println("jeheee!");
|
||||
}
|
||||
}
|
||||
15
java/src/pm/application/Application.java
Normal file
15
java/src/pm/application/Application.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package pm.application;
|
||||
|
||||
import pm.action.Action;
|
||||
|
||||
public abstract class Application {
|
||||
public void invoke(Action action) {
|
||||
switch (action) {
|
||||
case START:
|
||||
start();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void start();
|
||||
}
|
||||
@@ -1,31 +1,18 @@
|
||||
package pm.device;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Queue;
|
||||
|
||||
import pm.device.feature.Feature;
|
||||
import pm.event.Event;
|
||||
|
||||
|
||||
public abstract class Device {
|
||||
protected ArrayList<Feature> featureList;
|
||||
protected Queue<Event> eventQueue;
|
||||
|
||||
protected Device() {
|
||||
featureList = new ArrayList<Feature>();
|
||||
protected Device(Queue<Event> eventQueue) {
|
||||
this.eventQueue = eventQueue;
|
||||
initialise();
|
||||
}
|
||||
|
||||
public void addFeature(Feature feature) {
|
||||
if (!hasFeature(feature)) {
|
||||
if (this instanceof feature.getClass()) {
|
||||
|
||||
}
|
||||
featureList.add(feature);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeFeature(Feature feature) {
|
||||
featureList.remove(feature);
|
||||
}
|
||||
|
||||
public boolean hasFeature(Feature feature) {
|
||||
return featureList.contains(feature);
|
||||
}
|
||||
public void initialise() {}
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
package pm.device;
|
||||
|
||||
import pm.device.feature.Feature;
|
||||
import pm.device.feature.Restart;
|
||||
|
||||
public enum Features {
|
||||
Restart ((Class<Restart>)Restart.class);
|
||||
|
||||
Features(Class<Feature> feature) {
|
||||
}
|
||||
}
|
||||
18
java/src/pm/device/example/Example.java
Normal file
18
java/src/pm/device/example/Example.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package pm.device.example;
|
||||
|
||||
import java.util.Queue;
|
||||
|
||||
import pm.action.Action;
|
||||
import pm.device.Device;
|
||||
import pm.event.Event;
|
||||
|
||||
public class Example extends Device {
|
||||
public Example(Queue<Event> eventQueue) {
|
||||
super(eventQueue);
|
||||
}
|
||||
|
||||
public void initialise() {
|
||||
Event event = new Event(Action.START);
|
||||
eventQueue.add(event);
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package pm.device.exampledevice;
|
||||
|
||||
import pm.device.Device;
|
||||
import pm.device.Features;
|
||||
|
||||
public class ExampleDevice extends Device {
|
||||
public ExampleDevice() {
|
||||
addFeature(Features.Restart);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
|
||||
}
|
||||
|
||||
public void restart() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package pm.device.feature;
|
||||
|
||||
public interface Feature {
|
||||
public void apply();
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package pm.device.feature;
|
||||
|
||||
public interface Restart extends Feature {
|
||||
public static final String feature = "RESTART";
|
||||
|
||||
public void stop();
|
||||
public void restart();
|
||||
}
|
||||
@@ -1,16 +1,11 @@
|
||||
package pm.event;
|
||||
|
||||
import pm.device.feature.Feature;
|
||||
import pm.action.Action;
|
||||
|
||||
public class Event {
|
||||
public Feature feature;
|
||||
protected Action action;
|
||||
|
||||
public Event(Feature feature) {
|
||||
this.feature = feature;
|
||||
public Event(Action action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public void Apply() {
|
||||
feature.apply();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user