Skip to content

Commit

Permalink
FSM service and Emoji Service
Browse files Browse the repository at this point in the history
  • Loading branch information
supertick committed Mar 4, 2019
1 parent 727e2a7 commit da2903d
Show file tree
Hide file tree
Showing 32 changed files with 4,624 additions and 2,813 deletions.
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ Apache License
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright {yyyy} {name of copyright owner}
Copyright 2019 Greg Perry, Kevin Watters

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -198,4 +198,4 @@ Apache License
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
4 changes: 3 additions & 1 deletion src/main/java/org/myrobotlab/codec/Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ static public Message uriToMsg(String uri) {

if (parts.length < 4) {
// /api/service OR /api/service/
msg.method = "getEnvironments";
msg.method = "getEnvironments"; // Big one - webgui client depends on ..
// msg.method = "getServiceNames";
// msg.method = "getPlatform";
} else if (parts.length == 4) {
msg.name = "runtime";
if (requestUri.endsWith("/")) {
Expand Down
12 changes: 0 additions & 12 deletions src/main/java/org/myrobotlab/framework/ProcessData.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,6 @@ public ProcessData(ProcessData pd) {
this.in.add(pd.in.get(i));
}
}

// this.process = pd.process;
// this.startTs = System.currentTimeMillis();
// monitor = new Monitor(this);
// monitor.start();
}

/*
Expand All @@ -151,11 +146,6 @@ public ProcessData(Agent service, String jarPath, String[] inArgs, String defaul
ProcessData.service = service;
this.jarPath = jarPath;

// String protectedDomain =
// URLDecoder.decode(Agent.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath(),
// "UTF-8");
// log.info("protected domain {}", protectedDomain);

// convert to ArrayList to process
in = new ArrayList<String>();

Expand All @@ -167,8 +157,6 @@ public ProcessData(Agent service, String jarPath, String[] inArgs, String defaul
continue;
}

// if (inCmdLine.containsKey("-jvm") && inCmdLine.getArgumentCount("-jvm")
// > 0) {
if (cmd.equals("-jvm")) {
String tmp = inCmdLine.getArgument("-jvm", 0);
jvm = tmp.split(" ");
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/myrobotlab/framework/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ public class Task extends TimerTask {

String taskName;
Message msg;
int interval = 0;
long interval = 0;
Service myService;

// FIXME upgrade to ScheduledExecutorService
// http://howtodoinjava.com/2015/03/25/task-scheduling-with-executors-scheduledthreadpoolexecutor-example/

public Task(Service myService, String taskName, int interval, Message msg) {
public Task(Service myService, String taskName, long interval, Message msg) {
this.myService = myService;
this.taskName = taskName;
this.interval = interval;
Expand Down
70 changes: 70 additions & 0 deletions src/main/java/org/myrobotlab/fsm/api/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* The MIT License
*
* Copyright (c) 2017, Mahmoud Ben Hassine ([email protected])
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.myrobotlab.fsm.api;

import org.myrobotlab.fsm.util.Utils;

import java.util.Date;

/**
* Abstract class for events to which a FSM should react and make transitions.
*
* @author Mahmoud Ben Hassine ([email protected])
*/
public abstract class Event {

protected String name;
protected long timestamp;

protected Event() {
this.name = Utils.DEFAULT_EVENT_NAME;
timestamp = System.currentTimeMillis();
}

protected Event(final String name) {
this.name = name;
timestamp = System.currentTimeMillis();
}

public String getName() {
return name;
}

public long getTimestamp() {
return timestamp;
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append("Event");
sb.append("{name='").append(name).append('\'');
sb.append(", timestamp=").append(new Date(timestamp));
sb.append('}');
return sb.toString();
}

public abstract String getId();

}
41 changes: 41 additions & 0 deletions src/main/java/org/myrobotlab/fsm/api/EventHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* The MIT License
*
* Copyright (c) 2017, Mahmoud Ben Hassine ([email protected])
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.myrobotlab.fsm.api;


/**
* Abstraction for actions to perform when an event is triggered.
*
* @author Mahmoud Ben Hassine ([email protected])
*/
public interface EventHandler {

/**
* Action method to execute when an event occurs.
* @param event the triggered event
* @throws Exception thrown if a problem occurs during action performing
*/
void handleEvent(Event event) throws Exception;

}
90 changes: 90 additions & 0 deletions src/main/java/org/myrobotlab/fsm/api/FiniteStateMachine.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* The MIT License
*
* Copyright (c) 2017, Mahmoud Ben Hassine ([email protected])
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.myrobotlab.fsm.api;


import java.util.List;
import java.util.Set;

/**
* FSM interface. This is the main abstraction for a finite state machine.
*
* @author Mahmoud Ben Hassine ([email protected])
*/
public interface FiniteStateMachine {

/**
* Return current FSM state.
* @return current FSM state
*/
State getCurrentState();

/**
* Return FSM initial state.
* @return FSM initial state
*/

// State getInitialState();

/**
* Return FSM final states.
* @return FSM final states
*/
Set<State> getFinalStates();

/**
* Return FSM registered states.
* @return FSM registered states
*/
Set<State> getStates();

/**
* Return FSM registered transitions.
* @return FSM registered transitions
*/
Set<Transition> getTransitions();

/**
* Return the last triggered event.
* @return the last triggered event
*/
Event getLastEvent();

/**
* Return the last transition made.
* @return the last transition made
*/
Transition getLastTransition();

/**
* Fire an event. According to event type, the FSM will make the right transition.
* @param event to fire
* @return The next FSM state defined by the transition to make
* @throws FiniteStateMachineException thrown if an exception occurs during event handling
*/
// State fire(Event event) throws FiniteStateMachineException;

List<String> fire(Event event) throws FiniteStateMachineException;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* The MIT License
*
* Copyright (c) 2017, Mahmoud Ben Hassine ([email protected])
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.myrobotlab.fsm.api;


/**
* Exception thrown if a problem occurs during event handling.
* This class gives access to the {@link Transition} and {@link Event} related to the exception.
*
* @author Mahmoud Ben Hassine ([email protected])
*/
public class FiniteStateMachineException extends Exception {

/**
* The transition where the exception occurred.
*/
private Transition transition;

/**
* The event triggered when the exception occurred.
*/
private Event event;

/**
* The root cause of the exception.
*/
private Throwable cause;

/**
* Create a new {@link FiniteStateMachineException}.
*
* @param transition where the exception occurred
* @param event triggered when the exception occurred
* @param cause root cause of the exception
*/
public FiniteStateMachineException(final Transition transition, final Event event, final Throwable cause) {
this.transition = transition;
this.event = event;
this.cause = cause;
}

/**
* Get the transition where the exception occurred.
* @return the transition where the exception occurred.
*/
public Transition getTransition() {
return transition;
}

/**
* Get the event triggered when the exception occurred.
* @return the event triggered when the exception occurred.
*/
public Event getEvent() {
return event;
}

/**
* Get the root cause of the exception.
* @return the root cause of the exception
*/
public Throwable getCause() {
return cause;
}
}
Loading

0 comments on commit da2903d

Please sign in to comment.