Esempio n. 1
0
// Loads the router table from one or more of the urls
func ConnectionsFromSeed(urls ...string) (*Connections, error) {
	connections := &Connections{}

	var rt *RouterTable
	var err error
	for _, url := range urls {
		c := client.NewHttp(url)
		rt, err = RequestRouterTable(c)
		if err != nil {
			break
		}
	}
	if rt == nil {
		return nil, fmt.Errorf("Unable to get a router table from urls %s ERROR(%s)", urls, err)
	}
	_, err = connections.SetRouterTable(rt)
	return connections, err
}
Esempio n. 2
0
// Creates a new manager.  Uses the one or more seed urls to download the
// routing table.
func NewManagerSeed(partitioner Partitioner, serviceName, dataDir, myEntryId string, seedHttpUrls []string) (*Manager, error) {
	//TODO: can we get the servicename from the routing table?

	manager := NewManager(partitioner, serviceName, dataDir, myEntryId)
	var err error
	for _, url := range seedHttpUrls {

		client := client.NewHttp(url)
		tble, err := RequestRouterTable(client)
		client.Close()
		if err != nil {
			//found a table..  woot
			manager.SetRouterTable(tble)
			return manager, nil
		}
	}

	if manager.table != nil {
		//uhh, I guess we sucessfully loaded it elsewhere
		return manager, nil
	}
	//we still return the manager since it is usable just doesnt have a routing table.
	return manager, err
}