Re: Questions about Remoting, objects, threading. lease lifetime and object cleanup, and a couple of others.

From: Nick Palmer (nick_at_kcicorp.com)
Date: 03/19/04

  • Next message: James J: "Re: Windows Service"
    Date: Fri, 19 Mar 2004 13:33:06 -0800
    
    

    Allen,

    Thanks so much for the answers. Some follow ups ...

    > the server will handle your calls in multiple threads. You can't
    > count on any thread affinity.

    This means that one particular thread is not bound to a particular object
    and client correct ? This is no problem, so long as the Client app is
    always refering to the same server object.

    > InitializeLifetimeServices just gets the initial lifetime object. Set
    > this to null and the object will live forever, to get the types and
    > such for this check out the return type in MSDN.

    I tried this in my ClassLibrary code, but it doesn't seem to be doing
    anything.

      Public Overrides Function InitializeLifetimeService() As Object

       Return Nothing
      End Function

    After the default 5 minutes, any attempt to access the remote object from
    the client causes an exception that says the service is no longer available.

    > yea, this is because you need to setup a lease/sponsor to deal with
    > its lifetime. You can either set it to do the timeout (you can make
    > the timeout longer) or you can set it up to do a true lease/sponsor
    > releationship which is the optimal solution.

    I'm going to research the lease/sponsor deal, but in the mean time, can you
    point me to some examples or descriptions ...

    Thanks.
    Nick

    "Allen Anderson" <allen@sparkysystems.com> wrote in message
    news:bslm5054a9eebe20qjc0qotku0kn5m74q3@4ax.com...
    > (answers in line)
    >
    > On Fri, 19 Mar 2004 10:12:54 -0800, "Nick Palmer" <nick@kcicorp.com>
    > wrote:
    >
    > >I've got a some questions about Remoting, objects, threading. lease
    lifetime
    > >and object cleanup, and others.
    > >
    > >Here is a quick overview of what I've got going so far. I'm using CAO
    > >remoting to expose a class that my clients
    > >can access. Basically the client program connects to the server, gets a
    new
    > >ClassOne object and then does its work.
    > >When its done, it sets its ClassOne object to nothing and goes away. So,
    > >the involved programs are :
    > >
    > >
    > >ClassOne (APL) : Inherits MarshalByRefObject
    > > My class that actually does all the useful work for the client
    > >
    > >
    > >ClassLibrary (VB.Net) : : Inherits MarshalByRefObject
    > > Cover class that gives access to a ClassOne object. This class has
    one
    > >global variable, CL1 and
    > > exposes one function, GetClassOne () that returns a reference to a
    new
    > >ClassOne Object.
    > >
    > > GetClassOne is as follows :
    > > Public Function GetClassOne() As Object
    > > CL1 = New ClassOne
    > >
    > > Console.WriteLine("Created a new instance of ClassOne Object")
    > > GetClassOne() = CL1
    > > End Function
    > >
    > >
    > >Server (VB.Net - Command prompt app)
    > > Remotes the ClassLibrary
    > >
    > >
    > >Client (VB.Net - WinForm app)
    > > Creates a connection the Server and using the ClassLibrary Object.
    > > Call the ClassLibrary's GetClassOne function to get a new ClassOne
    > >object to use.
    > > i.e Dim MyClassOne as ClassOne = ClassLibrary.GetClassOne
    > >
    > > When done, sets its ClassOne object to nothing
    > > MyClassOne = Nothing
    > >
    > >
    > >So this all works fine. I can fire this up and it works fine.
    > >
    > >So, now for the questions.
    > >
    > >Am I correct in assuming that each time a client connects to the Server
    and
    > >gets an instance of the ClassLibrary
    > >object and then the ClassOne object, that they are getting there own copy
    ?
    > >I think I've already proved this
    > >to myself, but I just wanted to doulbe check.
    >
    > yes, each time they call the server and it new's a new copy of
    > classone, its gettin a new copy.
    >
    > >What is the threading model that will occur on the server when all this
    is
    > >running ? It seems that currently, there
    > >will only be one thread that will support any objects that get created.
    > >Does this mean that there will be blocking
    > >while the one thread executes ? Would it be better to spawn a new thread
    in
    > >the GetClassOne call that would support
    > >that particular object and then when that class goes away, destroy that
    > >thread ?
    > >
    >
    > the server will handle your calls in multiple threads. You can't
    > count on any thread affinity.
    >
    > >I want to increase the time that my objects will stay alive from the the
    > >default 5 minutes. I've found and
    > >read all the articles on increasing the lease lifetime, and put the code
    in
    > >but it doesn't seem to work.
    > >I have put the Public Overrides Function InitializeLifetimeService in my
    > >ClassLibrary object, but it doesn't seem
    > >like its working. Is this the correct place to put it ? Unfortunately
    due
    > >to the nature of the language used
    > >for ClassOne (APL), I can't really do much with this class.
    > >
    >
    > InitializeLifetimeServices just gets the initial lifetime object. Set
    > this to null and the object will live forever, to get the types and
    > such for this check out the return type in MSDN.
    >
    > >I'm wanting to make sure that the ClassOne object that gets created in
    the
    > >GetClassOne function is destroyed or
    > >cleaned up when the client finishes. So in the ClassLibrary code, I put
    in
    > >code to override the Finalize method. But
    > >it appears that this code isn't actually executed until I shut down the
    > >Server program. Does this sound correct ?
    > >I guess if I go with creating a new thread in the GetClassOne function, I
    > >should add another method
    > >to ClassLibrary that will not only clean up the thread, but at the same
    time
    > >can clean up the ClassOne object.
    >
    > yea, this is because you need to setup a lease/sponsor to deal with
    > its lifetime. You can either set it to do the timeout (you can make
    > the timeout longer) or you can set it up to do a true lease/sponsor
    > releationship which is the optimal solution.
    >
    > >The client app at some point is going to become an ASP.Net app also. Do
    I
    > >have to do anything special because
    > >of this ? My plan was to put the code that calls GetClassOne in the
    > >Session_Start code in the global.aspx so
    > >that each user that brings up the web app gets a connection to the remote
    > >server. Any problems with this ?
    >
    > nope, you should be able to use it the same way without any problems
    > at all.
    >
    > >I'm going to change the server program from a command prompt app to a
    > >Windows service once all this is working.
    > >Anything I should watch out for with this ?
    >
    > not really, however, I would recommend keeping your console app
    > around. As I've explained in other posts on this newsgroup, the best
    > way to handle this situation is to write all the important code into a
    > dll that you include into your console nad service apps. This way you
    > can always use the console app to debug and the service app to
    > publish.
    >
    >
    > Allen Anderson
    > http://www.glacialcomponents.com
    > mailto: allen@put my website url here.com
    >
    >


  • Next message: James J: "Re: Windows Service"

    Relevant Pages

    • RE: Using kerberosSecurity Throws Security Exception
      ... I am experiencing this error while trying to use a Windows XP client ... application to access a web service located on a W2k3 server. ... client app on the server, ... > Account with a Custom Principal Name using SetSPN.exe utility. ...
      (microsoft.public.dotnet.framework.webservices.enhancements)
    • Re: Remoting or windows service
      ... Thanks for writing up such a decent overview of the remoting dev process ... the client and the server. ... > 2) Implement this class in the server app and say that it can be accessed ...
      (microsoft.public.dotnet.framework.remoting)
    • Re: Schannel and Session Renegotiation
      ... Schannel does not support the server sending app ... We are discussing the option of providing support for the client blowing off ...
      (microsoft.public.platformsdk.security)
    • Re: Getting Events, for Windows Service
      ... else tries to run my client app he gets an timeout error. ... The server application has a public object called logger, ... So it seems that the logger is properly instantiated and works. ...
      (microsoft.public.dotnet.framework.remoting)
    • Questions about Remoting, objects, threading. lease lifetime and object cleanup, and a couple of oth
      ... Basically the client program connects to the server, ... it sets its ClassOne object to nothing and goes away. ... GetClassOne that returns a reference to a new ...
      (microsoft.public.dotnet.framework.remoting)