mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29244 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
67 lines
1.8 KiB
Java
67 lines
1.8 KiB
Java
package org.alfresco.repo.solr;
|
|
|
|
import java.util.concurrent.locks.ReadWriteLock;
|
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
|
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
|
|
|
|
import org.aopalliance.intercept.MethodInterceptor;
|
|
import org.aopalliance.intercept.MethodInvocation;
|
|
import org.springframework.context.ApplicationEventPublisher;
|
|
import org.springframework.context.ApplicationEventPublisherAware;
|
|
|
|
/**
|
|
* A method interceptor that intercepts method calls on the {@link SOLRTrackingComponent}
|
|
* in order to determine if a remote Solr instance is active. If so, an application event
|
|
* is generated to indicate this.
|
|
*
|
|
* This is used by the Solr JMX code to export Solr mbeans only if the remote Solr instance
|
|
* is active.
|
|
*
|
|
* since 4.0
|
|
*
|
|
*/
|
|
public class SolrTrackingMethodInterceptor implements MethodInterceptor, ApplicationEventPublisherAware
|
|
{
|
|
private final WriteLock writeLock;
|
|
private boolean solrActive = false;
|
|
private ApplicationEventPublisher applicationEventPublisher;
|
|
|
|
public SolrTrackingMethodInterceptor()
|
|
{
|
|
ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
|
|
writeLock = lock.writeLock();
|
|
}
|
|
|
|
private void broadcastSolrActive()
|
|
{
|
|
applicationEventPublisher.publishEvent(new SolrActiveEvent(this));
|
|
solrActive = true;
|
|
}
|
|
|
|
@Override
|
|
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
|
|
{
|
|
this.applicationEventPublisher = applicationEventPublisher;
|
|
}
|
|
|
|
public Object invoke(MethodInvocation mi) throws Throwable
|
|
{
|
|
writeLock.lock();
|
|
try
|
|
{
|
|
if(!solrActive)
|
|
{
|
|
broadcastSolrActive();
|
|
solrActive = true;
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
writeLock.unlock();
|
|
}
|
|
|
|
return mi.proceed();
|
|
}
|
|
|
|
}
|