org.apache.solr.util.plugin.SolrCoreAware Java Examples

The following examples show how to use org.apache.solr.util.plugin.SolrCoreAware. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PackagePluginHolder.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void handleAwareCallbacks(SolrResourceLoader loader, Object instance) {
  if (instance instanceof SolrCoreAware) {
    SolrCoreAware coreAware = (SolrCoreAware) instance;
    if (!core.getResourceLoader().addToCoreAware(coreAware)) {
      coreAware.inform(core);
    }
  }
  if (instance instanceof ResourceLoaderAware) {
    SolrResourceLoader.assertAwareCompatibility(ResourceLoaderAware.class, instance);
    try {
      ((ResourceLoaderAware) instance).inform(loader);
    } catch (IOException e) {
      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
    }
  }
  if (instance instanceof SolrInfoBean) {
    core.getResourceLoader().addToInfoBeans(instance);
  }
}
 
Example #2
Source File: SolrResourceLoader.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Tell all {@link SolrCoreAware} instances about the SolrCore
 */
public void inform(SolrCore core) {
  // make a copy to avoid potential deadlock of a callback calling newInstance and trying to
  // add something to waitingForCore.
  SolrCoreAware[] arr;

  while (waitingForCore.size() > 0) {
    synchronized (waitingForCore) {
      arr = waitingForCore.toArray(new SolrCoreAware[waitingForCore.size()]);
      waitingForCore.clear();
    }

    for (SolrCoreAware aware : arr) {
      aware.inform(core);
    }
  }

  // this is the last method to be called in SolrCore before the latch is released.
  live = true;
}
 
Example #3
Source File: ChangedSchemaMergeTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void beforeClass() throws Exception {

  simfac1 = LMJelinekMercerSimilarityFactory.class;
  simfac2 = SchemaSimilarityFactory.class;
  
  // sanity check our test...
  assertTrue("Effectiveness of tets depends on SchemaSimilarityFactory being SolrCoreAware " + 
             "something changed in the impl and now major portions of this test are useless",
             SolrCoreAware.class.isAssignableFrom(simfac2));
  
  // randomize the order these similarities are used in the changed schemas
  // to help test proper initialization in both code paths
  if (random().nextBoolean()) {
    Class<? extends SimilarityFactory> tmp = simfac1;
    simfac1 = simfac2;
    simfac2 = tmp;
  }
  System.setProperty("solr.test.simfac1", simfac1.getName());
  System.setProperty("solr.test.simfac2", simfac2.getName());
    
  initCore();
}
 
Example #4
Source File: UpdateRequestProcessorChain.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
static List<UpdateRequestProcessorFactory> getReqProcessors(String processor, SolrCore core) {
  if (processor == null) return Collections.emptyList();
  List<UpdateRequestProcessorFactory> result = new ArrayList<>();
  List<String> names = StrUtils.splitSmart(processor, ',');
  for (String s : names) {
    s = s.trim();
    if (s.isEmpty()) continue;
    UpdateRequestProcessorFactory p = null;
    PluginBag.PluginHolder<UpdateRequestProcessorFactory> holder = core.getUpdateProcessors().getRegistry().get(s);
    if (holder instanceof PackagePluginHolder) {
      p = new LazyUpdateRequestProcessorFactory(holder);
    } else {
      p = core.getUpdateProcessors().get(s);
    }
    if (p == null) {
      @SuppressWarnings({"unchecked"})
      Class<UpdateRequestProcessorFactory> factoryClass = implicits.get(s);
      if(factoryClass != null) {
        PluginInfo pluginInfo = new PluginInfo("updateProcessor",
            Utils.makeMap("name", s,
                "class", factoryClass.getName()));
        UpdateRequestProcessorFactory plugin = p = core.getUpdateProcessors().createPlugin(pluginInfo).get();
        if (plugin instanceof SolrCoreAware) ((SolrCoreAware) plugin).inform(core);
        core.getUpdateProcessors().put(s, plugin);
      }
      if (p == null)
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No such processor " + s);
    }
    result.add(p);
  }
  return result;
}
 
