
com.liferay.portal.search.internal.buffer.BufferedIndexerInvocationHandler Maven / Gradle / Ivy
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.portal.search.internal.buffer;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.model.BaseModel;
import com.liferay.portal.kernel.model.ClassedModel;
import com.liferay.portal.kernel.search.Bufferable;
import com.liferay.portal.kernel.search.Indexer;
import com.liferay.portal.kernel.security.auth.CompanyThreadLocal;
import com.liferay.portal.kernel.util.MethodKey;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.search.buffer.IndexerRequest;
import com.liferay.portal.search.buffer.IndexerRequestBuffer;
import com.liferay.portal.search.buffer.IndexerRequestBufferOverflowHandler;
import com.liferay.portal.search.configuration.IndexerRegistryConfiguration;
import com.liferay.portal.search.index.IndexStatusManager;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
/**
* @author Michael C. Han
*/
public class BufferedIndexerInvocationHandler implements InvocationHandler {
public BufferedIndexerInvocationHandler(
Indexer> indexer, IndexStatusManager indexStatusManager,
IndexerRegistryConfiguration indexerRegistryConfiguration) {
_indexer = indexer;
_indexStatusManager = indexStatusManager;
_indexerRegistryConfiguration = indexerRegistryConfiguration;
}
@Override
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
Annotation annotation = method.getAnnotation(Bufferable.class);
IndexerRequestBuffer indexerRequestBuffer = IndexerRequestBuffer.get();
if ((annotation == null) || (args.length == 0) || (args.length > 2) ||
(indexerRequestBuffer == null)) {
return method.invoke(_indexer, args);
}
if (_indexStatusManager.isIndexReadOnly()) {
if (_log.isDebugEnabled()) {
_log.debug(
"Skipping indexer request buffer because index is read " +
"only");
}
return null;
}
if (CompanyThreadLocal.isDeleteInProcess()) {
if (_log.isDebugEnabled()) {
_log.debug(
"Skipping indexer request buffer because a company " +
"delete is in process");
}
return null;
}
Class> args0Class = args[0].getClass();
if (!(args[0] instanceof BaseModel) &&
!(args[0] instanceof ClassedModel) &&
!(args0Class.isArray() ||
Collection.class.isAssignableFrom(args0Class)) &&
!((args.length == 2) && (args[0] instanceof String) &&
Validator.equals(args[1].getClass(), Long.class))) {
return method.invoke(_indexer, args);
}
if (args[0] instanceof ClassedModel) {
MethodKey methodKey = new MethodKey(
Indexer.class, method.getName(), Object.class);
bufferRequest(methodKey, args[0], indexerRequestBuffer);
}
else if (args.length == 2) {
MethodKey methodKey = new MethodKey(
Indexer.class, method.getName(), String.class, Long.TYPE);
String className = (String)args[0];
Long classPK = (Long)args[1];
bufferRequest(methodKey, className, classPK, indexerRequestBuffer);
}
else {
MethodKey methodKey = new MethodKey(
Indexer.class, method.getName(), Object.class);
Collection
© 2015 - 2025 Weber Informatics LLC | Privacy Policy