New Version of Ghost: the proxy library

I finished new version of Ghost:
  • DNU approach for basic proxies instead of #cannotInterpret: trick (trick used only for class proxies)
  • Abstract proxy classes uses Ghost name instead of Proxy: there are GHObjectGhost and GHClassGhost.
  • GHProxyHandler renamed to GHGhostBehaviour. Concrete ghosts should implement #ghostBehaviour instead of #proxyHandler.
  • GHGhostBehaviour should define #currentMetaLevel to specify set of messages which should not be intercepted. Such meta messages will be executed under ghost instance by subclass of GHMetaMessages.
In previous version there was dictionary which maps meta message selector to implementation selector. It was not suitable. Now meta messages should be directly implemented on particular GHMetaMessages subclass and all it methods are considered meta.
So GhostBehaviour should return instance of GHMetaLevel with meta messages implementation class:
    • GHMetaLevel with: GHEmptyMetaMessages “when all possible messages should intercepted”
    • GHMetaLevel with: GHStandartMetaMessages “when tools specific messages should not be intercepted”
For example standard meta messages implements #inspect:
“Create and schedule an Inspector in which the user can examine the receiver’s variables.”
^ Smalltalk tools inspector inspect: ghost
  • Traits for methods explicitly defined on ghosts: TMinimalProxy, TNotNilProxy, TIdentifiedProxy (with #=, #hash, #class). Concrete proxies can add this traits to itself independently from meta level. For example traits supply convenient methods to retrieve ghost information in polymorphic way with objects:
    • ghost isGhost
    • ghost ghostClass “returns actual class of receiver”
    • ghost ghostPrintString “returns string which represents ghost from meta level point of view”
This traits are suitable and they provide some kind of optimisation for proxies (methods from traits are executed directly instead of complex meta messages mechanizm). But maybe they are superfluous. For example they can’t be reused for class proxies which substitute real object classes (to intercept all instance messages).
  • GHClassGhost able to replace class of real objects. It implements cannotInterpret: trick to intercept all instance messages. Subclasses should define two behaviours: #ghostBehaviour (as any other ghost) and #instancesBehaviour which will process instance messages. In previous version it was different message to same #ghostBehaviour.
  • New kind of proxies:
    • GHObjectVirus. It is special kind of GHClassProxy. It infects real object to intercept it messages. From meta level infected object looks like healthy object which means that meta messages are executed by infected object itself. As class virus looks like real victim class. So in case when virus is created with standard meta level tools will not differ him from health object. There are special messages which allow ask object about viruses:
      • infectedObject isInfectedByVirus
      • infectedObject virus
      • infectedObject recoverFromVirus
    • GHLearningObject. It is suitable proxy which retrieves all unknown methods from teacher class. Thank’s Stephan for this idea.
This kind of proxy allows me easily find required set of messages to support inspectors and debuggers. You can create instance of learning object by:
GHLearningObject withTeacher: Object.
And any operation with it will fill studiedMessages dictionary. In my case I opened GTInspector on it and got all messages which was needed for him.
  • Ghosts works correctly with latest Pharo 5 tools (basic inspector, GTInspector, SpecDebugger, GTDebugger). Required methods for tools are extracted to ‘Ghost-GTSupport’ package.
  • Repackaging:
    • Ghost-ObjectProxies. It contains all core classes and abstract GHObjectGhost which is based on DNU
    • Ghost-ClassProxies. It contains code for proxy which can substitute class of real object. GHClassGhost implements cannotInterpret: trick to intercept all instance messages. And it implement support for debugging such methods.
    • Ghost-LearningObject
    • Ghost-ObjectVirus
    • Ghost-GTSupport
    • test packages
  • All code moved to Pharo repository!/~Pharo/Ghost (in includes packages from CAR repo too)
You can load new version by:
Gofer it
smalltalkhubUser: ‘Pharo’ project: ‘Ghost’;
configurationOf: ‘Ghost’;
I use it now in Seamless and Mocketry.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: