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

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:


what does it help? Will it reduce the confusion?

  Global glob = new Global(args);


 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 ...


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

I like the factory pattern you described. The factory would then be a singelton, right ?


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.


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


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


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

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



global = new Global(Global.instance());

I have set this to deprecated, please use getClone() instead.



I hope that's the preferred way to create multiple Globals. The


constructor is very cumbersome.