Ejemplo n.º 1
0
        /// <summary>
        /// Create server instance; use Start to start the server.
        /// </summary>
        /// <param name="opts"></param>
        public VarLenServer(ServerOptions opts)
        {
            this.opts = opts;

            if (opts.LogDir != null && !Directory.Exists(opts.LogDir))
            {
                Directory.CreateDirectory(opts.LogDir);
            }

            if (opts.CheckpointDir != null && !Directory.Exists(opts.CheckpointDir))
            {
                Directory.CreateDirectory(opts.CheckpointDir);
            }

            opts.GetSettings(out logSettings, out var checkpointSettings, out var indexSize);
            store = new FasterKV <SpanByte, SpanByte>(indexSize, logSettings, checkpointSettings);

            if (opts.EnablePubSub)
            {
                kvBroker = new SubscribeKVBroker <SpanByte, SpanByte, SpanByte, IKeyInputSerializer <SpanByte, SpanByte> >(new SpanByteKeySerializer(), null, true);
                broker   = new SubscribeBroker <SpanByte, SpanByte, IKeySerializer <SpanByte> >(new SpanByteKeySerializer(), null, true);
            }

            // Create session provider for VarLen
            provider = new SpanByteFasterKVProvider(store, kvBroker, broker, opts.Recover);

            server = new FasterServer(opts.Address, opts.Port);
            server.Register(WireFormat.DefaultVarLenKV, provider);
            server.Register(WireFormat.WebSocket, provider);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create server instance; use Start to start the server.
        /// </summary>
        /// <param name="opts"></param>
        /// <param name="functionsGen"></param>
        /// <param name="serializer"></param>
        /// <param name="keyInputSerializer"></param>
        /// <param name="maxSizeSettings"></param>
        public GenericServer(ServerOptions opts, Func <WireFormat, Functions> functionsGen, ParameterSerializer serializer, IKeyInputSerializer <Key, Input> keyInputSerializer, MaxSizeSettings maxSizeSettings = default)
        {
            this.opts = opts;

            if (opts.LogDir != null && !Directory.Exists(opts.LogDir))
            {
                Directory.CreateDirectory(opts.LogDir);
            }

            if (opts.CheckpointDir != null && !Directory.Exists(opts.CheckpointDir))
            {
                Directory.CreateDirectory(opts.CheckpointDir);
            }

            opts.GetSettings(out var logSettings, out var checkpointSettings, out var indexSize);
            store = new FasterKV <Key, Value>(indexSize, logSettings, checkpointSettings);

            if (opts.Recover)
            {
                try
                {
                    store.Recover();
                }
                catch { }
            }

            if (opts.EnablePubSub)
            {
                kvBroker = new SubscribeKVBroker <Key, Value, Input, IKeyInputSerializer <Key, Input> >(keyInputSerializer, null, true);
                broker   = new SubscribeBroker <Key, Value, IKeySerializer <Key> >(keyInputSerializer, null, true);
            }

            // Create session provider for VarLen
            provider = new FasterKVProvider <Key, Value, Input, Output, Functions, ParameterSerializer>(store, functionsGen, kvBroker, broker, serializer, maxSizeSettings);

            server = new FasterServer(opts.Address, opts.Port);
            server.Register(WireFormat.DefaultFixedLenKV, provider);
        }