public void shutdown() { drivers.forEach(it -> Try.run(it::close)); super.stop(); }
/** * Parse a string representation of a value and returns the correspondig property value. * * @param s the string to parse * @return the corresponding property * @throws NullPointerException if the argument is null * @throws IllegalArgumentException if the string value cannot be parsed for some reason */ public final Property<T> toProperty(String s) throws NullPointerException, IllegalArgumentException { T value = parse(s); return new Property<T>(this, value); }
/** * Create and start the plugin context. * * @param discovery the plugin discovery * @return the plugin context */ protected PluginContext start(Map<String, Object> attributes, PluginDiscovery discovery, ClassLoader loader) { PluginContext context = create(attributes, discovery, loader); if (context != null) { context.refresh(); start(context); } return context; }
public void testDisplayValue() { PropertyManager mgr = new PropertyManager(); mgr.setProperty(PropertyDescriptor.VFS_REFRESH_PERIOD, 4); Property<Integer> property = mgr.getProperty(PropertyDescriptor.VFS_REFRESH_PERIOD); assertEquals("4", property.getDisplayValue()); mgr.setProperty(SimpleAuthenticationPlugin.SIMPLE_PASSWORD, "the_password"); Property<String> secretProperty = mgr.getProperty(SimpleAuthenticationPlugin.SIMPLE_PASSWORD); assertEquals(PropertyDescriptor.SECRET_DISPLAY_VALUE, secretProperty.getDisplayValue()); assertEquals("the_password", secretProperty.getValue()); } }
static void install(final Env env, final Config conf) { String path = conf.getString("crash.httpshell.path"); Router router = env.router(); router.get(path + "/{cmd:.*}", router.promise("direct", (req, deferred) -> { MediaType type = req.accepts(MediaType.json) .map(it -> MediaType.json) .orElse(MediaType.html); PluginContext ctx = req.require(PluginContext.class); ShellFactory shellFactory = ctx.getPlugin(ShellFactory.class); Shell shell = shellFactory.create(null); String cmd = req.param("cmd").value().replaceAll("/", " "); ShellProcess process = shell.createProcess(cmd); ShellProcessContext spc = new SimpleProcessContext( result -> deferred.resolve(result.type(type))); process.execute(spc); })); }
public PluginContext start(final ClassLoader loader, final Properties props, final Map<String, Object> attributes, final Set<CRaSHPlugin<?>> plugins) throws IOException { FS conffs = newFS(CrashFSDriver.parse(loader, asList(new CrashPredicate("crash", ACCEPT)))); FS cmdfs = newFS(CrashFSDriver.parse(loader, asList( new CrashPredicate("cmd", ACCEPT), new CrashPredicate("org/jooby/crash", ACCEPT), new CrashPredicate("crash/commands", noneOf("jndi.groovy", "jdbc.groovy", "jpa.groovy", "jul.groovy"))))); setConfig(props); PluginContext ctx = new PluginContext(executor("crash"), scanner("crash-scanner"), () -> plugins, attributes, cmdfs, conffs, loader); ctx.refresh(); start(ctx); return ctx; }
/** * Create the service loader discovery, this can be subclassed to provide an implementation, the current * implementation returns a {@link ServiceLoaderDiscovery} instance. * * @param context the servlet context * @param classLoader the class loader * @return the plugin discovery */ protected PluginDiscovery createDiscovery(ServletContext context, ClassLoader classLoader) { return new ServiceLoaderDiscovery(classLoader); }
/** * @return the value returned by {@link #resolvePathProperty(String, String)} with the <code>crash.mountpointconfig.cmd</code> name * and the {@link #getDefaultCmdMountPointConfig()} default value */ @Override protected String resolveCmdMountPointConfig() { return resolvePathProperty("crash.mountpointconfig.cmd", getDefaultCmdMountPointConfig()); }
/** * @return the value returned by {@link #resolvePathProperty(String, String)} with the <code>crash.mountpointconfig.conf</code> name * and the {@link #getDefaultConfMountPointConfig()} default value */ @Override protected String resolveConfMountPointConfig() { return resolvePathProperty("crash.mountpointconfig.conf", getDefaultConfMountPointConfig()); }
/** * Create the command file system from the <code>crash.mountpointconfig.cmd</code> servlet context parameter. * * @return the command file system */ protected FS createCommandFS() throws IOException { return createFS(resolveCmdMountPointConfig()); }
/** * Create the conf file system from the <code>crash.mountpointconfig.conf</code> servlet context parameter. * * @return the conf file system */ protected FS createConfFS() throws IOException { return createFS(resolveConfMountPointConfig()); }
/** * Set a context property to a new value. If the provided value is null, then the property is removed. * * @param desc the property descriptor * @param value the property value * @param <T> the property parameter type * @throws NullPointerException if the descriptor argument is null */ public <T> void setProperty(PropertyDescriptor<T> desc, T value) throws NullPointerException { propertyManager.setProperty(desc, value); }
/** * List the resources id for a specific resource kind. * * @param kind the resource kind * @return the resource ids */ public Iterable<String> listResources(ResourceKind kind) { return resourceManager.listResourceId(kind); }
/** * Returns the plugins associated with this context. * * @param pluginType the plugin type * @param <T> the plugin generic type * @return the plugins */ public <T> Iterable<T> getPlugins(Class<T> pluginType) { return manager.getPlugins(pluginType); }
/** * Refresh the fs system view. This is normally triggered by the periodic job but it can be manually * invoked to trigger explicit refreshes. */ public void refresh() { resourceManager.refresh(); }
void shutdown() { if (plugins != null) { for (CRaSHPlugin<?> plugin : plugins) { plugin.destroy(); } } } }
public static PropertyDescriptor<String> create(String name, String defaultValue, String description, boolean secret) { return new PropertyDescriptor<String>(String.class, name, defaultValue, description, secret) { @Override protected String doParse(String s) throws Exception { return s; } }; }
/** * Set a context property to a new value. If the provided value is null, then the property is removed. * * @param desc the property descriptor * @param value the property value * @param <T> the property parameter type * @throws NullPointerException if the descriptor argument is null * @throws IllegalArgumentException if the string value cannot be converted to the property type */ public <T> void setProperty(PropertyDescriptor<T> desc, String value) throws NullPointerException, IllegalArgumentException { propertyManager.parseProperty(desc, value); }
public void testGetProperty() { PropertyManager mgr = new PropertyManager(); mgr.setProperty(FOO, foo); Property<Foo> property = mgr.getProperty(FOO); assertEquals(foo, property.getValue()); }
public void onOpen(final Request req, final WebSocket ws) throws Exception { PluginContext ctx = req.require(PluginContext.class); ShellFactory factory = ctx.getPlugin(ShellFactory.class); Shell shell = factory.create(null);