@Override
	public boolean commit(long txnID, long numOfMsgs)
			throws MessageNotFoundException, RemoteException {
		String fileName = tranx.get(txnID);
		masterHandler.notify(Global.BROADCASTSTARTACK, fileName);
		if (!fileLock.containsKey(fileName))
			fileLock.put(fileName, new ReentrantReadWriteLock());
		// lock
		fileLock.get(fileName).writeLock().lock();

		try {
			System.out.println("Commiting to replica : " + replicaPath
					+ "/replica" + this.replicaID + "/" + fileName);

			// Append to file and not overwrite
			PrintWriter fstream = new PrintWriter(new BufferedWriter(
					new FileWriter(replicaPath + "/replica" + this.replicaID
							+ "/" + fileName, true)));

			TreeMap<Long, String> tMap = txnToData.get(txnID);
			for (Iterator<String> iterator = tMap.values().iterator(); iterator
					.hasNext();) {
				fstream.print(iterator.next());
			}
			fstream.close();
		} catch (Exception e) {
			System.err.println("Error in commit: " + e.getMessage());
			return false;
		}

		try {
			broadcastToReplicas(txnID, fileName);

			// unlock
			fileLock.get(fileName).writeLock().unlock();
			// release locks
			for (Iterator<Entry<Integer, ReplicaLoc>> iterator = replicaSlaves
					.entrySet().iterator(); iterator.hasNext();) {
				Entry<Integer, ReplicaLoc> entry = iterator.next();

				// skip self-replica
				if (entry.getKey() == this.replicaID)
					continue;

				ReplicaLoc repl = entry.getValue();
				String replLoc = repl.location;
				int replPort = repl.replicaPort;

				Registry replicaReg = LocateRegistry.getRegistry(replLoc,
						replPort);
				ReplicaServerClientInterface replHandler = (ReplicaServerClientInterface) replicaReg
						.lookup(Global.REPLICA_LOOKUP);

				replHandler.unlockReentrantWriteLock(fileName);
			}

		} catch (NotBoundException e) {
			System.err.println("Error: Broadcast exception");
			return false;
		}
		masterHandler.notify(Global.BROADCASTENDACK, fileName);
		return true;
	}