This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sample.es.udith; | |
import org.elasticsearch.action.admin.indices.optimize.OptimizeResponse; | |
import org.elasticsearch.action.bulk.BulkRequestBuilder; | |
import org.elasticsearch.action.bulk.BulkResponse; | |
import org.elasticsearch.action.search.SearchResponse; | |
import org.elasticsearch.action.search.SearchType; | |
import org.elasticsearch.client.transport.TransportClient; | |
import org.elasticsearch.common.transport.InetSocketTransportAddress; | |
import org.elasticsearch.common.unit.TimeValue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sample.es.udith; | |
import org.elasticsearch.client.transport.TransportClient; | |
import org.elasticsearch.common.transport.InetSocketTransportAddress; | |
public class ESManager { | |
private final String ES_INDEX; | |
private final String ES_TYPE; | |
private final String ES_TIME_FIELD; | |
private final int EXPIRE_DAYS; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void cleanESDocs() { | |
final Calendar calendar = Calendar.getInstance(); | |
calendar.add(Calendar.DATE, -EXPIRE_DAYS); | |
SearchResponse scrollResp = elasticsearch.prepareSearch(ES_INDEX).setTypes(ES_TYPE) | |
.setSearchType(SearchType.SCAN) | |
.setScroll(new TimeValue(600000)) | |
.setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), | |
FilterBuilders.andFilter( | |
FilterBuilders.rangeFilter(ES_TIME_FIELD).to(calendar.getTimeInMillis()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void cleanESDocs() { | |
final Calendar calendar = Calendar.getInstance(); | |
calendar.add(Calendar.DATE, -EXPIRE_DAYS); | |
BulkRequestBuilder bulkRequest = elasticsearch.prepareBulk(); | |
SearchResponse scrollResp = elasticsearch.prepareSearch(ES_INDEX).setTypes(ES_TYPE) | |
.setSearchType(SearchType.SCAN) | |
.setScroll(new TimeValue(600000)) | |
.setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), | |
FilterBuilders.andFilter( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void optimizeIndex() { | |
OptimizeResponse optimizeResponse = elasticsearch.admin().indices() | |
.prepareOptimize(ES_INDEX) | |
.setFlush(true) | |
.setOnlyExpungeDeletes(false) | |
.execute().actionGet(); | |
System.out.println("Elasticsearch index optimization finished with " + | |
optimizeResponse.getSuccessfulShards() + " successful and " + | |
optimizeResponse.getFailedShards() + " failed shards out of " + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int c = ctl.get(); | |
if (workerCountOf(c) < corePoolSize) { | |
if (addWorker(command, true)) | |
return; | |
c = ctl.get(); | |
} | |
if (isRunning(c) && workQueue.offer(command)) { | |
int recheck = ctl.get(); | |
if (! isRunning(recheck) && remove(command)) | |
reject(command); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public boolean offer(Runnable e) { | |
return currentIdleThreadCount.get() > 0 && super.offer(e); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Runnable r = timed ? | |
workQueue.poll(keepAliveTime, TimeUnit.NANOSECONDS) : workQueue.take(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public Runnable take() throws InterruptedException { | |
currentIdleThreadCount.incrementAndGet(); | |
Runnable take = super.take(); | |
currentIdleThreadCount.decrementAndGet(); | |
return take; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public Runnable poll(long timeout, TimeUnit unit) throws InterruptedException { | |
currentIdleThreadCount.incrementAndGet(); | |
Runnable poll = super.poll(timeout, unit); | |
currentIdleThreadCount.decrementAndGet(); | |
return poll; | |
} |
OlderNewer