473,804 Members | 2,246 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Singleton on server

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?

Feb 15 '07 #1
9 2986
On Feb 15, 2:58 pm, oleg...@gmail.c om wrote:
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

Feb 15 '07 #2
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.
I think reading up onSingletonmigh t answer your question:

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

Scroll down in this article, findC#generics.

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

Quoc Linh

Feb 16 '07 #3
(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

Feb 16 '07 #4
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
<ol*****@gmail. comwrote in message
news:11******** **************@ a75g2000cwd.goo glegroups.com.. .
|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?
|
Feb 16 '07 #5
<ol*****@gmail. comwrote in message
news:11******** **************@ a75g2000cwd.goo glegroups.com.. .
>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.Enterpri seServices is exactly what you are looking for is, derive your class from
ServiceComponen t, 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.

Feb 16 '07 #6
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.

On Feb 16, 12:20 am, "Marc Gravell" <marc.grav...@g mail.comwrote:
(disclaimer: not a solution)
Can I quickly question *why* you want a system-widesingletonwi th
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

Feb 16 '07 #7
Will it work on w2k? One of the requirements I have is to make a
server able to be ran on w2k.

On Feb 16, 5:01 am, "Willy Denoyette [MVP]"
<willy.denoye.. .@telenet.bewro te:
<oleg...@gmail. comwrote in message

news:11******** **************@ a75g2000cwd.goo glegroups.com.. .>I hope, I misunderstood some basics here and it is easy to solve..
I need asingletonobjec t running onserverwhich 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 thissingleton- 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 mysingleton. But how can I make another apps
(webservice and COM interop) to work with the samesingleton? I
believe it is doable, but how?

System.Enterpri seServices is exactly what you are looking for is, derive your class from
ServiceComponen t, enable object pooling with max. pool size = 1 and register the class as aServertype in the COM+ catalog.
Check the docs for details on the attributes you need on the assembly and the class.

Willy.

Feb 16 '07 #8
<ol*****@gmail. comwrote in message
news:11******** *************@k 78g2000cwa.goog legroups.com...
Will it work on w2k? One of the requirements I have is to make a
server able to be ran on w2k.
Yep, W2K and up.

Willy.
Feb 16 '07 #9
On Feb 16, 12:03 pm, "Willy Denoyette [MVP]"
<willy.denoye.. .@telenet.bewro te:
<oleg...@gmail. comwrote in message

news:11******** *************@k 78g2000cwa.goog legroups.com...
Will it work on w2k? One of the requirements I have is to make a
serverable to be ran on w2k.

Yep, W2K and up.

Willy.
After reading about COM+ and Remoting I have decided to go with remote
object with WellKnownObject Mode.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?

Feb 16 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2298
by: Marc Pelletier | last post by:
Hello, I am still fairly new to CSharp and am trying to implement a singleton pattern. I found Jon Skeet's excellent page (http://www.yoda.arachsys.com/csharp/singleton.html), but am struggling a little to understand it. The 4th example seems to be the preferred: public sealed class Singleton
7
3619
by: Stephen Brown | last post by:
I have some strange behavior on my web server that seems to point to garbage collection. I have a singleton that tracks web activity on my web site. The singleton works great, except that it restarts periodically. The web services have not been restarted and the error log shows no problems. It is the same problem on 2 different servers, but is worse on the most used server. On the most used server, it gets restarted 5 to 10 times a day...
12
2457
by: solex | last post by:
Hello, I am trying to model a session object that is essentially a collection of different items (connection string, user name, maps etc.) I would like this session object to be available to other objects within my client application. I can do one of two things (1) make the session object a singleton (2) pass the session object to the methods that need them. Option 2 is a bit more complicated and messy then option 1. My other goal...
6
2088
by: Palvinder Singh | last post by:
Hello google group peeps, I am new to remoting, but have a grasp of it. I am trying to create a server/client application, which will be deployed over an intranet. I have upwards of five clients that connect to a main server. The client application sets the state of several switchs (on/off by means of clicking a button). When a switch is turned on/off, its state is updated on the server, which will then raise an event to update...
7
2241
by: fredd00 | last post by:
Hi I'm just starting with singleton and would like to implement in my new web app. I have a question lets say i create a singleton DataHelper that holds a static SqlConnection object to share and on my page I do
24
2576
by: Eric | last post by:
I created a singleton class as in the example below. The application sporadically crashes in the second line of the main function as shown. However, when I change the singleton such that the static pointer is a class member (defined in the cpp file) and the instance function creates the object if the pointer is NULL, then it works fine. I would appreciate any explanations as to why this happens. class CTestClass { public:
5
3816
by: sam_cit | last post by:
Hi everyone, I have the following code and it gives a linker error on MS vc++ 6.0. error LNK2001: unresolved external symbol "protected: __thiscall Singleton::Singleton(void)" (??0Singleton@@IAE@XZ) #include <stdlib.h> class Singleton
1
2457
by: Steve K. | last post by:
I'm working on my first remoting project. It's going well and I have one (that I know of!) bug left to work out. I understand how remote objects have leases and those leases expire. I fixed a problem earlier today where the EventShims that my clients were invoking to handle server -Client events were expiring and I was getting the "Service not found" exception. I solved it by returning null from InitializeLifetimeService() I think...
3
1808
by: stevewilliams2004 | last post by:
I am attempting to create a singleton, and was wondering if someone could give me a sanity check on the design - does it accomplish my constraints, and/or am I over complicating things. My design constraints/environment are as follows: 1) Everything is single-threaded during static initialization (as in prior to the open brace of main) 2) The environment may be multi-threaded during nominal program execution (within {} of main) 3) I...
0
9714
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10600
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10351
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9174
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7638
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6866
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5534
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.