[ENH][VM] Interpreter>>getThisSession

Stephan Rudlof sr at evolgo.de
Tue Nov 20 03:26:14 UTC 2001


David,

I have some remarks and ideas.

From your changeset:

!Interpreter methodsFor: 'session identification' stamp: 'dtl 11/10/2001
13:36'!
getThisSession
	"Answer a session identifier which represents the current instance of
Squeak.
	The identifier is expected to be unique among all instances of Squeak on a
	network at any point in time."

	| thisSessionIdentifier |
	self var: 'thisSessionIdentifier' declareC: 'static unsigned int
thisSessionIdentifier = 0'.
	[thisSessionIdentifier = 0]
		whileTrue:
			[thisSessionIdentifier _ self
				cCode: 'sqThisSessionIdentifier()'
				inSmalltalk: [(Random new next * SmallInteger maxVal) asInteger]].
	^ thisSessionIdentifier
! !

For ensuring that the session identifier is unique among all instances of
Squeak in a network this is *not* a safe method. But I have to admit: for
just a *few* instances it should almost always work...
But imagine a collaboration of thousands of Squeaks...

So I´d like to have a sessionID which consists of two parts:
- a startupSessionID which changes for each startup of the image where it
belongs to by incrementing it;
- an imageSessionID which identifies the image used.

Some time ago I´ve implemented the first one by storing it inside the image.
It is named as sessionID in the attached changeset VM_cachingMissingModules,
which also contains some other stuff. 
Pros:
- needs less resources (compared to full time/date info);
- there is an order of startupSessionIDs in time;
- each startupSessionID is guaranteed to be unique for the image holding it
(until the first overflow (if it is an Integer), but this takes *very* long
time...).

The imageSessionID could be realized by using the local file path to the
image (discrimination between different images at the same host) together
with some host/user identification (discrimation between different
hosts/users). The latter avoids using IPs and allows equal local paths used
by different users.



Greetings,

Stephan


"David T. Lewis" wrote:
> 
> Adds a #getThisSession method to the Interpreter, and makes it
> accessible to the interpreter proxy for plugins. Increments the
> VM_PROXY_MINOR version number to 5. Modifies FilePlugin and its
> support code to use the new mechanism.
> 
> The session identifier is a 32 bit integer which is used in
> SQFile data structures. It is also a field in the SQSocket data
> structure, although this is currently unused (at least in the
> unix implementation of the socket code). The session identifier
> is also potentially useful for identifying distributed squeak
> images, and for handling any external resource whose Squeak
> representation may become invalid after restarting the image.
> 
> This change set moves the session identifier code from the
> FilePlugin support code into the Interpreter, and makes it
> available to any plugin by means of the interpreter proxy.
> Any plugin which needs to obtain the session identifier may
> now do so with 'intepreterProxy getThisSession' (in Smalltalk)
> or 'interpreterProxy->getThisSession()' (in a hand-coded C plugin
> or support code).
> 
> The function which initializes the session identifier is defined
> as a macro in sq.h, so that it can be easily replaced by a
> function in support code if it needs to be improved.
> 
> There are several other way to implement this, and I think this
> one is the best way to do it. The implementions which I tried are:
> 
> 1) The current Squeak implemention. A global thisSession variable
> is declared in the FilePlugin support code, and managed there. Other
> plugins can use the global, but this requires that FilePlugin be
> built internally. This works, but it is rather kludgy.
> 
> 2) Same as #1, but add a #getThisSession method in FilePlugin, and
> export it for use by other plugins. Other plugins can use the dynamic
> loading mechanism to load the getThisSession function, regardless of
> whether the FilePlugin was built internally or externally. This works
> fine, but all that dynamic module loading seems a bit over the top
> for something this simple.
> 
> 3) Same as #1, but move the declaration of the global thisSession
> variable into the interpreter (as an instance variable in class
> Interpreter). This is simple and it works fine. However, having gone
> this far, but it would be better to have an accessor method like
> in option #2, which leads to the last thing I tried:
> 
> 4) Replace the global variable with an accessor method in Interpreter,
> and have the plugins use this. This works fine, gets rid of the
> global variable entirely, and puts responsibility for managing the
> session ID in the Interpreter where it belongs.
> 
> I think that #4 is the best overall, so that is what I am posting in
> this change set.
> 
> - Dave
> 
>   ----------------------------------------------------------------------------
>                                         Name: InterpreterGetThisSession.2.cs.gz
>    InterpreterGetThisSession.2.cs.gz    Type: application/x-gunzip
>                                     Encoding: base64

-- 
Stephan Rudlof (sr at evolgo.de)
   "Genius doesn't work on an assembly line basis.
    You can't simply say, 'Today I will be brilliant.'"
    -- Kirk, "The Ultimate Computer", stardate 4731.3
-------------- next part --------------
A non-text attachment was scrubbed...
Name: VM_cachingMissingModules.8.cs.gz
Type: application/octet-stream
Size: 11398 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20011120/557aa422/VM_cachingMissingModules.8.cs.obj


More information about the Squeak-dev mailing list