当前位置: 首页>>代码示例>>Python>>正文


Python dispatcher.Dispatcher类代码示例

本文整理汇总了Python中iron.dispatcher.Dispatcher的典型用法代码示例。如果您正苦于以下问题:Python Dispatcher类的具体用法?Python Dispatcher怎么用?Python Dispatcher使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Dispatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: inBound_onUnbind

	def inBound_onUnbind( self, event ):
		self.state = self.STATE_UNBINDING

		self.socket.close()
		self.socket = None

		event.binding = self
		self.state = self.STATE_UNBOUND
		Dispatcher.notify( StateEvent( State.EVENT_STATE_CHANGE, self.state, self.STATE_BOUND ) )
开发者ID:CaveMike,项目名称:mercury,代码行数:9,代码来源:udp_binding.py

示例2: inConnected_onUnbind

	def inConnected_onUnbind( self, event ):
		self.state = self.STATE_DISCONNECTING

		self.socket.shutdown( SHUT_RDWR )

		self.state = self.STATE_DISCONNECTED

		newEvent = NetEvent( NetEvent.EVENT_DISCONNECTED, self.transport, self.localAddress, self.localPort, self.remoteAddress, self.remotePort, connection=self )
		Dispatcher.notify( newEvent )
开发者ID:CaveMike,项目名称:mercury,代码行数:9,代码来源:tcp_binding.py

示例3: inInitial_onRequest

	def inInitial_onRequest( self, event ):
		self.request = event

		self.state.changeState( self.STATE_TRYING )

		# Send request to server.
		Dispatcher.getInstance().notify( Event( self.NOTIFICATION_STARTED ), messageEvent = event ) #FIXME: This notify is also below...

		# Inform the TU.
		Dispatcher.getInstance().notify( Event( self.NOTIFICATION_STARTED ) )
开发者ID:CaveMike,项目名称:mercury,代码行数:10,代码来源:uac_transaction.py

示例4: close

	def close( self, event ):
		self.state = self.STATE_DISCONNECTING

		self.socket.close()
		self.socket = None

		self.state = self.STATE_DISCONNECTED

		newEvent = NetEvent( NetEvent.EVENT_DISCONNECTED, self.transport, self.localAddress, self.localPort, self.remoteAddress, self.remotePort, connection=self )
		Dispatcher.notify( newEvent )
开发者ID:CaveMike,项目名称:mercury,代码行数:10,代码来源:tcp_binding.py

示例5: inInitial_onRequest

	def inInitial_onRequest( self, event ):
		self.lastRequest = event

		# Pass request to TU.
		if self.auto100:
			# Send 100 response to client.
			e = createResponseEvent( event, 100 )
			Dispatcher.getInstance().notify( e )

		self.state.changeState( self.STATE_TRYING )
开发者ID:CaveMike,项目名称:mercury,代码行数:10,代码来源:uas_transaction.py

示例6: inInitial_onBind

	def inInitial_onBind( self, event ):
		self.state = self.STATE_BINDING

		self.socket = socket( AF_INET, SOCK_DGRAM )
		self.socket.setblocking( 0 )
		self.socket.bind( ( self.localAddress, self.localPort ) )
		self.socket.setsockopt( SOL_SOCKET, SO_REUSEADDR, 1 )

		event.binding = self
		self.state = self.STATE_BOUND
		Dispatcher.notify( StateEvent( State.EVENT_STATE_CHANGE, self.state, self.STATE_INITIAL ) )
开发者ID:CaveMike,项目名称:mercury,代码行数:11,代码来源:udp_binding.py

示例7: inBound_onRead

	def inBound_onRead( self, event ):
		if self.socket:
			try:
				buffer, source = self.socket.recvfrom( self.query( 'network.maxmessage' ), self.query( 'network.recvfromflags' ) )
				self.log.info( 'recvfrom:\n%s(%s:%s %s:%s)\n%s.' % ( str(self.transport), str(self.localAddress), str(self.localPort), str(source[0]), str(source[1]), str(buffer) ) )

				newEvent = NetEvent( NetEvent.EVENT_RX_PACKET, self.transport, self.localAddress, self.localPort, remoteAddress=source[0], remotePort=source[1], packet=str(buffer) )
				Dispatcher.notify( newEvent )
			except error, e:
				newEvent = NetError( e[0], e[1], self.transport, self.localAddress, self.localPort )
				Dispatcher.notify( newEvent )
