Skip to Content.
Sympa Menu

notify-dpml - svn commit: r1553 - in development/laboratory/planet/components/fsm: api/src/main/net/dpml/fsm basic/src/main/net/dpml/fsm/basic demo/trafficlight/src/main/net/dpml/fsm/trafficlight

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: niclas AT netcompartner.com
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: svn commit: r1553 - in development/laboratory/planet/components/fsm: api/src/main/net/dpml/fsm basic/src/main/net/dpml/fsm/basic demo/trafficlight/src/main/net/dpml/fsm/trafficlight
  • Date: Sat, 22 Jan 2005 06:35:24 +0100

Author: niclas
Date: Sat Jan 22 06:35:24 2005
New Revision: 1553

Added:

development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/StateMachine.java
- copied, changed from r1552,
development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/TransitionMachine.java

development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/StateMachineImpl.java
- copied, changed from r1552,
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/TransitionMachineImpl.java
Removed:

development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/TransitionMachine.java

development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/TransitionMachineImpl.java
Modified:

development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/State.java

development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/Transition.java

development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/TransitionEvent.java

development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/TransitionListener.java

development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/TransitionRule.java

development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/CommandRuleComponent.java

development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/CommandRuleImpl.java

development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/StateComponent.java

development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/StateImpl.java

development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/TransitionComponent.java

development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/TransitionImpl.java

development/laboratory/planet/components/fsm/demo/trafficlight/src/main/net/dpml/fsm/trafficlight/TrafficLight.java
Log:
Completed the change from transitionmachine to fsm, and all the consequences
of that. Also added some more javadocs.

Modified:
development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/State.java
==============================================================================
---
development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/State.java
(original)
+++
development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/State.java
Sat Jan 22 06:35:24 2005
@@ -1,6 +1,5 @@
/*
- * Copyright 2004 Niclas Hedhman.
- * Created: Dec 20, 2004
+ * Copyright 2004-2005 Niclas Hedhman.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,20 +16,16 @@
* limitations under the License.
*/

-package net.dpml.transitionmachine;
+package net.dpml.fsm;

import java.util.Locale;
import java.io.Serializable;

/**
- * This interface represents each State internal in the TransitionMachine.
- * <p/>
- * Each StateImpl is defined as a Metro component, and has an Identity
(machine readable), a Name
- * and a Description, which are both human-readable in the caller's Locale.
+ * This interface represents each State internal in the StateMachine.
* <p/>
* The Name and Description is read from the java.util.ResourceBundle named
- * "net.dpml.transitionmachine.Resources", and can be either a properties
file, or a
- * net.dpml.i18n.BundleHandler.
+ * "net.dpml.fsm.Resources".
* <p/>
* For each "identity", i.e. each StateImpl, you need to have two resource
strings, with the same
* name as the identity, prepended with ".name" and ".description"
respectively. Example;
@@ -79,13 +74,13 @@
*/
String getDescription( Locale locale );

- /** Called by the TransitionMachine when this State is entered.
+ /** Called by the StateMachine when this State is entered.
* exit() on the "end" State is always called before entry() on the
* "begin" State of the Transition.
*/
void entry();

- /** Called by the TransitionMachine when this State is exited.
+ /** Called by the StateMachine when this State is exited.
* exit() on the "end" State is always called before entry() on the
* "begin" State of the Transition.
*/

Copied:
development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/StateMachine.java
(from r1552,
development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/TransitionMachine.java)
==============================================================================
---
development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/TransitionMachine.java
(original)
+++
development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/StateMachine.java
Sat Jan 22 06:35:24 2005
@@ -1,6 +1,5 @@
/*
- * Copyright 2004 Niclas Hedhman.
- * Created: Dec 20, 2004
+ * Copyright 2004-2005 Niclas Hedhman.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,30 +16,26 @@
* limitations under the License.
*/

-package net.dpml.transitionmachine;
+package net.dpml.fsm;

import java.util.Collection;

