Pre-init hook for container worker/class component?

#1

Hi All,

I have an ApplicationSession container like the following, and I’m wondering if there is any way to run some code before the class is constructed, which would be run with the configured “pythonpath”. I’d like to perform some static configuration on my class before it is actually constructed. Or perhaps there is a better way of thinking about this?

{

“controller”: {

},

“workers”: [

{

“type”: “container”,

“options”: {

“pythonpath”: ["/home/scott/projects/ParaView/build-make-debug/lib/site-packages","/home/scott/projects/ParaView/build-make-debug/lib"]

},

“components”: [

{

“type”: “class”,

“classname”: “paraview.web.pv_web_visualizer._VisualizerServer”,

“realm”: “vtkweb”,

“transport”: {

“type”: “websocket”,

“endpoint”: {

“type”: “tcp”,

“host”: “127.0.0.1”,

“port”: 8080

},

“url”: “ws://127.0.0.1:8080/ws”,

“debug”: true

}

}

]

}

]

}

Thanks!

Scott

0 Likes

#2

Hi Scott,

> I have an ApplicationSession container like the following, and I'm

wondering if there is any way to run some code before the class is
constructed, which would be run with the configured "pythonpath". I'd

Yes. In fact, Crossbar.io will be happy with anything "callable" instead of class that takes a ComponentConfig and returns an object that derives of ApplicationSession:

class _VisualizerServer(ApplicationSession):
    ...

def makeSession(config):

    ## tweak class _VisualizerServer here ..

    session = _VisualizerServer(config)
    return session

and then

"classname": "paraview.web.pv_web_visualizer._makeSession",

Does that do what you want?

Note: because of this option, "classname" is properly illnamed ..

Cheers,
/Tobias

PS: In case you really want to know how it's done, here are the relevant code pointers for creating sessions running side-by-side in a router:

https://github.com/crossbario/crossbar/blob/master/crossbar/crossbar/worker/router.py#L470

https://github.com/crossbario/crossbar/blob/master/crossbar/crossbar/worker/router.py#L513

and here is similar for containers:

https://github.com/crossbario/crossbar/blob/master/crossbar/crossbar/worker/container.py#L186
https://github.com/crossbario/crossbar/blob/master/crossbar/crossbar/worker/container.py#L243

···

like to perform some static configuration on my class before it is
actually constructed. Or perhaps there is a better way of thinking
about this?

{
    "controller": {
    },
    "workers": [
       {
          "type": "container",
          "options": {
             "pythonpath":
["/home/scott/projects/ParaView/build-make-debug/lib/site-packages","/home/scott/projects/ParaView/build-make-debug/lib"]
          },
          "components": [
             {
                "type": "class",
                "classname":
"paraview.web.pv_web_visualizer._VisualizerServer",
                "realm": "vtkweb",
                "transport": {
                   "type": "websocket",
                   "endpoint": {
                      "type": "tcp",
                      "host": "127.0.0.1",
                      "port": 8080
                   },
                   "url": "ws://127.0.0.1:8080/ws",
                   "debug": true
                }
             }
          ]
       }
    ]
}

Thanks!
Scott

--
You received this message because you are subscribed to the Google
Groups "Autobahn" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to autobahnws+...@googlegroups.com
<mailto:autobahnws+...@googlegroups.com>.
To post to this group, send email to autob...@googlegroups.com
<mailto:autob...@googlegroups.com>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/autobahnws/af87a47f-de12-43ed-8f6c-c7ae2c1d9410%40googlegroups.com
<https://groups.google.com/d/msgid/autobahnws/af87a47f-de12-43ed-8f6c-c7ae2c1d9410%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

0 Likes

#3

Hi Tobias,

Responses inline below…

Hi Scott,

I have an ApplicationSession container like the following, and I’m

wondering if there is any way to run some code before the class is

constructed, which would be run with the configured “pythonpath”. I’d

Yes. In fact, Crossbar.io will be happy with anything “callable” instead
of class that takes a ComponentConfig and returns an object that derives
of ApplicationSession:

