public UserFileSystem(UserMetaData metadata) { this.filemap = new Dictionary<string, UserFile> (); this.sharedFiles = new List<SharedFile> (); this.privateLock = new object (); this.metadata = metadata; }
public UserFileSystem(UserMetaData metadata) { this.filemap = new Dictionary <string, UserFile> (); this.sharedFiles = new List <SharedFile> (); this.privateLock = new object(); this.metadata = metadata; }
/* * The Handler Function which handles the User Meta Data Change */ public bool handleUserMetaData(UserMetaDataSync request) { try { Logger.Debug("handleFileUserMetaData - Begin"); if (request.initiatedSystemId.Equals(IsisSystem.GetMyAddress())) { TryReleaseLock(request.initiatedSystemId, request.transactionID); Logger.Debug("handleFileUserMetaData - End"); return(true); } UserMetaData userdata = new UserMetaData(request.clientId, request.password, request.versionNumber, 0); try { filesystem.updateMetadataSynchronized(userdata); TryReleaseLock(request.initiatedSystemId, request.transactionID); Logger.Debug("handleFileUserMetaData - End"); } catch (UserNotLoadedInMemoryException e) { Logger.Debug("Exception: " + e.ToString()); filesystem.addUserSynchronized(request.clientId, request.password); TryReleaseLock(request.initiatedSystemId, request.transactionID); Logger.Debug("handleFileUserMetaData - End"); } return(true); } catch (Exception e) { Logger.Debug("handleUserMetaData Encountered an exception " + e.ToString()); return(false); } }
public UserMetaDataSync(string transactionId, Address localAddress, UserMetaData data) { this.clientId = data.clientId; this.password = data.password; this.versionNumber = data.versionNumber; this.transactionID = transactionId; this.initiatedSystemId = localAddress; }
public bool updateMetadataSynchronized(UserMetaData md) { Logger.Debug("updating user meta data for user id :" + md.clientId); UserFileSystem fs = getUserFSFromMapSynchronized(md.clientId); if (fs != null) { fs.SetMetadataSychronized(md); } else { throw new UserNotLoadedInMemoryException("Update meta data operation failed for user id : " + md.clientId); } return(true); }
/**/ public UserFileSystem GetClonedInMemoryUserFileSystem(string clientId) { if (this.clientToFileSystemMap.ContainsKey(clientId)) { UserFileSystem filesystem = this.clientToFileSystemMap[clientId]; return(filesystem.CloneSynchronized()); } else { throw new UserNotLoadedInMemoryException("Client not found in memory :" + clientId); } } /* Synchronized method to add user. Returns false if the user is already present * Otherwise creates an empty file system and adds that user with that empty file system. */ public bool addUserSynchronized(string clientid, string password, long versionNumber) { UserFileSystem fs = getUserFSFromMapSynchronized(clientid); if (fs != null) { return(false); } else { UserMetaData md = new UserMetaData(clientid, password, versionNumber); UserFileSystem filesystem = new UserFileSystem(md); addFSToMapSynchronized(filesystem, clientid); } return(true); }
/**/ public UserFileSystem GetClonedInMemoryUserFileSystem(string clientId) { if (this.clientToFileSystemMap.ContainsKey(clientId)) { UserFileSystem filesystem = this.clientToFileSystemMap[clientId]; return(filesystem.CloneSynchronized()); } else { throw new UserNotLoadedInMemoryException("Client not found in memory :" + clientId); } } /* Synchronized method to add user. Returns false if the user is already present * Otherwise creates an empty file system and adds that user with that empty file system. */ public bool addUserSynchronized(string clientid, string password, long versionNumber) { Logger.Debug("Adding user with client id : " + clientid + " and password : "******" and version number :" + versionNumber); UserFileSystem fs = getUserFSFromMapSynchronized(clientid); if (fs != null) { return(false); } else { UserMetaData md = new UserMetaData(clientid, password, versionNumber); UserFileSystem filesystem = new UserFileSystem(md); addFSToMapSynchronized(filesystem, clientid); } return(true); }
public void Post(AddUser request) { logger.Info("****Request received for adding user with client id :" + request.clientId + " and password : "******"User is already present in inmemory map, throwing back exception"); throw new Exception("User is already present in memory"); } else { logger.Debug("User added succesfully"); } } catch (Exception e) { logger.Debug(e); throw e; } } else { throw new Exception("User Add Exception"); } }
/* * This Function is called when a New User Is Added or the Meta Data of the User Needs to be Changed and Synched */ public bool sendsynchUserMetaData(UserMetaData data, OOBHandler handler, Group group, bool waitToFinish = true) { try { Logger.Debug("File Operations Synch - sendsynchUserMetaData >> BEGIN"); bool operationResult = false; if (waitToFinish) { string transactionId = FileServerComm.getInstance().transManager.generateTransactionId(data.clientId); Transaction trans = new Transaction(transactionId); if (true == FileServerComm.getInstance().transManager.insertTransaction(trans)) { UserMetaDataSync sync = new UserMetaDataSync(transactionId, IsisSystem.GetMyAddress(), data); group.OrderedSend(FileServerComm.UpdateUserMetaData, sync); Logger.Debug("File Operations Synch - Making a Ordered Send"); trans.waitTillSignalled(); FileServerComm.getInstance().transManager.removeAndGetTransaction(transactionId); operationResult = !trans.isTimedOut; } else { Logger.Debug("File Operations Synch - sendsynchUserMetaData >> Generation of Transaction ID Failed: " + transactionId); } } else { UserMetaDataSync sync = new UserMetaDataSync("", IsisSystem.GetMyAddress(), data); group.OrderedSend(FileServerComm.UpdateUserMetaData, sync); operationResult = true; } Logger.Debug("File Operations Synch - sendsynchUserMetaData >> END Operation Status " + operationResult); return(operationResult); } catch (Exception e) { Logger.Debug("File Operations Synch - sendsynchUserMetaData threw an Exception " + e.ToString()); return(false); } }
public bool updateMetadataSynchronized(UserMetaData md) { Logger.Debug("updating user meta data for user id :" + md.clientId); UserFileSystem fs = getUserFSFromMapSynchronized (md.clientId); if (fs != null) { fs.SetMetadataSychronized(md); } else { throw new UserNotLoadedInMemoryException("Update meta data operation failed for user id : " + md.clientId); } return true; }
/* Synchronized method to add user. Returns false if the user is already present Otherwise creates an empty file system and adds that user with that empty file system. */ public bool addUserSynchronized(string clientid, string password, long versionNumber) { Logger.Debug ("Adding user with client id : " + clientid + " and password : "******" and version number :" + versionNumber ); UserFileSystem fs = getUserFSFromMapSynchronized (clientid); if (fs != null) { return false; } else { Logger.Debug ("User : "******" present in map, adding"); UserMetaData md = new UserMetaData(clientid, password, versionNumber,0); UserFileSystem filesystem = new UserFileSystem(md); addFSToMapSynchronized(filesystem, clientid); } return true; }
/* * This Function is called when a New User Is Added or the Meta Data of the User Needs to be Changed and Synched */ public bool sendsynchUserMetaData(UserMetaData data, OOBHandler handler, Group group, bool waitToFinish = true) { try { Logger.Debug ("File Operations Synch - sendsynchUserMetaData >> BEGIN"); bool operationResult = false; if (waitToFinish) { string transactionId = FileServerComm.getInstance ().transManager.generateTransactionId (data.clientId); Transaction trans = new Transaction (transactionId); if (true == FileServerComm.getInstance ().transManager.insertTransaction (trans)) { UserMetaDataSync sync = new UserMetaDataSync (transactionId, IsisSystem.GetMyAddress (), data); group.OrderedSend (FileServerComm.UpdateUserMetaData, sync); Logger.Debug ("File Operations Synch - Making a Ordered Send"); trans.waitTillSignalled (); FileServerComm.getInstance ().transManager.removeAndGetTransaction (transactionId); operationResult = !trans.isTimedOut; } else { Logger.Debug ("File Operations Synch - sendsynchUserMetaData >> Generation of Transaction ID Failed: " + transactionId); } } else { UserMetaDataSync sync = new UserMetaDataSync ("", IsisSystem.GetMyAddress (), data); group.OrderedSend (FileServerComm.UpdateUserMetaData, sync); operationResult = true; } Logger.Debug ("File Operations Synch - sendsynchUserMetaData >> END Operation Status " + operationResult); return operationResult; } catch (Exception e) { Logger.Debug("File Operations Synch - sendsynchUserMetaData threw an Exception " + e.ToString()); return false; } }
/* * The Handler Function which handles the User Meta Data Change */ public bool handleUserMetaData(UserMetaDataSync request) { try { Logger.Debug ("handleFileUserMetaData - Begin"); if (request.initiatedSystemId.Equals (IsisSystem.GetMyAddress ())) { TryReleaseLock (request.initiatedSystemId, request.transactionID); Logger.Debug ("handleFileUserMetaData - End"); return true; } UserMetaData userdata = new UserMetaData (request.clientId, request.password, request.versionNumber, 0); try { filesystem.updateMetadataSynchronized (userdata); TryReleaseLock (request.initiatedSystemId, request.transactionID); Logger.Debug ("handleFileUserMetaData - End"); } catch (UserNotLoadedInMemoryException e) { Logger.Debug ("Exception: " + e.ToString ()); filesystem.addUserSynchronized (request.clientId, request.password); TryReleaseLock (request.initiatedSystemId, request.transactionID); Logger.Debug ("handleFileUserMetaData - End"); } return true; } catch (Exception e) { Logger.Debug("handleUserMetaData Encountered an exception " + e.ToString()); return false; } }
public void SetMetadataSychronized(UserMetaData metadata) { lock (this.privateLock) { this.metadata = metadata; } }