/**
 * 
 */
package eu.dnetlib.data.collective.manager.log;

import java.io.IOException;
import java.util.Properties;

import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.store.LockObtainFailedException;

/**
 * @author js
 *
 */
public class GenericInfoService extends AbstractInfoService {

	/**
	 * @param aInstanceId
	 * @param aProperties
	 * @throws CorruptIndexException
	 * @throws LockObtainFailedException
	 * @throws IOException
	 */
	public synchronized void persist(String aInstanceId, Properties aProperties) throws CorruptIndexException, LockObtainFailedException, IOException{
		GenericInfoWriter writer = new GenericInfoWriter();
		writer.init(dir, create);
		writer.store(aInstanceId, aProperties);
		create = false;
	}
	
	/**
	 * @param aInstanceId
	 * @return
	 * @throws IOException
	 */
	public synchronized Properties findProperties(String aInstanceId) throws IOException{
		if (create){
			return new Properties();
		}
		GenericInfoReader reader = new GenericInfoReader();
		reader.init(dir);
		return reader.getProperties(aInstanceId);
	}
}
