Skip to content

Commit ad4520c

Browse files
Merge pull request #9 from aljoshakoecher/prepare-for-release
v1.1.0 release
2 parents 9ccd018 + e5bb71f commit ad4520c

19 files changed

Lines changed: 319 additions & 220 deletions

README.md

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[![Maven Central](https://img.shields.io/maven-central/v/com.github.aljoshakoecher/isa88-state-machine.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.github.aljoshakoecher%22%20AND%20a:%22isa88-state-machine%22)
22

33
# Java ISA88-StateMachine
4-
A Java implementation of the state machine standardized in ISA 88. The state machine guarantees that only transitions that only 'valid' transitions can be executed. Have a look at the following figure which depicts the state machine of ISA 88:
4+
A Java implementation of the state machine standardized in ISA 88. The state machine guarantees that only 'valid' transitions can be executed. Have a look at the following figure which depicts the state machine of ISA 88:
55

66
![State machine as defined in ISA 88 (figure taken from http://omac.org/wp-content/uploads/2016/11/PackML_Unit_Machine_Implementation_Guide-V1-00.pdf](https://github.com/aljoshakoecher/ISA88-StateMachine/blob/documentation/images/documentation/isa88-state-machine.png?raw=true)
77

@@ -10,10 +10,11 @@ As you can see in the figure, the state machine defines states and transitions t
1010
* After production of an order has been completed, the state machine will change its current state to 'Complete'. It can only be reset from this state.
1111
* When you fire a 'stop'-transition while being in 'Stopped' state, nothing happens
1212
The state machine makes sure that no invalid transitions can be fired.
13+
<br>
1314

1415
## Documentation
15-
### Simple state machine without actions
16-
To use the simplest version of the state machine in your code, you simply obtain an instance from the state machine builder. This state machine will then be in 'Idle' state and you can invoke the transitions shown in the figure above. Note that this simple state machine can just be used to simulate the state machine behavior.
16+
### A simple state machine without actions
17+
To use the simplest version of the state machine in your code, you simply obtain an instance from the state machine builder. This state machine will then be in 'Idle' state and you can invoke the transitions shown in the figure above. Note that this state machine cannot execute any actions while being in the active states and that it can just be used to simulate the state machine behavior.
1718

1819
```Java
1920
// necessary imports
@@ -35,14 +36,36 @@ stateMachine.stop();
3536
// see figure for more transitions
3637
```
3738

38-
You can also create a state machine with a different initial state than 'Idle'. This can be done with the `withInitialState(State s)`-function of the builder. Simply pass in the state you want to have as the initial state to that function.
39+
You can also create a state machine with a different initial state than 'Idle'. This can be done with the `withInitialState(State s)`-function of the builder. Simply pass in the state you want to have as the initial state to this function. The following example creates a state machine instance that start in the 'Stopped' state:
3940

4041
```java
4142
stateMachine = new StateMachineBuilder().withInitialState(new StoppedState()).build();
4243
```
4344

44-
### Creating a real state machine that executes actions
45-
The state machine of ISA88 allows for executing actions in all active states. You can create arbitrary actions and pass them to the state machine to let the state machine execute these actions in the correct states. To implement your own actions, simply implement the interface `IStateAction` as shown here:
45+
As shown above, you can invoke transitions by calling the corresponing methods (start(), stop(), hold(), ...) on the state machine. Alternatively, you can also use this more dynamic version:
46+
47+
```java
48+
invokeTransition(TransitionName transitionName)
49+
```
50+
This will invoke a transition with the given TransitionName.
51+
<br>
52+
53+
### A real state machine that executes actions
54+
The state machine of ISA88 allows for executing actions in all active states. These active states are:
55+
56+
* Starting
57+
* Execute
58+
* Holding
59+
* Unholding
60+
* Suspending
61+
* Unsuspending
62+
* Completing
63+
* Resetting
64+
* Stopping
65+
* Aborting
66+
* Clearing
67+
68+
You can create arbitrary actions and pass them to the state machine to let the state machine execute these actions in the correct states. To implement your own actions, simply implement the interface `IStateAction` as shown here:
4669

4770
```Java
4871
import states.IStateAction;
@@ -100,12 +123,21 @@ Sets action to be the action that is going to be executed when the state machine
100123
##### withActionInResetting(IStateAction action)
101124
Sets action to be the action that is going to be executed when the state machine is in 'Resetting' state.
102125

126+
<br><br>
127+
Alternatively, you can also use the more flexible way of adding actions to states:
128+
129+
```java
130+
withAction(IStateAction action, ActiveStateName stateName)
131+
```
132+
You can pass in an action and the name of an active state to add this action to a state.
133+
134+
103135
### Getting notified on state changes
104136
Work in progress, coming soon
105137

106138

107139
## Usage
108-
With Maven, it's very easy to use this library in your own projects. Releases are published to the Maven Central Repo, snapshot version can be obtained from Sonatype.
140+
With Maven, it's very easy to use this library in your own projects. Releases are published to the Maven Central Repo, snapshot version can be obtained from Sonatype. Furthermore, you could also grab the .jar from the releases on this github repository. Note that the jar is built as an OSGi-bundle and can therefore be used in an OSGi environment.
109141

110142
### Releases
111143
Releases can be found on the Maven Central repository. Just add this dependency to your pom.xml:
@@ -114,7 +146,7 @@ Releases can be found on the Maven Central repository. Just add this dependency
114146
<dependency>
115147
<groupId>com.github.aljoshakoecher</groupId>
116148
<artifactId>isa88-state-machine</artifactId>
117-
<version>1.0.0</version>
149+
<version>1.1.0</version>
118150
</dependency>
119151
```
120152

pom.xml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.github.aljoshakoecher</groupId>
66
<artifactId>isa88-state-machine</artifactId>
7-
<version>1.0.0</version>
8-
<packaging>jar</packaging>
7+
<version>1.1.0</version>
8+
<packaging>bundle</packaging>
99

1010
<name>ISA 88 State Machine</name>
1111
<description>State Machine according to ISA 88 that can be used to quickly implement a behavior that is consistent with ISA 88</description>
@@ -14,7 +14,7 @@
1414
<properties>
1515
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1616
</properties>
17-
17+
1818
<developers>
1919
<developer>
2020
<name>Aljosha Koecher</name>
@@ -58,6 +58,12 @@
5858
<release>11</release>
5959
</configuration>
6060
</plugin>
61+
<plugin>
62+
<groupId>org.apache.felix</groupId>
63+
<artifactId>maven-bundle-plugin</artifactId>
64+
<version>4.2.1</version>
65+
<extensions>true</extensions>
66+
</plugin>
6167
<plugin>
6268
<groupId>org.apache.maven.plugins</groupId>
6369
<artifactId>maven-surefire-plugin</artifactId>
@@ -142,8 +148,12 @@
142148
<version>5.6.0</version>
143149
<scope>test</scope>
144150
</dependency>
151+
<dependency>
152+
<groupId>org.junit.jupiter</groupId>
153+
<artifactId>junit-jupiter-params</artifactId>
154+
<version>5.2.0</version>
155+
<scope>test</scope>
156+
</dependency>
145157
</dependencies>
146158

147-
148-
149159
</project>
Lines changed: 58 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package statemachine;
22

3+
import states.ActiveStateName;
34
import states.IStateAction;
45
import states.NullStateAction;
56

@@ -18,158 +19,63 @@ public class StateActionManager {
1819
IStateAction actionInClearing = new NullStateAction();
1920

2021

21-
/**
22-
* @return the actionInStarting
23-
*/
24-
public IStateAction getActionInStarting() {
25-
return actionInStarting;
22+
public IStateAction getAction(ActiveStateName stateName) {
23+
switch (stateName) {
24+
case Starting:
25+
return this.actionInStarting;
26+
case Execute:
27+
return this.actionInExecute;
28+
case Completing:
29+
return this.actionInCompleting;
30+
case Holding:
31+
return this.actionInHolding;
32+
case Unholding:
33+
return this.actionInUnholding;
34+
case Suspending:
35+
return this.actionInSuspending;
36+
case Unsuspending:
37+
return this.actionInUnsuspending;
38+
case Stopping:
39+
return this.actionInStopping;
40+
case Clearing:
41+
return this.actionInClearing;
42+
case Aborting:
43+
return this.actionInAborting;
44+
case Resetting:
45+
return this.actionInResetting;
46+
default:
47+
return null;
48+
}
2649
}
27-
28-
/**
29-
* @param actionInStarting the actionInStarting to set
30-
*/
31-
protected void setActionInStarting(IStateAction actionInStarting) {
32-
this.actionInStarting = actionInStarting;
33-
}
34-
35-
/**
36-
* @return the actionInExecute
37-
*/
38-
public IStateAction getActionInExecute() {
39-
return actionInExecute;
40-
}
41-
42-
/**
43-
* @param actionInExecute the actionInExecute to set
44-
*/
45-
protected void setActionInExecute(IStateAction actionInExecute) {
46-
this.actionInExecute = actionInExecute;
47-
}
48-
49-
/**
50-
* @return the actionInCompleting
51-
*/
52-
public IStateAction getActionInCompleting() {
53-
return actionInCompleting;
54-
}
55-
56-
/**
57-
* @param actionInCompleting the actionInCompleting to set
58-
*/
59-
protected void setActionInCompleting(IStateAction actionInCompleting) {
60-
this.actionInCompleting = actionInCompleting;
61-
}
62-
63-
/**
64-
* @return the actionInSuspending
65-
*/
66-
public IStateAction getActionInSuspending() {
67-
return actionInSuspending;
68-
}
69-
70-
/**
71-
* @param actionInSuspending the actionInSuspending to set
72-
*/
73-
protected void setActionInSuspending(IStateAction actionInSuspending) {
74-
this.actionInSuspending = actionInSuspending;
75-
}
76-
77-
/**
78-
* @return the actionInUnsuspending
79-
*/
80-
public IStateAction getActionInUnsuspending() {
81-
return actionInUnsuspending;
82-
}
83-
84-
/**
85-
* @param actionInUnsuspending the actionInUnsuspending to set
86-
*/
87-
protected void setActionInUnsuspending(IStateAction actionInUnsuspending) {
88-
this.actionInUnsuspending = actionInUnsuspending;
89-
}
90-
91-
/**
92-
* @return the actionInHolding
93-
*/
94-
public IStateAction getActionInHolding() {
95-
return actionInHolding;
96-
}
97-
98-
/**
99-
* @param actionInHolding the actionInHolding to set
100-
*/
101-
protected void setActionInHolding(IStateAction actionInHolding) {
102-
this.actionInHolding = actionInHolding;
103-
}
104-
105-
/**
106-
* @return the actionInUnholding
107-
*/
108-
public IStateAction getActionInUnholding() {
109-
return actionInUnholding;
110-
}
111-
112-
/**
113-
* @param actionInUnholding the actionInUnholding to set
114-
*/
115-
protected void setActionInUnholding(IStateAction actionInUnholding) {
116-
this.actionInUnholding = actionInUnholding;
117-
}
118-
119-
/**
120-
* @return the actionInResetting
121-
*/
122-
public IStateAction getActionInResetting() {
123-
return actionInResetting;
124-
}
125-
126-
/**
127-
* @param actionInResetting the actionInResetting to set
128-
*/
129-
protected void setActionInResetting(IStateAction actionInResetting) {
130-
this.actionInResetting = actionInResetting;
131-
}
132-
133-
/**
134-
* @return the actionInStopping
135-
*/
136-
public IStateAction getActionInStopping() {
137-
return actionInStopping;
138-
}
139-
140-
/**
141-
* @param actionInStopping the actionInStopping to set
142-
*/
143-
protected void setActionInStopping(IStateAction actionInStopping) {
144-
this.actionInStopping = actionInStopping;
145-
}
146-
147-
/**
148-
* @return the actionInAborting
149-
*/
150-
public IStateAction getActionInAborting() {
151-
return actionInAborting;
152-
}
153-
154-
/**
155-
* @param actionInAborting the actionInAborting to set
156-
*/
157-
protected void setActionInAborting(IStateAction actionInAborting) {
158-
this.actionInAborting = actionInAborting;
159-
}
160-
161-
/**
162-
* @return the actionInClearing
163-
*/
164-
public IStateAction getActionInClearing() {
165-
return actionInClearing;
166-
}
167-
168-
/**
169-
* @param actionInClearing the actionInClearing to set
170-
*/
171-
protected void setActionInClearing(IStateAction actionInClearing) {
172-
this.actionInClearing = actionInClearing;
50+
51+
52+
public void setAction(IStateAction action, ActiveStateName stateName) {
53+
switch (stateName) {
54+
case Starting:
55+
this.actionInStarting = action;
56+
case Execute:
57+
this.actionInExecute = action;
58+
case Completing:
59+
this.actionInCompleting = action;
60+
case Holding:
61+
this.actionInHolding = action;
62+
case Unholding:
63+
this.actionInUnholding = action;
64+
case Suspending:
65+
this.actionInSuspending = action;
66+
case Unsuspending:
67+
this.actionInUnsuspending = action;
68+
case Stopping:
69+
this.actionInStopping = action;
70+
case Clearing:
71+
this.actionInClearing = action;
72+
case Aborting:
73+
this.actionInAborting = action;
74+
case Resetting:
75+
this.actionInResetting = action;
76+
default:
77+
break;
78+
}
17379
}
174-
80+
17581
}

0 commit comments

Comments
 (0)