Comet and doing work in a Process

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Comet and doing work in a Process

zecke
Hi All,

in my web application I am starting a process and I want to do comet
updates from within this process. The problem is that this process
does not have a ILContext in the current Process and any usage of self
session, self application will fail and one needs to have another
option to make this work. In general one could attempt to dispatch a
block and execute it on another process, or establish the dynamic
variable on the new process.

Some ideas would be more than helpful.


Error:
Object: nil error: did not understand #session
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #session (SysExcept.st:
1407)
ServerConfigWidget(Iliad.ILObject)>>session (Iliad-
Core.star#VFS.ZipFile/Utilities/ILObject.st:60)
ServerConfigWidget(Iliad.ILWidget)>>triggerCometEvent: (Iliad-More-
Comet.star#VFS.ZipFile/Extensions.st:15)
optimized [] in ServerConfigWidget>>connectServer (CometUseCase.st:43)

Example Code:
PackageLoader fileInPackage: 'Iliad-Core'.
PackageLoader fileInPackage: 'Iliad-More-Comet'.
PackageLoader fileInPackage: 'Iliad-More-Formula'.
PackageLoader fileInPackage: 'Iliad-Swazoo'.


Iliad.ILCometEvent subclass: ConnectRefresh [
]

Iliad.ILWidget subclass: ServerConfigWidget [
    initialize [
        super initialize.
        self subscribeToCometEvent: ConnectRefresh.
    ]

    contents [
        ^ [:e |
            self application isConnected
                ifTrue: [ e text: 'It is connected' ]
                ifFalse: [
                    e text: 'It is not connected'.
                    e a
                        text: 'Connect';
                        action: [self connectServer]
                ].
        ]
    ]

    waitForConnected [
        (Delay forSeconds: 5) wait.
    ]

    connectServer [
        "self application server connect...."

        [
            self waitForConnected.
            "
            self session/application/cometHandler will fail as
            this is a new process and does not have a ILContext
            process local variable
            "
            self triggerCometEvent: ConnectRefresh new.
        ] fork.
    ]
]

Iliad.ILApplication subclass: TestphoneApp [
    | serverConfig  connected |
    TestphoneApp class >> path [ ^ 'testphone' ]

    serverConfig [
        ^ serverConfig ifNil: [serverConfig := ServerConfigWidget new]
    ]

    index [
        <category: 'controllers'>
        ^ [:e |
            e
                build: self cometConnection;
                build: self serverConfig.
        ].
    ]

    isConnected [
        "Make sure it is connected on second call"
        ^ connected ifNil: [connected := true. false ]
    ]
]

Eval [
    TestphoneApp initialize.
    Iliad.SwazooIliad startOn: 8080.

    stdin next.
]
Reply | Threaded
Open this post in threaded view
|

Re: Comet and doing work in a Process

zecke


On Dec 11, 1:38 pm, zecke <[hidden email]> wrote:
> Hi All,

>             self waitForConnected.
>             "
>             self session/application/cometHandler will fail as
>             this is a new process and does not have a ILContext
>             process local variable
>             "
>             self triggerCometEvent: ConnectRefresh new.
>         ] fork.

        context := self context.
         [
            ILCurrentContext processVariable value: context.
            self session cometHandler handleEvent: ConnectRefresh new.
         ] fork


so if i abuse CometHandler and I set the context in the new process I
can update my widget. The only not so nice thing is that the browser
does not finish loading. I am sure the work on WebSocket will fix this.