Hello Joost,

> I'd like to have one unique stream to write to. I could make a
> ClassMethod Write(data As %String), but then I need a ClassProperty
> out As %AbstractStream or something to write to. A global variable (=
> unique, and available in every object) would do the trick, too.
> 
> How can I specify something like that?
> 
> For more information: This is the Singleton programming pattern, see
> http://www.campusprogram.com/reference/en/wikipedia/s/si/singleton_patt
> ern.html 


if the stream should be process-global, you can set a %-variable.

But shouldn't access it directly, because it have to be set before.

I use a macro to access a singleton.

#define $$$UniqueStream  ##class(SinletonManager).GetUniqueStream()

It works like a GetMethod of an object-property.


Class SingletonManager {

ClassMethod GetUniqueStream() as UniqueStream
{
   s:'$d(%uniqueStream) %uniqueStream=##class(UniqueStream).%New()
   q %uniqueStream
}

}


If you want a system-wide singleton, you should make the singleton 
persistent and save the OID.
But then you have to open it on every access and must synchronize the 
write-access on it, or use a background-process that manages it...

HTH
^Florian

Reply via email to