func (s *Server) clearSessionTimer(id string) error {
	s.sessionTimersLock.Lock()
	defer s.sessionTimersLock.Unlock()
	if timer, ok := s.sessionTimers[id]; ok {
		timer.Stop()
		delete(s.sessionTimers, id)
	}
	return nil
}
clearSessionTimer is used to clear the session time for
a single session. This is used when a session is destroyed
explicitly and no longer needed.
package consul
import (
	"fmt"
	"time"
	"github.com/socketplane/socketplane/Godeps/_workspace/src/github.com/armon/go-metrics"
	"github.com/socketplane/socketplane/Godeps/_workspace/src/github.com/hashicorp/consul/consul/structs"
)
func (s *Server) initializeSessionTimers() error {
	state := s.fsm.State()
	_, sessions, err := state.SessionList()
	if err != nil {
		return err
	}
	for _, session := range sessions {
		if err := s.resetSessionTimer(session.ID, session); err != nil {
			return err
		}
	}
	return nil
}
func (s *Server) resetSessionTimer(id string, session *structs.Session) error {
	if session == nil {
		state := s.fsm.State()
		_, s, err := state.SessionGet(id)
		if err != nil {
			return err
		}
		if s == nil {
			return fmt.Errorf("Session '%s' not found", id)
		}
		session = s
	}
	switch session.TTL {
	case "", "0", "0s", "0m", "0h":
		return nil
	}
	ttl, err := time.ParseDuration(session.TTL)
	if err != nil {
		return fmt.Errorf("Invalid Session TTL '%s': %v", session.TTL, err)
	}
	if ttl == 0 {
		return nil
	}
	s.sessionTimersLock.Lock()
	defer s.sessionTimersLock.Unlock()
	s.resetSessionTimerLocked(id, ttl)
	return nil
}
func (s *Server) resetSessionTimerLocked(id string, ttl time.Duration) {
	if s.sessionTimers == nil {
		s.sessionTimers = make(map[string]*time.Timer)
	}
	ttl = ttl * structs.SessionTTLMultiplier
	if timer, ok := s.sessionTimers[id]; ok {
		timer.Reset(ttl)
		return
	}
	timer := time.AfterFunc(ttl, func() {
		s.invalidateSession(id)
	})
	s.sessionTimers[id] = timer
}
func (s *Server) invalidateSession(id string) {
	defer metrics.MeasureSince([]string{"consul", "session_ttl", "invalidate"}, time.Now())
	s.sessionTimersLock.Lock()
	delete(s.sessionTimers, id)
	s.sessionTimersLock.Unlock()
	args := structs.SessionRequest{
		Datacenter: s.config.Datacenter,
		Op:         structs.SessionDestroy,
		Session: structs.Session{
			ID: id,
		},
	}
	s.logger.Printf("[DEBUG] consul.state: Session %s TTL expired", id)
	if _, err := s.raftApply(structs.SessionRequestType, args); err != nil {
		s.logger.Printf("[ERR] consul.session: Invalidation failed: %v", err)
	}
}