Java Code Examples for org.pf4j.PluginManager#loadPlugins()

The following examples show how to use org.pf4j.PluginManager#loadPlugins() . 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: Hive2StoragePluginConfig.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public StoragePlugin newPlugin(SabotContext context, String name, Provider<StoragePluginId> pluginIdProvider) {
  final PluginManager manager = new NativeLibPluginManager();
  manager.loadPlugins();
  manager.startPlugins();

  // Just statically create the plugin creator for this module.
  return new Hive2PluginCreator().createStoragePlugin(manager, this, context, name, pluginIdProvider);
}
 
Example 2
Source File: Hive3StoragePluginConfig.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public StoragePlugin newPlugin(SabotContext context, String name, Provider<StoragePluginId> pluginIdProvider) {
  final PluginManager manager = new NativeLibPluginManager();

  manager.loadPlugins();
  manager.startPlugin(getPf4jPluginId());
  final StoragePluginCreator pluginCreator =
    manager.getExtensions(StoragePluginCreator.class, getPf4jPluginId()).get(0);

  return pluginCreator.createStoragePlugin(manager, this, context, name, pluginIdProvider);
}
 
Example 3
Source File: Hive2StoragePluginConfig.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public StoragePlugin newPlugin(SabotContext context, String name, Provider<StoragePluginId> pluginIdProvider) {
  final PluginManager manager = new NativeLibPluginManager();

  manager.loadPlugins();
  manager.startPlugin(getPf4jPluginId());
  final StoragePluginCreator pluginCreator =
    manager.getExtensions(StoragePluginCreator.class, getPf4jPluginId()).get(0);

  return pluginCreator.createStoragePlugin(manager, this, context, name, pluginIdProvider);
}
 
Example 4
Source File: BuckPluginManagerFactory.java    From buck with Apache License 2.0 5 votes vote down vote up
/** Creates a {@link PluginManager} and loads plugins. */
public static PluginManager createPluginManager() {
  PluginManager pluginManager = new DefaultBuckPluginManager();
  pluginManager.loadPlugins();
  pluginManager.startPlugins();

  return pluginManager;
}
 
Example 5
Source File: Container.java    From pf4j-spring-tutorial with MIT License 4 votes vote down vote up
public static void main(String[] args){
    final PluginManager pm = new DefaultPluginManager();

    pm.loadPlugins();

    pm.startPlugins();

    final List<PluginInterface> plugins = pm.getExtensions(PluginInterface.class);

    log.info(MessageFormat.format(" {0} Plugin(s) found ", String.valueOf(plugins.size())));

    plugins.forEach(g ->
            log.info(MessageFormat.format(" {0}: {1}",
                    g.getClass().getCanonicalName(),
                    g.identify())));

    pm.stopPlugins();

}
 
Example 6
Source File: AuthcPluginTest.java    From spring-boot-starter-samples with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
	
	System.setProperty("pf4j.mode", RuntimeMode.DEPLOYMENT.toString());
	System.setProperty("pf4j.pluginsDir", "plugins");
	
	if(RuntimeMode.DEPLOYMENT.compareTo(RuntimeMode.DEPLOYMENT) == 0) {
		//System.setProperty("pf4j.pluginsDir", System.getProperty("app.home","e:/root") + "/plugins");
	}
	
	/**
	 * 创建PluginManager对象,此处根据生产环境选择合适的实现,或者自定义实现
	 */
	PluginManager pluginManager = new DefaultPluginManager();
	// PluginManager pluginManager = new Pf4jPluginManager();
	// PluginManager pluginManager = new SpringPluginManager();
	// PluginManager pluginManager = new Pf4jJarPluginManager();
	// PluginManager pluginManager = new Pf4jJarPluginWhitSpringManager();

	/**
	 * 加载插件到JVM
	 */
    pluginManager.loadPlugins();

    /**
     * 调用Plugin实现类的start()方法: 
     */
    pluginManager.startPlugins();
    
    List<PluginWrapper> list = pluginManager.getPlugins();
    for (PluginWrapper pluginWrapper : list) {
		System.out.println(pluginWrapper.getPluginId());
	}
    
    
    List<AuthcExtensionPoint> extensions = pluginManager.getExtensions(AuthcExtensionPoint.class);
    
    for (AuthcExtensionPoint point : extensions) {
    	
    	ExtensionMapping m = point.getClass().getAnnotation(ExtensionMapping.class);
    	System.out.println(m.title());
    	
	}
    
    /**
     * 调用Plugin实现类的stop()方法
     */
    pluginManager.stopPlugins();
    
    System.out.println("=============");
	
}