image start/shutdown notification

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

image start/shutdown notification

Ingo Blank
Hi all,

Scenario:
Several instances of a class share a common resource,
stored in a *class* variable. In this case an instance of
a COM server.
When the image terminates, the COM server process is naturally terminated
too.
The instances, that use this variable are not necessarily terminated, so
finalization
is of no use here.

When the image is restarted, the reference to the COM object has,
not surprisingly, become invalid.

And of course that is not what I want ;-)

Q: How can I get a notification of starting/terminating the image ?
   With either of these one could reset the class variable to nil, what
would
   allow an automatic reload of the COM process.

In short: I look for a mechanism to keep a server connection valid across
several image restarts.

I already looked up the "pattern book", but didn't find any appropriate
solution.

-----------------------

"Class methods for class providing a shared COM server object."

getCOMsvr

(COMsvr isNil) ifTrue: [COMsvr := "<Create COM Server Process>"].
^COMsvr

reset
"This should be called automatically by any mechanism
 triggered by image start/shutdown"

COMsvr := nil.
^self

------------------------

Who can help me ?

Thanks in advance

Ingo


Reply | Threaded
Open this post in threaded view
|

Re: image start/shutdown notification

Ian Bartholomew
Ingo,

> In short: I look for a mechanism to keep a server connection valid across
> several image restarts.

The singleton instance of the SessionManager class (see "SessionManager
current") looks after this via the "sessionStarted" event.

The easiest way to arrange for startUp notification is to use the package
script mechanism. Assuming that the #reset method you gave is a method in
the MyCOMInterface class (you didn't give a class name) you add a
postinstall script to the package that contains the MyCOMInterface class

SessionManager current when: #sessionStarted send: #reset to: MyCOMInterface

and a preuninstall script that reads

SessionManager current removeEventsTriggeredFor: MyCOMInterface

The uninstall script is needed to ensure you don't get walkbacks after you
uninstall the package and save the image.

For a deployed application it is usually easier to override the
#tertiaryStartup method in any SessionManager subclass that you create for
the deployed application.

Ian


Reply | Threaded
Open this post in threaded view
|

Re: image start/shutdown notification

Blair McGlashan
In reply to this post by Ingo Blank
Ingo

You wrote in message news:3ac41fb8$0$24799$[hidden email]...

>...
> Q: How can I get a notification of starting/terminating the image ?
>    With either of these one could reset the class variable to nil, what
> would
>    allow an automatic reload of the COM process.
>
> In short: I look for a mechanism to keep a server connection valid across
> several image restarts.
>
> I already looked up the "pattern book", but didn't find any appropriate
> solution.
> ....

Ian has answered your question directly (thanks Ian), but in fact it
probably isn't necessary to hook the session start and stop events here.
Assuming that the COMSvr class variable you mention is holding an interface
pointer (i.e. a subclass of IUnknown) then you can replace the #isNil test
in your lazy-initialiser with a #isNull test and you will get your desired
behaviour. This is because "old" COM interface objects have their pointer
nulled during session startup anyway, i.e. modifying your example:

"Class methods for class providing a shared COM server object."

 getCOMsvr

    COMsvr isNull ifTrue: [COMsvr := "<Create COM Server Process>"].
    ^COMsvr

Regards

Blair