public IDisposable Start(IServerInformation serverInformation, Func <object, Task> application) { var startInstance = new StartInstance(application); _startInstances.Add(startInstance); return(startInstance); }
public ServerPacketProcessor(ServerBuilderOptions options, ILogger <ServerPacketProcessor> logger, IPacketHandlers packetHandlers, IServerInformation serverInformation, IPacketSerialiser packetSerialiser, IEnumerable <IMiddlewareHandler> middlewares) { this.logger = logger; this.packetHandlers = packetHandlers; this.serverInformation = serverInformation; this.packetSerialiser = packetSerialiser; this.middlewares = middlewares.ToList(); tcpSenderObjectPool = new ObjectPool <ISender>(options.TcpMaxConnections); for (var i = 0; i < tcpSenderObjectPool.Capacity; i++) { tcpSenderObjectPool.Push(new TcpSender(packetSerialiser)); } udpSenderObjectPool = new ObjectPool <ISender>(options.TcpMaxConnections * 2); for (var i = 0; i < udpSenderObjectPool.Capacity; i++) { udpSenderObjectPool.Push(new UdpSender(_socketSender)); } packetContextObjectPool = new ObjectPool <IPacketContext>(options.TcpMaxConnections * 2); for (var i = 0; i < packetContextObjectPool.Capacity; i++) { packetContextObjectPool.Push(new PacketContext()); } }
private static SqlServerVersion GetTargetServerVersion(IServerInformation srv) { var version = srv.VersionMajor + srv.VersionMinor.ToString(); if (version == "80") { return(SqlServerVersion.Version80); } if (version == "90") { return(SqlServerVersion.Version90); } if (version == "100") { return(SqlServerVersion.Version100); } if (version == "1050") { return(SqlServerVersion.Version105); } throw new Exception("Unsupported Server Version"); }
public IDisposable Start(IServerInformation serverInformation, Func<IFeatureCollection, Task> application) { var disposables = new List<IDisposable>(); var information = (ServerInformation)serverInformation; var engine = new KestrelEngine(_libraryManager, _appShutdownService); engine.Start(1); foreach (var address in information.Addresses) { disposables.Add(engine.CreateServer( address.Scheme, address.Host, address.Port, async frame => { var request = new ServerRequest(frame); await application.Invoke(request.Features); })); } disposables.Add(engine); return new Disposable(() => { foreach (var disposable in disposables) { disposable.Dispose(); } }); }
public IDisposable Start(IServerInformation serverInformation, Func <IFeatureCollection, Task> application) { var disposables = new List <IDisposable>(); var information = (ServerInformation)serverInformation; var engine = new KestrelEngine(_libraryManager, _appShutdownService); engine.Start(1); foreach (var address in information.Addresses) { disposables.Add(engine.CreateServer( address.Scheme, address.Host, address.Port, async frame => { var request = new ServerRequest(frame); await application.Invoke(request.Features); })); } disposables.Add(engine); return(new Disposable(() => { foreach (var disposable in disposables) { disposable.Dispose(); } })); }
public ReplicationInfo(IServerInformation main) : base(main, Name) { if (main == null) { throw new ArgumentNullException(nameof(main)); } Role = GetType <ReplicationRole>("role"); if (Role == ReplicationRole.Slave) { LastSync = GetType <long>("master_last_io_seconds_ago"); MasterLinkStatus = GetType <MasterLinkStatus>("master_link_status"); SlaveReplOffset = GetType <long>("slave_repl_offset"); IsMasterSyncInProgress = GetType <byte>("master_sync_in_progress"); } else if (Role == ReplicationRole.Master) { MasterReplOffset = GetType <long>("master_repl_offset"); ConnectedSlaves = GetType <int>("connected_slaves"); if (ConnectedSlaves != null) { Slaves = new SlaveInformation[ConnectedSlaves.Value]; for (int i = 0; i < ConnectedSlaves.Value; i++) { Slaves[i] = SlaveInformation.Parse(GetType($"slave{i}")); } } } }
public IDisposable Start(IServerInformation serverInformation, Func<IFeatureCollection, Task> application) { var startInstance = new StartInstance(application); _startInstances.Add(startInstance); application(_featuresSupportedByThisHost); return startInstance; }
private RequestDelegate BuildApplication() { if (ServerFactory == null) { // Blow up if we don't have a server set at this point if (ServerFactoryLocation == null) { throw new InvalidOperationException("IHostingBuilder.UseServer() is required for " + nameof(Start) + "()"); } ServerFactory = _applicationServices.GetRequiredService <IServerLoader>().LoadServerFactory(ServerFactoryLocation); } _serverInstance = ServerFactory.Initialize(_config); var builderFactory = _applicationServices.GetRequiredService <IApplicationBuilderFactory>(); var builder = builderFactory.CreateBuilder(_serverInstance); builder.ApplicationServices = _applicationServices; var startupFilters = _applicationServices.GetService <IEnumerable <IStartupFilter> >(); var configure = Startup.ConfigureDelegate; foreach (var filter in startupFilters) { configure = filter.Configure(configure); } configure(builder); return(builder.Build()); }
public ServerPacketProcessor(ServerBuilderOptions options, ILogger <ServerPacketProcessor> logger, IPacketHandlers packetHandlers, IServerInformation serverInformation, IPacketSerialiser packetSerialiser) { this.logger = logger; this.packetHandlers = packetHandlers; this.serverInformation = serverInformation; this.packetSerialiser = packetSerialiser; tcpSenderObjectPool = new ObjectPool <ISender>(options.TcpMaxConnections); for (var i = 0; i < tcpSenderObjectPool.Capacity; i++) { tcpSenderObjectPool.Push(new TcpSender(packetSerialiser)); } udpSenderObjectPool = new ObjectPool <ISender>(options.TcpMaxConnections * 2); for (var i = 0; i < udpSenderObjectPool.Capacity; i++) { udpSenderObjectPool.Push(new UdpSender(packetSerialiser)); } }
public IDisposable Start(IServerInformation serverInformation, Func <IFeatureCollection, Task> application) { var startInstance = new StartInstance(application); _startInstances.Add(startInstance); application(_featuresSupportedByThisHost); return(startInstance); }
public IDisposable Start(IServerInformation serverInformation, Func<IFeatureCollection, Task> application) { if (serverInformation.GetType() != typeof(StdioServerInformation)) { throw new ArgumentException("wrong server", "serverInformation"); } return new StdioServer(_input, _output, application); }
public IDisposable Start(IServerInformation serverInformation, Func<object, Task> application) { var information = (NowinServerInformation)serverInformation; _callback = application; INowinServer server = information.Builder.Build(); server.Start(); return server; }
public IDisposable Start(IServerInformation serverInformation, Func <IFeatureCollection, Task> application) { if (serverInformation.GetType() != typeof(StdioServerInformation)) { throw new ArgumentException("wrong server", "serverInformation"); } return(new StdioServer(_input, _output, application)); }
public Server(ServerBuilderOptions options, ILogger logger, IServiceProvider serviceProvider, IPacketHandlers packetHandlers, ITcpConnections tcpConnections, IServerPacketProcessor serverPacketProcessor, ITcpSocketListenerFactory tcpSocketListenerFactory, IUdpSocketListenerFactory udpSocketListenerFactory, IBufferManager bufferManager, IServerInformation serverInformation, IPacketSerialiser packetSerialiser) { this.tcpConnections = tcpConnections; this.serverInformation = serverInformation; this.packetSerialiser = packetSerialiser; bufferManager.InitBuffer(); if (options.TcpPort > 0) { this.TcpListener = tcpSocketListenerFactory.Create(); } if (options.UdpPort > 0) { this.UdpListener = udpSocketListenerFactory.Create(); } Task.Factory.StartNew(() => { while (this.serverInformation.IsRunning) { if (this.eventArgs == null) { this.eventArgs = new ServerInformationEventArgs(); } this.eventArgs.ProcessedTcpPackets = serverInformation.ProcessedTcpPackets; this.eventArgs.InvalidTcpPackets = serverInformation.InvalidTcpPackets; this.eventArgs.ProcessedUdpPackets = serverInformation.ProcessedUdpPackets; this.eventArgs.InvalidUdpPackets = serverInformation.InvalidUdpPackets; this.eventArgs.TcpConnections = tcpConnections.GetConnections() .Count; this.ServerInformationUpdated?.Invoke(this, this.eventArgs); this.serverInformation.ProcessedTcpPackets = 0; this.serverInformation.InvalidTcpPackets = 0; this.serverInformation.ProcessedUdpPackets = 0; this.serverInformation.InvalidUdpPackets = 0; Thread.Sleep(10000); } }); }
public DefaultUdpSocketListenerFactory(ServerBuilderOptions options, ILogger <UdpClientListener> logger, IServerPacketProcessor serverPacketProcessor, IServerInformation serverInformation) { this.options = options; this.logger = logger; this.serverPacketProcessor = serverPacketProcessor; this.serverInformation = serverInformation; }
protected BaseInformation(IServerInformation main, string category) { if (string.IsNullOrEmpty(category)) { throw new ArgumentException("Value cannot be null or empty.", nameof(category)); } Main = main ?? throw new ArgumentNullException(nameof(main)); this.category = category; }
public StatsInfo(IServerInformation main) : base(main, Name) { if (main == null) { throw new System.ArgumentNullException(nameof(main)); } TotalCommands = GetType <long>("total_commands_processed"); }
public IDisposable Start(IServerInformation serverInformation, Func <IFeatureCollection, Task> application) { if (!(serverInformation.GetType() == typeof(ServerInformation))) { throw new ArgumentException(string.Format("The server must be {0}", ServerName), "serverInformation"); } _appDelegate = application; return(this); }
private static HostStatus[] GetSlaveInformation(IServerInformation information) { var slaves = new List <HostStatus>(information.Replication.Slaves.Length); foreach (var slaveInformation in information.Replication.Slaves) { slaves.Add(new HostStatus(slaveInformation.EndPoint, slaveInformation.Offset)); } return(slaves.ToArray()); }
public DefaultUdpSocketListenerFactory(ServerBuilderOptions options, ILogger logger, IServerPacketProcessor serverPacketProcessor, IBufferManager bufferManager, IServerInformation serverInformation) { this.options = options; this.logger = logger; this.serverPacketProcessor = serverPacketProcessor; this.bufferManager = bufferManager; this.serverInformation = serverInformation; }
public PersistenceInfo(IServerInformation main) : base(main, Name) { if (main == null) { throw new ArgumentNullException(nameof(main)); } AofSize = GetType <long>("aof_current_size"); IsRdbSaving = GetType <byte>("rdb_bgsave_in_progress"); IsAofRewriting = GetType <byte>("aof_rewrite_in_progress"); }
public UdpClientListener(ServerBuilderOptions options, ILogger <UdpClientListener> logger, IServerPacketProcessor serverPacketProcessor, IServerInformation serverInformation) { this.options = options; this.logger = logger; this.serverPacketProcessor = serverPacketProcessor; this.serverInformation = serverInformation; endPointPool = new ObjectPool <EndPoint>(this.options.UdpSocketObjectPoolSize); for (var i = 0; i < endPointPool.Capacity; i++) { endPointPool.Push(new IPEndPoint(IPAddress.Loopback, this.options.UdpPort)); } }
public IDisposable Start(IServerInformation serverInformation, Func <object, Task> application) { var _services = (IFireflyService)serverInformation; _services.Trace.Event(TraceEventType.Start, TraceMessage.ServerFactory); var endpoint = new IPEndPoint(IPAddress.Loopback, 3001); var listenSocket = new Socket(endpoint.AddressFamily, SocketType.Stream, ProtocolType.IP); listenSocket.Bind(endpoint); listenSocket.Listen(-1); WaitCallback connectionExecute = connection => { _services.Trace.Event(TraceEventType.Verbose, TraceMessage.ServerFactoryConnectionExecute); ((Connection)connection).Execute(); }; var stop = false; var acceptEvent = new SocketAsyncEventArgs(); Action accept = () => { while (!stop) { _services.Trace.Event(TraceEventType.Verbose, TraceMessage.ServerFactoryAcceptAsync); if (listenSocket.AcceptAsync(acceptEvent)) { return; } _services.Trace.Event(TraceEventType.Verbose, TraceMessage.ServerFactoryAcceptCompletedSync); if (acceptEvent.SocketError != SocketError.Success) { _services.Trace.Event(TraceEventType.Error, TraceMessage.ServerFactoryAcceptSocketError); } if (acceptEvent.SocketError == SocketError.Success && acceptEvent.AcceptSocket != null) { ThreadPool.QueueUserWorkItem( connectionExecute, new Connection( _services, application, new SocketWrapper(acceptEvent.AcceptSocket), OnDisconnect)); } acceptEvent.AcceptSocket = null; } }; acceptEvent.Completed += (_, __) => { _services.Trace.Event(TraceEventType.Verbose, TraceMessage.ServerFactoryAcceptCompletedAsync); if (acceptEvent.SocketError == SocketError.Success && acceptEvent.AcceptSocket != null) { ThreadPool.QueueUserWorkItem( connectionExecute, new Connection( _services, application, new SocketWrapper(acceptEvent.AcceptSocket), OnDisconnect)); } acceptEvent.AcceptSocket = null; accept(); }; accept(); return(new Disposable( () => { _services.Trace.Event(TraceEventType.Stop, TraceMessage.ServerFactory); stop = true; listenSocket.Close(); acceptEvent.Dispose(); })); }
public IDisposable Start(IServerInformation serverInformation, Func<IFeatureCollection, Task> application) { return new StartInstance(application); }
public MemoryInfo(IServerInformation main) : base(main, Memory) { UsedMemory = GetType <long>("used_memory"); MemoryFragmentation = GetType <double>("mem_fragmentation_ratio"); }
public IDisposable Start(IServerInformation serverInformation, Func<IFeatureCollection, Task> application) { if (!(serverInformation.GetType() == typeof(ServerInformation))) { throw new ArgumentException(string.Format("The server must be {0}", ServerName), "serverInformation"); } _appDelegate = application; return this; }
private static SqlServerVersion GetTargetServerVersion(IServerInformation srv) { var version = srv.VersionMajor + srv.VersionMinor.ToString(); if (version == "80") return SqlServerVersion.Version80; if (version == "90") return SqlServerVersion.Version90; if (version == "100") return SqlServerVersion.Version100; if (version == "1050") return SqlServerVersion.Version105; throw new Exception("Unsupported Server Version"); }
public static IServiceCollection AddKafkaBusServer(this IServiceCollection services, IServerInformation information) { var serverFeatures = new KafkaBusFeatureCollection(); serverFeatures.Set <IServerInformation>(information); serverFeatures.Set <IServerAddressesFeature>(information); services.AddSingleton(serverFeatures); services.AddTransient <Server>(); return(services); }
private RequestDelegate BuildApplication() { if (ServerFactory == null) { // Blow up if we don't have a server set at this point if (ServerFactoryLocation == null) { throw new InvalidOperationException("IHostingBuilder.UseServer() is required for " + nameof(Start) + "()"); } ServerFactory = _applicationServices.GetRequiredService<IServerLoader>().LoadServerFactory(ServerFactoryLocation); } _serverInstance = ServerFactory.Initialize(_config); var builderFactory = _applicationServices.GetRequiredService<IApplicationBuilderFactory>(); var builder = builderFactory.CreateBuilder(_serverInstance); builder.ApplicationServices = _applicationServices; var startupFilters = _applicationServices.GetService<IEnumerable<IStartupFilter>>(); var configure = Startup.ConfigureDelegate; foreach (var filter in startupFilters) { configure = filter.Configure(configure); } configure(builder); return builder.Build(); }
public IDisposable Start(IServerInformation serverInformation, Func <IFeatureCollection, Task> application) { return(new StartInstance(application)); }
public IDisposable Start(IServerInformation serverInformation, Func<object, Task> application) { var _services = (IFireflyService)serverInformation; _services.Trace.Event(TraceEventType.Start, TraceMessage.ServerFactory); var endpoint = new IPEndPoint(IPAddress.Loopback, 3001); var listenSocket = new Socket(endpoint.AddressFamily, SocketType.Stream, ProtocolType.IP); listenSocket.Bind(endpoint); listenSocket.Listen(-1); WaitCallback connectionExecute = connection => { _services.Trace.Event(TraceEventType.Verbose, TraceMessage.ServerFactoryConnectionExecute); ((Connection)connection).Execute(); }; var stop = false; var acceptEvent = new SocketAsyncEventArgs(); Action accept = () => { while (!stop) { _services.Trace.Event(TraceEventType.Verbose, TraceMessage.ServerFactoryAcceptAsync); if (listenSocket.AcceptAsync(acceptEvent)) { return; } _services.Trace.Event(TraceEventType.Verbose, TraceMessage.ServerFactoryAcceptCompletedSync); if (acceptEvent.SocketError != SocketError.Success) { _services.Trace.Event(TraceEventType.Error, TraceMessage.ServerFactoryAcceptSocketError); } if (acceptEvent.SocketError == SocketError.Success && acceptEvent.AcceptSocket != null) { ThreadPool.QueueUserWorkItem( connectionExecute, new Connection( _services, application, new SocketWrapper(acceptEvent.AcceptSocket), OnDisconnect)); } acceptEvent.AcceptSocket = null; } }; acceptEvent.Completed += (_, __) => { _services.Trace.Event(TraceEventType.Verbose, TraceMessage.ServerFactoryAcceptCompletedAsync); if (acceptEvent.SocketError == SocketError.Success && acceptEvent.AcceptSocket != null) { ThreadPool.QueueUserWorkItem( connectionExecute, new Connection( _services, application, new SocketWrapper(acceptEvent.AcceptSocket), OnDisconnect)); } acceptEvent.AcceptSocket = null; accept(); }; accept(); return new Disposable( () => { _services.Trace.Event(TraceEventType.Stop, TraceMessage.ServerFactory); stop = true; listenSocket.Close(); acceptEvent.Dispose(); }); }