org.crsh.plugin
Class PluginContext

java.lang.Object
  extended by org.crsh.plugin.PluginContext

public final class PluginContext
extends Object


Field Summary
private  Map<String,Object> attributes
          .
private  ExecutorService executor
          The shared executor.
private  ClassLoader loader
          .
private static Logger log
          .
(package private)  PluginManager manager
          .
private  PropertyManager propertyManager
          .
private  ResourceManager resourceManager
          .
private  ScheduledExecutorService scanner
          .
private  ScheduledFuture scannerFuture
          .
private  boolean started
          .
private  String version
          .
 
Constructor Summary
PluginContext(ExecutorService executor, ScheduledExecutorService scanner, PluginDiscovery discovery, Map<String,Object> attributes, FS cmdFS, FS confFS, ClassLoader loader)
          Create a new plugin context.
PluginContext(PluginDiscovery discovery, Map<String,Object> attributes, FS cmdFS, FS confFS, ClassLoader loader)
          Create a new plugin context with preconfigured executor and scanner, this is equivalent to invoking:
 
Method Summary
 Map<String,Object> getAttributes()
           
 ExecutorService getExecutor()
           
 ClassLoader getLoader()
          Returns the classloader associated with this context.
<T> T
getPlugin(Class<T> pluginType)
          Returns the first plugin associated with this context implementing the specified type.
 Iterable<CRaSHPlugin<?>> getPlugins()
           
<T> Iterable<T>
getPlugins(Class<T> pluginType)
          Returns the plugins associated with this context.
<T> T
getProperty(PropertyDescriptor<T> desc)
          Returns a context property or null if it cannot be found.
<T> T
getProperty(String propertyName, Class<T> type)
          Returns a context property or null if it cannot be found.
 String getVersion()
           
 List<String> listResourceId(ResourceKind kind)
          List the resources id for a specific resource kind.
 Resource loadResource(String resourceId, ResourceKind resourceKind)
          Load a resource from the context.
 void refresh()
          Refresh the fs system view.
<T> void
setProperty(PropertyDescriptor<T> desc, String value)
          Set a context property to a new value.
<T> void
setProperty(PropertyDescriptor<T> desc, T value)
          Set a context property to a new value.
(package private)  void start()
           
(package private)  void stop()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final Logger log
.


manager

final PluginManager manager
.


loader

private final ClassLoader loader
.


version

private final String version
.


scanner

private final ScheduledExecutorService scanner
.


attributes

private final Map<String,Object> attributes
.


executor

private final ExecutorService executor
The shared executor.


started

private boolean started
.


scannerFuture

private ScheduledFuture scannerFuture
.


resourceManager

private final ResourceManager resourceManager
.


propertyManager

private final PropertyManager propertyManager
.

Constructor Detail

PluginContext

public PluginContext(PluginDiscovery discovery,
                     Map<String,Object> attributes,
                     FS cmdFS,
                     FS confFS,
                     ClassLoader loader)
              throws NullPointerException
Create a new plugin context with preconfigured executor and scanner, this is equivalent to invoking:
new PluginContext(
    Executors.newFixedThreadPool(20),
    new ScheduledThreadPoolExecutor(1),
    discovery,
    attributes,
    cmdFS,
    confFS,
    loader);

Parameters:
discovery - the plugin discovery
cmdFS - the command file system
attributes - the attributes
confFS - the conf file system
loader - the loader
Throws:
NullPointerException - if any parameter argument is null

PluginContext

public PluginContext(ExecutorService executor,
                     ScheduledExecutorService scanner,
                     PluginDiscovery discovery,
                     Map<String,Object> attributes,
                     FS cmdFS,
                     FS confFS,
                     ClassLoader loader)
              throws NullPointerException
Create a new plugin context.

Parameters:
executor - the executor for executing asynchronous jobs
scanner - the background scanner for scanning commands
discovery - the plugin discovery
cmdFS - the command file system
attributes - the attributes
confFS - the conf file system
loader - the loader
Throws:
NullPointerException - if any parameter argument is null
Method Detail

getVersion

public String getVersion()

getAttributes

public Map<String,Object> getAttributes()

getExecutor

public ExecutorService getExecutor()

getProperty

public <T> T getProperty(PropertyDescriptor<T> desc)
              throws NullPointerException
Returns a context property or null if it cannot be found.

Type Parameters:
T - the property parameter type
Parameters:
desc - the property descriptor
Returns:
the property value
Throws:
NullPointerException - if the descriptor argument is null

getProperty

public <T> T getProperty(String propertyName,
                         Class<T> type)
              throws NullPointerException
Returns a context property or null if it cannot be found.

Type Parameters:
T - the property parameter type
Parameters:
propertyName - the name of the property
type - the property type
Returns:
the property value
Throws:
NullPointerException - if the descriptor argument is null

setProperty

public <T> void setProperty(PropertyDescriptor<T> desc,
                            T value)
                 throws NullPointerException
Set a context property to a new value. If the provided value is null, then the property is removed.

Type Parameters:
T - the property parameter type
Parameters:
desc - the property descriptor
value - the property value
Throws:
NullPointerException - if the descriptor argument is null

setProperty

public <T> void setProperty(PropertyDescriptor<T> desc,
                            String value)
                 throws NullPointerException,
                        IllegalArgumentException
Set a context property to a new value. If the provided value is null, then the property is removed.

Type Parameters:
T - the property parameter type
Parameters:
desc - the property descriptor
value - the property value
Throws:
NullPointerException - if the descriptor argument is null
IllegalArgumentException - if the string value cannot be converted to the property type

loadResource

public Resource loadResource(String resourceId,
                             ResourceKind resourceKind)
Load a resource from the context.

Parameters:
resourceId - the resource id
resourceKind - the resource kind
Returns:
the resource or null if it cannot be found

listResourceId

public List<String> listResourceId(ResourceKind kind)
List the resources id for a specific resource kind.

Parameters:
kind - the resource kind
Returns:
the resource ids

getLoader

public ClassLoader getLoader()
Returns the classloader associated with this context.

Returns:
the class loader

getPlugins

public Iterable<CRaSHPlugin<?>> getPlugins()

getPlugins

public <T> Iterable<T> getPlugins(Class<T> pluginType)
Returns the plugins associated with this context.

Type Parameters:
T - the plugin generic type
Parameters:
pluginType - the plugin type
Returns:
the plugins

getPlugin

public <T> T getPlugin(Class<T> pluginType)
Returns the first plugin associated with this context implementing the specified type.

Type Parameters:
T - the plugin generic type
Parameters:
pluginType - the plugin type
Returns:
the plugins

refresh

public void refresh()
Refresh the fs system view. This is normally triggered by the periodic job but it can be manually invoked to trigger explicit refreshes.


start

void start()

stop

void stop()


Copyright © 2014 eXo Platform SAS. All Rights Reserved.