-/** The TransitionMachine interface.
+/** The StateMachine interface.
* <p/>
- * A TransitionMachine is essentially equal to a StateMachine, except that
it is Transition centric
- * instead of State centric. You can find this by examining the methods
below.
- * <p/>
- * The TransitionMachine abstraction assumes that it is completely
re-programmable on the fly,
- * but requires that the client <code>stop()</code> the TransitionMachine
prior to changing its
- * setup. This leaves the configuration method open, not only to the
implementation itself, but
- * external setup/configuration tools.
+ * The StateMachine abstraction assumes that it is completely re-programmable
+ * on the fly. This leaves the configuration method open, not only to the
+ * implementation itself, but also to external setup/configuration tools.
* <p/>
*
- * @metro.service type="net.dpml.transitionmachine.TransitionMachine"
version="1.0"
+ * @metro.service type="net.dpml.fsm.StateMachine" version="1.0"
*/
-public interface TransitionMachine
+public interface StateMachine
{

- final String BUNDLE_NAME = "net.dpml.transitionmachine.Resources";
+ final String BUNDLE_NAME = "net.dpml.fsm.Resources";

/**
- * Trigger a change in the TransitionMachine.
+ * Trigger a change in the StateMachine.
* <p/>
* The
* @param commandString The command string to be evaluated.
@@ -50,19 +45,19 @@
*/
void trigger( Object source, String commandString );

- /** Returns the State the TransitionMachine currently is in.
+ /** Returns the State the StateMachine currently is in.
* @return instance of the current state, or null if the current state is
- * unknown, which happens after the creation of the
TransitionMachine
+ * unknown, which happens after the creation of the StateMachine
* and whenever the current state is is no longer part of the
model.
*/
State getCurrentState();

- /** Add a Transition to the TransitionMachine model.
+ /** Add a Transition to the StateMachine model.
* @param transition The transition to be added.
*/
void addTransition( Transition transition );

- /** Add a Transition collection to the TransitionMachine model.
+ /** Add a Transition collection to the StateMachine model.
* Each element in the <code>transition</code> collection must
* implement the Transition interface.
*
@@ -70,22 +65,63 @@
*/
void addTransitions( Collection transitions );

- /** Remove a Transition from the TransitionMachine model.
+ /** Remove a Transition from the StateMachine model.
* @param transition The transition to be removed.
*/
void removeTransition( Transition transition );

- /** Remove all Transitions from the TransitionMachine model.
+ /** Remove all Transitions from the StateMachine model.
* After this method is called, the current state will be unknown.
*/
void removeAllTransitions();


+ /** Add a TransitionListener to the StateMachine.
+ * <p/>
+ * It is <strong>required</strong> that the implementation can handle any
+ * number of TransitionListeners.
+ * Implementations should probably delegate the management of the
+ * TransitionListeners down to the Transition itself, as to easier allow
+ * for the requirement that a TransitionListener can be register with a
+ * null transitionId argument, followed by a removeTransitionListener
+ * for one or more Transitions that is of no interest, and get the
+ * notifications for the other Transitions.
+ *
+ * @param listener the TransitionListener to be added. More than one
+ * registration of the same TransitionListener instance *must* be
+ * allowed.
+ * @param transitionId the Transition of interest, or null if all
Transitions
+ * should be notified.
+ */
void addTransitionListener( TransitionListener listener, String
transitionId );

+ /** Remove a TransitionListener from the StateMachine.
+ * If the TransitionListener is registered with a null
<code>transitionId</code>,
+ * i.e. for all Transitions, this method must ONLY remove the
+ * TransitionListener for the provided transitionId in this method call.
+
+ * @param listener the TransitionListener to remove. If more than one
+ * registration is found only one of them should be removed.
+ * @param transitionId the Transition that is no longer of interest.
+ */
void removeTransitionListener( TransitionListener listener, String
transitionId );

+ /** Remove a TransitionListener from the StateMachine.
+ * <p/>
+ * The TransitionListener is to be removed completely, and no longer is
+ * interested in any more notifications.
+ *
+ * @param listener the TransitionListener to remove. If more than one
+ * registration is found only one of them should be removed.
+ */
void removeTransitionListener( TransitionListener listener );

+ /** Resets the StateMachine into a known initial State.
+ * Reset is an asynchronous method, and implementations
<strong>must</strong>
+ * ensure that any on-going Transition is completed, prior to setting the
+ * current State into the provided <code>initialState</code>.
+ *
+ * @param initialState the State to put the StateMachine into.
+ */
void reset( State initialState );
}

Modified:
development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/Transition.java
==============================================================================
---
development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/Transition.java
(original)
+++
development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/Transition.java
Sat Jan 22 06:35:24 2005
@@ -1,6 +1,5 @@
/*
- * Copyright 2004 Niclas Hedhman.
- * Created: Dec 20, 2004
+ * Copyright 2004-2005 Niclas Hedhman.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,23 +16,24 @@
* limitations under the License.
*/

-package net.dpml.transitionmachine;
+package net.dpml.fsm;

import java.util.Locale;
import java.io.Serializable;