开发者ID:CaveMike,项目名称:mercury,代码行数:11,代码来源:udp_binding.py

示例8: inConnected_onRead

	def inConnected_onRead( self, event ):
		if self.socket:
			buffer = self.socket.recv( self.query( 'network.maxmessage' ), self.query( 'network.recvflags' ) )
			if buffer:
				self.log.info( 'recv:\n%s(%s:%s %s:%s)\n%s.' % ( str(self.transport), str(self.localAddress), str(self.localPort), str(self.remoteAddress), str(self.remotePort), str(buffer) ) )

				newEvent = NetEvent( NetEvent.EVENT_RX_PACKET, self.transport, self.localAddress, self.localPort, self.remoteAddress, self.remotePort, packet=str(buffer), connection=self )
				Dispatcher.notify( newEvent )
			else:
				# Remote disconnect.
				self.close( event )
开发者ID:CaveMike,项目名称:mercury,代码行数:11,代码来源:tcp_binding.py

示例9: onTxPacket

	def onTxPacket( self, event ):
		event.id = BindingBase.EVENT_QUEUE

		name = Network.getBindingName( event.transport, event.localAddress, event.localPort )
		binding = self.bindings[name]
		if binding:
			Dispatcher.send( event, srcObj=self, dstObj=binding )
		else:
			for binding in self.bindings.itervalues():
				result = Dispatcher.send( event, srcObj=self, dstObj=binding )
				if result:
					break
开发者ID:CaveMike,项目名称:mercury,代码行数:12,代码来源:network.py

示例10: inInitial_onBind

	def inInitial_onBind( self, event ):
		self.state = self.STATE_BINDING
		#Dispatcher.notify( StateEvent( State.EVENT_STATE_CHANGE, self.state, self.STATE_INITIAL ) )

		self.socket = socket( AF_INET, SOCK_STREAM )
		self.socket.setblocking( 0 )
		self.socket.bind( ( self.localAddress, self.localPort ) )
		self.socket.setsockopt( SOL_SOCKET, SO_REUSEADDR, 1 )
		self.socket.listen( self.query( 'network.maxconnections' ) )

		event.binding = self
		self.state = self.STATE_BOUND
		Dispatcher.notify( StateEvent( State.EVENT_STATE_CHANGE, self.state, self.STATE_INITIAL ) )
开发者ID:CaveMike,项目名称:mercury,代码行数:13,代码来源:tcp_binding.py

示例11: runTest

	def runTest( self ):
		d = Dispatcher.getInstance()

		c = Context( 'Root' )
		c.start()

		p = TestParent()
		d.add( obj=p, parentObj=None, context=c )

		t = UasTransaction()
		d.add( obj=t, parentObj=None, context=c )
		d.addListener( t, p )

		s = 'SUBSCRIBE sip:[email protected];treats SIP/2.0\r\nTo: "Matt"<sip:[email protected]>\r\nContact: "RileyMan"<sip:[email protected]>\r\nFrom: "Josh"<sip:[email protected]>\r\n\r\n'
		m = Message( s )
		e = MessageEvent( MessageEvent.EVENT_RX, message=m, transport='udp', localAddress='127.0.0.1', localPort=9000, remoteAddress='127.0.0.1', remotePort=9001 )
		d.send( e, srcObj = p, dstObj = t )

		s = 'SIP/2.0 100 Trying\r\nTo: "Matt"<sip:[email protected]>\r\nContact: "RileyMan"<sip:[email protected]>\r\nFrom: "Josh"<sip:[email protected]>\r\n\r\n'
		m = Message( s )
		e = MessageEvent( MessageEvent.EVENT_TX, message=m, transport='udp', localAddress='127.0.0.1', localPort=9000, remoteAddress='127.0.0.1', remotePort=9001 )
		d.send( e, srcObj = p, dstObj = t )

		s = 'SIP/2.0 200 OK\r\nTo: "Matt"<sip:[email protected]>\r\nContact: "RileyMan"<sip:[email protected]>\r\nFrom: "Josh"<sip:[email protected]>\r\n\r\n'
		m = Message( s )
		e = MessageEvent( MessageEvent.EVENT_TX, message=m, transport='udp', localAddress='127.0.0.1', localPort=9000, remoteAddress='127.0.0.1', remotePort=9001 )
		d.send( e, srcObj = p, dstObj = t )

		d.send( Event( t.EVENT_TIMER_J ), srcObj = p, dstObj = t )

		c.stop()