Example #5
Source File: SolrCore.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the latest schema snapshot to be used by this core instance.
 * If the specified <code>replacementSchema</code> uses a {@link SimilarityFactory} which is
 * {@link SolrCoreAware} then this method will {@link SolrCoreAware#inform} that factory about
 * this SolrCore prior to using the <code>replacementSchema</code>
 *
 * @see #getLatestSchema
 */
public void setLatestSchema(IndexSchema replacementSchema) {
  // 1) For a newly instantiated core, the Similarity needs SolrCore before inform() is called on
  // any registered SolrCoreAware listeners (which will likeley need to use the SolrIndexSearcher.
  //
  // 2) If a new IndexSchema is assigned to an existing live SolrCore (ie: managed schema
  // replacement via SolrCloud) then we need to explicitly inform() the similarity because
  // we can't rely on the normal SolrResourceLoader lifecycle because the sim was instantiated
  // after the SolrCore was already live (see: SOLR-8311 + SOLR-8280)
  final SimilarityFactory similarityFactory = replacementSchema.getSimilarityFactory();
  if (similarityFactory instanceof SolrCoreAware) {
    ((SolrCoreAware) similarityFactory).inform(this);
  }
  this.schema = replacementSchema;
}
 
Example #6
Source File: SolrResourceLoader.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/** the inform() callback should be invoked on the listener.
 * If this is 'live', the callback is not called so currently this returns 'false'
 *
 */
public <T> boolean addToCoreAware(T obj) {
  if (!live) {
    if (obj instanceof SolrCoreAware) {
      assertAwareCompatibility(SolrCoreAware.class, obj);
      waitingForCore.add((SolrCoreAware) obj);
    }
    return true;
  } else {
    return false;
  }
}
 
Example #7
Source File: SecureAdminHandlers.java    From incubator-sentry with Apache License 2.0 4 votes vote down vote up
/**
 * NOTE: ideally we'd just override the list of admin handlers, but
 * since AdminHandlers in solr doesn't allow it, let's just copy the
 * entire function.  This is deprecated in Solr 5.0, so we should do something
 * different with Solr 5.0 anyway.
 */
@Override
public void inform(SolrCore core) 
{
  String path = null;
  for( Map.Entry<String, SolrRequestHandler> entry : core.getRequestHandlers().entrySet() ) {
    if( entry.getValue() == this ) {
      path = entry.getKey();
      break;
    }
  }
  if( path == null ) {
    throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, 
        "The AdminHandler is not registered with the current core." );
  }
  if( !path.startsWith( "/" ) ) {
    throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, 
      "The AdminHandler needs to be registered to a path.  Typically this is '/admin'" );
  }
  // Remove the parent handler 
  core.registerRequestHandler(path, null);
  if( !path.endsWith( "/" ) ) {
    path += "/";
  }
  
  StandardHandler[] list = new StandardHandler[] {
     new StandardHandler( "luke", new SecureLukeRequestHandler() ),
     new StandardHandler( "system", new SecureSystemInfoHandler() ),
     new StandardHandler( "mbeans", new SecureSolrInfoMBeanHandler() ),
     new StandardHandler( "plugins", new SecurePluginInfoHandler() ),
     new StandardHandler( "threads", new SecureThreadDumpHandler() ),
     new StandardHandler( "properties", new SecurePropertiesRequestHandler() ),
     new StandardHandler( "logging", new SecureLoggingHandler() ),
     new StandardHandler( "file", new SecureShowFileRequestHandler() )
  };
  
  for( StandardHandler handler : list ) {
    if( core.getRequestHandler( path+handler.name ) == null ) {
      handler.handler.init( initArgs );
      core.registerRequestHandler( path+handler.name, handler.handler );
      if( handler.handler instanceof SolrCoreAware ) {
        ((SolrCoreAware)handler.handler).inform(core);
      }
    }
  }
}