Example #1
0
func newLogic() *Logic {
	return &Logic{
		AppConf:     cache.Task,
		Traversal:   spider.Menu,
		status:      status.STOPPED,
		Teleport:    teleport.New(),
		TaskJar:     distribute.NewTaskJar(),
		SpiderQueue: crawl.NewSpiderQueue(),
		CrawlPool:   crawl.NewCrawlPool(),
	}
}
Example #2
0
func New() App {
	app := &Logic{
		AppConf:     cache.Task,
		Traversal:   spider.Menu,
		Scheduler:   scheduler.Sdl,
		status:      status.STOP,
		Teleport:    teleport.New(),
		TaskJar:     distribute.NewTaskJar(),
		SpiderQueue: crawl.NewSpiderQueue(),
		CrawlPool:   crawl.NewCrawlPool(),
	}
	return app
}
Example #3
0
// 使用App前必须进行先Init初始化,SetLog()除外
func (self *Logic) Init(mode int, port int, master string, w ...io.Writer) App {
	self.canSocketLog = false
	if len(w) > 0 {
		self.SetLog(w[0])
	}
	self.LogGoOn()

	cache.Task.RunMode, cache.Task.Port, cache.Task.Master = mode, port, master

	self.Traversal = spider.Menu
	self.RunMode = mode
	self.Port = ":" + strconv.Itoa(port)
	self.Master = master
	self.Teleport = teleport.New()
	self.TaskJar = distribute.NewTaskJar()
	self.SpiderQueue = crawl.NewSpiderQueue()
	self.CrawlPool = crawl.NewCrawlPool()

	switch self.RunMode {
	case status.SERVER:
		if self.checkPort() {
			logs.Log.SetStealLevel()
			logs.Log.Informational("                                                                                               !!当前运行模式为:[ 服务器 ] 模式!!")
			self.Teleport.SetAPI(distribute.ServerApi(self)).Server(self.Port)
		}

	case status.CLIENT:
		if self.checkAll() {
			logs.Log.SetStealLevel()
			logs.Log.Informational("                                                                                               !!当前运行模式为:[ 客户端 ] 模式!!")
			self.Teleport.SetAPI(distribute.ClientApi(self)).Client(self.Master, self.Port)
		}
	case status.OFFLINE:
		logs.Log.Informational("                                                                                               !!当前运行模式为:[ 单机 ] 模式!!")
		return self
	default:
		logs.Log.Warning(" *    ——请指定正确的运行模式!——")
		return self
	}
	// 根据RunMode判断是否开启节点间log打印
	self.canSocketLog = true
	go self.socketLog()
	return self
}