class _VisualizerServer(ApplicationSession):

...

def makeSession(config):

## tweak class _VisualizerServer here ..



session = _VisualizerServer(config)

return session

and then

“classname”: “paraview.web.pv_web_visualizer._makeSession”,

Does that do what you want?

I think this will do what I need, as long as I can add arbitrary json structure to the configuration object that I can make use of in my makeSession function. I’ll check it out and get back to you.

Note: because of this option, “classname” is properly illnamed …

Cheers,

/Tobias

PS: In case you really want to know how it’s done, here are the relevant
code pointers for creating sessions running side-by-side in a router:

https://github.com/crossbario/crossbar/blob/master/crossbar/crossbar/worker/router.py#L470

https://github.com/crossbario/crossbar/blob/master/crossbar/crossbar/worker/router.py#L513

and here is similar for containers:

https://github.com/crossbario/crossbar/blob/master/crossbar/crossbar/worker/container.py#L186

https://github.com/crossbario/crossbar/blob/master/crossbar/crossbar/worker/container.py#L243

Thanks for the code pointers, that makes it easier to get right to the relevant source.

Thanks again for all your help Tobias, it is making investigation much smoother :slight_smile:

Cheers,

Scott

···

On Saturday, August 30, 2014 12:43:18 AM UTC-6, Tobias Oberstein wrote:

like to perform some static configuration on my class before it is

actually constructed. Or perhaps there is a better way of thinking

about this?

{

"controller": {
},
"workers": [
   {
      "type": "container",
      "options": {
         "pythonpath":

["/home/scott/projects/ParaView/build-make-debug/lib/site-packages","/home/scott/projects/ParaView/build-make-debug/lib"]

      },
      "components": [
         {
            "type": "class",
            "classname":

“paraview.web.pv_web_visualizer._VisualizerServer”,

            "realm": "vtkweb",
            "transport": {
               "type": "websocket",
               "endpoint": {
                  "type": "tcp",
                  "host": "127.0.0.1",
                  "port": 8080
               },
               "url": "ws://[127.0.0.1:8080/ws](http://127.0.0.1:8080/ws)",
               "debug": true
            }
         }
      ]
   }
]

}

Thanks!

Scott

You received this message because you are subscribed to the Google

Groups “Autobahn” group.

To unsubscribe from this group and stop receiving emails from it, send

an email to autobahnws+...@googlegroups.com

mailto:autobahnws+unsub...@googlegroups.com.

To post to this group, send email to auto...@googlegroups.com

mailto:autob...@googlegroups.com.

To view this discussion on the web visit

https://groups.google.com/d/msgid/autobahnws/af87a47f-de12-43ed-8f6c-c7ae2c1d9410%40googlegroups.com

<https://groups.google.com/d/msgid/autobahnws/af87a47f-de12-43ed-8f6c-c7ae2c1d9410%40googlegroups.com?utm_medium=email&utm_source=footer>.

For more options, visit https://groups.google.com/d/optout.

0 Likes

#4

Hi Tobias,

Responses inline below…

Hi Scott,

I have an ApplicationSession container like the following, and I’m

wondering if there is any way to run some code before the class is

constructed, which would be run with the configured “pythonpath”. I’d

Yes. In fact, Crossbar.io will be happy with anything “callable” instead
of class that takes a ComponentConfig and returns an object that derives
of ApplicationSession:

class _VisualizerServer(ApplicationSession):

...

def makeSession(config):

## tweak class _VisualizerServer here ..



session = _VisualizerServer(config)

return session

and then

“classname”: “paraview.web.pv_web_visualizer._makeSession”,

Does that do what you want?

I think this will do what I need, as long as I can add arbitrary json structure to the configuration object that I can make use of in my makeSession function. I’ll check it out and get back to you.

It seems that an “extra” field is allowed inside the “class” type component, and can be some arbitrary json object. Is this what we should use to pass some extra configuration that we can do what we want with?

Thanks!

Scott

···

On Tuesday, September 2, 2014 10:50:24 AM UTC-6, Scott Wittenburg wrote:

