-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from FIUS/feature/entityProgram
Add entity programs and necessary stuff.
- Loading branch information
Showing
20 changed files
with
980 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...in/java/de/unistuttgart/informatik/fius/icge/simulation/entity/program/EntityProgram.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* This source file is part of the FIUS ICGE project. | ||
* For more information see github.com/FIUS/ICGE2 | ||
* | ||
* Copyright (c) 2019 the ICGE project authors. | ||
* | ||
* This software is available under the MIT license. | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
package de.unistuttgart.informatik.fius.icge.simulation.entity.program; | ||
|
||
import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; | ||
|
||
|
||
/** | ||
* A program to be executed by an entity | ||
* | ||
* @author Tim Neumann | ||
*/ | ||
public interface EntityProgram { | ||
|
||
/** | ||
* Run this program on the given entity. | ||
* | ||
* @param entity | ||
* The entity to run this program on | ||
* @throws IllegalArgumentException | ||
* if this program cannot run on the given entity | ||
*/ | ||
void run(Entity entity); | ||
|
||
/** | ||
* Check whether this program could run on the given entity. | ||
* | ||
* @param entity | ||
* The entity to check | ||
* @return true if this program could run on that entity | ||
*/ | ||
boolean canRunOn(Entity entity); | ||
} |
90 changes: 90 additions & 0 deletions
90
...de/unistuttgart/informatik/fius/icge/simulation/entity/program/EntityProgramRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* This source file is part of the FIUS ICGE project. | ||
* For more information see github.com/FIUS/ICGE2 | ||
* | ||
* Copyright (c) 2019 the ICGE project authors. | ||
* | ||
* This software is available under the MIT license. | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
package de.unistuttgart.informatik.fius.icge.simulation.entity.program; | ||
|
||
import java.util.NoSuchElementException; | ||
import java.util.Set; | ||
import java.util.function.Supplier; | ||
|
||
import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; | ||
import de.unistuttgart.informatik.fius.icge.simulation.exception.ElementExistsException; | ||
|
||
|
||
/** | ||
* The registry for all {@link EntityProgram}s. | ||
* | ||
* @author Tim Neumann | ||
*/ | ||
public interface EntityProgramRegistry { | ||
/** | ||
* Register an entity program with the given name. | ||
* | ||
* @param name | ||
* the name of the program; must not be null; must be unique | ||
* | ||
* @param program | ||
* the program to register; must not be null | ||
* | ||
* @throws IllegalArgumentException | ||
* if an argument is null | ||
* @throws ElementExistsException | ||
* if the name is already used | ||
*/ | ||
void registerEntityProgram(String name, EntityProgram program); | ||
|
||
/** | ||
* Register many entity programs of the same type with the given name. | ||
* | ||
* @param name | ||
* the name for these programs; must not be null; must be unique | ||
* | ||
* @param programGenerator | ||
* a generator for the type of program; must not be null; must provide non null programs | ||
* | ||
* @throws IllegalArgumentException | ||
* if an argument is null | ||
* | ||
* @throws ElementExistsException | ||
* if the name is already used | ||
*/ | ||
void registerManyEntityProgram(String name, Supplier<EntityProgram> programGenerator); | ||
|
||
/** | ||
* Get the names of all registered entity programs. | ||
* | ||
* @return a set of the names of all registered entity programs | ||
*/ | ||
Set<String> getPrograms(); | ||
|
||
/** | ||
* Get the names of all entity programs, which could run on the given entity. | ||
* | ||
* @param entity | ||
* the entity to get the programs for; must not be null | ||
* @return a set of the names of all entity programs which could be run on this entity | ||
* | ||
* @throws IllegalArgumentException | ||
* if an argument is null | ||
*/ | ||
Set<String> getProgramsForEntity(Entity entity); | ||
|
||
/** | ||
* Get the entity program for a given name. | ||
* | ||
* @param name | ||
* The name to get the program for; must not be null | ||
* @return The program for the given name | ||
* @throws IllegalArgumentException | ||
* if an argument is null | ||
* @throws NoSuchElementException | ||
* if the given name is not registered | ||
*/ | ||
EntityProgram getEntityProgram(String name); | ||
} |
96 changes: 96 additions & 0 deletions
96
...a/de/unistuttgart/informatik/fius/icge/simulation/entity/program/EntityProgramRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* This source file is part of the FIUS ICGE project. | ||
* For more information see github.com/FIUS/ICGE2 | ||
* | ||
* Copyright (c) 2019 the ICGE project authors. | ||
* | ||
* This software is available under the MIT license. | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
package de.unistuttgart.informatik.fius.icge.simulation.entity.program; | ||
|
||
import java.util.NoSuchElementException; | ||
|
||
import de.unistuttgart.informatik.fius.icge.simulation.entity.Entity; | ||
import de.unistuttgart.informatik.fius.icge.simulation.exception.CannotRunProgramException; | ||
|
||
|
||
/** | ||
* A class to run {@link EntityProgram}s. | ||
* | ||
* @author Tim Neumann | ||
*/ | ||
public interface EntityProgramRunner { | ||
|
||
/** | ||
* Get the state of an entity program. | ||
* | ||
* @param program | ||
* The name of program to get the state of; must be a registered program in the {@link EntityProgramRegistry} | ||
* @return The state of the given program | ||
* @throws NoSuchElementException | ||
* if the program is not registered in the {@link EntityProgramRegistry} | ||
* @throws IllegalArgumentException | ||
* if an argument is null | ||
*/ | ||
public EntityProgramState getState(String program); | ||
|
||
/** | ||
* Check whether the given program can run. | ||
* | ||
* @param program | ||
* The name of program to check; must be a registered program in the {@link EntityProgramRegistry} | ||
* | ||
* @return true if the program can run | ||
* @throws NoSuchElementException | ||
* if the program is not registered in the {@link EntityProgramRegistry} | ||
* @throws IllegalArgumentException | ||
* if an argument is null | ||
*/ | ||
public boolean canRunProgram(String program); | ||
|
||
/** | ||
* Check whether the given program can be run to the given entity. | ||
* <p> | ||
* First checks {@link #canRunProgram(String)} and then {@link EntityProgram#canRunOn(Entity)}. | ||
* </p> | ||
* | ||
* @param program | ||
* The name of the program to check; must be a registered program in the {@link EntityProgramRegistry} | ||
* @param entity | ||
* The entity to check; must not be null | ||
* @return true if the program can run on that entity | ||
* @throws NoSuchElementException | ||
* if the program is not registered in the {@link EntityProgramRegistry} | ||
* @throws IllegalArgumentException | ||
* if an argument is null | ||
*/ | ||
public boolean canRunProgramOn(String program, Entity entity); | ||
|
||
/** | ||
* Run an entity program on an entity. | ||
* | ||
* @param program | ||
* The program to run; must be a registered program in the {@link EntityProgramRegistry}; must be able to run on | ||
* the entity now | ||
* @param entity | ||
* The entity to run the program on | ||
* @throws IllegalArgumentException | ||
* if an argument is null | ||
* @throws NoSuchElementException | ||
* if the program is not registered in the {@link EntityProgramRegistry} | ||
* @throws CannotRunProgramException | ||
* if the program is not able to run on the entity now | ||
* @throws RuntimeException | ||
* if an exception occurred in the entity program | ||
*/ | ||
public void run(String program, Entity entity); | ||
|
||
/** | ||
* Force stop all running entity programs. | ||
* <p> | ||
* This does not block until successful shutdown | ||
* </p> | ||
*/ | ||
public void forceStop(); | ||
} |
26 changes: 26 additions & 0 deletions
26
...va/de/unistuttgart/informatik/fius/icge/simulation/entity/program/EntityProgramState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* This source file is part of the FIUS ICGE project. | ||
* For more information see github.com/FIUS/ICGE2 | ||
* | ||
* Copyright (c) 2019 the ICGE project authors. | ||
* | ||
* This software is available under the MIT license. | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
package de.unistuttgart.informatik.fius.icge.simulation.entity.program; | ||
|
||
/** | ||
* The state of a entity program | ||
* | ||
* @author Tim Neumann | ||
*/ | ||
public enum EntityProgramState { | ||
/** When the entity program is new and was not started yet. */ | ||
NEW, | ||
/** When the entity program is currently running. */ | ||
RUNNING, | ||
/** When the entity program finished nominally. */ | ||
FINISHED, | ||
/** When the entity program was killed by the {@link EntityProgramRunner}. */ | ||
KILLED | ||
} |
Oops, something went wrong.