@Override
	public boolean commit(long txnID, long numOfMsgs)
			throws MessageNotFoundException, RemoteException {
		if (fileNameTransaction.containsKey(txnID)) {
			String fileName = fileNameTransaction.remove(txnID);
			FileContent content = cache.remove(fileName);
			ReplicaLoc[] locations = null;
			try {
				locations = masterServer.read(fileName);
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			boolean success = true;
			System.out.println(locations[0]);
			// check if this is the master replica
			if (locations[0].getName().equals(name)) {
				for (int i = 1; i < locations.length; i++) {
					ReplicaLoc loc = locations[i];
					Registry reg = LocateRegistry.getRegistry(loc.getHost(),
							loc.getPort());
					try {
						ReplicaServerClientInterface repServer = (ReplicaServerClientInterface) reg
								.lookup(loc.getName());
						repServer.write(txnID, 1, content);
						success |= repServer.commit(txnID, 1);
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
			try {
				FileContent fc = new FileContent(fileName);
				fc.setData(null);
				masterServer.write(fc);
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}

			ReadWriteLock lock = null;
			if (!fileReadWriteLock.containsKey(fileName)) {
				lock = new ReentrantReadWriteLock();
				fileReadWriteLock.put(fileName, lock);
			} else {
				lock = fileReadWriteLock.get(fileName);
			}
			try {
				lock.writeLock().lock();
				File f = new File(dir + "/" + fileName);
				FileWriter fw = new FileWriter(f, true);
				fw.write(content.getData());
				fw.close();
			} catch (IOException e) {
				e.printStackTrace();
				success = false;
			} finally {
				lock.writeLock().unlock();
			}
			fileLock.get(fileName).release();
			return success;
		}
		return false;
	}