yung 4 днів тому
батько
коміт
beb0803adc
1 змінених файлів з 299 додано та 76 видалено
  1. 299 76
      src/actorBase.ts

+ 299 - 76
src/actorBase.ts

@@ -1,17 +1,18 @@
+import { Interface } from "readline"
 import { Observer, Subject, Subscribable, Unsubscribable } from "rxjs"
 /*Fis actor to declare its own subscribable but extended from RXJS */
 
 
-/*  ===========Actor Message Mode Start =============
+/*  ===========Message Schema Mode =============
 
-    Following intefaces pertain to an Actor messaging model.
+    Following intefaces pertain to messaging model.
     Declared as interfaces so that new member elements can be 
     added. This definition only list type of messages recognised 
     by the base Actor. Messages streamed from subscribables if 
     necessary need to be mapped to message type recognised by 
     the actor.
     
-    The concrete actor will need to add type
+    The concrete message will need to add type
     of schema corresponding to each of the message type in the 
     message model (refer to src.common.messageModel.messageSchema)
     
@@ -19,24 +20,38 @@ import { Observer, Subject, Subscribable, Unsubscribable } from "rxjs"
     
     */
 
-interface messageSchemaType {
-    undefined:  "UNDEFINED" // when not defined
-    element:    "ELEMENT" // fundamental unit
-    composite:  "COMPOSITE" // has other schema
-}
 
 export interface MessageSchemaService extends CRUD {
     /*  collection of method signatures*/
 }
 
