Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7746875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:23:31+00:00 2026-06-01T10:23:31+00:00

I am using Stateless to implement FSM’s in multiple classes. ( http://code.google.com/p/stateless/ ) I

  • 0

I am using Stateless to implement FSM’s in multiple classes. (http://code.google.com/p/stateless/)

I want to use a base class for firing triggers and logging, etc..
I also want to enforce that any class inheriting my baseFSM class implements a StateMachine with their own local States and Triggers.

However my problem is, enum’s cannot be abstracted or passed to functions.

By the way, Stateless says “Generic support for states and triggers of any .NET type (numbers, strings, enums, etc.)” so if there is a better way to go about this let me know.

Ideally this is what I would like to implement (or something that can work the same way).

BaseFSM class:

public abstract class BaseFSM : IStateMachine
{
    #region Implementation of IStateMachine

    public ICall LocalCall { get; set; }

    #endregion

    internal abstract enum State {}
    internal abstract enum Trigger {}

    internal abstract StateMachine<State, Trigger> fsm { get; set; }

    public abstract void Fire(Enum trigger);
}

A class that implements BaseFSM:

class Incoming_Initial : BaseFSM
{
    private enum State
    {
        WaitForCallToBeAnswered,
        CallConnected,
        CallNeverConnected,
        CheckForCustomIntro,
        PlayIntro,
        PlayPleaseEnterPin,
        ReadLanguageSettings,
        ChooseLanguage,
        ValidatePIN,
        PINWasInvalid,
        IdentifyUser
    }

    private enum Trigger
    {
        Yes,
        No,
        DigitPressed,
        PromptDonePlaying,
        PromptTimerElapse,
        Done
    }

    public Incoming_Initial(ICall call)
    {
        LocalCall = call;
        fsm = new StateMachine<this.State, this.Trigger>(State.WaitForCallToBeAnswered);
        ....

OR I would even take something like this:

public class myStateMachine
{
    private enum State{}
    private enum Trigger{}
    private StateMachine<State, Trigger> stateMachine;

    public myStateMachine (Enum _states, Enum _triggers, Enum _startState)
    {
        State = _states;
        Trigger = _triggers;

        stateMachine = new StateMachine<State, Trigger>(_startState);
    }
}

Any insight on how I can go about implementing this would be greatly appreciated!

Edit: My ultimate goal is using Stateless to implement an IVR (IVR) system that has ~40 different FSM’s. The state machines will be responsible for call flow and how the user interacts with the system. I already have a demo state machine working, but the States and Triggers are local to that class.

I am just trying to see if I can pull the state machine out to a base class so I don’t have to pass the state machine to helper functions.

If I can put the state machine in a base class, I think I could use one set of Triggers (these would be events from the phone call like CallConnected, UserPressedDigit, CallDisconnected, PromptDonePlaying, etc) and only have to implement States for each FSM.

ANSWER (at least how I am using this) thanks to @phoog:

     public abstract class BaseFSM <TState> : IStateMachine
    {
        #region Implementation of IStateMachine

        public ICall LocalCall { get; set; }

        #endregion

        public enum Triggers
        {
            Yes = 0,
            No,
            DigitPressed,
            PromptDonePlaying,
            PromptTimerElapse,
            Done
        }

        protected IList<TState> States { get; set; }
        protected StateMachine<TState, Triggers> fsm { get; set; }
        ...

    class Incoming_Initial : BaseFSM<Incoming_Initial.State>
    {
        internal enum State
        {
            WaitForCallToBeAnswered,
            CallConnected,
            CallNeverConnected,
            CheckForCustomIntro,
            PlayIntro,
            PlayPleaseEnterPin,
            ReadLanguageSettings,
            ChooseLanguage,
            ValidatePIN,
            PINWasInvalid,
            IdentifyUser
        }

        public Incoming_Initial(ICall call)
        {
            LocalCall = call;
            LocalCall.CallEventHandler += new CallEventHandler(LocalCall_CallEventHandler);

            States = (State[]) Enum.GetValues(typeof (State));

            fsm = new StateMachine<State, Triggers>(State.WaitForCallToBeAnswered);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:23:33+00:00Added an answer on June 1, 2026 at 10:23 am

    Note that the Enum type represents a reference to a boxed value of an enum; it doesn’t refer to the entire enum type. So, for example, this code is valid:

    enum Something { Value0, Value1, Value2, Value3 }
    void ProcessAnEnumValue(Enum value)
    {
        //...whatever
    }
    void CallTheMethod()
    {
        ProcessAnEnumValue(Something.Value2);
    }
    

    You are trying to parameterize the entire enum type; the tool for parameterizing types is generics. With that in mind, your code could be made to work with some modifications:

    public abstract class BaseFSM<TState, TTrigger> : IStateMachine 
    {
        #region Implementation of IStateMachine 
        public ICall LocalCall { get; set; } 
        #endregion 
    
        protected IList<TState> States { get; set; }
        protected IList<TTrigger> Triggers { get; set; }
    
        protected StateMachine<TState, TTrigger> fsm { get; set; } 
    
        public abstract void Fire(TTrigger trigger); 
    } 
    
    class Incoming_Initial : BaseFSM<Incoming_Initial.State, Incoming_Initial.Trigger>
    { 
        public enum State 
        { 
            WaitForCallToBeAnswered, 
            CallConnected, 
            CallNeverConnected, 
            CheckForCustomIntro, 
            PlayIntro, 
            PlayPleaseEnterPin, 
            ReadLanguageSettings, 
            ChooseLanguage, 
            ValidatePIN, 
            PINWasInvalid, 
            IdentifyUser 
        } 
    
        public enum Trigger 
        { 
            Yes, 
            No, 
            DigitPressed, 
            PromptDonePlaying, 
            PromptTimerElapse, 
            Done 
        } 
    
        public Incoming_Initial(ICall call) 
        { 
            States = (State[])Enum.GetValues(typeof(State));
            Triggers = (Trigger[])Enum.GetValues(typeof(Trigger));
    
            LocalCall = call; 
            fsm = new StateMachine<State, Trigger>(State.WaitForCallToBeAnswered); 
            .... 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement stateless session bean ejb3 in jboss5 using netbeans6.8 as a
Say I have the following EJB (using ejb3): @Stateless(name=Queries) @Remote(Queries.class) @Local(Queries.class) public final class
Using NetBeans 7.1 / GlassFish 3.1, I created a new TimerSessionBean. @Stateless public class
I am currently running a simple EJB application using a stateless Session Bean. I
Starting a new project using EJB 3 / JPA, mainly stateless session beans and
i have created a demo application Using JSF & EJB 3.0 (Stateless session bean
I want to create a timer EJB3 when a stateless bean is created in
I have simple map-reduce type algorithm, which I want to implement in python and
I'm working on a large legacy application using stateless session beans that has recently
I'm trying to implement an ejb-call by using JNDI-naming. Setup: JBoss-6.1.0.Final ear-deploy: gwt.war ejb.jar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.