/**
- * This class represents each Transition coupling between the States in the
TransitionMachine.
+ * This class represents each Transition coupling between the States in the
+ * StateMachine.
* <p/>
- * Each StateImpl is defined as a Metro component, and has an Identity
(machine readable), a Name
+ * Each State has an Identity (machine readable), a Name
* and a Description, which are both human-readable in the caller's Locale.
* <p/>
* The Name and Description is read from the java.util.ResourceBundle named
- * "net.dpml.transitionmachine.Resources", and can be either a properties
file, or a
- * net.dpml.i18n.BundleHandler.
+ * "net.dpml.fsm.Resources".
* <p/>
- * For each "identity", i.e. each StateImpl, you need to have two resource
strings, with the same
- * name as the identity, prepended with ".name" and ".description"
respectively. Example;
+ * For each "identity", i.e. each State instance, you need to have two
resource
+ * strings, with the same name as the identity, prepended with ".name" and
+ * ".description" respectively. Example;
* <p/>
* <code><pre>
* reset.name=Reset
@@ -44,25 +44,75 @@
* finishedprint.description=Printing has finished, and it will return to
normal state.
* </pre></code>
*
- * @metro.service type="net.dpml.transitionmachine.Transition" version="1.0"
+ * @metro.service type="net.dpml.fsm.Transition" version="1.0"
*/
public interface Transition extends Serializable
{
+ /** Returns the TransitionRule for this Transition.
+ * @return the TransitionRule for this Transition.
+ */
TransitionRule getTransitionRule();

+ /** Return the State where the Transition is originating from.
+ * @return the State where the Transition is originating from.
+ */
State getBeginState();

+ /** Return the State to where the Transition is leading.
+ * @return the State to where the Transition is leading.
+ */
State getEndState();

+ /** Return the Identity of the Transition.
+ * <p/>
+ * The Identity is important to identify the Transition in the running
+ * system, as well as to locate the localized name and description of the
+ * Transition.
+ * @return the Identity of the Transition.
+ */
String getIdentity();

+ /** Return the Name of the Transition in the provided Locale.
+ * @return the human-readable Name of the Transition in the provided
Locale.
+ */
String getName( Locale locale );

+ /** Return the Description of the Transition in the provided Locale.
+ * @return the human-readable Description of the Transition in the
provided
+ * Locale.
+ */
String getDescription( Locale locale );

+ /** Add a TransitionListener to the Transition.
+ * <p/>
+ * It is <strong>required</strong> that the implementation can handle any
+ * number of TransitionListeners.
+ *
+ * @param listener the TransitionListener to be added. More than one
+ * registration of the same TransitionListener instance *must* be
+ * allowed.
+ */
void addTransitionListener( TransitionListener listener );

+ /** Remove a TransitionListener from the Transition.
+ * @param listener the TransitionListener to remove. If there is more
than]
+ * one entry of the TransitionListener register, only remove one
of
+ * the instances.
+ */
void removeTransitionListener( TransitionListener listener );

- State execute( Object source, TransitionMachine machine );
+ /** Called by the StateMachine to execute the Transition.
+ * <p/>
+ * The implementation should notify the begin and end States of the
exit()
+ * and entry() respectively, and notify all the TransitionListeners.
+ * The TransitionListeners <strong>must</strong> be notified after both
the
+ * States has been notified.
+ *
+ * @param source the client object instance that issued the trigger in
the
+ * StateMachine, causing the Transition to occur.
+ * @param machine the StateMachine that this Transition belongs to.
+ *
+ * @return the State that is now the new current state.
+ */
+ State execute( Object source, StateMachine machine );
}

Modified:
development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/TransitionEvent.java
==============================================================================
---
development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/TransitionEvent.java
(original)
+++
development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/TransitionEvent.java
Sat Jan 22 06:35:24 2005
@@ -1,6 +1,5 @@
/*
- * Copyright 2004 Niclas Hedhman.
- * Created: Dec 20, 2004
+ * Copyright 2004-2005 Niclas Hedhman.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,7 +16,7 @@
* limitations under the License.
*/

-package net.dpml.transitionmachine;
+package net.dpml.fsm;

import java.util.Date;
import java.io.Serializable;
@@ -34,23 +33,23 @@
static final long serialVersionUID = 1L;

private Transition m_transition;
- private TransitionMachine m_transitionMachine;
+ private StateMachine m_stateMachine;
private Object m_source;
private Date m_TransitionDate;

/** Normal constructor.
* <p/>
- * NOTE: Only TransitionMachine implementations should be instantiating
TransitionEvents.
+ * NOTE: Only StateMachine implementations should be instantiating
TransitionEvents.
*
- * @param source The source that is passed to the
<code>TransitionMachine.trigger()</code> method.
+ * @param source The source that is passed to the
<code>StateMachine.trigger()</code> method.
* @param transition The Transition that was performed.
- * @param transitionMachine The TransitionMachine instance where the
Transition was performed.
+ * @param machine The StateMachine instance where the Transition
occurred.
*/
public TransitionEvent(
- Object source, Transition transition, TransitionMachine
transitionMachine )
+ Object source, Transition transition, StateMachine machine )
{
m_transition = transition;
- m_transitionMachine = transitionMachine;
+ m_stateMachine = machine;
m_source = source;
m_TransitionDate = new Date();
}
@@ -66,20 +65,20 @@
}

/**
- * Returns the TransitionMachine from where the Transition took place.
+ * Returns the StateMachine where the Transition took place.
*
- * @return the TransitionMachine instance in which the Transition
occurred.
+ * @return the StateMachine instance in which the Transition occurred.
*/
- public TransitionMachine getTransitionMachine()
+ public StateMachine getStateMachine()
{
- return m_transitionMachine;
+ return m_stateMachine;
}