-export class MessageSchemaDataModel {
-    schemaId!:       string // identifier 
-    schemaName!:     string // unique legible name
-    schemaDef!:      string // jason description of schema
-    schemaType!:     messageSchemaType // one of selection 
+export interface MessageSchema {
+    schemaId:       string // identifier 
+    schemaName:     string // unique legible name
+    schemaDef:      string // jason description of schema
 }
 
-export interface MessageSchema {
+export interface MessageNameSchemaMap {
+/* mapping message name to message schema by 
+    message domain */
+    messageName:    string
+    schemaId:       string
+    messageDomain:  string
+    /*  a same message name can be used in different domain
+        but with different schema.  */
+}
+export class MessageNameSchemMapImpl implements MessageNameSchemaMap {
+    messageName!:    string
+    schemaId!:       string
+    messageDomain!:  string //"DEFAULT"  "ACTOR" "CQRSACTOR"
+    constructor (schemaId: string, messageDomain: string) {
+        /*  all constructor parameter values to be provided upon creation. 
+            Class unique by all fields */
+
+    } 
+}
+
+export interface MessageSchemaModel {
 /*  Descsription steriotype for all Fis messages.
     Has reference to message schema described as interfaces.
     MessageSchema is a network structure (not a tree hierarchy) where
@@ -45,11 +60,11 @@ export interface MessageSchema {
     schema, or lowest node.
     On handling version of message schema, refer to version model
 */
-    messageSchemaDataModel: MessageSchemaDataModel
+    messageSchema: MessageSchema
     messageSchemaService: MessageSchemaService
 }
 
-export class MessageSchemaCompositeAssociation {
+export class MessageSchemaComposite {
 /*  Associated nodes of a composite schema.*/
     messageSchema: MessageSchema
     compositeEntries: Array <MessageSchema>[]
@@ -65,32 +80,22 @@ export class MessageSchemaCompositeAssociation {
          - messageSchema is the container of composite entries */
 }
 
-/*  ======= the following section to be filed as:
-    src/common/grouping/ ============ */
 
-export class GroupDataModel {
-/*  Grouping of any entity. */
-    groupId!     : string // unique value
-    groupName!   : string // unique value
-    groupShortName!  : string // can be duplicated
-}
+export class MessageSchemaGrouping {}
+/* multi-level grouping message schema type */ 
 
-export class GroupChildDataModel {
-    childrenList!    : Array<GroupDataModel>[]
-}
 
 
-export class MessageSchemaGrouping {}
 
-export class MessageSchemaImpl implements MessageSchema {
+export class MessageSchemaModelImpl implements MessageSchemaModel {
 
-    messageSchemaDataModel: MessageSchemaDataModel
+    messageSchema: MessageSchema
     messageSchemaService: MessageSchemaService
-
-    constructor (messageSchemaDataModel: MessageSchemaDataModel,
+    
+    constructor (messageSchema: MessageSchema,
         messageSchemaService: MessageSchemaService
     ) {
-        this.messageSchemaDataModel = messageSchemaDataModel
+        this.messageSchema = messageSchema
         this.messageSchemaService = messageSchemaService
     }
     /*  base validation:
@@ -105,10 +110,27 @@ export class MessageSchemaImpl implements MessageSchema {
 }
 
 
+/*  ======= the following section to be filed as:
+    src/common/grouping/ ============ 
+    
+    This section to be completed ....
+    
+    */
 
+export class GroupDataModel {
+/*  Grouping of any entity. */
+    groupId!     : string // unique value
+    groupName!   : string // unique value
+    groupShortName!  : string // can be duplicated
+}
+        
+export class GroupChildDataModel extends GroupDataModel{
+    groupChildList!    : Array<GroupDataModel>[]
+}
+          
 
-/*  this section of the code to be saved in file 
-    src/common/services/ */
+/*  ======= this section of the code to be saved in file 
+    src/common/services/ ========*/
 
 export interface CRUD {
     /*  standard method signature for common entity behaviour*/
@@ -139,66 +161,266 @@ export class FisError extends Error {
 
 
 
-export interface ActorCommands { 
-/*  base actor commands*/
-    Subscribe: "SUBSCRIBE", // subsribe to incoming bus
+/*  ======= 
+    Message names recognized by Actor. Names are defined
+    as object constants. Can be extended via object union.
+
+       
+    file: ..src/common/fisactor/messages ========*/
+
+/* Actor finite state */
+export const ActorFiniteState = { 
+/*  Actor finite state. Refer to Actor FSM doc. 
+    For CQRS Actor which is an 'extension' to Actor,
+    only one command is executed at any one time.*/
+    Initialising: "INITIALISING", 
+    Ready: "READY", 
+    Executing: "EXECUTING", 
+    Paused: "PAUSED", 
+    ShuttingDown: "SHUTTINGDOWN", 
+    Terminated: "TERMINATED" 
+} as const
+
+
+/** Below section: Define Actor message names (enumerators) */
+export const CommandsTemp = {
+    Initialise: "INITIALISE", // initialise after created
+    Start:  "START", // start listening and responding
+    Subscribe:  "SUBSCRIBE", // subscribe a subscribable
     UnSubscribe: "UNSUBSCRIBE", // unsubscribe a subscribable
-    Initialise: "INITIALISE", // initialise to ready actor
-    Reset:  "RESET", // reset actor to initial state
-    ShutDown: "SHUTDOWN" // shutdown actor
+    Pause:  "PAUSE", // pause further execution 
+    Reset:  "RESET", // reset to initial state
+    ShutDown: "SHUTDOWN", // shutdown
+ } as const
+
+//////
+
+export type ActorMessageName = string
+
+export interface ActorMessages <T> {
+    // command requests
+    Initialise: T       // initialise after created
+    Start:  T           // start listening and responding
+    UnSubscribe: T      // unsubscribe a subscribable
+    Pause:  T           // pause further execution 
+    Reset:  T           // reset to initial state
+    ShutDown: T         // shutdown   
+
+    // query requests
+    GetActorIdentifier: T
+    GetActorState:  T
+    GetSubscribables: T // return list of subscribable identities
+    GetSubscribabers: T, // return list of observer identities
+
+    // query responses
+    QueryData: T
+    QuerySummary: T // return list of subscribable identities
+    QueryStatus: T, // return list of observer identities
+
+    // subscription requests
+    Subscribe:  T
+    
+    // subscription responses
+    subscriptionData:   T
+    subscriptionSummary: T
+    subscriptionStatus: T
+
+    // general request status
+    RequestReceived: T // received and que
+    RequestCancelled: T // cancelled from que
+    RequestExeStarted: T
+    RequestExeEnded: T
+    RequestCompleted: T
+    RequestUnRecognised: T
+    RequestExecutionError: T
+
+    // notification: irrecoverable error
+    InternalError: T // within actor
+    EnvironmentError: T // due to external factor
+    UnknownError: T // unable to identify source
+    
+}
+
+export class ActorMessagesNameImpl <MessageName> implements ActorMessages <string> {
+    Initialise = "INITIALISE"       // initialise after created
+    Start = "START"           // start listening and responding
+    UnSubscribe = "UNSUBSCRIBE"     // unsubscribe a subscribable
+    Pause = "PAUSE"           // pause further execution 
+    Reset = "RESET"       // reset to initial state
+    ShutDown = "SHUTDOWN"      // shutdown   
+
+    // query requests
+    GetActorIdentifier = "GETACTORIDENTIFIER"
+    GetActorState = "GETACTORSTATE"
+    GetSubscribables = "GETSUBSCRIBABLES" // return list of subscribable identities
+    GetSubscribabers = "GETSUBSCRIBERS" // return list of observer identities
+
+    // query responses
+    QueryData = "QUERYDATA"
+    QuerySummary = "QUERYSUMMARY" // return list of subscribable identities
+    QueryStatus = "QUERYSTATUS" // return list of observer identities
+
+    // subscription requests
+    Subscribe = "SUBSCRIBE"
+    
+    // subscription responses
+    subscriptionData = "SUBSCRIPTIONDATA"
+    subscriptionSummary = "SUBSCRIPTIONSUMMARY"
+    subscriptionStatus = "SUBSCRIPTIONSTATUS"
+
+    // general request status
+    RequestReceived = "REQUESTRECEIVED" // received and que
+    RequestCancelled = "REQUESTCANCELLED" // cancelled from que
+    RequestExeStarted = "REQUESTEXESTARTED"
+    RequestExeEnded = "REQUESTEXEENDED"
+    RequestExeSuccessful = "REQUESTEXESUCCESSFUL"
+    RequestUnRecognised = "REQUESTUNRECOGNISED"
+    RequestExeError = "REQUESTEXEERROR"
+
+    // notification: irrecoverable error
+    InternalError = "INTERNALERROR" // within actor
+    EnvironmentError = "ENVIRONMENTERROR" // due to external factor
+    UnknownError = "UNKNOWNERROR" // unable to identify source
+
 }
-export interface ActorCommandStatus { 
+
+export interface ActorCommands <T>  {
+    Initialise: T     // initialise after created
+    Start:  T         // start listening and responding
+    Subscribe:  T     // subscribe a subscribable
+    UnSubscribe: T  // unsubscribe a subscribable
+    Pause:  T             // pause further execution 
+    Reset:  T             // reset to initial state
+    ShutDown: T        // shutdown
+    
+ }
+
+/** Below section: Define Actor message names (enumerators) */
+export class ActorCommandNamesImpl <MessageName> implements ActorCommands <string> {
+    Initialise = "INITIALISE" // initialise after created
+    Start = "START" // start listening and responding
+    Subscribe = "SUBSCRIBE" // subscribe a subscribable
+    UnSubscribe = "UNSUBSCRIBE" // unsubscribe a subscribable
+    Pause = "PAUSE" // pause further execution 
+    Reset = "RESET" // reset to initial state
+    ShutDown = "SHUTDOWN" // shutdown
+ }
+
+//////
+
+/** Below section: Define Actor message names (enumerators) */
+export const Commands = {
+    Initialise: "INITIALISE", // initialise after created
+    Start:  "START", // start listening and responding
+    Subscribe:  "SUBSCRIBE", // subscribe a subscribable
+    UnSubscribe: "UNSUBSCRIBE", // unsubscribe a subscribable
+    Pause:  "PAUSE", // pause further execution 
+    Reset:  "RESET", // reset to initial state
+    ShutDown: "SHUTDOWN", // shutdown
+ } as const
+
+export const CommandResponses = {
     CommandReceived: "COMMANDRECEIVED", // received and que
     CommandCancelled: "COMMANDCANCELLED", // cancelled from que
-    CommandExeStarted: "COMMANDEXESTARTS",
+    CommandExeStarted: "COMMANDEXESTARTED",
     CommandExeEnded: "COMMANDEXEENDED",
-    CommandCompleted: "COMMANDCOMPLETED"
-}
-export interface ActorCommandError {
-/* recoverable errors */
-    UnRecognisedCommand: "UNRECOGNISEDCOMMAND"
+    CommandCompleted: "COMMANDCOMPLETED",
+    UnRecognisedCommand: "UNRECOGNISEDCOMMAND",
     CommandExecutionError: "COMMANDEXECUTIONERROR"
-}
-export interface CommandNotification {
-    ActorCommandStatus: ActorCommandStatus
-    ActorCommandError: ActorCommandError
-}
+}   as const
 
-export interface ActorQuery { 
+export const Queries = {
+    
     GetActorIdentifier: "GETACTORIDENTY",
     GetSubscribables: "GETSUBSCRIBABLES", // return list of subscribable identities
     GetSubscribabers: "GETSUBSCRIBERS", // return list of observer identities
-}
-export interface ActorQueriesResponse { 
-    QueryData: "GETACTORIDENTY",
-    QuerySummary: "GETSUBSCRIBABLES", // return list of subscribable identities
-    QueryStatus: "GETSUBSCRIBERS", // return list of observer identities
-}
-export interface ActorIrrecoverableError { 
+}   as const
+
+export const QueryResponses = {
+    QueryData: "QUERYDATA",
+    QuerySummary: "QUERYSUMMARY", // return list of subscribable identities
+    QueryStatus: "QUERYSTATUS", // return list of observer identities
+}   as const
+
+export const Subscriptions = { 
+    Subscribe:  "SUBSCRIBE"
+}   as const
+
+export const SubscriptionResponses = {
+    subscriptionData:   "SUBSCRIPTIONDATA",
+    subscriptionSummary: "SUBSCRIPTIONSUMMARY",
+    subscriptionStatus: {
+        Completed: "COMPLETED",
+        Error: "ERROR"                        
+    }
+} as const
+
+export const IrrecoverableError = {
     InternalError: "INTERNAL ERROR", // withinn actor
     EnvironmentError: "ENVIRONMENTERROR", // outside actor
-    UnknownError: "UNKNOWNERROR" } // unable to identify
-export interface ActorNotification { 
-    ActorLifeCycle: ActorFiniteState, 
-    ActorIrrecoverableError: ActorIrrecoverableError
+    UnknownError: "UNKNOWNERROR" // unable to identify
+} as const
+
+export const StateChanged = "STATECHANGED" as const
+
+export const RequestMessages = {
+    Commands,
+    Queries,
+    Subscriptions
 }
-export interface ActorFiniteState { 
-    Initialising: "INITIALISING", 
-    Ready: "READY", 
-    Executing: "EXECUTING", 
-    Paused: "PAUSED", 
-    ShuttingDown: "SHUTDOWN", 
-    Ended: "ENDED" 
+
+/** Following Section: Fis message schema */
+
+export interface FisMessageSchema {
+    /** Standard Fis message schema definition */
+    schemaId:       string
+    messageName:    string
+}
+
+/** Following Section: Actor message schema */
+
+export interface ActorMessageSchema {
+/*  schema definition of an Actor message.
+    T correspond to a message group such as ActorCommands */
+
+    messageType!:   T // e.g. "SUBSCRIBE", "GETACTORIDENTITY"
+    schemaId!:      S
+
+    constructor (messageType: T, messageSchema: S) {}
 }
-//export type actorMessageModel = (commands: ActorCommands, queries: ActorQueries)
 
-/*  ===========Actor Message Model End ============= */
 
 
-interface ActorService { 
+/* ======= file: ..src/common/fisactor/services ============*/
+
+export class ActorCommandServicesImpl { 
 /*  Stateful actor service to be instantiated by concrete class.
     To add in behaviour and model state repository */
+    
+    context :ActorServicesContext
+    // commandService = this.context
+
+    constructor (context: ActorServicesContext) {
+        this.context = context
+    }
+    
+    executeCommand (command: string) {
+        /* 
+         */
+        return null}
 }
+    
+
+interface ActorQueryServices { 
+/*  Stateful actor service to be instantiated by concrete class.
+    To add in behaviour and model state repository */
+}
+
+interface ActorSubscriptionServices { 
+/*  Stateful actor service to be instantiated by concrete class.
+    To add in behaviour and model state repository */
+}
+
 
 interface ActorContext<T> { 
 /*  Environment within which actor operates. Provided by creator in 
@@ -208,9 +430,10 @@ interface ActorContext<T> {
     defaultSubscribables: FisActor<T>[]
     /*  instances of actors to auto subscribe to upon creation.
         This would include the Supervisor */
+//    actorMessages: 
 }
 
-interface ActorServiceContext { 
+export interface ActorServicesContext { 
 /* environment within which the actor service operates */
 }