Ejemplo n.º 1
0
 def destroy(self, aSessionToken):
     """
     Destroy a session before the expiration
     
     @param aSessionToken: a valid session token
     @type aSessionToken: string
     @return: True if session destroyed, False if aSessionToken is invalid
     @rtype: boolean
     """
     with self._lock:
         try:
             for serviceName in self._factory.services():
                 try:
                     myclips_server.timeout_call(self._factory.instance(serviceName).onSessionDestroy, 2, args=(aSessionToken))
                 except MyClipsServerException:
                     pass
                 
         except myclips_server.FunctionCallTimeout:
             myclips_server.logger.warning("Session cleanup took more than 2 seconds...")
             pass
         
         try:    
             del self._sessions[aSessionToken]
             return True
         except:
             return False
Ejemplo n.º 2
0
 def register(self, aSessionToken, aListenerName, aListenerAddress, aReverseToken, *eventsName):
     '''
     Register a xmlrpc end-point of the client as a myclips's event listener
     If a listener with the same identifier is already registered,
     it will be unregister and then replaced
     
     The registration protocol requires the client end-point to
     reply to a <client-end-point>.ping(aReverseToken) method call
     before the registration is completed
     
     Standard event names for MyClips's Network Engine are:
     
         action-performed, debug-options-changed, fact-asserted, 
         fact-retracted, network-reset-post, network-reset-pre, 
         network-ready, network-reset-post, network-reset-pre, 
         network-shutdown, node-activated, node-activated-left, 
         node-activated-right, node-added, node-linked, node-removed, 
         node-shared, node-unlinked, rule-activated, rule-added, 
         rule-deactivated, rule-fired, rule-removed, strategy-changed
         
     More info about event's args and meanings are available in the myclips's documentation
     
     
     @param aSessionToken: a token for a valid session
     @type aSessionToken: string
     @param aListenerName: the identifier of the listener after the registration
     @type aListenerName: string
     @param aListenerAddress: the url of the xmlrpc server of the client where events will be forwarded
     @type aListenerAddress: string
     @param aReverseToken: a <secret-code> the server will send with data to identify a valid transmission 
     @type aReverseToken: mixed
     @param eventsName: a list of event names to register for
     @type eventsName: list of strings 
     '''        
     
     someListeners = self.getListeners(aSessionToken)
     if someListeners.has_key(aListenerName):
         self.unregister(aSessionToken, aListenerName)
     
     theListener = xmlrpclib.Server(aListenerAddress, allow_none=True)
     
     try:
         myclips_server.timeout_call(theListener.ping, 2, args=(aReverseToken))
     except myclips_server.FunctionCallTimeout:
         myclips_server.logger.info("...a ClientListener ping check took more than 2 seconds. Ignored!")
     else:
         # if the events[0] is a list, then the client failed to expand the list of 
         # events (just like myclips-javalib)
         if len(eventsName) and isinstance( eventsName[0], list ):
             eventsName = eventsName[0] + list(eventsName)[1:]
         
         theListener = ClientListener(aReverseToken, theListener, self, eventsName)
         
         theNetwork = self._broker.Engine.getNetwork(aSessionToken)
         theListener.install(theNetwork.eventsManager)
             
         someListeners[aListenerName] = theListener
Ejemplo n.º 3
0
 def forward(self, *args, **kwargs):
     '''
     Forward a notify call to the client listener add the reverse token arg
     '''
     args = [self._theReverseToken] + [args[0]] + [[self._theOwner._broker.Registry.toSkeleton(x, True) for x in args[1:]]]
     try:
         myclips_server.timeout_call( self._theServer.Listener.notify, timeout=5, args=args)
     except myclips_server.FunctionCallTimeout:
         myclips_server.logger.info("...a listener forwarding took more than 5 second. Aborted")
     except:
         myclips_server.logger.info("A listener could be not valid anymore: %s", self)
Ejemplo n.º 4
0
    def register(self, aSessionToken, aStreamName, aStreamAddress, aReverseToken):
        """
        Register a xmlrpc end-point of the client as a stream
        If a stream with the same identifier is already registered,
        it will be unregister and then replaced
        
        The registration protocol requires the client end-point to
        reply to a <client-end-point>.ping(aReverseToken) method call
        before the registration is completed
        
        @param aSessionToken: a token for a valid session
        @type aSessionToken: string
        @param aStreamName: the identifier of the stream after the registration
        @type aStreamName: string
        @param aStreamAddress: the url of the xmlrpc server of the client where streams methods will be redirected
        @type aStreamAddress: string
        @param aReverseToken: a <secret-code> the server will send with data to identify a valid transmission 
        @type aReverseToken: mixed
        """

        # theStreamName = "ClientIO_ClientIO.streams.%s"%aStreamName
        theSessionsService = self._broker.Sessions

        try:
            self.unregister(aSessionToken, aStreamName)
        except:
            # ignore any error
            pass

        try:
            theStreamsDict = theSessionsService.getProperty(aSessionToken, "ClientIO_ClientIO.streams")
        except:
            theStreamsDict = {}
            theSessionsService.setProperty(aSessionToken, "ClientIO_ClientIO.streams", theStreamsDict)

        theStream = xmlrpclib.Server(aStreamAddress, allow_none=True)

        try:
            myclips_server.timeout_call(theStream.ping, 2, args=(aReverseToken))
        except myclips_server.FunctionCallTimeout:
            myclips_server.logger.info("...a ClientIOStream ping check took more than 2 seconds. Ignored!")
        else:
            theStreamsDict[aStreamName] = ClientIOStream(aReverseToken, theStream)
Ejemplo n.º 5
0
 def __forward_call(*args, **kwargs):
     try:
         # return getattr(self._theServer, name)(self._theReverseToken, *args, **kwargs)
         return myclips_server.timeout_call(
             getattr(self._theServer.Stream, name),
             timeout=60,
             args=[self._theReverseToken] + list(args),
             kwargs=kwargs,
         )
     except xmlrpclib.Fault:
         return self._theServer.Stream.__call(self._theReverseToken, name, *args, **kwargs)
     except FunctionCallTimeout:
         myclips_server.logger.warning("...a ClientIOStream request took more than 60 seconds. Aborted")
         raise IOError()