@SuppressWarnings("unchecked")
	public <KeyType, ValueType> HGIndex<KeyType, ValueType> getIndex(String name,
			ByteArrayConverter<KeyType> keyConverter, ByteArrayConverter<ValueType> valueConverter,
			Comparator<?> comparator, boolean isBidirectional, boolean createIfNecessary) {
		indicesLock.readLock().lock();
		
		try {
			HGIndex<KeyType, ValueType> idx = (HGIndex<KeyType, ValueType>)openIndices.get(name);
			if (idx != null)
				return idx;
			if (!checkIndexExisting(name) && !createIfNecessary)
				return null;
		}
		finally {
			indicesLock.readLock().unlock();
		}

		indicesLock.writeLock().lock();
		
		try {
			HGIndex<KeyType, ValueType> idx = (HGIndex<KeyType, ValueType>)openIndices.get(name);
			if (idx != null)
				return idx;
			if (!checkIndexExisting(name) && !createIfNecessary)
				return null;

			DefaultIndexImpl<KeyType, ValueType> result = null;

			if (isBidirectional) {
				result = new DefaultBiIndexImpl<KeyType, ValueType>(name, this, store.getTransactionManager(),
						keyConverter, valueConverter, comparator);
			}
			else {
				result = new DefaultIndexImpl<KeyType, ValueType>(name, this, store.getTransactionManager(), keyConverter,
						valueConverter, comparator);
			}
			
			result.open();
			openIndices.put(name, result);
			return result;
		}
		finally {
			indicesLock.writeLock().unlock();
		}
	}