public DBServer() { //Console.WriteLine("Remember: spaces in filenames not allowed atm"); IPAddress localIP = LocalIPAddress(); if (localIP == null) { Console.WriteLine("Server does not have internet connectivity, cannot continue."); Environment.Exit(-1); } azureLink = new Backend(); int pid = System.Diagnostics.Process.GetCurrentProcess().Id; ILocks distLockDb = DBLocks.DBLocks.initLocks(localIP.ToString(), pid); lockDb = new LockTable(distLockDb); try { serverSocket = new TcpListener(localIP, SERVER_CONTROL_PORT); serverSocket.Start(); } catch (Exception e) { Console.WriteLine("Error creating server socket: {0}", e.Message); Environment.Exit(-1); } }
public LockTable(ILocks lockMgr) { this.distLockMgr = lockMgr; activeLocks = new Dictionary <string, Lock>(); updaterThread = new System.Threading.Thread(new System.Threading.ThreadStart(clean)); updaterThread.IsBackground = true; updaterThread.Start(); }
private DBTransferManager(DBServer srv) { this.azureLink = srv.getAzureLink(); this.globalLocks = srv.getLocks(); pendingUploads = new Dictionary <string, UPLOAD_INFO>(); listenSocket = new TcpListener(IPAddress.Any, DBServer.SERVER_CONTROL_PORT + 1); listenSocket.Start(); new Thread(new ThreadStart(listen)).Start(); //control returns to DBServerWorker }
private void doCleanup() { lock (activeLocks) { List <String> dropKey = new List <String>(); foreach (String key in activeLocks.Keys) { Lock l = activeLocks[key]; if (l.isWriteLock) { if (l.lockCreation.AddMinutes(W_TIMEOUT).CompareTo(new DateTime()) < 0) { if (DBTransferManager.getManager(null).abortDownload(key)) { dropKey.Add(key); //activeLocks.Remove(key); } else { l.lockCreation = l.lockCreation.AddMinutes(W_TIMEOUT); } } } else { if (l.lockCreation.AddMinutes(R_TIMEOUT).CompareTo(new DateTime()) < 0) { dropKey.Add(key); //((ILocks)(this)).releaseReadLock(key); //activeLocks.Remove(key); } } } //forEach ILocks ilock = (ILocks)this; foreach (string s in dropKey) { Lock l = activeLocks[s]; if (l.isWriteLock) { ilock.releaseWriteLock(s); } else { ilock.releaseReadLock(s); } } } //lock }