Esempio n. 1
0
func NewTlsServer(engine *Momonga, config *configuration.Config, inherit bool) *TlsServer {
	t := &TlsServer{
		Engine:        engine,
		ListenAddress: config.GetTlsListenAddress(),
		config:        config,
		stop:          make(chan bool, 1),
		inherit:       inherit,
	}

	return t
}
Esempio n. 2
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
}