コード例 #1
0
		static void Main ()
		{
            String hostName = Dns.GetHostName();
			Log.Info("Starting .NET Gearman Server v0.5 on host " + hostName);
            var redisClient = new RedisClient("localhost");
            var redisQueue = new RedisQueue(redisClient); 
            var jobQueue = new JobQueue(redisQueue);
			//var jobQueue = new JobQueue();
			new Daemon(jobQueue, hostName); 
		}
コード例 #2
0
ファイル: Daemon.cs プロジェクト: johnewart/gearman.net
		public Daemon(JobQueue queue, string hostName) {

			GearmanServer.Log.Info("Server listening on port 4730");
			
			TCPServer = new System.Net.Sockets.TcpListener(4730);
            workers = new ConcurrentDictionary<string, List<Connection>>(); 

			while(true) { 
				TCPServer.Start(); 

				if(TCPServer.Pending()) { 
					try {
                        new ConnectionHandler(TCPServer.AcceptTcpClient(), queue, hostName, workers); 
					} catch (Exception e) {
						GearmanServer.Log.Error("Exception waiting for connection: ", e);
					}
				} 

				System.Threading.Thread.Sleep(1);
			} 
		} 
コード例 #3
0
ファイル: Daemon.cs プロジェクト: johnewart/gearman.net
        public ConnectionHandler(TcpClient c, JobQueue _queue, string _hostName, ConcurrentDictionary<string, List<Gearman.Connection>> _workers)
		{
			try {
                hostName = _hostName;
				abilities = new List<string>(); 
				queue = _queue;
                workers = _workers; 

                client = c;
				conn = new Gearman.Connection(c.Client);

				IPAddress remoteIP = ((IPEndPoint)c.Client.RemoteEndPoint).Address;
				GearmanServer.Log.Info(String.Format("Connection made by {0}", remoteIP)); 
			
				Thread t = new Thread(new ThreadStart(run)); 
				t.Start(); 
				
			} catch (Exception e) {
				GearmanServer.Log.Error("Problem getting remote IP: ", e);
			}		   		
			
		}