Announcement

Collapse
No announcement yet.

Can someone explain how to convert a plugin to support Multiple Instances

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can someone explain how to convert a plugin to support Multiple Instances

    I'm trying to convert an existing plugin to allow multiple instances. the documentation and sample plugin don't help all that much.

    I need to understand the architecture of how the plugin behavior changes with multiple instances. How does hs3 interact with/call the plugin?

    I want the instances to run completely independently. that is, HS3 should call the correct instance based on the device definition (dv.interfaceinstance=x) i don't want to have to manage this.

    Regarding SupportsMultipleInstancesSingleEXE, what are the coding requirements for setting this to True vs False? this property seems to change the behavior of the Plugin Manage page

    For registered config pages, is the URL parameter config?instance=x necessary if you give the instance config link a unique name (ie link=config_instancex)?

    any guidance would be appreciated

    Mark

    HS3 Pro 3.0.0.534
    Hardware: Insteon Serial PLM | AD2USB for Vista Alarm | HAI Omnistat2 | 1-Wire HA7E | RFXrec433 | Dahua Cameras | LiftMaster Internet Gateway
    Plugins: Insteon (mine) | Vista Alarm (mine) | Omnistat 3 (by Kirby) | Ultra1Wire3 | RFXCOM | NetCAM | MyQ | BLRadar | BLDenon | Jon00 Charting
    Platform: HP h8-1360t, Windows Server 2012 R2, i7-3.4GHz, 16GB memory

  • #2
    Originally posted by mnsandler View Post
    I'm trying to convert an existing plugin to allow multiple instances. the documentation and sample plugin don't help all that much.

    I need to understand the architecture of how the plugin behavior changes with multiple instances. How does hs3 interact with/call the plugin?

    I want the instances to run completely independently. that is, HS3 should call the correct instance based on the device definition (dv.interfaceinstance=x) i don't want to have to manage this.

    Regarding SupportsMultipleInstancesSingleEXE, what are the coding requirements for setting this to True vs False? this property seems to change the behavior of the Plugin Manage page

    For registered config pages, is the URL parameter config?instance=x necessary if you give the instance config link a unique name (ie link=config_instancex)?

    any guidance would be appreciated
    Hi Mark, see if I can answer a few of your questions:

    Yes you need to return true on the SupportsMultipleInstanceSingleExe call AND the SupportsMultipleInstances call .

    HS will do everything exactly the same as a normal PI, so a comm channel will be established through Main() and initIO will be called. My implementation is to set a boolean that indicates that this first instance is THE MAIN instance. Now I start calling AddInstance (with an instance name which is unique) for each instance I need, which in turns will do exactly the same that happens for your main instance ie a comm channel will be created for EACH instance and InitIO will be called with your unique instance name (which you store). After this, HS can call each instance directly, no need for you to do anything. If you study the Addinstance code, you see that each instance is added to a SortedList, so from your MAIN instance, you can now use that SortedList so manage (add/remove) your instances, whereas all instances now are ships in the night, and work totally independent. The beauty of them being one single exe is that you can pass pointers between them. For example, when I create another instance, I always pass a pointer to what I call the main instance into the child instances, so the children can call functions in main. Sounds confusing, think of it this way, the children know about the parent but have zero visibility into their siblings so any info or calls you want to make between children, I typically do through the parent. In my case, the parent instance typically does all the house keeping from starting up the right instances, create weblinks etc, deal with shutdowns, create directories, create and maintain the .ini file etc.

    As to your question on web (config) pages; yes you create them with unique names as you need and if you use the instancename with say RegisterLink(wpd), HS will automatically call the right PI instance, again, nothing you need to do special. However, one thing to remember, if you create multiple config pages with same content, just for different devices, you need to make sure that any of the jsquery objects you put on the page have a UNIQUE name as well. So when I create a webpage, I pass the instance name into the page and use it. See example here
    Public Sub New(ByVal pagename As String)
    MyBase.New(pagename)
    MyPageName = pagename
    NavigationBox = New clsJQuery.jqListBoxEx("NavigationBox", pagename)

    Ok, last but not least, calls from HS wrt SetIOEx I do need to do my own lookup and figure out from the HSRef that was received, to which instance it belongs. I do all of this through lookup tables in my .ini file but you could store that info directly into the HSDevice.

    Hope this info gives you some direction.

    Dirk

    Comment


    • #3
      Thanks Dirk, it helps.

      SetIOEx does not call the correct Instance of the plugin, strange. So dv.InterfaceInstance is only for our use, but hs doesn't bother with it?

      If one were to set SupportsMultipleInstanceSingleExe = False, how does that change how HS interfaces with the plugin instances? it appears HS allows you to create additional instances right on the Manage Plugin page, however, it doesn't seem to 'start' a new copy of the plugin code.

      Mark

      HS3 Pro 3.0.0.534
      Hardware: Insteon Serial PLM | AD2USB for Vista Alarm | HAI Omnistat2 | 1-Wire HA7E | RFXrec433 | Dahua Cameras | LiftMaster Internet Gateway
      Plugins: Insteon (mine) | Vista Alarm (mine) | Omnistat 3 (by Kirby) | Ultra1Wire3 | RFXCOM | NetCAM | MyQ | BLRadar | BLDenon | Jon00 Charting
      Platform: HP h8-1360t, Windows Server 2012 R2, i7-3.4GHz, 16GB memory

      Comment


      • #4
        Originally posted by mnsandler View Post
        Thanks Dirk, it helps.

        SetIOEx does not call the correct Instance of the plugin, strange. So dv.InterfaceInstance is only for our use, but hs doesn't bother with it?

        If one were to set SupportsMultipleInstanceSingleExe = False, how does that change how HS interfaces with the plugin instances? it appears HS allows you to create additional instances right on the Manage Plugin page, however, it doesn't seem to 'start' a new copy of the plugin code.
        Let’s jusy say that’s how I did it in setioex. I may need to check my code again, could be that it can directly call PI.
        Not sure what the function in Hs does to add additional instances, whether these are child instance or, I suspect main instances. I allow to run more than one instance of the whole PI, I use this for people who run a version local and one remote (ex beach house).

        Comment


        • #5
          Dirk,

          i guess there are at least two uses cases for multiple instances: (1) running multiple instances on the same hs server, and (2) running one locally and one remotely (ie beach house that talks back to the hs server). i think for the short term, i'm dealing with #1

          do you also have to save the users instances, and start them each time, or does HS manage this once the user creates the instances? or is the user responsible for starting the instances?

          why is none of this documented anywhere...

          Mark

          HS3 Pro 3.0.0.534
          Hardware: Insteon Serial PLM | AD2USB for Vista Alarm | HAI Omnistat2 | 1-Wire HA7E | RFXrec433 | Dahua Cameras | LiftMaster Internet Gateway
          Plugins: Insteon (mine) | Vista Alarm (mine) | Omnistat 3 (by Kirby) | Ultra1Wire3 | RFXCOM | NetCAM | MyQ | BLRadar | BLDenon | Jon00 Charting
          Platform: HP h8-1360t, Windows Server 2012 R2, i7-3.4GHz, 16GB memory

          Comment


          • #6
            Originally posted by mnsandler View Post
            Dirk,

            i guess there are at least two uses cases for multiple instances: (1) running multiple instances on the same hs server, and (2) running one locally and one remotely (ie beach house that talks back to the hs server). i think for the short term, i'm dealing with #1

            do you also have to save the users instances, and start them each time, or does HS manage this once the user creates the instances? or is the user responsible for starting the instances?

            why is none of this documented anywhere...
            You can run multiple instances of the PI on the same server, doesn’t really matter, they would have different instance names for what I call the main instance of the PI. See these as multiple executables doing totally their own thing!! You can run them on same pc or different, I support them to run totally remotely so the user what have to manually start them but I suspect you can use the Hs add instance function to run multiple executables, think of them as totally separate PIs. Multiple instances within the same exe is something your PI does. So yes my PI keeps track of which child instances I need and when the main instance gets created, my PI takes care of creating the children. I’m pretty sure HS does not create your child instances but it will kick off multiple versions of your executable . May sounds frustrating but once you get your mind around it, it is pretty straight forward. I guess being there from day one probably helped me a lot, meaning I would ask Rich if I couldn’t get my head around it when we were doing alpha testing of HS3.
            Hang in there and just ask me questions
            Dirk

            Comment


            • #7
              Dirk,
              Can you check your code, i think we are talking about using the following: SupportsMultipleInstances=True and SupportsMultipleInstancesSingleEXE=False

              if i set SupportsMultipleInstancesSingleEXE=True, the manage plugin page allows you to add instances


              Ignore the above i think i got the setting backwards

              SupportsMultipleInstancesSingleEXE=True seems to rely on the plugin to create another instance, or requires the user starting the exe again with the instance argument
              Mark

              HS3 Pro 3.0.0.534
              Hardware: Insteon Serial PLM | AD2USB for Vista Alarm | HAI Omnistat2 | 1-Wire HA7E | RFXrec433 | Dahua Cameras | LiftMaster Internet Gateway
              Plugins: Insteon (mine) | Vista Alarm (mine) | Omnistat 3 (by Kirby) | Ultra1Wire3 | RFXCOM | NetCAM | MyQ | BLRadar | BLDenon | Jon00 Charting
              Platform: HP h8-1360t, Windows Server 2012 R2, i7-3.4GHz, 16GB memory

              Comment


              • #8
                Originally posted by mnsandler View Post
                Dirk,
                Can you check your code, i think we are talking about using the following: SupportsMultipleInstances=True and SupportsMultipleInstancesSingleEXE=False

                if i set SupportsMultipleInstancesSingleEXE=True, the manage plugin page allows you to add instances


                Ignore the above i think i got the setting backwards

                SupportsMultipleInstancesSingleEXE=True seems to rely on the plugin to create another instance, or requires the user starting the exe again with the instance argument
                OK, just got home and I see no option to add instances for my PIs. When I change the PI code and return false for SupportsMultipleInstancesSingleEXE I do see the add instance and when I use it, it asks me to enter an instance name, which seems to kick off a new instance of the PI itself, or at least that how my code deals with it.

                Comment


                • #9
                  Dirk,

                  I'm still not sure i understand exactly what SupportsMultipleInstancesSingleEXE does? is it just a UI feature?

                  i can start the plugin exe from a cmd prompt with argument instance=test regardless of the SingleEXE value and still see another instance on the plugin manage page.

                  how do you debug a second running instance? I'm using VS15

                  Mark

                  HS3 Pro 3.0.0.534
                  Hardware: Insteon Serial PLM | AD2USB for Vista Alarm | HAI Omnistat2 | 1-Wire HA7E | RFXrec433 | Dahua Cameras | LiftMaster Internet Gateway
                  Plugins: Insteon (mine) | Vista Alarm (mine) | Omnistat 3 (by Kirby) | Ultra1Wire3 | RFXCOM | NetCAM | MyQ | BLRadar | BLDenon | Jon00 Charting
                  Platform: HP h8-1360t, Windows Server 2012 R2, i7-3.4GHz, 16GB memory

                  Comment


                  • #10
                    Originally posted by mnsandler View Post
                    Dirk,

                    I'm still not sure i understand exactly what SupportsMultipleInstancesSingleEXE does? is it just a UI feature?

                    i can start the plugin exe from a cmd prompt with argument instance=test regardless of the SingleEXE value and still see another instance on the plugin manage page.

                    how do you debug a second running instance? I'm using VS15
                    I use it internal to my PI to create a separate instance for each player (sonos or MediaController) the PI manages, so each instance runs 100% independent and HS can call it directly (or through scripting calls). I could have set SupportsMultipleInstancesSingleEXE to false and had the user create a dedicate instance for each player, but that would be a lot less user friendly AND it would be impossible to communicate (easily) between the instance NOR have a "master" overlooking the instances. Sonos has a lot of behaviors that are more system wide (discover players, link them etc) and I coded these in my main instance and the individual instance are one for each active player.

                    Comment


                    • #11
                      Dirk,
                      I'm back at this now that i have the hw to run two alarm panels from the same hs server.

                      I'm stuck on web UI. since this plugin was a port from hs2 to hs3, i'm still using genpage and pageput (as opposed to the new hs3 ui methods). I don't think this should be an issue.

                      i guess what i thought would happen is the two different instances would each have their own webpages objects associated with the hspi object (so they would be logically linked). that is, i create my own webinterface object during InitIO. Thus I wouldn't need to deal with the 'instance' URL parameter assuming the underlying code already took the instance value (from the hspi object) into account

                      is HS only using one webpage (the first one registered) object to support all instances? Thus there is no need to register a second page with a second instance

                      I really wish there was better documentation on all of this rjh
                      Mark

                      HS3 Pro 3.0.0.534
                      Hardware: Insteon Serial PLM | AD2USB for Vista Alarm | HAI Omnistat2 | 1-Wire HA7E | RFXrec433 | Dahua Cameras | LiftMaster Internet Gateway
                      Plugins: Insteon (mine) | Vista Alarm (mine) | Omnistat 3 (by Kirby) | Ultra1Wire3 | RFXCOM | NetCAM | MyQ | BLRadar | BLDenon | Jon00 Charting
                      Platform: HP h8-1360t, Windows Server 2012 R2, i7-3.4GHz, 16GB memory

                      Comment


                      • #12
                        Originally posted by mnsandler View Post
                        Dirk,
                        I'm back at this now that i have the hw to run two alarm panels from the same hs server.

                        I'm stuck on web UI. since this plugin was a port from hs2 to hs3, i'm still using genpage and pageput (as opposed to the new hs3 ui methods). I don't think this should be an issue.

                        i guess what i thought would happen is the two different instances would each have their own webpages objects associated with the hspi object (so they would be logically linked). that is, i create my own webinterface object during InitIO. Thus I wouldn't need to deal with the 'instance' URL parameter assuming the underlying code already took the instance value (from the hspi object) into account

                        is HS only using one webpage (the first one registered) object to support all instances? Thus there is no need to register a second page with a second instance

                        I really wish there was better documentation on all of this rjh
                        My webpages are objects and I instantiate them, one for each player and I give them unique names and then call HS to register the page and create a weblink. Then I pass a reference to the HSPI object associated with the player into the web object and now the web-code is almost like and extension to the HSPI class.
                        By passing the proper Instance Name, ie. the name you used to instantiate HSPI objects, HS will now call back the right instance of HSPI.PostbackProc when anything on that webpage changed.
                        Clear as mud?
                        Dirk
                        ps I use GetPagePlugIn and not GenPage/PagePut

                        Comment


                        • #13
                          I've been through this pain - I never managed to get the single EXE option working correctly (I think there is still a complete lack of information about how to handle this), I can tell I had pain with it as it is one of the only times I have put swear words in my code comments.

                          When I call .RegisterLink I pass in the WebPageDesc which contains the instance name, I don't think that matter is particularly well documented and IIRC I was not getting my web pages called and that was the reason why. I only call RegisterLink once when the plugin is launched, each instance gets a separate link.



                          My Plugins:

                          Pushover 3P | DoorBird 3P | Current Cost 3P | Velleman K8055 3P | LAMetric 3P | Garadget 3P | Hive 3P |
                          Yeelight 3P | Nanoleaf 3P

                          Comment


                          • #14
                            Originally posted by mrhappy View Post
                            I've been through this pain - I never managed to get the single EXE option working correctly (I think there is still a complete lack of information about how to handle this), I can tell I had pain with it as it is one of the only times I have put swear words in my code comments.

                            When I call .RegisterLink I pass in the WebPageDesc which contains the instance name, I don't think that matter is particularly well documented and IIRC I was not getting my web pages called and that was the reason why. I only call RegisterLink once when the plugin is launched, each instance gets a separate link.


                            thanks for the info.

                            so what is your working solution return value for SupportsMultipleInstancesSingleEXE?

                            regarding RegisterLink; sounds like you registering unique links (eg. primary instance is '/plugin', and a second instance is '/plugin_instance2'. is that right?

                            i'm struggling as to how to debug one or both of the running instances. (im using vs2015 with vb.net)
                            Mark

                            HS3 Pro 3.0.0.534
                            Hardware: Insteon Serial PLM | AD2USB for Vista Alarm | HAI Omnistat2 | 1-Wire HA7E | RFXrec433 | Dahua Cameras | LiftMaster Internet Gateway
                            Plugins: Insteon (mine) | Vista Alarm (mine) | Omnistat 3 (by Kirby) | Ultra1Wire3 | RFXCOM | NetCAM | MyQ | BLRadar | BLDenon | Jon00 Charting
                            Platform: HP h8-1360t, Windows Server 2012 R2, i7-3.4GHz, 16GB memory

                            Comment


                            • #15
                              Just to clarify, using RegisterConfigLink, I only register one "config page". This page hold settable items that are common to all instances in the PI, I also call it my main instance with no-instance name (empty string). Then for each player I discover, I instantiate an HSPI object (using AddInstance) and provide it with a unique name. HS actually builds a communication channel for each instance, so even though you are running as a single .exe, there are now multiple comm channels between HS and each instance, this is how all your instances can run in their own space. This InstanceName must be used to call all HS functions that expect you to call them with. Now for each player, I register a webpage (use RegisterPage) but add them to the dropdown list when you click on Plugins by calling RegisterLinkEx with the WebPageDesc info properly set with Instancename etc.
                              As to your question of debugging, indeed all the code in HSPI is the same for each instance you created, so if you set breakpoints, you need to check which instance just got interrupted but in general that has never given me too many issues but be aware of it. I store the instanceName as a variable in the HSPI instance, so I would always use it to add to any logging statement so you know which instance is doing what.

                              Comment

                              Working...
                              X