[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [xmlblaster] Subscriber getting first message only - big clue!



Currently, I'm using the "copy constructor" [ like this: new
Global(Global.instance()) ] which calls shallowCopy which in effect does
the same as the "savedArgs" below.  I like using static "creator"
methods because I don't have to pass objects around all over the place.

In my code, I set up the configuration args in one place... but I may
need to create Global objects in many other places where I don't have
access (and don't want access) to the args.  new Global(Global.instance)
works for me... but (1) is kinda confusing and (2) is vulnerable to
problems of create order.  With static methods, I can more closely
control exactly what I want.



-----Original Message-----
From: Marcel Ruff [mailto:mr at marcelruff.info] 
Sent: Tuesday, April 08, 2003 10:41 AM
To: xmlblaster at server.xmlblaster.org
Subject: Re: [xmlblaster] Subscriber getting first message only - big
clue!


David Hooker wrote:

>The way I use the pattern is to have static methods of the class used
to
>create instances... so it's not really a Singleton pattern since
there's
>no initial instance.  Here's a trivial example:
>
Hmm,

what does it help? Will it reduce the confusion?

   Global glob = new Global(args);

or

  Global glob = Global.create(args);

The second variant allows to hides the 'new Global'
and would allow us to secretly use another class loader
or doing other nice things ...
Using 'savedArgs' is probably a trap, as we don't know
if sombody else already has provided them - so the behaviour
could be different suddenly.

Additional rename:

ConnectionConfig cfg = ConnectionConfig.create(args);
XmlBlasterAccess a = cfg.getXmlBlasterAccess();
...

Is it the silver bullet? I'm not yet convinced ...

Marcel



>
>
>public class Global
>{
>	private static String[] savedArgs;
>
>	public static Global create(String[] args)
>	{
>		savedArgs = args;
>		return new Global();
>	}
>
>	public static Global create()
>	{
>		// maybe check to make sure savedArgs is non-null.
>		// if it's null, setup some defaults first.
>		return new Global();
>	}
>
>	private Global()
>	{
>		// uses savedArgs to initialize
>	}
>}
>
>-----Original Message-----
>From: Michael Atighetchi [mailto:matighet at bbn.com] 
>Sent: Tuesday, April 08, 2003 10:11 AM
>To: xmlblaster at server.xmlblaster.org
>Subject: Re: [xmlblaster] Subscriber getting first message only - big
>clue!
>
>
>I like the factory pattern you described. The factory would then be a
>singelton, right ?
>
>Michael
>
>
>On Tue, Apr 08, 2003 at 09:09:34AM -0500, David Hooker wrote:
>  
>
>>Global is confusing because it acts like a singleton... but isn't.
>>    
>>
>I'd
>  
>
>>suggest that it be made into a factory - make the constructors private
>>and provide static methods to create each connection-specific global.
>>In order to avoid having to pass in the args everytime, have one of
>>    
>>
>the
>  
>
>>static factory methods take the config parameters and store them as
>>static members.  Have another no-arg factory method which creates a
>>global using those stored values.  I think this is much cleaner.
>>
>>From: Marcel Ruff [mailto:mr at marcelruff.info] 
>>Sent: Tuesday, April 08, 2003 2:43 AM
>>To: xmlblaster at server.xmlblaster.org
>>Subject: Re: [xmlblaster] Subscriber getting first message only - big
>>clue!
>>
>>
>>Hi,
>>
>>HelloWorld5.java uses two connections, here
>>the second connection clones a global:
>>
>>   ...
>>   Global globReceiver = glob.getClone(null);
>>   receiver = globReceiver.getXmlBlasterAccess();
>>
>>   ConnectQos qos = new ConnectQos(receiver.getGlobal());
>>   ConnectReturnQos conRetQos = receiver.connect(qos, new I_Callback()
>>    
>>
>{
>  
>
>>   ...
>>
>>The getClone(String[]) is probably the way to go.
>>
>>The Global is a 'local stack' of execution, the
>>local settings of a client connection (and as well
>>the local settings of an embedded xmlBlaster server).
>>With this approach you can have many independent
>>client connections and embedded servers in the same
>>JVM.
>>
>>We don't use ANY singletons in xmlBlaster (apart from
>>finals) as they are only causing problems.
>>Global can be seen as a connection specific singleton.
>>
>>Since this is now the second time that somebody
>>gets confused about using different global instances
>>for different connections we need to think about
>>the design or a better naming ... any ideas?
>>
>>
>>David Hooker wrote:
>>    
>>
>>>Well, if I call "new Global()" more than once, it prints a warning
>>>message to the screen.  So the best thing I see is to do something
>>>      
>>>
>>like
>>    
>>
>>>this:
>>>
>>>	global = new Global(Global.instance());
>>>      
>>>
>>I have set this to deprecated, please use getClone() instead.
>>
>>thanks
>>
>>Marcel
>>    
>>
>>>I hope that's the preferred way to create multiple Globals.  The
>>>      
>>>
>3-arg
>  
>
>>>constructor is very cumbersome.
>>>      
>>>
>
>  
>