Package eu.tneitzel.rmg.plugin
Class PluginSystem
- java.lang.Object
-
- eu.tneitzel.rmg.plugin.PluginSystem
-
public class PluginSystem extends Object
The PluginSystem class allows rmg to be extended by user defined classes. It can be used to setup payload and argument providers that are used to create call arguments and to setup response handlers that process return values of RMI calls. Plugins can be loaded by using the --plugin option on the command line. By default, rmg uses the DefaultProvider as plugin, which implements the IPayloadProvider and IArgumentProvider interfaces.- Author:
- Tobias Neitzel (@qtc_de)
-
-
Field Summary
Fields Modifier and Type Field Description static URLClassLoaderpluginLoaderThe class loader that was used to load the plugin
-
Constructor Summary
Constructors Constructor Description PluginSystem()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddPluginActions(eu.tneitzel.argparse4j.inf.Subparsers parser)Add actions added by a user defined plugin to an argument parser.static voiddispatchPluginAction(eu.tneitzel.argparse4j.global.IAction pluginAction)Dispatch an action that was provided by a plugin.static Object[]getArgumentArray(String[] args)Is called during rmg's 'call' action to obtain the Object argument array.static RMIClientSocketFactorygetClientSocketFactory(String host, int port)Returns the RMIClientSocketFactory that is used for RMI connections.static RMISocketFactorygetDefaultSocketFactory(String host, int port)Returns the RMISocketFactory that is used for all RMI connections that use the default RMISocketFactory.static StringgetDefaultSSLSocketFactory(String host, int port)Java RMI also contains a default implementation for SSL protected RMI communication.static ObjectgetPayloadObject(Operation action, String name, String args)Is called from each action that requires a payload object.static eu.tneitzel.argparse4j.global.IAction[]getPluginActions()Return actions added by a user defined plugin.static List<eu.tneitzel.argparse4j.global.IOption>getPluginOptions()Return options added by a user defined plugin.static IResponseHandlergetResponseHandler()Returns the currently set ResponseHandlerstatic voidhandleResponse(Object o)Is called on incoming server responses if a response handler is defined.static booleanhasArgumentProvider()Checks whether a argumentProvider was registered.static booleanhasPayloadProvider()Checks whether a payloadProvider was registered.static booleanhasResponseHandler()Checks whether a responseHandler was registered.static voidinit(String pluginPath, boolean genericPrint)Initializes the plugin system.static voidsetResponeHandler(IResponseHandler handler)Sets a new ResponseHandler.
-
-
-
Field Detail
-
pluginLoader
public static URLClassLoader pluginLoader
The class loader that was used to load the plugin
-
-
Method Detail
-
init
public static void init(String pluginPath, boolean genericPrint)
Initializes the plugin system. By default, the payloadProvider and argumentProvider get a DefaultProvider instance assigned. The responseHandler is not initialized by default and stays at null. If a user specified pluginPath was specified, the plugin is attempted to be loaded and may overwrite previous settings.- Parameters:
pluginPath- user specified plugin path or nullgenericPrint- whether to use the GenericPrint builtin plugin
-
handleResponse
public static void handleResponse(Object o)
Is called on incoming server responses if a response handler is defined. Just forwards the call to the responseHandler plugin.- Parameters:
o- return value of a RMI method call
-
getPayloadObject
public static Object getPayloadObject(Operation action, String name, String args)
Is called from each action that requires a payload object. Just forwards the call to the corresponding plugin.- Parameters:
action- action that requests the payload objectname- name of the payload that is requestedargs- arguments that should be used for the payload- Returns:
- generated payload object
-
getArgumentArray
public static Object[] getArgumentArray(String[] args)
Is called during rmg's 'call' action to obtain the Object argument array. Just forwards the call to the corresponding plugin.- Parameters:
args- as specified on the command line- Returns:
- Object array to use for the call
-
getClientSocketFactory
public static RMIClientSocketFactory getClientSocketFactory(String host, int port)
Returns the RMIClientSocketFactory that is used for RMI connections. The factory returned by this function is used for all direct RMI calls. So e.g. if you call the registry or another RMI endpoint directly. If you first lookup a bound name and use the obtained reference to make calls on the object, another factory is used (check the getDefaultClientSocketFactory function for more details).- Parameters:
host- remote hostport- remote port- Returns:
- RMIClientSocketFactory that is used for direct RMI calls
-
getDefaultSocketFactory
public static RMISocketFactory getDefaultSocketFactory(String host, int port)
Returns the RMISocketFactory that is used for all RMI connections that use the default RMISocketFactory. The factory returned by this function is used when you perform RMI actions on a remote object reference that was obtained from the RMI registry and the RMI server did not assign a custom socket factory to the object.- Parameters:
host- remote hostport- remote port- Returns:
- RMISocketFactory that is used for "after lookup" RMI calls
-
getDefaultSSLSocketFactory
public static String getDefaultSSLSocketFactory(String host, int port)
Java RMI also contains a default implementation for SSL protected RMI communication. If the server uses the corresponding SocketFactory on the server side, the RMI client does too and the only way to overwrite the default SSLSocketFactory is by setting a Java property. Therefore, this function should return the name of a class that you want to use as your default SSLSocketFactory. Notice that the factory needs to be available on the class path and it is not sufficient to define it within the plugin.- Parameters:
host- remote hostport- remote port- Returns:
- String that indicates the desired SSLSocketFactories class name
-
hasResponseHandler
public static boolean hasResponseHandler()
Checks whether a responseHandler was registered.- Returns:
- true or false
-
hasPayloadProvider
public static boolean hasPayloadProvider()
Checks whether a payloadProvider was registered.- Returns:
- true or false
-
hasArgumentProvider
public static boolean hasArgumentProvider()
Checks whether a argumentProvider was registered.- Returns:
- true or false
-
getResponseHandler
public static IResponseHandler getResponseHandler()
Returns the currently set ResponseHandler- Returns:
- currently set ResponseHandler
-
setResponeHandler
public static void setResponeHandler(IResponseHandler handler)
Sets a new ResponseHandler.- Parameters:
handler- the new ResponseHandler to set
-
getPluginActions
public static eu.tneitzel.argparse4j.global.IAction[] getPluginActions()
Return actions added by a user defined plugin. If no plugin was specified, an empty array of actions is returned.- Returns:
- array of additional actions
-
getPluginOptions
public static List<eu.tneitzel.argparse4j.global.IOption> getPluginOptions()
Return options added by a user defined plugin. If no plugin was specified, an empty list of options is returned.- Returns:
- array of additional options
-
addPluginActions
public static void addPluginActions(eu.tneitzel.argparse4j.inf.Subparsers parser)
Add actions added by a user defined plugin to an argument parser.- Parameters:
parser- the argument parser to add the actions to
-
dispatchPluginAction
public static void dispatchPluginAction(eu.tneitzel.argparse4j.global.IAction pluginAction)
Dispatch an action that was provided by a plugin.- Parameters:
pluginAction- the plugin action to dispatch
-
-