Package org.apache.solr.embedded
Class JettySolrRunner
java.lang.Object
org.apache.solr.embedded.JettySolrRunner
- All Implemented Interfaces:
AutoCloseable,SolrBackend
Run solr using jetty
- Since:
- solr 1.3
-
Constructor Summary
ConstructorsConstructorDescriptionJettySolrRunner(String solrHome, int port) Create a new JettySolrRunner.JettySolrRunner(String solrHome, Properties nodeProperties, JettyConfig config) Construct a JettySolrRunnerJettySolrRunner(String solrHome, Properties nodeProperties, JettyConfig config, boolean enableProxy) Construct a JettySolrRunnerJettySolrRunner(String solrHome, JettyConfig config) Construct a JettySolrRunner -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Shuts down this backend, releases the admin client, and all other resources.voidcreateCollection(org.apache.solr.client.solrj.request.CollectionAdminRequest.Create create) Creates a collection (or core for single-node backends).voidReturns a base URL likehttp://localhost:8983/solrgetBaseUrl(Random r) Returns the base URL of a Solr node.org.apache.solr.core.CoreContainerProvides access to an embedded/in-processCoreContainer-- if available (else null).<T extends jakarta.servlet.Filter>
TintReturns the Local Port of the jetty Server.intgetLocalPort(boolean internalPort) Returns the Local Port of the jetty Server.getProxy()Returns a base URL consisting of the protocol, host, and port for a Connector in use by the Jetty Server contained in this runner.getRestClient(String collection) Creates a REST client useful for HTTP operations.org.apache.solr.client.solrj.jetty.HttpJettySolrClientReturns the node / admin (collection-less)SolrClientowned by this backend.booleanhasCollection(String name) Checks if a collection or core with the given name exists.protected org.eclipse.jetty.server.Handler.WrapperinjectJettyHandlers(org.eclipse.jetty.server.Handler.Wrapper chain) descendants may inject own handler chaining it to the given root and then returning that own onebooleanbooleanstatic voidA main class that starts jetty+solr This is useful for debuggingorg.apache.solr.client.solrj.jetty.HttpJettySolrClientnewSolrClient(String collection) Creates a newSolrClientdefaulted to the given collection.voidoutputMetrics(PrintStream out) voidreloadCollection(String name) Reloads a collection or core by this name.voidsetProxyPort(int proxyPort) Sets the port of a local socket proxy that sits in front of this server; if set then all client traffic will flow through the proxy, giving us the ability to simulate network partitions very easily.voidstart()Start the Jetty servervoidstart(boolean reusePort) Start the Jetty servervoidstop()Stop the Jetty serverMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.solr.SolrBackend
dumpCoreInfo, dumpMetrics, hasConfigSet, uploadConfigSet
-
Constructor Details
-
JettySolrRunner
Create a new JettySolrRunner.After construction, you must start the jetty with
start()- Parameters:
solrHome- the solr home directory to useport- the port to run on
-
JettySolrRunner
Construct a JettySolrRunnerAfter construction, you must start the jetty with
start()- Parameters:
solrHome- the base path to run fromconfig- the configuration
-
JettySolrRunner
Construct a JettySolrRunnerAfter construction, you must start the jetty with
start()- Parameters:
solrHome- the solrHome to usenodeProperties- the container propertiesconfig- the configuration
-
JettySolrRunner
public JettySolrRunner(String solrHome, Properties nodeProperties, JettyConfig config, boolean enableProxy) Construct a JettySolrRunnerAfter construction, you must start the jetty with
start()- Parameters:
solrHome- the solrHome to usenodeProperties- the container propertiesconfig- the configurationenableProxy- enables proxy feature to disable connections
-
-
Method Details
-
injectJettyHandlers
protected org.eclipse.jetty.server.Handler.Wrapper injectJettyHandlers(org.eclipse.jetty.server.Handler.Wrapper chain) descendants may inject own handler chaining it to the given root and then returning that own one -
getFilter
- Returns:
- the first filter implemented by the specified class, or throws an exception
-
getCoreContainer
public org.apache.solr.core.CoreContainer getCoreContainer()Description copied from interface:SolrBackendProvides access to an embedded/in-processCoreContainer-- if available (else null). If there is more than one node, then one is returned.- Specified by:
getCoreContainerin interfaceSolrBackend- Returns:
- can be null.
-
getNodeName
-
isRunning
public boolean isRunning() -
isStopped
public boolean isStopped() -
start
Start the Jetty serverIf the server has been started before, it will restart using the same port
- Throws:
Exception- if an error occurs on startup
-
start
Start the Jetty server- Parameters:
reusePort- when true, will start up on the same port as used by any previous runs of this JettySolrRunner. If false, will use the port specified by the server's JettyConfig.- Throws:
Exception- if an error occurs on startup
-
stop
Stop the Jetty server- Throws:
Exception- if an error occurs on shutdown
-
outputMetrics
- Throws:
IOException
-
dumpCoresInfo
-
getLocalPort
public int getLocalPort()Returns the Local Port of the jetty Server.- Throws:
RuntimeException- if there is no Connector
-
getLocalPort
public int getLocalPort(boolean internalPort) Returns the Local Port of the jetty Server.- Parameters:
internalPort- pass true to get the true jetty port rather than the proxy port if configured- Throws:
RuntimeException- if there is no Connector
-
setProxyPort
public void setProxyPort(int proxyPort) Sets the port of a local socket proxy that sits in front of this server; if set then all client traffic will flow through the proxy, giving us the ability to simulate network partitions very easily. -
getBaseUrl
Returns a base URL likehttp://localhost:8983/solr -
getBaseURLV2
-
getProxyBaseUrl
Returns a base URL consisting of the protocol, host, and port for a Connector in use by the Jetty Server contained in this runner. -
main
A main class that starts jetty+solr This is useful for debugging- Throws:
Exception
-
getSolrHome
- Returns:
- the Solr home directory of this JettySolrRunner
-
getNodeProperties
- Returns:
- this node's properties
-
getProxy
-
getRestClient
Creates a REST client useful for HTTP operations. It closes when thisJettySolrRunneris stopped. -
newSolrClient
Description copied from interface:SolrBackendCreates a newSolrClientdefaulted to the given collection. The caller owns this client and is responsible for closing it. Callers that want a long-lived client should cache it themselves.- Specified by:
newSolrClientin interfaceSolrBackend
-
getSolrClient
public org.apache.solr.client.solrj.jetty.HttpJettySolrClient getSolrClient()Description copied from interface:SolrBackendReturns the node / admin (collection-less)SolrClientowned by this backend. The caller must NOT close it; it is released when this backend isSolrBackend.close()d. ACloudSolrClientshould be returned if appropriate. While it *can* be used to target specific collections, please useSolrBackend.newSolrClient(String)for that instead.- Specified by:
getSolrClientin interfaceSolrBackend
-
createCollection
public void createCollection(org.apache.solr.client.solrj.request.CollectionAdminRequest.Create create) Description copied from interface:SolrBackendCreates a collection (or core for single-node backends). Cloud backends honournumShardsandreplicationFactor; single-node backends (JettySolrRunner,EmbeddedSolrBackend) ignore those fields. Callers should useSolrBackend.hasCollection(String)first if they want to avoid errors when the collection already exists. Tests/benchmarks that want to test how this works should not use this to do so.- Specified by:
createCollectionin interfaceSolrBackend
-
hasCollection
Description copied from interface:SolrBackendChecks if a collection or core with the given name exists.- Specified by:
hasCollectionin interfaceSolrBackend- Parameters:
name- collection or core name to check- Returns:
- true if the collection/core exists, false otherwise
-
reloadCollection
public void reloadCollection(String name) throws org.apache.solr.client.solrj.SolrServerException, IOException Description copied from interface:SolrBackendReloads a collection or core by this name. The purpose is typically to clear caches.- Specified by:
reloadCollectionin interfaceSolrBackend- Throws:
org.apache.solr.client.solrj.SolrServerExceptionIOException
-
getBaseUrl
Description copied from interface:SolrBackendReturns the base URL of a Solr node. For cloud backends with multiple nodes, a live node is chosen at random. The URL does not include a trailing slash.- Specified by:
getBaseUrlin interfaceSolrBackend- Returns:
- base URL (e.g., "http://localhost:8983/solr"). Null for EmbeddedSolrServer.
-
close
public void close()Description copied from interface:SolrBackendShuts down this backend, releases the admin client, and all other resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceSolrBackend
-