mò Mã¸Ec@s$dkZdkZdkZdkZdkZdkZdkZdkZdkZdk l Z dk l Z dk lZdkZdklZdefd„ƒYZeedƒo%eifZdeieifZneifZdeifZd eifd „ƒYZd fd „ƒYZdS( N(s ReadOnlyError(sBLATHER(slog(sManagedClientConnectiontConnectionManagercBsqtZdZddd„Zd„Zd„Zd„Zd„Zd„Zd d „Z d „Z d „Z d „Z RS(sKeeps a connection up over timeii´cCsd|i|ƒ|_||_||_||_titi ƒƒ|_ d|_ d|_ d|_dS(Ni(tselft _parse_addrstaddrstaddrlisttclientttminttmaxt threadingt ConditiontLocktcondtNonet connectiontclosedtthread(RRRRR((t./data/zmath/zope/lib/python/ZEO/zrpc/client.pyt__init__"s     cCsd|ii|ifS(Ns <%s for %s>(Rt __class__t__name__R(R((Rt__repr__.scCs•|i|ƒ}|dj o||fgSneg}xW|D]O}|i|ƒ}|djotdt|ƒƒ‚n|i ||fƒq:W|SdS(Nsunknown address in list: %s( Rt _guess_typeRt addr_typeR Rtaddrt ValueErrortreprtappend(RRRRR((RR1s  cCsnt|tiƒo tiSnt|ƒdjo9t|dtiƒo"t|dtiƒo tiSndS(Niii( t isinstanceRttypest StringTypetsockettAF_UNIXtlentIntTypetAF_INETR (RR((RREs  A cCs»d|_|iiƒz|i}d|_|i}Wd|ii ƒX|dj oIt dƒ|i ƒ|i dƒ|i ƒot ddtiƒqœn|dj o|iƒndS(s6Prevent ConnectionManager from opening new connectionsiNs'CM.close(): stopping and joining threadis(CM.close(): self.thread.join() timed outtlevel(RRR tacquireRttR R tconntreleasetlogtstoptjointisAlivetloggingtWARNINGtclose(RR%R&((RR.Qs$           cCs¤|iƒ|iiƒz|i}|i}Wd|iiƒX|dj oO|djoB|i }|i ƒ|iiƒz |i}Wd|iiƒXn|dj S(s§Attempt a connection to the server without blocking too long. There isn't a crisp definition for too long. When a ClientStorage is created, it attempts to connect to the server. If the server isn't immediately available, it can operate from the cache. This method will start the background connection thread and wait a little while to see if it finishes quickly. N( RtconnectR R$RR%R R&R'R t one_attemptteventtwait(RR%R&R1((Rtattempt_connectfs"        icCs|iiƒzÓ|idj odSn|i}|djoPtdƒt||i |i |i |i ƒ|_}|i dƒ|iƒn|oJxG|idjo2|iidƒ|idjotdƒq˜q˜WnWd|iiƒX|o|idj pt‚ndS(Ns$CM.connect(): starting ConnectThreadiis$CM.connect(sync=1): still waiting...(RR R$R R RR%R(t ConnectThreadRRRRt setDaemontstarttsyncR2R'tAssertionError(RR7R%((RR/Šs,      cCs^td|ƒ|iiƒz.||_|o d|_n|ii ƒWd|ii ƒXdS(NsCM.connect_done(preferred=%s)( R(t preferredRR R$R&R R Rt notifyAllR'(RR&R9((Rt connect_done¡s   cCs†|iiƒz?||ij otddtƒdSntdƒd|_Wd|iiƒX|i i ƒ|i p|i ƒndS(NsCM.close_conn() non-currentR#sCM.close_conn()( RR R$R&R R(tBLATHERR R'RtnotifyDisconnectedRR/(RR&((Rt close_conn­s     cCs3|iiƒz|idj SWd|iiƒXdS(N(RR R$R R R'(R((Rt is_connected½s  ( Rt __module__t__doc__RRRRR.R3R/R;R>R?(((RRs     $  tWSAEWOULDBLOCKiR4cBsYtZdZeiiZd„Zd„Zd„Zd„Z d„Z d„Z d„Z RS(sóThread that tries to connect to server given one or more addresses. The thread is passed a ConnectionManager and the manager's client as arguments. It calls testConnection() on the client when a socket connects; that should return 1 or 0 indicating whether this is a preferred or a fallback connection. It may also raise an exception, in which case the connection is abandoned. The thread will continue to run, attempting connections, until a preferred connection is seen and successfully handed over to the manager and client. As soon as testConnection() finds a preferred connection, or after all sockets have been tried and at least one fallback connection has been seen, notifyConnected(connection) is called on the client and connect_done() on the manager. If this was a preferred connection, the thread then exits; otherwise, it keeps trying until it gets a preferred connection, and then reconnects the client using that connection. cCs]|idd|ƒ||_||_||_||_||_d|_ti ƒ|_ dS(Ntnames Connect(%s)i( Rt_ConnectThread__super_initRtmgrRRRtstoppedRtEventR0(RRERRRR((RRðs      cCs d|_dS(Ni(RRF(R((RR)þscCsÑ|i}d}d}x¡|ip–|i|ƒ}|iiƒp|ii ƒd}n|djoPnt i |ƒ|i i ƒotddtiƒnt|d|iƒ}qWtd|iƒƒdS(NiiiKs/CT: still trying to replace fallback connectionR#isCT: exiting thread: %s(RRtdelaytsuccesstattempt_timeoutRFttry_connectingR0tisSettsetttimetsleepRER?R(R,tINFOtminRtgetName(RRIRJRH((Rtruns"      cCs%tdt|iƒƒtiƒ|}|iƒ}x,|i ƒD]}|i djodSq@q@Wz—tiƒ|jodSn|i ||ƒ}|dj o|Sntiƒ|jodSn|i||ƒ}|dj o|Sn| pt‚Wdx|i ƒD]}|iƒq W~XdS(s Try connecting to all self.addrlist addresses. Return 1 if a preferred connection was found; 0 if no connection was found; and -1 if a fallback connection was found. If no connection is found within timeout seconds, return 0. s'CT: attempting to connect on %d socketstnotifiediiN(R(R RRRNttimeouttdeadlinet_create_wrapperstwrapperstkeystwraptstatet_connect_wrapperstrR t_fallback_wrappersR8R.(RRURXR]RVRZ((RRKs4      cCs©h}xœ|iD]‘\}}t|||i|iƒ}|i ƒ|i djo2x|i ƒD]}|i ƒq^Wh||