001
014
015 package com.liferay.portal.search.lucene.cluster;
016
017 import com.liferay.portal.kernel.cluster.Address;
018 import com.liferay.portal.kernel.exception.SystemException;
019 import com.liferay.portal.search.lucene.LuceneHelperUtil;
020
021 import java.io.IOException;
022 import java.io.InputStream;
023
024
028 public class LuceneClusterUtil {
029
030 public static void loadIndexesFromCluster(long companyId)
031 throws SystemException {
032
033 Address bootupAddress = LuceneHelperUtil.selectBootupClusterAddress(
034 companyId, LuceneHelperUtil.getLastGeneration(companyId));
035
036 loadIndexesFromCluster(new long[] {companyId}, bootupAddress);
037 }
038
039 public static void loadIndexesFromCluster(
040 long[] companyIds, Address bootupAddress)
041 throws SystemException {
042
043 if (bootupAddress == null) {
044 return;
045 }
046
047 InputStream inputStream = null;
048
049 for (long companyId : companyIds) {
050 try {
051 inputStream =
052 LuceneHelperUtil.getLoadIndexesInputStreamFromCluster(
053 companyId, bootupAddress);
054
055 LuceneHelperUtil.loadIndex(companyId, inputStream);
056 }
057 catch (SystemException se) {
058 throw se;
059 }
060 catch (IOException ioe) {
061 throw new SystemException(ioe);
062 }
063 finally {
064 if (inputStream != null) {
065 try {
066 inputStream.close();
067 }
068 catch (IOException ioe) {
069 throw new SystemException(ioe);
070 }
071 }
072 }
073 }
074 }
075
076 }