@Override public void writeExternal(ObjectOutput out) throws IOException { if (pluginConfigurer == null) { throw new IllegalStateException("Serialization not supported from an executor"); } byte[] plugins = getGson().toJson(pluginConfigurer.getPlugins(), PLUGINS_TYPE).getBytes(StandardCharsets.UTF_8); out.writeInt(plugins.length); out.write(plugins); }
@Nullable @Override public <T> T usePlugin(String pluginType, String pluginName, String pluginId, PluginProperties properties, PluginSelector selector) { return pluginConfigurer.usePlugin(pluginType, pluginName, pluginId, properties, selector); }
@Nullable @Override public <T> Class<T> usePluginClass(String pluginType, String pluginName, String pluginId, PluginProperties properties, PluginSelector selector) { return pluginConfigurer.usePluginClass(pluginType, pluginName, pluginId, properties, selector); } }
protected AbstractConfigurer(Id.Namespace deployNamespace, Id.Artifact artifactId, ArtifactRepository artifactRepository, PluginInstantiator pluginInstantiator) { this.deployNamespace = deployNamespace; this.extraPlugins = new HashMap<>(); this.pluginConfigurer = new DefaultPluginConfigurer(artifactId.toEntityId(), deployNamespace.toEntityId(), pluginInstantiator, new LocalPluginFinder(artifactRepository)); }
@Nullable @Override public final <T> Class<T> usePluginClass(String pluginType, String pluginName, String pluginId, PluginProperties properties, PluginSelector selector) { try { Plugin plugin = addPlugin(pluginType, pluginName, pluginId, properties, selector); return pluginInstantiator.loadClass(plugin); } catch (PluginNotExistsException | IOException e) { return null; } catch (ClassNotFoundException e) { // Shouldn't happen throw Throwables.propagate(e); } }
protected AbstractConfigurer(Id.Namespace deployNamespace, Id.Artifact artifactId, ArtifactRepository artifactRepository, PluginInstantiator pluginInstantiator) { this.deployNamespace = deployNamespace; this.extraPlugins = new HashMap<>(); this.pluginConfigurer = new DefaultPluginConfigurer(artifactId.toEntityId(), deployNamespace.toEntityId(), pluginInstantiator, new LocalPluginFinder(artifactRepository)); }
@Nullable @Override public final <T> T usePlugin(String pluginType, String pluginName, String pluginId, PluginProperties properties, PluginSelector selector) { try { Plugin plugin = addPlugin(pluginType, pluginName, pluginId, properties, selector); return pluginInstantiator.newInstance(plugin); } catch (PluginNotExistsException | IOException e) { return null; } catch (ClassNotFoundException e) { // Shouldn't happen throw Throwables.propagate(e); } }
/** * Returns the {@link Plugin} information for the given plugin id that were configured via this context. */ private Plugin getExtraPlugin(String pluginId) { // Get the map of plugins from either the configurer (handler method) or the extra plugins map (executor) Map<String, PluginWithLocation> plugins = pluginConfigurer == null ? extraPlugins : pluginConfigurer.getPlugins(); PluginWithLocation plugin = plugins.get(pluginId); if (plugin == null) { throw new IllegalArgumentException("Plugin with id " + pluginId + " does not exist"); } return plugin.getPlugin(); }
@Override public PluginConfigurer createPluginConfigurer() { File tmpDir = new File(cConf.get(Constants.CFG_LOCAL_DATA_DIR), cConf.get(Constants.AppFabric.TEMP_DIR)).getAbsoluteFile(); try { File pluginsDir = Files.createTempDirectory(tmpDir.toPath(), "plugins").toFile(); PluginInstantiator instantiator = new PluginInstantiator(cConf, getProgram().getClassLoader(), pluginsDir); closeables.add(() -> { try { instantiator.close(); } finally { DirUtils.deleteDirectoryContents(pluginsDir, true); } }); return new DefaultPluginConfigurer(artifactId, namespaceId, instantiator, pluginFinder); } catch (IOException e) { throw new RuntimeException(e); } }
@Nullable @Override public <T> Class<T> usePluginClass(String pluginType, String pluginName, String pluginId, PluginProperties properties, PluginSelector selector) { return pluginConfigurer.usePluginClass(pluginType, pluginName, pluginId, properties, selector); } }
@Nullable @Override public <T> T usePlugin(String pluginType, String pluginName, String pluginId, PluginProperties properties, PluginSelector selector) { return pluginConfigurer.usePlugin(pluginType, pluginName, pluginId, properties, selector); }
@Nullable @Override public final <T> Class<T> usePluginClass(String pluginType, String pluginName, String pluginId, PluginProperties properties, PluginSelector selector) { try { Plugin plugin = addPlugin(pluginType, pluginName, pluginId, properties, selector); return pluginInstantiator.loadClass(plugin); } catch (PluginNotExistsException | IOException e) { return null; } catch (ClassNotFoundException e) { // Shouldn't happen throw Throwables.propagate(e); } }
/** * Returns the {@link Plugin} information for the given plugin id that were configured via this context. */ private Plugin getExtraPlugin(String pluginId) { // Get the map of plugins from either the configurer (handler method) or the extra plugins map (executor) Map<String, PluginWithLocation> plugins = pluginConfigurer == null ? extraPlugins : pluginConfigurer.getPlugins(); PluginWithLocation plugin = plugins.get(pluginId); if (plugin == null) { throw new IllegalArgumentException("Plugin with id " + pluginId + " does not exist"); } return plugin.getPlugin(); }
/** * Constructor. This should be called from the service handler via * the {@link SparkHttpServiceContext#getPluginContext()} method. */ public DefaultSparkHttpServicePluginContext(SparkRuntimeContext runtimeContext) throws IOException { this.runtimeContext = runtimeContext; this.pluginInstantiator = createPluginsInstantiator(runtimeContext); this.pluginConfigurer = new DefaultPluginConfigurer(runtimeContext.getArtifactId(), runtimeContext.getProgram().getId().getNamespaceId(), pluginInstantiator, runtimeContext.getPluginFinder()); this.extraPlugins = null; }
@Nullable @Override public <T> Class<T> usePluginClass(String pluginType, String pluginName, String pluginId, PluginProperties properties, PluginSelector selector) { checkCanConfigure(pluginId); return pluginConfigurer.usePluginClass(pluginType, pluginName, pluginId, properties, selector); }
@Nullable @Override public <T> T usePlugin(String pluginType, String pluginName, String pluginId, PluginProperties properties, PluginSelector selector) { checkCanConfigure(pluginId); return pluginConfigurer.usePlugin(pluginType, pluginName, pluginId, properties, selector); }
@Nullable @Override public final <T> T usePlugin(String pluginType, String pluginName, String pluginId, PluginProperties properties, PluginSelector selector) { try { Plugin plugin = addPlugin(pluginType, pluginName, pluginId, properties, selector); return pluginInstantiator.newInstance(plugin); } catch (PluginNotExistsException | IOException e) { return null; } catch (ClassNotFoundException e) { // Shouldn't happen throw Throwables.propagate(e); } }
public Map<String, Plugin> getPlugins() { Map<String, Plugin> plugins = pluginConfigurer.getPlugins().entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().getPlugin())); plugins.putAll(extraPlugins); return plugins; }
/** * Constructor. This should be called from the service handler via * the {@link SparkHttpServiceContext#getPluginContext()} method. */ public DefaultSparkHttpServicePluginContext(SparkRuntimeContext runtimeContext) throws IOException { this.runtimeContext = runtimeContext; this.pluginInstantiator = createPluginsInstantiator(runtimeContext); this.pluginConfigurer = new DefaultPluginConfigurer(runtimeContext.getArtifactId(), runtimeContext.getProgram().getId().getNamespaceId(), pluginInstantiator, runtimeContext.getPluginFinder()); this.extraPlugins = null; }
@Nullable @Override public <T> Class<T> usePluginClass(String pluginType, String pluginName, String pluginId, PluginProperties properties, PluginSelector selector) { checkCanConfigure(pluginId); return pluginConfigurer.usePluginClass(pluginType, pluginName, pluginId, properties, selector); }