func Launch(option *options.SysOption) {
	signalChannel := make(chan os.Signal, 1)
	signal.Notify(signalChannel, os.Interrupt)
	signal.Notify(signalChannel, syscall.SIGTERM)
	coremethods.Setup()
	mustExit := false
	stat := statistic.NewStatistic(*option)
	manager := coresupport.NewCoreWorkerManager(*option, stat)
	server := connectionserver.NewServer(*option, stat)
	server.Start(manager)
	manager.Start(server)
	// wait
	for !mustExit {
		select {
		case newSig := <-signalChannel:
			{
				if newSig != nil {
					rllogger.Output(rllogger.LogInfo, "Stoping service, now wait..")
					server.Stop()
					manager.Stop()
				}
			}
		case <-manager.OutSignalChannel:
			{
				rllogger.Output(rllogger.LogInfo, "Close manager.")
				mustExit = true
			}
		}
	}
	manager.Close()
	stat.Close()
	close(signalChannel)
}
Exemple #2
0
func statProcessing(stat *Statistic) {
	timer := time.NewTicker(time.Duration((*stat).iterTime) * time.Second)
	out := func() {
		rllogger.Output(rllogger.LogInfo, "Statistic closing...")
		timer.Stop()
		close((*stat).closeChan)
		close((*stat).messages)
	}
	defer out()
	for (*stat).active {
		select {
		case msg := <-(*stat).messages:
			{
				stat.add(&msg)
			}
		case <-(*stat).closeChan:
			{
				stat.stop()
			}
		case now := <-timer.C:
			{
				(*stat).lastSendTime = now
				stat.calc()
				stat.SendResult()
			}
		}
	}
}
Exemple #3
0
func (server RlServer) Run() {
	server.SetActive(true)
	msgToCoreBuffer := make(chan protocol.CoreMsg, server.option.BufferSize)
	statistic := NewRlStatistic()
	statistic.Run(&server)
	answerDispatcher := NewAnswerDispatcher()
	serverBusyAccounting := helpers.NewServerBusyAccounting()
	serverMethods := helpers.NewServerMethods()
	go upConnection(&server, &msgToCoreBuffer, answerDispatcher, statistic)
	//connectionSupport := connectionsupport.NewConnectionAccounting()
	// TODO: use it
	//connectionSupport.Dec()

	for index := 1; index < server.option.Workers+1; index++ {
		go coreWorker(
			index,
			&server,
			&msgToCoreBuffer,
			answerDispatcher,
			serverBusyAccounting,
			serverMethods,
			statistic)
	}
	// status service
	go serviceBroadcasting(&server, answerDispatcher)
	// wait sigterm
	signalChannel := make(chan os.Signal, 1)
	signal.Notify(signalChannel, os.Interrupt)
	signal.Notify(signalChannel, syscall.SIGTERM)
	for server.IsActive() {
		newSig := <-signalChannel
		if newSig != nil {
			server.SetActive(false)
		}
	}
	rllogger.Output(rllogger.LogInfo, "stoping server, wait...")
	answerDispatcher.CloseAll()
	close(signalChannel)
	for server.HasConnection() {
		rllogger.Output(rllogger.LogInfo, "wait closing client connection.")
		time.Sleep(1 * time.Second)
	}
	close(msgToCoreBuffer)
	statistic.Finish()
}
Exemple #4
0
func NewServerCreate(optionSrc options.OptionLoder) *RlServer {
	option, err := optionSrc.Load(true)
	if err != nil {
		rllogger.Outputf(rllogger.LogTerminate, "Option load failed: %s", err)
	}
	server := RlServer{
		option:                  *option,
		changeCountLock:         new(sync.RWMutex),
		CoroutineActiveResource: *(helpers.NewCoroutineActiveResource())}

	rllogger.Output(rllogger.LogInfo, server.info())
	return &server
}
func (mng *CoreWorkerManager) Stop() {
	manager := *mng
	count := manager.options.Workers
	for index := 0; index < count; index++ {
		manager.workerStopSignalChannel <- true
	}
	rllogger.Output(rllogger.LogInfo, "Stoping workers..")
	close(manager.instructionsChannel)
	close(manager.workerStopSignalChannel)
	for _, groupPtr := range manager.outChannels {
		if groupPtr != nil {
			groupPtr.SendExit()
		}
	}
	manager.OutSignalChannel <- true
}
func (dict *MethodInstructionDict) check() {
	if len((*dict).content) <= 0 {
		// use once instance only!
		rllogger.Output(rllogger.LogTerminate, "Use NewMethodInstructionDict()")
	}
}
func (server *ConnectionServer) Stop() {
	server.SetStatus(ServerStatusOff)
	rllogger.Output(rllogger.LogInfo, "Connection server stopping..")
}