mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Checkin of remaining files for ALF-8793: "RSOLR 036: Update IndexChecker to call SOLR check APIs"
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29244 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user