twisted.spread.flavors.ViewPoint

Package twisted :: Package spread :: Module flavors :: Class ViewPoint |
[frames | no frames]

## Class ViewPoint

    Jellyable --+
                |
     Serializable --+
                    |
        Referenceable --+
                        |
                       ViewPoint

I act as an indirect reference to an object accessed through a `pb.Perspective`.

Simply put, I combine an object with a perspective so that when a peer calls methods on the object I refer to, the method will be invoked with that perspective as a first argument, so that it can know who is calling it.

While `Viewable` objects will be converted to ViewPoints by default when they are returned from or sent as arguments to a remote method, any object may be manually proxied as well. (XXX: Now that this class is no longer named `Proxy`, this is the only occourance of the term 'proxied' in this docstring, and may be unclear.)

This can be useful when dealing with `pb.Perspective`s, `Copyable`s, and `Cacheable`s. It is legal to implement a method as such on a perspective:

    | def perspective_getViewPointForOther(self, name):
    |     defr = self.service.getPerspectiveRequest(name)
    |     defr.addCallbacks(lambda x, self=self: ViewPoint(self, x), log.msg)
    |     return defr

This will allow you to have references to Perspective objects in two different ways. One is through the initial 'attach' call -- each peer will have a `pb.RemoteReference` to their perspective directly. The other is through this method; each peer can get a `pb.RemoteReference` to all other perspectives in the service; but that `pb.RemoteReference` will be to a `ViewPoint`, not directly to the object.

The practical offshoot of this is that you can implement 2 varieties of remotely callable methods on this Perspective; view_xxx and `perspective_xxx`. `view_xxx` methods will follow the rules for ViewPoint methods (see ViewPoint.`remoteMessageReceived`), and `perspective_xxx` methods will follow the rules for Perspective methods.

Method Summary
| ``__init__`(self, perspective, object)` Initialize me with a Perspective and an Object.
| ``processUniqueID`(self)` Return an ID unique to a proxy for this perspective+object combination.
| ``remoteMessageReceived`(self, broker, message, args, kw)` A remote message has been received.
Inherited from Referenceable
| ``jellyFor`(self, jellier)` (internal)
Inherited from Jellyable
| ``getStateFor`(self, jellier)`

Class Variable Summary
Inherited from Referenceable
`NoneType` | `perspective` = None
Inherited from Jellyable
`tuple` | `__implements__` = `(<class twisted.spread.interfaces.IJell...`

Method Details

### __init__(self, perspective, object) (Constructor) Initialize me with a Perspective and an Object.

### processUniqueID(self) Return an ID unique to a proxy for this perspective+object combination. Overrides: `twisted.spread.flavors.Serializable.processUniqueID`

### remoteMessageReceived(self, broker, message, args, kw) A remote message has been received. Dispatch it appropriately. The default implementation is to dispatch to a method called '`view_messagename`' to my Object and call it on my object with the same arguments, modified by inserting my Perspective as the first argument. Overrides: `twisted.spread.flavors.Referenceable.remoteMessageReceived`

Generated by Epydoc 2.0 on Sat May 15 20:08:30 2004 | http://epydoc.sf.net