Example #1
0
func NewActorCell(props Props, parent *PID) *actorCell {

	cell := actorCell{
		parent:     parent,
		props:      props,
		supervisor: props.Supervisor(),
		behavior:   linkedliststack.New(),
		children:   hashset.New(),
		watchers:   hashset.New(),
		watching:   hashset.New(),
		message:    nil,
	}
	cell.incarnateActor()
	return &cell
}
Example #2
0
func GetHealthSlaverfromzk() {
	strs, _, err := zk.Children(utils.Cfg.GetString("sendslavers"))
	if err != nil {
		//		log.Fatalf("Can't connect: %v", err)
		fmt.Println(err)
	}
	flag := false
	res := hashset.New()
	var err3 error
	var healthstr string
	for _, str := range strs {
		healthstr, _, err3 = zk.Get(utils.Cfg.GetString("sendslavers") + "/" + str) //healthstr=ok/err
		if err3 != nil {
			//		log.Fatalf("Can't connect: %v", err)
			fmt.Println(err3)
		}
		if healthstr == "ok" {
			flag = true
			res.Add(str)
			break
		}
	}
	if flag == false {
		err3 = errors.New("no have healthy slaver now!!!!!!")
	}
	utils.SethealthSlavers(res)
}
Example #3
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	remoting.Start("127.0.0.1:8080")
	clients := hashset.New()
	props := actor.FromFunc(func(context actor.Context) {
		switch msg := context.Message().(type) {
		case *messages.Connect:
			log.Printf("Client %v connected", msg.Sender)
			clients.Add(msg.Sender)
			msg.Sender.Tell(&messages.Connected{Message: "Welcome!"})
		case *messages.SayRequest:
			notifyAll(clients, &messages.SayResponse{
				UserName: msg.UserName,
				Message:  msg.Message,
			})
		case *messages.NickRequest:
			notifyAll(clients, &messages.NickResponse{
				OldUserName: msg.OldUserName,
				NewUserName: msg.NewUserName,
			})
		}
	})
	actor.SpawnNamed(props, "chatserver")
	console.ReadLine()
}
Example #4
0
func watchslavers() {
	_, _, session1, err := zk.ChildrenW(utils.Cfg.GetString("sendslavers"))
	if err != nil {
		//		log.Fatalf("Can't connect: %v", err)
		fmt.Println(err)
	}
	event := <-session1
	alivedset := hashset.New()
	deadset := hashset.New()
	alivedset.Clear()
	deadset.Clear()
	if event.Type == zookeeper.EVENT_CHILD {
		slavers, _, err2 := zk.Children(utils.Cfg.GetString("sendslavers"))
		if err2 != nil {
			//		log.Fatalf("Can't connect: %v", err)
			fmt.Println(err2)
		}
		for _, slaver := range slavers {
			//			utils.AddlivedSlavers(slaver)
			alivedset.Add(slaver)
		}
	}
	for _, oldslave := range utils.GetlivedSlavers().Values() {
		if oldslave == nil {
			break
		}
		alivedset.Contains(oldslave) //判断获取的活着的slave里面是否包换之前的活着的列表里面的slave,如果没有,说明过去的节点死了
		deadset.Add(oldslave)
	}
	utils.SetlivedSlavers(alivedset)
	//容错,重新下发死了的节点的任务
	for _, slave := range deadset.Values() {
		utils.RemlivedSlaver(slave.(string))
		utils.RemhealthSlaver(slave.(string))
		taskid, _ := utils.TakeTask(slave.(string))
		utils.RemhealthslaveAndtask(slave.(string))
		utils.RemhealthtaskAndslave(taskid.(string))
		//重新发送任务
		process.SendTask(taskid.(string))
	}
	watchslavers()
}
Example #5
0
// HashSetExample to demonstrate basic usage of HashSet
func HashSetExample() {
	set := hashset.New()   // empty (keys are of type int)
	set.Add(1)             // 1
	set.Add(2, 2, 3, 4, 5) // 3, 1, 2, 4, 5 (random order, duplicates ignored)
	set.Remove(4)          // 5, 3, 2, 1 (random order)
	set.Remove(2, 3)       // 1, 5 (random order)
	set.Contains(1)        // true
	set.Contains(1, 5)     // true
	set.Contains(1, 6)     // false
	_ = set.Values()       // []int{5,1} (random order)
	set.Clear()            // empty
	set.Empty()            // true
	set.Size()             // 0
}
Example #6
0
package utils

import (
	"bufio"
	"github.com/emirpasic/gods/maps/hashmap"
	"github.com/emirpasic/gods/sets/hashset"
	"io"
	"os"
	"strconv"
	"strings"
)

//var slavers1 []string
var healthslaveAndtask *hashmap.Map = hashmap.New() //key是主机,value是任务
var healthtaskAndslave *hashmap.Map = hashmap.New() //key是主机,value是任务
var healthSlaversSet *hashset.Set = hashset.New()   //可以分配任务的从节点列表
var livedSlaverSet *hashset.Set = hashset.New()     //活着的从节点列表
func AddhealthSlavers(slaver string) {
	healthSlaversSet.Add(slaver)
}
func GethealthSlavers() *hashset.Set {
	return healthSlaversSet
}
func SethealthSlavers(slavers *hashset.Set) {
	healthSlaversSet = slavers
}
func RemhealthSlaver(slave string) {
	healthSlaversSet.Remove(slave)
}
func AddlivedSlavers(slaver string) {
	livedSlaverSet.Add(slaver)