// New creates a new Olric instance, otherwise returns an error.
New creates a new Olric instance, otherwise returns an error.
// New creates a new Olric instance otherwise returns an error .
func New(c *config.Config) (*Olric, error) {
	var err error
	c, err = prepareConfig(c)
	if err != nil {
		return nil, err
	}
	e := environment.New()
	e.Set("config", c)
	partitions.SetHashFunc(c.Hasher)
	flogger := flog.New(c.Logger)
	flogger.SetLevel(c.LogVerbosity)
	if c.LogLevel == "DEBUG" {
		flogger.ShowLineNumber(1)
	}
	e.Set("logger", flogger)
	sc := &transport.ServerConfig{
		BindAddr:        c.BindAddr,
		BindPort:        c.BindPort,
		KeepAlivePeriod: c.KeepAlivePeriod,
		GracefulPeriod:  10 * time.Second,
	}
	client := transport.NewClient(c.Client)
	e.Set("client", client)
	e.Set("primary", partitions.New(c.PartitionCount, partitions.PRIMARY))
	e.Set("backup", partitions.New(c.PartitionCount, partitions.BACKUP))
	e.Set("locker", locker.New())
	e.Set("streams", streams.New(e))
	srv := transport.NewServer(sc, flogger)
	ctx, cancel := context.WithCancel(context.Background())
	db := &Olric{
		name:       c.MemberlistConfig.Name,
		env:        e,
		log:        flogger,
		config:     c,
		hashFunc:   c.Hasher,
		serializer: c.Serializer,
		client:     e.Get("client").(*transport.Client),
		primary:    e.Get("primary").(*partitions.Partitions),
		backup:     e.Get("backup").(*partitions.Partitions),
		streams:    e.Get("streams").(*streams.Streams),
		operations: make(map[protocol.OpCode]func(w, r protocol.EncodeDecoder)),
		server:     srv,
		started:    c.Started,
		ctx:        ctx,
		cancel:     cancel,
	}
	err = initializeServices(db)
	if err != nil {
		return nil, err
	}
	db.registerOperations()
	db.server.SetDispatcher(db.requestDispatcher)
	return db, nil
}
func New ( c * config . Config ) ( * Olric , error ) { var err error c , err = prepareConfig ( c ) if err != nil { return nil , err } e := environment . New ( ) e . Set ( " " , c ) partitions . SetHashFunc ( c . Hasher ) flogger := flog . New ( c . Logger ) flogger . SetLevel ( c . LogVerbosity ) if c . LogLevel == " " { flogger . ShowLineNumber ( 1 ) } e . Set ( " " , flogger ) sc := & transport . ServerConfig { BindAddr : c . BindAddr , BindPort : c . BindPort , KeepAlivePeriod : c . KeepAlivePeriod , GracefulPeriod : 10 * time . Second , } client := transport . NewClient ( c . Client ) e . Set ( " " , client ) e . Set ( " " , partitions . New ( c . PartitionCount , partitions . PRIMARY ) ) e . Set ( " " , partitions . New ( c . PartitionCount , partitions . BACKUP ) ) e . Set ( " " , locker . New ( ) ) e . Set ( " " , streams . New ( e ) ) srv := transport . NewServer ( sc , flogger ) ctx , cancel := context . WithCancel ( context . Background ( ) ) db := & Olric { name : c . MemberlistConfig . Name , env : e , log : flogger , config : c , hashFunc : c . Hasher , serializer : c . Serializer , client : e . Get ( " " ) . ( * transport . Client ) , primary : e . Get ( " " ) . ( * partitions . Partitions ) , backup : e . Get ( " " ) . ( * partitions . Partitions ) , streams : e . Get ( " " ) . ( * streams . Streams ) , operations : make ( map [ protocol . OpCode ] func ( w , r protocol . EncodeDecoder ) ) , server : srv , started : c . Started , ctx : ctx , cancel : cancel , } err = initializeServices ( db ) if err != nil { return nil , err } db . registerOperations ( ) db . server . SetDispatcher ( db . requestDispatcher ) return db , nil }
New creates a new Olric instance, otherwise returns an error.
New creates a new Olric instance otherwise returns an error .
// Set the hash function. Olric distributes keys over partitions by hashing. // Start a concurrent TCP server