Bend.Repl.ReplHandler.InitFresh C# (CSharp) Method

InitFresh() public static method

public static InitFresh ( IStepsSnapshotKVDB db, ServerContext ctx ) : ReplHandler
db IStepsSnapshotKVDB
ctx ServerContext
return ReplHandler
        public static ReplHandler InitFresh(IStepsSnapshotKVDB db, ServerContext ctx)
        {
            // init fresh

            // record our instance ID
            db.setValue(new RecordKey()
                .appendKeyPart("_config")
                .appendKeyPart("MY-SERVER-ID"),
                RecordUpdate.WithPayload(ctx.server_guid));

            // create and record a new instance ID
            db.setValue(new RecordKey()
                .appendKeyPart("_config")
                .appendKeyPart("DATA-INSTANCE-ID"),
                RecordUpdate.WithPayload(Lsd.numberToLsd(ReplHandler.myrnd.Next(), 15)));

            // record the "start of fresh log" record

            db.setValue(new RecordKey()
                .appendKeyPart("_logs")
                .appendKeyPart(ctx.server_guid)
                .appendKeyPart(new RecordKeyType_Long(0)),
                RecordUpdate.WithPayload(new byte[0]));

            // record ourself as a seed/log
            db.setValue(new RecordKey()
                .appendKeyPart("_config").appendKeyPart("seeds").appendKeyPart(ctx.server_guid),
                RecordUpdate.WithPayload(""));

            ReplHandler repl = new ReplHandler(db, ctx);

            repl.state = ReplState.active; // TODO: is this the right way to become active?
            return repl;
        }