Singleton on server

O

oleggus

I hope, I misunderstood some basics here and it is easy to solve..
I need a singleton object running on server which can be used(write
and read) by different client interfaces - for example there is
webservice that simply transfer calls to this object and there is a
COM Interop, that does the same. Also I need to control lifecycle and
behaviour of this singleton - and for that I am going to have window
application, that will start and finish it.
I do not have problem with the last part :) - I run window app and
request an instance of my singleton. But how can I make another apps
(webservice and COM interop) to work with the same singleton? I
believe it is doable, but how?
 
Q

Quoc Linh

I hope, I misunderstood some basics here and it is easy to solve..
I need a singleton object running on server which can be used(write
and read) by different client interfaces - for example there is
webservice that simply transfer calls to this object and there is a
COM Interop, that does the same. Also I need to control lifecycle and
behaviour of this singleton - and for that I am going to have window
application, that will start and finish it.
I do not have problem with the last part :) - I run window app and
request an instance of my singleton. But how can I make another apps
(webservice and COM interop) to work with the same singleton? I
believe it is doable, but how?

I think reading up on Singleton might answer your question:

http://en.wikipedia.org/wiki/Singleton_pattern

Scroll down in this article, find C# generics.

Just curious, have you also go as Olegik on fool.com?

Quoc Linh
 
O

oleg.gusyev

I think I have some understanding of how singleton works. WHat I do
not understand is how to make it singleton systemwise, not only
processwise(or appdomain wise if you wish). I created a singleton
instance in my window app, but now how webservice can read/write to
it?
The closest thing to what I want is Singleton model in NET Remoting,
but because ther will be no remote direct connections to this object
( only through web service or pure SOAP), there is no reason to do
Remoting.

PS. No, I am not Olegik from fool.com.
 
M

Marc Gravell

(disclaimer: not a solution)
Can I quickly question *why* you want a system-wide singleton with
read/write on a web-server? In most cases, this is a bag call: the
write access forces you to make the class thread-safe, which means
that you are serializing all web-requests. This is not a good thing in
terms of scalability. Usually when I see this, the correct answer is
to use a database to handle the centralised access to common data (in
a controlled manner).

One other issue with the above approach is that it also doesn't scale
out if the idea is to have a single version of the truth; in a
cluster, you start having to remote between them to a single throttle-
point (singleton). Database servers are more geared-up to do this job.

Anyway; your scenario could be different, and it might be a good
idea... but worth challenging ;-p

Marc
 
W

William Stacey [C# MVP]

This will require some form of remoting to marshal between processes. The
first two that come directly to mind is Remoting and WCF. Based on the
limited info I gleen from post, I might create a .Net service that hosts the
singleton. Then use remoting to surface the MBR singleton object as it is
easy and fast (other ipc options could be namedpipes, memmappedfile,
sockets, etc). All your other apps then become clients of the service.
Your win management app becomes a remoting client, your web service becomes
a remoting client, a console mgmt app becomes a remoting client, your com
app becomes a remoting app - they all acess the same library the same way
with the same MBR proxy api. Pretty clean solution imo (you could use WCF
in same kinda way). You don't actually need to use a real service if you
don't want. You could use a console app to host the service as long as you
want to start it each time (i.e. via boot or from scheduler or something).
The console host is probably easiest during testing, then convert to service
if needed. hth

--
William Stacey [C# MVP]
PCR concurrency library: www.codeplex.com/pcr
PSH Scripts Project www.codeplex.com/psobject


|I hope, I misunderstood some basics here and it is easy to solve..
| I need a singleton object running on server which can be used(write
| and read) by different client interfaces - for example there is
| webservice that simply transfer calls to this object and there is a
| COM Interop, that does the same. Also I need to control lifecycle and
| behaviour of this singleton - and for that I am going to have window
| application, that will start and finish it.
| I do not have problem with the last part :) - I run window app and
| request an instance of my singleton. But how can I make another apps
| (webservice and COM interop) to work with the same singleton? I
| believe it is doable, but how?
|
 
W

Willy Denoyette [MVP]

I hope, I misunderstood some basics here and it is easy to solve..
I need a singleton object running on server which can be used(write
and read) by different client interfaces - for example there is
webservice that simply transfer calls to this object and there is a
COM Interop, that does the same. Also I need to control lifecycle and
behaviour of this singleton - and for that I am going to have window
application, that will start and finish it.
I do not have problem with the last part :) - I run window app and
request an instance of my singleton. But how can I make another apps
(webservice and COM interop) to work with the same singleton? I
believe it is doable, but how?
System.EnterpriseServices is exactly what you are looking for is, derive your class from
ServiceComponent, enable object pooling with max. pool size = 1 and register the class as a
Server type in the COM+ catalog.
Check the docs for details on the attributes you need on the assembly and the class.

Willy.
 
O

oleggus

Marc,
this singleton will serve three tasks - to count a number of connected
users, to log activity and to provide users with application-wide data
in timely manner.
Also this singleton is in charge to update this data from external
source (another WS somewhere over there).
I believe it is pretty common set of tasks. Of course it can be done
in database, but we already have almost all code written and worked in
one-client environment, and all that I want is to adapt it somehow to
work behind webservices and COM.
 
O

oleggus

Will it work on w2k? One of the requirements I have is to make a
server able to be ran on w2k.
 
O

oleg.gusyev

Yep, W2K and up.

Willy.

After reading about COM+ and Remoting I have decided to go with remote
object with WellKnownObjectMode.Singleton.
It works but i have one question of its lifetime. I specified infinite
lease for this object but ..is it indeed infinite? I have Manager app,
and I'd like to kill this object when I click Stop button in Manager.
What is the proper way of doing that?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top