You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2014/12/20 17:49:51 UTC
svn commit: r1647018 - in
/lucene/dev/trunk/solr/core/src/java/org/apache/solr/core:
JarRepository.java RequestHandlers.java
Author: markrmiller
Date: Sat Dec 20 16:49:50 2014
New Revision: 1647018
URL: http://svn.apache.org/r1647018
Log:
SOLR-6801: Fix formatting.
Modified:
lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/JarRepository.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/RequestHandlers.java
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/JarRepository.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/JarRepository.java?rev=1647018&r1=1647017&r2=1647018&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/JarRepository.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/JarRepository.java Sat Dec 20 16:49:50 2014
@@ -17,6 +17,8 @@ package org.apache.solr.core;
* limitations under the License.
*/
+import static org.apache.solr.common.SolrException.ErrorCode.SERVICE_UNAVAILABLE;
+import static org.apache.solr.common.cloud.ZkStateReader.BASE_URL_PROP;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -36,87 +38,84 @@ import org.apache.solr.common.cloud.Clus
import org.apache.solr.common.cloud.DocCollection;
import org.apache.solr.common.cloud.Replica;
import org.apache.solr.common.cloud.Slice;
-import org.apache.solr.handler.BlobHandler;
import org.apache.solr.handler.admin.CollectionsHandler;
import org.apache.solr.util.SimplePostTool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.apache.solr.common.SolrException.ErrorCode.SERVICE_UNAVAILABLE;
-import static org.apache.solr.common.cloud.ZkStateReader.BASE_URL_PROP;
-
-/**The purpose of this class is to store the Jars loaded in memory and to keep
- * only one copy of the Jar in a single node.
+/**
+ * The purpose of this class is to store the Jars loaded in memory and to keep only one copy of the Jar in a single node.
*/
public class JarRepository {
public static Logger log = LoggerFactory.getLogger(JarRepository.class);
-
+
private final CoreContainer coreContainer;
-
- private Map<String, JarContent> jars = new ConcurrentHashMap<>();
-
+
+ private Map<String,JarContent> jars = new ConcurrentHashMap<>();
+
public JarRepository(CoreContainer coreContainer) {
this.coreContainer = coreContainer;
}
-
- /**Returns the contents of a jar and increments a reference count. Please return the same
- * object to decerease the refcount
- * @param key it is a combination of blobname and version like blobName/version
+
+ /**
+ * Returns the contents of a jar and increments a reference count. Please return the same object to decerease the refcount
+ *
+ * @param key
+ * it is a combination of blobname and version like blobName/version
* @return The reference of a jar
*/
public JarContentRef getJarIncRef(String key) throws IOException {
JarContent jar = jars.get(key);
- if(jar ==null){
- if(this.coreContainer.isZooKeeperAware()){
+ if (jar == null) {
+ if (this.coreContainer.isZooKeeperAware()) {
ClusterState cs = this.coreContainer.getZkController().getZkStateReader().getClusterState();
DocCollection coll = cs.getCollectionOrNull(CollectionsHandler.SYSTEM_COLL);
- if(coll == null) throw new SolrException(SERVICE_UNAVAILABLE,
- ".system collection not available");
+ if (coll == null) throw new SolrException(SERVICE_UNAVAILABLE, ".system collection not available");
Slice slice = coll.getActiveSlices().iterator().next();
- if(slice == null) throw new SolrException(SERVICE_UNAVAILABLE,
- ".no active slices for .system collection");
+ if (slice == null) throw new SolrException(SERVICE_UNAVAILABLE, ".no active slices for .system collection");
Replica replica = slice.getReplicas().iterator().next();
- if(replica == null) throw new SolrException(SERVICE_UNAVAILABLE,
- ".no active replica available for .system collection");
- String url = replica.getStr(BASE_URL_PROP) + "/.system/blob/"+ key+"?wt=filestream";
-
+ if (replica == null) throw new SolrException(SERVICE_UNAVAILABLE, ".no active replica available for .system collection");
+ String url = replica.getStr(BASE_URL_PROP) + "/.system/blob/" + key + "?wt=filestream";
+
HttpClient httpClient = coreContainer.getUpdateShardHandler().getHttpClient();
HttpGet httpGet = new HttpGet(url);
ByteBuffer b;
try {
- HttpResponse entity = httpClient.execute(httpGet);
+ HttpResponse entity = httpClient.execute(httpGet);
int statusCode = entity.getStatusLine().getStatusCode();
- if(statusCode != 200){
- throw new SolrException(SolrException.ErrorCode.NOT_FOUND,"no such blob or version available: "+ key);
+ if (statusCode != 200) {
+ throw new SolrException(SolrException.ErrorCode.NOT_FOUND, "no such blob or version available: " + key);
}
b = SimplePostTool.inputStreamToByteArray(entity.getEntity().getContent());
} finally {
httpGet.releaseConnection();
}
- jars.put(key,jar = new JarContent(key,b));
+ jars.put(key, jar = new JarContent(key, b));
} else {
-
- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,"Jar loading is not supported in non-cloud mode");
- //todo
-
+
+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Jar loading is not supported in non-cloud mode");
+ // todo
+
}
-
+
}
-
+
JarContentRef ref = new JarContentRef(jar);
synchronized (jar.references) {
jar.references.add(ref);
}
return ref;
-
+
}
-
-
- /**This is to decrement a ref count
- * @param ref The reference that is already there. Doing multiple calls with same ref will not matter
+
+ /**
+ * This is to decrement a ref count
+ *
+ * @param ref
+ * The reference that is already there. Doing multiple calls with same ref will not matter
*/
- public void decrementJarRefCount(JarContentRef ref){
- if(ref == null) return;
+ public void decrementJarRefCount(JarContentRef ref) {
+ if (ref == null) return;
synchronized (ref.jar.references) {
if (!ref.jar.references.remove(ref)) {
log.error("Multiple releases for the same reference");
@@ -125,34 +124,33 @@ public class JarRepository {
jars.remove(ref.jar.key);
}
}
-
+
}
-
-
+
public static class JarContent {
private final String key;
- //TODO move this off-heap
+ // TODO move this off-heap
private final ByteBuffer buffer;
// ref counting mechanism
private final Set<JarContentRef> references = new HashSet<>();
-
+
public JarContent(String key, ByteBuffer buffer) {
this.key = key;
this.buffer = buffer;
}
-
+
public ByteBuffer getFileContent(String entryName) throws IOException {
- ByteArrayInputStream zipContents=new ByteArrayInputStream(buffer.array(),buffer.arrayOffset(),buffer.limit());
- ZipInputStream zis=new ZipInputStream(zipContents);
+ ByteArrayInputStream zipContents = new ByteArrayInputStream(buffer.array(), buffer.arrayOffset(), buffer.limit());
+ ZipInputStream zis = new ZipInputStream(zipContents);
try {
ZipEntry entry;
- while ((entry=zis.getNextEntry()) != null) {
+ while ((entry = zis.getNextEntry()) != null) {
if (entryName == null || entryName.equals(entry.getName())) {
- SimplePostTool.BAOS out=new SimplePostTool.BAOS();
- byte[] buffer=new byte[2048];
+ SimplePostTool.BAOS out = new SimplePostTool.BAOS();
+ byte[] buffer = new byte[2048];
int size;
- while ((size=zis.read(buffer,0,buffer.length)) != -1) {
- out.write(buffer,0,size);
+ while ((size = zis.read(buffer, 0, buffer.length)) != -1) {
+ out.write(buffer, 0, size);
}
out.close();
return out.getByteBuffer();
@@ -163,14 +161,15 @@ public class JarRepository {
}
return null;
}
-
+
}
-
- public static class JarContentRef {
+
+ public static class JarContentRef {
public final JarContent jar;
+
private JarContentRef(JarContent jar) {
this.jar = jar;
}
}
-
+
}
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/RequestHandlers.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/RequestHandlers.java?rev=1647018&r1=1647017&r2=1647018&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/RequestHandlers.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/RequestHandlers.java Sat Dec 20 16:49:50 2014
@@ -119,8 +119,8 @@ public final class RequestHandlers {
*/
public SolrRequestHandler register( String handlerName, SolrRequestHandler handler ) {
String norm = normalize( handlerName );
- if( handler == null ) {
- return handlers.remove( norm );
+ if (handler == null) {
+ return handlers.remove(norm);
}
SolrRequestHandler old = handlers.put(norm, handler);
if (0 != norm.length() && handler instanceof SolrInfoMBean) {
@@ -165,7 +165,7 @@ public final class RequestHandlers {
//deduping implicit and explicit requesthandlers
for (PluginInfo info : implicits) infoMap.put(info.name,info);
for (PluginInfo info : config.getPluginInfos(SolrRequestHandler.class.getName()))
- if(infoMap.containsKey(info.name)) infoMap.remove(info.name);
+ if (infoMap.containsKey(info.name)) infoMap.remove(info.name);
for (Map.Entry e : core.getSolrConfig().getOverlay().getReqHandlers().entrySet())
infoMap.put((String)e.getKey(), new PluginInfo(SolrRequestHandler.TYPE, (Map)e.getValue()));
@@ -174,33 +174,32 @@ public final class RequestHandlers {
for (PluginInfo info : infos) {
try {
SolrRequestHandler requestHandler;
- String startup = info.attributes.get("startup") ;
+ String startup = info.attributes.get("startup");
String lib = info.attributes.get("lib");
- if(lib != null){
+ if (lib != null) {
requestHandler = new DynamicLazyRequestHandlerWrapper(core);
- } else if( startup != null ) {
- if( "lazy".equals(startup) ) {
+ } else if (startup != null) {
+ if ("lazy".equals(startup)) {
log.info("adding lazy requestHandler: " + info.className);
- requestHandler = new LazyRequestHandlerWrapper( core);
+ requestHandler = new LazyRequestHandlerWrapper(core);
} else {
- throw new Exception( "Unknown startup value: '"+startup+"' for: "+info.className );
+ throw new Exception("Unknown startup value: '" + startup + "' for: " + info.className);
}
} else {
requestHandler = core.createRequestHandler(info.className);
}
if (requestHandler instanceof RequestHandlerBase) ((RequestHandlerBase) requestHandler).setPluginInfo(info);
-
- handlers.put(info,requestHandler);
+
+ handlers.put(info, requestHandler);
SolrRequestHandler old = register(info.name, requestHandler);
- if(old != null) {
+ if (old != null) {
log.warn("Multiple requestHandler registered to the same name: " + info.name + " ignoring: " + old.getClass().getName());
}
- if(info.isDefault()){
- old = register("",requestHandler);
- if(old != null)
- log.warn("Multiple default requestHandler registered" + " ignoring: " + old.getClass().getName());
+ if (info.isDefault()) {
+ old = register("", requestHandler);
+ if (old != null) log.warn("Multiple default requestHandler registered" + " ignoring: " + old.getClass().getName());
}
- log.info("created "+info.name+": " + info.className);
+ log.info("created " + info.name + ": " + info.className);
} catch (Exception ex) {
throw new SolrException
(ErrorCode.SERVER_ERROR, "RequestHandler init failure", ex);
@@ -387,8 +386,8 @@ public final class RequestHandlers {
@Override
public void close() throws Exception {
- if(_handler == null) return;
- if (_handler instanceof AutoCloseable && !(_handler instanceof DynamicLazyRequestHandlerWrapper) ) {
+ if (_handler == null) return;
+ if (_handler instanceof AutoCloseable && !(_handler instanceof DynamicLazyRequestHandlerWrapper)) {
((AutoCloseable) _handler).close();
}
}
@@ -493,7 +492,7 @@ public final class RequestHandlers {
@Override
public void close() throws Exception {
super.close();
- if(_closed) return;
+ if (_closed) return;
classLoader.releaseJar();
_closed = true;
}