func (c *gcmClient) replaceXMPPClient(activeMonitor bool) {
	prevc := c.xmppClient
	c.cerr = make(chan error)
	xmppc, err := connectXMPP(nil, c.sandbox, c.senderID, c.apiKey,
		c.onCCSMessage, c.cerr, c.debug, c.omitRetry)
	if err != nil {
		log.WithFields(log.Fields{"sender id": c.senderID, "error": err}).
			Error("connect gcm xmpp client")
		// Wait and try again.
		// TODO: remove infinite loop.
		time.Sleep(c.pingTimeout)
		c.replaceXMPPClient(activeMonitor)
	} else {
		c.xmppClient = xmppc
		// Close the previous client
		go prevc.Close(true)

		log.WithField("xmpp client ref", xmppc.ID()).WithField("previous xmpp client ref", prevc.ID()).
			Warn("gcm xmpp client replaced")

		if activeMonitor {
			c.spinUpActiveMonitor()
		}
	}
}
// Replace the active client.
Replace the active client.
// Replace the active client .
func (c *gcmClient) replaceXMPPClient(activeMonitor bool) {
	prevc := c.xmppClient
	c.cerr = make(chan error)
	xmppc, err := connectXMPP(nil, c.sandbox, c.senderID, c.apiKey,
		c.onCCSMessage, c.cerr, c.debug, c.omitRetry)
	if err != nil {
		log.WithFields(log.Fields{"sender id": c.senderID, "error": err}).
			Error("connect gcm xmpp client")
		time.Sleep(c.pingTimeout)
		c.replaceXMPPClient(activeMonitor)
	} else {
		c.xmppClient = xmppc
		go prevc.Close(true)
		log.WithField("xmpp client ref", xmppc.ID()).WithField("previous xmpp client ref", prevc.ID()).
			Warn("gcm xmpp client replaced")
		if activeMonitor {
			c.spinUpActiveMonitor()
		}
	}
}
func ( c * gcmClient ) replaceXMPPClient ( activeMonitor bool ) { prevc := c . xmppClient c . cerr = make ( chan error ) xmppc , err := connectXMPP ( nil , c . sandbox , c . senderID , c . apiKey , c . onCCSMessage , c . cerr , c . debug , c . omitRetry ) if err != nil { log . WithFields ( log . Fields { " " : c . senderID , " " : err } ) . Error ( " " ) time . Sleep ( c . pingTimeout ) c . replaceXMPPClient ( activeMonitor ) } else { c . xmppClient = xmppc go prevc . Close ( true ) log . WithField ( " " , xmppc . ID ( ) ) . WithField ( " " , prevc . ID ( ) ) . Warn ( " " ) if activeMonitor { c . spinUpActiveMonitor ( ) } } }
Replace the active client.
Replace the active client .
// Wait and try again. // TODO: remove infinite loop. // Close the previous client