On Saturday, August 30, 2014 12:43:18 AM UTC-6, Tobias Oberstein wrote:

Note: because of this option, “classname” is properly illnamed …

Cheers,

/Tobias

PS: In case you really want to know how it’s done, here are the relevant
code pointers for creating sessions running side-by-side in a router:

https://github.com/crossbario/crossbar/blob/master/crossbar/crossbar/worker/router.py#L470

https://github.com/crossbario/crossbar/blob/master/crossbar/crossbar/worker/router.py#L513

and here is similar for containers:

https://github.com/crossbario/crossbar/blob/master/crossbar/crossbar/worker/container.py#L186

https://github.com/crossbario/crossbar/blob/master/crossbar/crossbar/worker/container.py#L243

Thanks for the code pointers, that makes it easier to get right to the relevant source.

Thanks again for all your help Tobias, it is making investigation much smoother :slight_smile:

Cheers,

Scott

like to perform some static configuration on my class before it is

actually constructed. Or perhaps there is a better way of thinking

about this?

{

"controller": {
},
"workers": [
   {
      "type": "container",
      "options": {
         "pythonpath":

["/home/scott/projects/ParaView/build-make-debug/lib/site-packages","/home/scott/projects/ParaView/build-make-debug/lib"]

      },
      "components": [
         {
            "type": "class",
            "classname":

“paraview.web.pv_web_visualizer._VisualizerServer”,

            "realm": "vtkweb",
            "transport": {
               "type": "websocket",
               "endpoint": {
                  "type": "tcp",
                  "host": "127.0.0.1",
                  "port": 8080
               },
               "url": "ws://[127.0.0.1:8080/ws](http://127.0.0.1:8080/ws)",
               "debug": true
            }
         }
      ]
   }
]

}

Thanks!

Scott

You received this message because you are subscribed to the Google

Groups “Autobahn” group.

To unsubscribe from this group and stop receiving emails from it, send

an email to autobahnws+...@googlegroups.com

mailto:autobahnws+unsub...@googlegroups.com.

To post to this group, send email to auto...@googlegroups.com

mailto:autob...@googlegroups.com.

To view this discussion on the web visit

https://groups.google.com/d/msgid/autobahnws/af87a47f-de12-43ed-8f6c-c7ae2c1d9410%40googlegroups.com

<https://groups.google.com/d/msgid/autobahnws/af87a47f-de12-43ed-8f6c-c7ae2c1d9410%40googlegroups.com?utm_medium=email&utm_source=footer>.

For more options, visit https://groups.google.com/d/optout.

0 Likes

#5

Hi Scott,

    I think this will do what I need, as long as I can add arbitrary
    json structure to the configuration object that I can make use of in
    my makeSession function. I'll check it out and get back to you.

It seems that an "extra" field is allowed inside the "class" type
component, and can be some arbitrary json object. Is this what we
should use to pass some extra configuration that we can do what we want
with?

Yes. You can pass arbitrary config (anything JSON) here, and Crossbar will give it to your components as config.extra.

It's designed exactly for this purpose: pass arbitrary application specific configuration from Crossbar configs.

This will also work when you define a "makeSession" function ..

To give you an example of how we use it, here is a WAMP component that is an IRC bot configured like above:

             {
                "type": "wamplet",
                "package": "clandeck",
                "entrypoint": "irc",
                "realm": "com.tavendo.clandeck",
                "extra": {
                   "server": "tcp:irc.freenode.net:6667",
                   "nick": "clandeck",
                   "channels": ["arduino",
                                "autobahn",
                                "twisted",
                                "twisted-dev",
                                "cryptography-dev",
                                "websocketpp",
                                "pypy",
                                "foobar2323",
                                "foobar2324"]
                },
                "transport": {
                   "type": "rawsocket",
                   "serializer": "msgpack",
                   "endpoint": {
                      "type": "unix",
                      "path": "clandeck.sock"
                   }
                }
             }

Cheers,
/Tobias

0 Likes