473,320 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Architectural issue (Singleton?)

Hi everybody,

I have class library used by an application to log it's activity. This
application has got several Plug-Ins, and all these Plug-Ins use the same
library to log their activity. As the application logs everything on the
same log file for each day, I implemented a LogManager that's actually a
Singleton, in order to manage concurrent accesses on daily log files.
For each running Plug-In the LogManager creates a LogSession, that's
actually nothing more than a buffer, in which the running Plug-in writes
its log entries. When a Plug-In has finished its work, it closes its
LogSession, that rises an event (LogSessionClosed), the event is caught
from the LogManager that writes the content of the closed LogSession on the
current log files (I think it's quite simple and intuitive...).

Now, I have to write a new Plug-In, made by several interoperating objects,
and I need all of them to be able to log their activity. So I'll have a
general Client class which ask the LogManager for a new LogSession object.
Within this Client object, I'll have a lot of SubClient objects. What can I
do, in order to make them log on the same LogSession? I have three
solutions (may be all wrong :-) ):

A) add a LogSession argument to all the SubClient class constructors;
B) add to each SubClient class an event LogSomething: they rise this event
when they want to log anything, the Client class catch it and log on the
LogSession (actually I think this is the most flexible implementation,
anyway, because of the tipically high number of log entries I think this
approach can depply impact the application performances...);
C) build a sort of Singleton within the main Client class, so that each
SubClient can refer to the same LogSession object... Actually I cannot
either think to a way to implement such a solution: how can I create a
Singleton (that's a static class) using a non-static instance (the
LogSession object)?

Do you have any suggestion?
Thanks in advance!
Kind regards,
Giulio - Italia

--
Jun 29 '06 #1
2 1054
Giulio,

Personally, I would go with B), because it doesn't couple your class
with the log provider as A) and C) does. The event doesn't necessarily have
to be "LogSomething", but rather, if the component exposes events, then your
client class can subscribe to them and log the appropriate information.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Giulio Petrucci" <gi*************@SUPERCALIFRAGILISTICHESPIRALIDOSO .com>
wrote in message news:%2****************@TK2MSFTNGP04.phx.gbl...
Hi everybody,

I have class library used by an application to log it's activity. This
application has got several Plug-Ins, and all these Plug-Ins use the same
library to log their activity. As the application logs everything on the
same log file for each day, I implemented a LogManager that's actually a
Singleton, in order to manage concurrent accesses on daily log files.
For each running Plug-In the LogManager creates a LogSession, that's
actually nothing more than a buffer, in which the running Plug-in writes
its log entries. When a Plug-In has finished its work, it closes its
LogSession, that rises an event (LogSessionClosed), the event is caught
from the LogManager that writes the content of the closed LogSession on
the current log files (I think it's quite simple and intuitive...).

Now, I have to write a new Plug-In, made by several interoperating
objects, and I need all of them to be able to log their activity. So I'll
have a general Client class which ask the LogManager for a new LogSession
object. Within this Client object, I'll have a lot of SubClient objects.
What can I do, in order to make them log on the same LogSession? I have
three solutions (may be all wrong :-) ):

A) add a LogSession argument to all the SubClient class constructors;
B) add to each SubClient class an event LogSomething: they rise this event
when they want to log anything, the Client class catch it and log on the
LogSession (actually I think this is the most flexible implementation,
anyway, because of the tipically high number of log entries I think this
approach can depply impact the application performances...);
C) build a sort of Singleton within the main Client class, so that each
SubClient can refer to the same LogSession object... Actually I cannot
either think to a way to implement such a solution: how can I create a
Singleton (that's a static class) using a non-static instance (the
LogSession object)?

Do you have any suggestion?
Thanks in advance!
Kind regards,
Giulio - Italia

--

Jun 29 '06 #2
On 2006-06-29, Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.com> wrote:
Giulio,

Personally, I would go with B), because it doesn't couple your class
with the log provider as A) and C) does. The event doesn't necessarily have
to be "LogSomething", but rather, if the component exposes events, then your
client class can subscribe to them and log the appropriate information.

Hope this helps.


Just to show there's another point of view, I'd personally go with
something like A. Instead of passing the LogSession object though, I'd
pass some kind of ILogger interface instead, which would allow you to
swap out logging mechanisms with ease.

If you could really get away with not having a LogSomething event, then
I'd be more likely to agree with Nicholas here, but in my experience the
sub-clients are going to want to log things that don't correspond well
to other events.

Jul 1 '06 #3

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

Similar topics

0
by: Zuel | last post by:
Sup everyone! I wrote this code for Tomcat appserver but I am told from an associate that it has threading issues. The basic idea is to store a read only data table for everyone to use. It...
2
by: Pete the Perplexed Programmer | last post by:
Consider the following problem (which I state with a simple example, but it corresponds to a real problem that I'm facing): Junior loves pets, and that's fine with Mom and Dad, as long as he only...
10
by: E. Robert Tisdale | last post by:
Could somebody please help me with the definition of a singleton? > cat singleton.cc class { private: // representation int A; int B; public: //functions
1
by: Hendrik Schober | last post by:
Hi, consider the following small program created to test the optimizer: #include <iostream> struct X { X(int i) : i_(i) {} int i_;
2
by: Viet | last post by:
I have an architectural issue that I have been working on for quite awhile now and I would like another person's point of view. This issue involves the conversion of a VB6 app to VB.NET. In this...
11
by: stax | last post by:
Hi, Assuming having a method that calls another method which also calls other methods and so on having a long winded tree of methods. What do I do in case it turns out everything has to be...
6
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...
3
weaknessforcats
by: weaknessforcats | last post by:
Design Pattern: The Singleton Overview Use the Singleton Design Pattern when you want to have only one instance of a class. This single instance must have a single global point of access. That...
0
by: George2 | last post by:
Hello gurus, For the wellknown Double-Checked Locking pattern, http://www.ddj.com/184405726?pgno=1 Step 1: Allocate memory to hold a Singleton object. Step 2: Construct a Singleton object...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.