Server Smalltalk Guide : Remote object model : Remote references : Managing access to remote references
Managing access to remote references
SST provides some infrastructure for managing access to objects in general and remote references in particular. The concept of a naming service is a familiar one, allowing you to associate arbitrary objects with names. File systems are a common example of a naming service, where the objects are files, within a hierarchical structure of named directories. The SST naming service facilities adopt the same API protocol as CORBA's CosNaming services, using the standard IDL-to-Smalltalk mapping for operations.
The benefit of using a naming service in a client-server environment is that only a single object--the naming service itself--needs to be made available by the server. Individual services the server supports are then bound to particular names within the naming service. Clients know either the name of the service in which they are interested or how to navigate the naming service itself. Given some name, the naming service resolves the name and answers the associated object.
In SST, a naming service is an instance of SstNamingContext, which contains bindings from instances of SstName to arbitrary objects. Strings are mapped to an instance of SstName using the following protocol:
from: value
Creates an instance of the receiver from the structured string value. For example, foo/bar.type as an instance of the receiver is interpreted to mean the object bound to a name bar or kind type within the naming context called foo which in turn will be bound within some other naming context.
The same protocol is provided by the class method nameFrom: in SstNamingContext. The basic API of SstNamingContext is:
bind: name obj: value
Binds @value to @name within the receiver. If @value is an instance of the receiver, it will not participate in compound name resolution. If @name is a compound name, each component except the last identifies a naming context which must already exist.
bindContext: name nc: value
Binds @value to @name within the receiver. @value will participate in compound name resolution. If @name is a compound name, each component except the last identifies a naming context which must already exist.
bindNewContext: name
Creates a new instance of the receiver and binds it to @name within the receiver.
destroy
Prevents further participation of the receiver in any actions. There must be no existing bindings within the receiver when this operation is called.
list: number bl: bindingListHolder bi: bindingIteratorHolder
Reports a collection of at most @number bindings discovered in the receiver. These are placed in @bindingListHolder. If there were more bindings available, creates an SstNameBindingIterator which will iterate through the remaining bindings and place it in @bindingIteratorHolder.
newContext
Answers an instance of the receiver, not bound to any name.
rebind: name obj: value
Binds @value to @name within the receiver. If @value is an instance of the receiver, it will not participate in compound name resolution. If @name is a compound name, each component except the last identifies a naming context which must already exist.
rebindContext: name nc: value
Binds @value to @name within the receiver. @value will participate in compound name resolution. If @name is a compound name, each component except the last identifies a naming context which must already exist.
resolve: name
Retrieves the object bound to @name in the receiver. If the name is a compound name, each component except the last identifies a naming context which must already exist.
unbind: name
Removes a binding for @name within the receiver. If @name is a compound name, each component except the last identifies a naming context which must already exist.
The list:bl:bi: operation sets the @bindingListHolder object value to collection of SstNameBinding objects, where each object contains both a name and a type, indicating whether the object bound to the name is a naming context or an actual object. The @bindingIteratorHolder object value is set to an instance of SstNameBindingIterator if there are any more bindings left. This object supports API to progressively obtain more name bindings.
The following code illustrates creating a naming service within SST, creating a name myNames for another naming service and binding a new naming context to that name in the naming service. Then another name example.txt is created, and a string bound to that name within the naming context myNames. Note that myNames/example.txt is an example of a compound name, where all components but the last are expected to refer to existing naming contexts discovered by navigating through the naming hierarchy of the naming service itself. The naming service is then asked to resolve the name myNames/example.txt, and finally to unbind the binding for that name. The doit returns the example text object previously bound within the naming service.
| namingService serviceName name exampleText |
namingService := SstNamingContext new.
serviceName := SstName from: 'myNames'.
namingService bindNewContext: serviceName.
name := SstName from: 'myNames/example.txt'.
namingService bind: name obj: 'This is an object in myNames'.
exampleText := namingService resolve: name.
namingService unbind: name.
^exampleText
Last modified date: 01/29/2015