Example #1
0
func NewUnixServer(engine *Momonga, config *configuration.Config, inherit bool) *UnixServer {
	t := &UnixServer{
		Engine:  engine,
		Address: config.GetSocketAddress(),
		stop:    make(chan bool, 1),
		inherit: inherit,
	}

	return t
}
Example #2
0
func NewTcpServer(engine *Momonga, config *configuration.Config, inherit bool) *TcpServer {
	t := &TcpServer{
		Engine:        engine,
		ListenAddress: config.GetListenAddress(),
		config:        config,
		stop:          make(chan bool, 1),
		inherit:       inherit,
	}

	return t
}
Example #3
0
// QoS 1, 2 are available. but really suck implementation.
// reconsider qos design later.
func NewMomonga(config *configuration.Config) *Momonga {
	engine := &Momonga{
		OutGoingTable: util.NewMessageTable(),
		TopicMatcher:  util.NewQlobber(),
		Connections:   map[uint32]map[string]*MmuxConnection{},
		RetryMap:      map[string][]*Retryable{},
		Started:       time.Now(),
		EnableSys:     false,
		DataStore:     datastore.NewMemstore(),
		LockPool:      map[uint32]*sync.RWMutex{},
		config:        config,
		InflightTable: map[string]*util.MessageTable{},
	}

	// initialize lock pool
	for i := 0; i < config.GetLockPoolSize(); i++ {
		engine.LockPool[uint32(i)] = &sync.RWMutex{}
		engine.Connections[uint32(i)] = make(map[string]*MmuxConnection)
	}

	auth := config.GetAuthenticators()
	if len(auth) > 0 {
		for i := 0; i < len(auth); i++ {
			var authenticator Authenticator
			switch auth[i].Type {
			case "empty":
				authenticator = &EmptyAuthenticator{}
				authenticator.Init(config)
			default:
				panic(fmt.Sprintf("Unsupported type specified: [%s]", auth[i].Type))
			}
			engine.registerAuthenticator(authenticator)
		}
	} else {
		authenticator := &EmptyAuthenticator{}
		authenticator.Init(config)
		engine.registerAuthenticator(authenticator)
	}

	engine.setupCallback()
	return engine
}