开发者ID:CaveMike,项目名称:mercury,代码行数:31,代码来源:test_transaction.py

示例12: inBound_onQueue

	def inBound_onQueue( self, event ):
		self.__queue.put( event )

		self.remoteAddress = event.remoteAddress
		self.remotePort = event.remotePort
#FIXME:		self.socket.settimeout( self.query( 'network.connecttimeout' ) )
		try:
			self.socket.connect( (event.remoteAddress, event.remotePort) )

			self.state = self.STATE_CONNECTING

			return True
		except error, e:
			newEvent = NetError( e[0], e[1], self.transport, self.localAddress, self.localPort, connection=self )
			Dispatcher.notify( newEvent )

			self.close( event )

			return False
开发者ID:CaveMike,项目名称:mercury,代码行数:19,代码来源:tcp_binding.py

示例13: run

	def run( self ):
		while True:
			timeout = self.query( 'network.selecttimeout' )

			readSet = set()
			writeSet = set()
			errorSet = set()
			#FIXME: There needs to be locking here since a socket can
			#       be killed while we are enumerating.
			for binding in self.bindings.itervalues():
				binding.getReadyBindings( readSet, writeSet, errorSet )

			read = [ binding for binding in readSet ]
			write = [ binding for binding in writeSet ]
			error = [ binding for binding in errorSet ]

			if len(errorSet) or len(readSet) or len(writeSet):
				read, write, error = select( read, write, error, timeout )

 				for binding in read:
 					event = Event( binding.EVENT_READ )
					Dispatcher.send( event, srcObj=self, dstObj=binding )

 				for binding in write:
 					event = Event( binding.EVENT_WRITE )
					Dispatcher.send( event, srcObj=self, dstObj=binding )

 				for binding in error:
 					event = Event( binding.EVENT_ERROR )
					Dispatcher.send( event, srcObj=self, dstObj=binding )
			else:
				sleep( timeout )
开发者ID:CaveMike,项目名称:mercury,代码行数:32,代码来源:network.py

示例14: changeState

    def changeState( self, newState, notify = False ):
        """
        Transition to the new state and optionally notify listeners.
        The state transition will also generate and process internal leave and enter events.
        """

        if self.currentState == None:
            raise Exception( 'This state does not have a current state.' )

        oldState = self.currentState

        # Only execute block if the state is really changing.
        if oldState != newState:
            # Stop state timer.
            self.stopStateTimer()

            # Leave pseudo-event.
            Dispatcher.getInstance().send( StateEvent( self.EVENT_LEAVE, newState = newState, oldState = oldState ), self.obj, self.obj )

            # Change state.
            self.log.info( 'Changing state from %s to %s.' % ( str(oldState), str(newState) ) )
            self.currentState = newState

            # Enter pseudo-event.
            Dispatcher.getInstance().send( StateEvent( self.EVENT_ENTER, newState = newState, oldState = oldState ), self.obj, self.obj )

            # Notify listeners.
            if notify:
                self.log.info( 'Notify listeners of the state change.' )
                Dispatcher.getInstance().notify( StateEvent( self.EVENT_STATE_CHANGE, newState = newState, oldState = oldState ), self.obj )

            # Start state timer.
            self.startStateTimer()
开发者ID:,项目名称:,代码行数:33,代码来源:

示例15: startStateTimer

    def startStateTimer( self ):
        """
        If the current state is configured with a state timeout, then start the state timer.
        """

        stateTimeout = self.stateTimeouts.get( self.currentState, None )

        if stateTimeout:
            self.log.info( 'Start state timer with a timeout of ' + str(stateTimeout) + '.' )

            if self.stateTimer:
                self.stopStateTimer()

            self.stateTimer = Dispatcher.getInstance().schedule( stateTimeout, StateEvent( self.EVENT_TIMEOUT, newState = self.currentState ), self.obj, self.obj )
开发者ID:,项目名称:,代码行数:14,代码来源:


注:本文中的iron.dispatcher.Dispatcher类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。