Replace RecyclerUtils with Releasables.

This commit is contained in:
Adrien Grand 2014-01-07 14:44:24 +01:00
parent b9714eae60
commit 107ae66a60
6 changed files with 12 additions and 63 deletions

View File

@ -1,51 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.common.recycler;
/**
*/
public final class RecyclerUtils {
private RecyclerUtils() {
}
// Borrowed from IOUtils#close
public static void release(Recycler.V... recyclers) {
Throwable th = null;
for (Recycler.V recycler : recyclers) {
try {
if (recycler != null) {
recycler.release();
}
} catch (Throwable t) {
if (th == null) {
th = t;
}
}
}
if (th != null) {
throw new RuntimeException(th);
}
}
}

View File

@ -30,11 +30,11 @@ import org.apache.lucene.util.BytesRef;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.bytes.HashedBytesArray;
import org.elasticsearch.common.lease.Releasable;
import org.elasticsearch.common.lease.Releasables;
import org.elasticsearch.common.lucene.docset.DocIdSets;
import org.elasticsearch.common.lucene.search.ApplyAcceptedDocsFilter;
import org.elasticsearch.common.lucene.search.Queries;
import org.elasticsearch.common.recycler.Recycler;
import org.elasticsearch.common.recycler.RecyclerUtils;
import org.elasticsearch.index.cache.id.IdReaderTypeCache;
import org.elasticsearch.index.mapper.Uid;
import org.elasticsearch.index.mapper.internal.UidFieldMapper;
@ -193,7 +193,7 @@ public class ChildrenConstantScoreQuery extends Query {
@Override
public boolean release() throws ElasticsearchException {
RecyclerUtils.release(collectedUids);
Releasables.release(collectedUids);
return true;
}

View File

@ -32,12 +32,12 @@ import org.apache.lucene.util.ToStringUtils;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.bytes.HashedBytesArray;
import org.elasticsearch.common.lease.Releasable;
import org.elasticsearch.common.lease.Releasables;
import org.elasticsearch.common.lucene.docset.DocIdSets;
import org.elasticsearch.common.lucene.search.AndFilter;
import org.elasticsearch.common.lucene.search.ApplyAcceptedDocsFilter;
import org.elasticsearch.common.lucene.search.Queries;
import org.elasticsearch.common.recycler.Recycler;
import org.elasticsearch.common.recycler.RecyclerUtils;
import org.elasticsearch.index.cache.id.IdReaderTypeCache;
import org.elasticsearch.index.mapper.Uid;
import org.elasticsearch.index.mapper.internal.UidFieldMapper;
@ -252,7 +252,7 @@ public class ChildrenQuery extends Query {
@Override
public boolean release() throws ElasticsearchException {
RecyclerUtils.release(uidToScore, uidToCount);
Releasables.release(uidToScore, uidToCount);
return true;
}

View File

@ -28,12 +28,12 @@ import org.apache.lucene.util.Bits;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.bytes.HashedBytesArray;
import org.elasticsearch.common.lease.Releasable;
import org.elasticsearch.common.lease.Releasables;
import org.elasticsearch.common.lucene.docset.DocIdSets;
import org.elasticsearch.common.lucene.search.ApplyAcceptedDocsFilter;
import org.elasticsearch.common.lucene.search.NoopCollector;
import org.elasticsearch.common.lucene.search.Queries;
import org.elasticsearch.common.recycler.Recycler;
import org.elasticsearch.common.recycler.RecyclerUtils;
import org.elasticsearch.index.cache.id.IdReaderTypeCache;
import org.elasticsearch.search.internal.SearchContext;
@ -156,7 +156,7 @@ public class ParentConstantScoreQuery extends Query {
@Override
public boolean release() throws ElasticsearchException {
RecyclerUtils.release(parents);
Releasables.release(parents);
return true;
}

View File

@ -29,12 +29,12 @@ import org.apache.lucene.util.ToStringUtils;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.bytes.HashedBytesArray;
import org.elasticsearch.common.lease.Releasable;
import org.elasticsearch.common.lease.Releasables;
import org.elasticsearch.common.lucene.docset.DocIdSets;
import org.elasticsearch.common.lucene.search.ApplyAcceptedDocsFilter;
import org.elasticsearch.common.lucene.search.NoopCollector;
import org.elasticsearch.common.lucene.search.Queries;
import org.elasticsearch.common.recycler.Recycler;
import org.elasticsearch.common.recycler.RecyclerUtils;
import org.elasticsearch.index.cache.id.IdReaderTypeCache;
import org.elasticsearch.search.internal.SearchContext;
@ -229,7 +229,7 @@ public class ParentQuery extends Query {
@Override
public boolean release() throws ElasticsearchException {
RecyclerUtils.release(uidToScore);
Releasables.release(uidToScore);
return true;
}
}

View File

@ -30,9 +30,9 @@ import org.elasticsearch.ElasticsearchIllegalStateException;
import org.elasticsearch.cache.recycler.CacheRecycler;
import org.elasticsearch.common.bytes.HashedBytesArray;
import org.elasticsearch.common.lease.Releasable;
import org.elasticsearch.common.lease.Releasables;
import org.elasticsearch.common.lucene.search.EmptyScorer;
import org.elasticsearch.common.recycler.Recycler;
import org.elasticsearch.common.recycler.RecyclerUtils;
import org.elasticsearch.search.internal.SearchContext;
import java.io.IOException;
@ -206,10 +206,10 @@ public class TopChildrenQuery extends Query {
ParentDoc[] _parentDocs = value.v().values().toArray(ParentDoc.class);
Arrays.sort(_parentDocs, PARENT_DOC_COMP);
parentDocs.v().put(keys[i], _parentDocs);
RecyclerUtils.release(value);
Releasables.release(value);
}
}
RecyclerUtils.release(parentDocsPerReader);
Releasables.release(parentDocsPerReader);
return parentHitsResolved;
}
@ -282,7 +282,7 @@ public class TopChildrenQuery extends Query {
@Override
public boolean release() throws ElasticsearchException {
RecyclerUtils.release(parentDocs);
Releasables.release(parentDocs);
return true;
}