/**
- * Returns the Object that triggered the Transition from outside the
TransitionMachine.
+ * Returns the Object that triggered the Transition from outside the
StateMachine.
*
* @return the Object that was passed as the <code>source</code>
argument in the
- * <code>TransitionMachine.trigger()</code> method.
+ * <code>StateMachine.trigger()</code> method.
*/
public Object getSource()
{
@@ -129,7 +128,7 @@
{
return false;
}
- if( !m_transitionMachine.equals( event.m_transitionMachine ) )
+ if( !m_stateMachine.equals( event.m_stateMachine ) )
{
return false;
}
@@ -153,7 +152,7 @@
{
int result;
result = m_transition.hashCode();
- result = 29 * result + m_transitionMachine.hashCode();
+ result = 29 * result + m_stateMachine.hashCode();
result = 29 * result + m_source.hashCode();
result = 29 * result + m_TransitionDate.hashCode();
return result;
@@ -163,6 +162,11 @@

/** This method is used by the object serialization framework, and is
accessed through
* reflection. See the Serialization specification for details.
+ * The ObjectInputStream is read and the members are assigned. If the
+ * StateMachine and/or the Source memeber were not Serializable during
the
+ * writeObject invocation, the restored instance of this class will have
+ * these member fields set to null.
+ *
* @param in The ObjectInputStream to read the serialized values of this
instance from.
* @throws IOException when an underlying IO problem occurs.
* @throws ClassNotFoundException if the Class referenced in the
ObjectInputStream is not available
@@ -174,15 +178,19 @@
m_transition = (Transition) in.readObject();
m_TransitionDate = (Date) in.readObject();
Object placeholder = in.readObject();
- if( placeholder instanceof TransitionMachine )
- m_transitionMachine = (TransitionMachine) placeholder;
+ if( placeholder instanceof StateMachine )
+ m_stateMachine = (StateMachine) placeholder;
placeholder = in.readObject();
if( ! (placeholder instanceof Boolean ) )
m_source = placeholder;
}

- /** This method is used by the object serialization framework, and is
accessed through
- * reflection. See the Serialization specification for details.
+ /** This method is used by the object serialization framework, and is
+ * accessed through reflection. See the Serialization specification for
+ * details.
+ * The StateMachine and Source are only written to the
ObjectOutputStream
+ * if they are Serializable. The readObject is designed to handle this.
+ *
* @param out The ObjectOutputStream to write this object to.
* @throws IOException when an underlying IO problem occurs.
*/
@@ -191,9 +199,9 @@
{
out.writeObject( m_transition );
out.writeObject( m_TransitionDate );
- if( m_transitionMachine instanceof Serializable )
+ if( m_stateMachine instanceof Serializable )
{
- out.writeObject( m_transitionMachine );
+ out.writeObject( m_stateMachine );
}
else
out.writeObject( Boolean.FALSE );

Modified:
development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/TransitionListener.java
==============================================================================
---
development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/TransitionListener.java
(original)
+++
development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/TransitionListener.java
Sat Jan 22 06:35:24 2005
@@ -1,6 +1,5 @@
/*
- * Copyright 2004 Niclas Hedhman.
- * Created: Dec 20, 2004
+ * Copyright 2004-2005 Niclas Hedhman.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,15 +16,17 @@
* limitations under the License.
*/

-package net.dpml.transitionmachine;
+package net.dpml.fsm;

/**
- * The TransitionListener register itself with the TransitionMachine, and
normally performs something
- * upon a Transition occurring.
+ * The TransitionListener can be registered with the StateMachine or directly
+ * to the Transition.
* <p/>
- * Only events for Transitions that has been registered at the
TransitionMachine will be fired to the
- * TransitionListener. If all events are requested, a null argument should
have been passed to the
- * <code>TransitionMachine.addTransitionListener()</code> method. </p>
+ * Only events for Transitions that has been registered at the StateMachine
+ * or directly for the Transition in-progress will be fired to the
+ * TransitionListener. If all events are requested, a null
+ * <code>transitionId</code> argument should have been passed to the
+ * <code>StateMachine.addTransitionListener()</code> method. </p>
*/
public interface TransitionListener
{

Modified:
development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/TransitionRule.java
==============================================================================
---
development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/TransitionRule.java
(original)
+++
development/laboratory/planet/components/fsm/api/src/main/net/dpml/fsm/TransitionRule.java
Sat Jan 22 06:35:24 2005
@@ -1,6 +1,5 @@
/*
- * Copyright 2004 Niclas Hedhman.
- * Created: Dec 20, 2004
+ * Copyright 2004-2005 Niclas Hedhman.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,14 +16,14 @@
* limitations under the License.
*/

-package net.dpml.transitionmachine;
+package net.dpml.fsm;

import java.io.Serializable;

/**
* A TransitionRule is associated with a Transition.
* <p/>
- * The TransitionMachine will pass the commandString to each TransitionRule,
in priority order, and
+ * The StateMachine will pass the commandString to each TransitionRule, in
priority order, and
* perform the Transition of the first TransitionRule that returns
<code>true</code> when the
* <code>isTransition</code> method is called. A lower priority number
indicates higher priority,
* i.e. the TransitionRule list is sorted in numerical order and iterated
from low towards higher
@@ -32,15 +31,14 @@
* to compare with, even if more elaborate priority schemes are employed.
* </p>
*
- * @metro.service type="net.dpml.transitionmachine.TransitionRule"
version="1.0"
+ * @metro.service type="net.dpml.fsm.TransitionRule" version="1.0"
*/
public interface TransitionRule extends Comparable, Serializable
{
-
/**
* Returns whether the command string corresponds to this transition
rule.
*
- * @param commandString An command string passed to the
TransitionMachine.
+ * @param commandString An command string passed to the StateMachine.
*
* @return true if the Transition defined by this TransitionRule should
be performed, false
* otherwise.

Modified:
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/CommandRuleComponent.java
==============================================================================
---
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/CommandRuleComponent.java
(original)
+++
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/CommandRuleComponent.java
Sat Jan 22 06:35:24 2005
@@ -1,6 +1,5 @@
/*
- * Copyright 2004 Niclas Hedhman.
- * Created: Dec 20, 2004
+ * Copyright 2004-2005 Niclas Hedhman.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,9 +16,9 @@
* limitations under the License.
*/

-package net.dpml.transitionmachine.basic;
+package net.dpml.fsm.basic;

-import net.dpml.transitionmachine.TransitionRule;
+import net.dpml.fsm.TransitionRule;
import net.dpml.parameters.Parameters;
import net.dpml.parameters.ParameterException;

@@ -31,7 +30,7 @@
* re-programmable statemachines are needed.
*
* @metro.component name="CommandRule" lifestyle="singleton"
collection="hard"
- * @metro.service type="net.dpml.transitionmachine.TransitionRule"
+ * @metro.service type="net.dpml.fsm.TransitionRule"
*/
public class CommandRuleComponent extends CommandRuleImpl
implements TransitionRule

Modified:
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/CommandRuleImpl.java
==============================================================================
---
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/CommandRuleImpl.java
(original)
+++
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/CommandRuleImpl.java
Sat Jan 22 06:35:24 2005
@@ -1,6 +1,5 @@
/*
- * Copyright 2004 Niclas Hedhman.
- * Created: Dec 20, 2004
+ * Copyright 2004-2005 Niclas Hedhman.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,12 +16,12 @@
* limitations under the License.
*/

-package net.dpml.transitionmachine.basic;
+package net.dpml.fsm.basic;

import net.dpml.lang.NullArgumentException;
import net.dpml.parameters.Parameters;
import net.dpml.parameters.ParameterException;
-import net.dpml.transitionmachine.TransitionRule;
+import net.dpml.fsm.TransitionRule;

/**
* The CommandRule is a plain rule, that checks if the Command string is of
a particular and
@@ -53,7 +52,7 @@
/**
* Returns whether the command string corresponds to this transition
rule.
*
- * @param commandString An command string passed to the
TransitionMachine.
+ * @param commandString An command string passed to the StateMachine.
*
* @return true if the Transition defined by this TransitionRule should
be performed, false
* otherwise.

Modified:
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/StateComponent.java
==============================================================================
---
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/StateComponent.java
(original)
+++
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/StateComponent.java
Sat Jan 22 06:35:24 2005
@@ -1,6 +1,5 @@
/*
- * Copyright 2004 Niclas Hedhman.
- * Created: Dec 20, 2004
+ * Copyright 2004-2005 Niclas Hedhman.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,23 +16,20 @@
* limitations under the License.
*/

-package net.dpml.transitionmachine.basic;
+package net.dpml.fsm.basic;

import java.util.Locale;
import java.util.ResourceBundle;
import net.dpml.parameters.ParameterException;
import net.dpml.parameters.Parameters;
-import net.dpml.transitionmachine.State;
-import net.dpml.transitionmachine.TransitionMachine;
+import net.dpml.fsm.State;
+import net.dpml.fsm.StateMachine;

/**
- * This class represents each State internal in the TransitionMachine.
- * <p/>
- * Each State is defined as a Metro component, and has an Identity (machine
readable), a Name
- * and a Description, which are both human-readable in the caller's Locale.
</p>
+ * This class represents each State internal in the StateMachine.
* <p/>
* The Name and Description is read from the java.util.ResourceBundle named
- * "net.dpml.transitionmachine.Resources", and can be either a properties
file, or a
+ * "net.dpml.fsm.Resources", and can be either a properties file, or a
* net.dpml.i18n.BundleHandler. </p>
* <p/>
* For each "identity", i.e. each StateComponent, you need to have two
resource strings, with the same
@@ -50,7 +46,7 @@
* </pre></code>
*
* @metro.component name="state" lifestyle="singleton"
- * @metro.service type="net.dpml.transitionmachine.State"
+ * @metro.service type="net.dpml.fsm.State"
*/
public class StateComponent extends StateImpl
implements State

Modified:
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/StateImpl.java
==============================================================================
---
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/StateImpl.java
(original)
+++
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/StateImpl.java
Sat Jan 22 06:35:24 2005
@@ -1,6 +1,5 @@
/*
- * Copyright 2004 Niclas Hedhman.
- * Created: Dec 20, 2004
+ * Copyright 2004-2005 Niclas Hedhman.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,25 +16,21 @@
* limitations under the License.
*/

-package net.dpml.transitionmachine.basic;
+package net.dpml.fsm.basic;

import java.util.Locale;
import java.util.ResourceBundle;
import net.dpml.lang.NullArgumentException;
import net.dpml.parameters.ParameterException;
import net.dpml.parameters.Parameters;
-import net.dpml.transitionmachine.State;
-import net.dpml.transitionmachine.TransitionMachine;
+import net.dpml.fsm.State;
+import net.dpml.fsm.StateMachine;

/**
- * This class represents each State internal in the TransitionMachine.
- * <p/>
- * <p/>
- * Each StateImpl has an Identity (machine readable), a Name
- * and a Description, which are both human-readable in the caller's Locale.
</p>
+ * This class represents each State internal in the StateMachine.
* <p/>
* The Name and Description is read from the java.util.ResourceBundle named
- * "net.dpml.transitionmachine.Resources", and can be either a properties
file, or a
+ * "net.dpml.fsm.Resources", and can be either a properties file, or a
* net.dpml.i18n.BundleHandler. </p>
* <p/>
* For each "identity", i.e. each StateImpl, you need to have two resource
strings, with the same
@@ -74,13 +69,13 @@

public String getName( Locale locale )
{
- ResourceBundle bundle = ResourceBundle.getBundle(
TransitionMachine.BUNDLE_NAME, locale );
+ ResourceBundle bundle = ResourceBundle.getBundle(
StateMachine.BUNDLE_NAME, locale );
return bundle.getString( m_identity + ".name" );
}

public String getDescription( Locale locale )
{
- ResourceBundle bundle = ResourceBundle.getBundle(
TransitionMachine.BUNDLE_NAME, locale );
+ ResourceBundle bundle = ResourceBundle.getBundle(
StateMachine.BUNDLE_NAME, locale );
return bundle.getString( m_identity + ".description" );
}


Copied:
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/StateMachineImpl.java
(from r1552,
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/TransitionMachineImpl.java)
==============================================================================
---
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/TransitionMachineImpl.java
(original)
+++
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/StateMachineImpl.java
Sat Jan 22 06:35:24 2005
@@ -1,6 +1,5 @@
/*
- * Copyright 2004 Niclas Hedhman.
- * Created: Dec 20, 2004
+ * Copyright 2004-2005 Niclas Hedhman.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,7 +16,7 @@
* limitations under the License.
*/

-package net.dpml.transitionmachine.basic;
+package net.dpml.fsm.basic;

import java.util.Collection;
import java.util.HashMap;
@@ -25,33 +24,33 @@
import java.util.TreeSet;
import java.util.WeakHashMap;
import net.dpml.activity.Startable;
-import net.dpml.transitionmachine.State;
-import net.dpml.transitionmachine.Transition;
-import net.dpml.transitionmachine.TransitionListener;
-import net.dpml.transitionmachine.TransitionMachine;
-import net.dpml.transitionmachine.TransitionRule;
+import net.dpml.fsm.State;
+import net.dpml.fsm.StateMachine;
+import net.dpml.fsm.Transition;
+import net.dpml.fsm.TransitionListener;
+import net.dpml.fsm.TransitionRule;

/**
- * Basic TransitionMachine implementation.
+ * Basic StateMachine implementation.
*
- * @metro.component name="basic-transitionmachine" lifestyle="singleton"
collection="hard"
- * @metro.service type="net.dpml.transitionmachine.TransitionMachine"
+ * @metro.component name="basic-statemachine" lifestyle="singleton"
collection="hard"
+ * @metro.service type="net.dpml.fsm.StateMachine"
*/
-public class TransitionMachineImpl
- implements TransitionMachine
+public class StateMachineImpl
+ implements StateMachine
{
private HashMap m_transitions;
private WeakHashMap m_crossIndex;
private State m_currentState;

- public TransitionMachineImpl()
+ public StateMachineImpl()
{
m_transitions = new HashMap();
m_crossIndex = new WeakHashMap();
}

/**
- * Trigger a change in the TransitionMachine.
+ * Trigger a change in the StateMachine.
*
* @param commandString The command string to be evaluated.
*/
@@ -125,6 +124,7 @@
{
m_transitions.clear();
m_crossIndex.clear();
+ m_currentState.exit();
m_currentState = null;
}
}
@@ -162,6 +162,7 @@
synchronized( this )
{
m_currentState = initialState;
+ m_currentState.entry();
}
}
}

Modified:
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/TransitionComponent.java
==============================================================================
---
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/TransitionComponent.java
(original)
+++
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/TransitionComponent.java
Sat Jan 22 06:35:24 2005
@@ -1,5 +1,22 @@
+/*
+ * Copyright 2004-2005 Niclas Hedhman.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * 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.
+ */

-package net.dpml.transitionmachine.basic;
+package net.dpml.fsm.basic;

import java.util.ArrayList;
import java.util.Iterator;
@@ -14,16 +31,16 @@
import net.dpml.service.ServiceException;
import net.dpml.service.ServiceManager;

-import net.dpml.transitionmachine.State;
-import net.dpml.transitionmachine.Transition;
-import net.dpml.transitionmachine.TransitionEvent;
-import net.dpml.transitionmachine.TransitionListener;
-import net.dpml.transitionmachine.TransitionMachine;
-import net.dpml.transitionmachine.TransitionRule;
+import net.dpml.fsm.State;
+import net.dpml.fsm.StateMachine;
+import net.dpml.fsm.Transition;
+import net.dpml.fsm.TransitionEvent;
+import net.dpml.fsm.TransitionListener;
+import net.dpml.fsm.TransitionRule;

/**
* @metro.component name="transition" lifestyle="transient" collection="hard"
- * @metro.service type="net.dpml.transitionmachine.Transition"
+ * @metro.service type="net.dpml.fsm.Transition"
*/
public class TransitionComponent
implements Transition
@@ -44,14 +61,14 @@
* @throws ServiceException if the "begin" and "end" StateImpl
dependencies can not be
* satisfied.
*
- * @metro.logger name="transitionmachine"
+ * @metro.logger name="fsm"
*
* @metro.entry key="urn:metro:name"
* type="java.lang.String"
- * @metro.dependency key="begin" type="net.dpml.transitionmachine.State"
- * @metro.dependency key="end" type="net.dpml.transitionmachine.State"
- * @metro.dependency key="tm"
type="net.dpml.transitionmachine.TransitionMachine"
- * @metro.dependency key="rule"
type="net.dpml.transitionmachine.TransitionRule"
+ * @metro.dependency key="begin" type="net.dpml.fsm.State"
+ * @metro.dependency key="end" type="net.dpml.fsm.State"
+ * @metro.dependency key="fsm" type="net.dpml.fsm.StateMachine"
+ * @metro.dependency key="rule" type="net.dpml.fsm.TransitionRule"
*/
public TransitionComponent( ServiceManager man, Context ctx, Logger
logger )
throws ContextException, ServiceException
@@ -62,7 +79,7 @@
m_beginState = beginState;
State endState = (State) man.lookup( "end" );
m_endState = endState;
- TransitionMachine sm = (TransitionMachine) man.lookup( "tm" );
+ StateMachine sm = (StateMachine) man.lookup( "fsm" );
sm.addTransition( this );
m_Rule = (TransitionRule) man.lookup( "rule" );

@@ -91,22 +108,22 @@

public String getName( Locale locale )
{
- ResourceBundle bundle = ResourceBundle.getBundle(
TransitionMachine.BUNDLE_NAME, locale );
+ ResourceBundle bundle = ResourceBundle.getBundle(
StateMachine.BUNDLE_NAME, locale );
return bundle.getString( m_identity + ".name" );
}

public String getDescription( Locale locale )
{
- ResourceBundle bundle = ResourceBundle.getBundle(
TransitionMachine.BUNDLE_NAME, locale );
+ ResourceBundle bundle = ResourceBundle.getBundle(
StateMachine.BUNDLE_NAME, locale );
return bundle.getString( m_identity + ".description" );
}

- public State execute( Object source, TransitionMachine tm )
+ public State execute( Object source, StateMachine fsm )
{
m_beginState.exit();
m_endState.entry();

- TransitionEvent event = new TransitionEvent( source, this, tm );
+ TransitionEvent event = new TransitionEvent( source, this, fsm );
Iterator list;
synchronized( m_listeners )
{

Modified:
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/TransitionImpl.java
==============================================================================
---
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/TransitionImpl.java
(original)
+++
development/laboratory/planet/components/fsm/basic/src/main/net/dpml/fsm/basic/TransitionImpl.java
Sat Jan 22 06:35:24 2005
@@ -1,5 +1,22 @@
+/*
+ * Copyright 2004-2005 Niclas Hedhman.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * 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.
+ */

-package net.dpml.transitionmachine.basic;
+package net.dpml.fsm.basic;

import java.util.ArrayList;
import java.util.Iterator;
@@ -10,12 +27,12 @@

import net.dpml.logging.Logger;

-import net.dpml.transitionmachine.State;
-import net.dpml.transitionmachine.Transition;
-import net.dpml.transitionmachine.TransitionEvent;
-import net.dpml.transitionmachine.TransitionListener;
-import net.dpml.transitionmachine.TransitionMachine;
-import net.dpml.transitionmachine.TransitionRule;
+import net.dpml.fsm.State;
+import net.dpml.fsm.StateMachine;
+import net.dpml.fsm.Transition;
+import net.dpml.fsm.TransitionEvent;
+import net.dpml.fsm.TransitionListener;
+import net.dpml.fsm.TransitionRule;

/** A non-Metro implementation of a basic Transition.
* This is the equivalent of the TransitionComponent, except that it does not
@@ -82,22 +99,22 @@

public String getName( Locale locale )
{
- ResourceBundle bundle = ResourceBundle.getBundle(
TransitionMachine.BUNDLE_NAME, locale );
+ ResourceBundle bundle = ResourceBundle.getBundle(
StateMachine.BUNDLE_NAME, locale );
return bundle.getString( m_identity + ".name" );
}

public String getDescription( Locale locale )
{
- ResourceBundle bundle = ResourceBundle.getBundle(
TransitionMachine.BUNDLE_NAME, locale );
+ ResourceBundle bundle = ResourceBundle.getBundle(
StateMachine.BUNDLE_NAME, locale );
return bundle.getString( m_identity + ".description" );
}

- public State execute( Object source, TransitionMachine tm )
+ public State execute( Object source, StateMachine fsm )
{
m_beginState.exit();
m_endState.entry();

- TransitionEvent event = new TransitionEvent( source, this, tm );
+ TransitionEvent event = new TransitionEvent( source, this, fsm );
Iterator list;
synchronized( m_listeners )
{

Modified:
development/laboratory/planet/components/fsm/demo/trafficlight/src/main/net/dpml/fsm/trafficlight/TrafficLight.java
==============================================================================
---
development/laboratory/planet/components/fsm/demo/trafficlight/src/main/net/dpml/fsm/trafficlight/TrafficLight.java
(original)
+++
development/laboratory/planet/components/fsm/demo/trafficlight/src/main/net/dpml/fsm/trafficlight/TrafficLight.java
Sat Jan 22 06:35:24 2005
@@ -1,6 +1,5 @@
/*
- * Copyright 2004 Niclas Hedhman.
- * Created: Dec 21, 2004
+ * Copyright 2004-2005 Niclas Hedhman.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,7 +16,7 @@
* limitations under the License.
*/

-package net.dpml.transitionmachine.trafficlight.demo;
+package net.dpml.fsm.trafficlight;

import java.io.Serializable;

@@ -28,14 +27,17 @@
import java.util.Locale;

import net.dpml.activity.Startable;
+
import net.dpml.parameters.Parameters;
+
import net.dpml.service.ServiceException;
import net.dpml.service.ServiceManager;
-import net.dpml.transitionmachine.Transition;
-import net.dpml.transitionmachine.TransitionEvent;
-import net.dpml.transitionmachine.TransitionListener;
-import net.dpml.transitionmachine.TransitionMachine;
-import net.dpml.transitionmachine.State;
+
+import net.dpml.fsm.State;
+import net.dpml.fsm.StateMachine;
+import net.dpml.fsm.Transition;
+import net.dpml.fsm.TransitionEvent;
+import net.dpml.fsm.TransitionListener;

/**
* This TrafficLight implements a traffic light, by cycling the states
according to the selected
@@ -51,32 +53,32 @@
implements Runnable, Startable, Serializable, TransitionListener
{

- private TransitionMachine m_transitionMachine;
- private ArrayList m_internationalTransitions;
- private ArrayList m_swedishTransitions;
- private Thread m_thread;
- private boolean m_run;
- private State m_red;
- private boolean m_type;
+ private StateMachine m_stateMachine;
+ private ArrayList m_internationalTransitions;
+ private ArrayList m_swedishTransitions;
+ private Thread m_thread;
+ private boolean m_run;
+ private State m_red;
+ private boolean m_type;

/**
* @param man ServiceManager servicing this Part.
*
* @throws ServiceException if any of the required dependencies can not
be satisfied.
- * @metro.dependency type="net.dpml.transitionmachine.TransitionMachine"
key="tm"
- * @metro.dependency type="net.dpml.transitionmachine.Transition"
key="red-to-green"
- * @metro.dependency type="net.dpml.transitionmachine.Transition"
key="green-to-yellow"
- * @metro.dependency type="net.dpml.transitionmachine.Transition"
key="yellow-to-red"
- * @metro.dependency type="net.dpml.transitionmachine.Transition"
key="red-to-redyellow"
- * @metro.dependency type="net.dpml.transitionmachine.Transition"
key="redyellow-to-green"
- * @metro.dependency type="net.dpml.transitionmachine.Transition"
key="green-to-greenyellow"
- * @metro.dependency type="net.dpml.transitionmachine.Transition"
key="greenyellow-to-red"
+ * @metro.dependency type="net.dpml.fsm.TransitionMachine" key="fsm"
+ * @metro.dependency type="net.dpml.fsm.Transition" key="red-to-green"
+ * @metro.dependency type="net.dpml.fsm.Transition" key="green-to-yellow"
+ * @metro.dependency type="net.dpml.fsm.Transition" key="yellow-to-red"
+ * @metro.dependency type="net.dpml.fsm.Transition"
key="red-to-redyellow"
+ * @metro.dependency type="net.dpml.fsm.Transition"
key="redyellow-to-green"
+ * @metro.dependency type="net.dpml.fsm.Transition"
key="green-to-greenyellow"
+ * @metro.dependency type="net.dpml.fsm.Transition"
key="greenyellow-to-red"
*/
public TrafficLight( ServiceManager man, Parameters params )
throws ServiceException
{
System.out.println( "Creating Trafficlight." );
- m_transitionMachine = (TransitionMachine) man.lookup( "tm" );
+ m_stateMachine = (StateMachine) man.lookup( "fsm" );

m_internationalTransitions = new ArrayList();
m_swedishTransitions = new ArrayList();
@@ -125,8 +127,8 @@
*/
public void international()
{
- m_transitionMachine.removeAllTransitions();
- m_transitionMachine.addTransitions( m_internationalTransitions );
+ m_stateMachine.removeAllTransitions();
+ m_stateMachine.addTransitions( m_internationalTransitions );
}

/**
@@ -134,8 +136,8 @@
*/
public void swedish()
{
- m_transitionMachine.removeAllTransitions();
- m_transitionMachine.addTransitions( m_swedishTransitions );
+ m_stateMachine.removeAllTransitions();
+ m_stateMachine.addTransitions( m_swedishTransitions );
}

public void start()
@@ -156,7 +158,7 @@
{
m_run = true;
String command = "tick";
- m_transitionMachine.reset( m_red );
+ m_stateMachine.reset( m_red );
try
{
while( m_run )
@@ -164,7 +166,7 @@
synchronized( this )
{
wait( 5000 );
- m_transitionMachine.trigger( this, command );
+ m_stateMachine.trigger( this, command );
}
}
} catch( InterruptedException e )



  • svn commit: r1553 - in development/laboratory/planet/components/fsm: api/src/main/net/dpml/fsm basic/src/main/net/dpml/fsm/basic demo/trafficlight/src/main/net/dpml/fsm/trafficlight, niclas, 01/22/2005

Archive powered by MHonArc 2.6.24.

Top of Page