Package org.restlet.engine
Class Engine
- java.lang.Object
-
- org.restlet.engine.Engine
-
public class Engine extends java.lang.Object
Engine supporting the Restlet API. The engine acts as a registry of variousHelper
types:AuthenticatorHelper
,ClientHelper
,ConverterHelper
andServerHelper
classes.
Note that by default the JULI logging mechanism is used but it is possible to replace it by providing an alternateLoggerFacade
implementation. For this, just pass a system property named "org.restlet.engine.loggerFacadeClass" with the qualified class name as a value.- Author:
- Jerome Louvel
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DESCRIPTOR
static java.lang.String
DESCRIPTOR_AUTHENTICATOR
static java.lang.String
DESCRIPTOR_AUTHENTICATOR_PATH
static java.lang.String
DESCRIPTOR_CLIENT
static java.lang.String
DESCRIPTOR_CLIENT_PATH
static java.lang.String
DESCRIPTOR_CONVERTER
static java.lang.String
DESCRIPTOR_CONVERTER_PATH
static java.lang.String
DESCRIPTOR_PROTOCOL
static java.lang.String
DESCRIPTOR_PROTOCOL_PATH
static java.lang.String
DESCRIPTOR_SERVER
static java.lang.String
DESCRIPTOR_SERVER_PATH
static java.lang.String
MAJOR_NUMBER
Major version number.static java.lang.String
MINOR_NUMBER
Minor version number.static java.lang.String
RELEASE_NUMBER
Release number.static java.lang.String
VERSION
Complete version.static java.lang.String
VERSION_HEADER
Complete version header.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
clear()
Clears the current Restlet Engine altogether.static void
clearThreadLocalVariables()
Clears the thread local variables set by the Restlet API and engine.protected java.lang.ClassLoader
createClassLoader()
Creates a new class loader.ConnectorHelper<org.restlet.Client>
createHelper(org.restlet.Client client, java.lang.String helperClass)
Creates a new helper for a given client connector.ConnectorHelper<org.restlet.Server>
createHelper(org.restlet.Server server, java.lang.String helperClass)
Creates a new helper for a given server connector.static java.lang.Thread
createThreadWithLocalVariables(java.lang.Runnable runnable, java.lang.String name)
Creates a new standalone thread with local Restlet thread variable properly set.ConverterHelper
findHelper()
Finds the converter helper supporting the given conversion.AuthenticatorHelper
findHelper(org.restlet.data.ChallengeScheme challengeScheme, boolean clientSide, boolean serverSide)
Finds the authenticator helper supporting the given scheme.static java.util.logging.Logger
getAnonymousLogger()
Returns an anonymous logger.java.lang.ClassLoader
getClassLoader()
Returns the class loader.static Engine
getInstance()
Returns the registered Restlet engine.static java.util.logging.Logger
getLogger(java.lang.Class<?> clazz)
Returns a logger based on the class name of the given object.static java.util.logging.Logger
getLogger(java.lang.Class<?> clazz, java.lang.String defaultLoggerName)
Returns a logger based on the class name of the given object.static java.util.logging.Logger
getLogger(java.lang.Object object, java.lang.String defaultLoggerName)
Returns a logger based on the class name of the given object.static java.util.logging.Logger
getLogger(java.lang.String loggerName)
Returns a logger based on the given logger name.LoggerFacade
getLoggerFacade()
Returns the logger facade to use.java.util.List<AuthenticatorHelper>
getRegisteredAuthenticators()
Returns the list of available authentication helpers.java.util.List<ConnectorHelper<org.restlet.Client>>
getRegisteredClients()
Returns the list of available client connectors.java.util.List<ConverterHelper>
getRegisteredConverters()
Returns the list of available converters.java.util.List<ProtocolHelper>
getRegisteredProtocols()
Returns the list of available protocol connectors.java.util.List<ConnectorHelper<org.restlet.Server>>
getRegisteredServers()
Returns the list of available server connectors.static java.net.URL
getResource(java.lang.String name)
Returns the classloader resource for a given name/path.java.lang.ClassLoader
getUserClassLoader()
Returns the class loader specified by the user and that should be used in priority.static java.lang.Class<?>
loadClass(java.lang.String className)
Returns the class object for the given name using the engine classloader.static Engine
register()
Registers a new Restlet Engine.static Engine
register(boolean discoverPlugins)
Registers a new Restlet Engine.void
registerDefaultAuthentications()
Registers the default authentication helpers.void
registerDefaultConnectors()
Registers the default client and server connectors.void
registerDefaultConverters()
Registers the default converters.void
registerDefaultProtocols()
Registers the default protocols.void
registerHelper(java.lang.ClassLoader classLoader, java.lang.String provider, java.util.List helpers, java.lang.Class constructorClass)
Registers a helper.void
registerHelpers(java.lang.ClassLoader classLoader, java.net.URL configUrl, java.util.List<?> helpers, java.lang.Class<?> constructorClass)
Registers a helper.void
registerHelpers(java.lang.String descriptorPath, java.util.List<?> helpers, java.lang.Class<?> constructorClass)
Registers a list of helpers.void
registerUrlFactory()
Registers a factory that is used by the URL class to create theURLConnection
instances when theURL.openConnection()
orURL.openStream()
methods are invoked.void
setClassLoader(java.lang.ClassLoader newClassLoader)
Sets the engine class loader.void
setLoggerFacade(LoggerFacade loggerFacade)
Sets the logger facade to use.void
setRegisteredAuthenticators(java.util.List<AuthenticatorHelper> registeredAuthenticators)
Sets the list of available authentication helpers.void
setRegisteredClients(java.util.List<ConnectorHelper<org.restlet.Client>> registeredClients)
Sets the list of available client helpers.void
setRegisteredConverters(java.util.List<ConverterHelper> registeredConverters)
Sets the list of available converter helpers.void
setRegisteredProtocols(java.util.List<ProtocolHelper> registeredProtocols)
Sets the list of available protocol helpers.void
setRegisteredServers(java.util.List<ConnectorHelper<org.restlet.Server>> registeredServers)
Sets the list of available server helpers.void
setUserClassLoader(java.lang.ClassLoader newClassLoader)
Sets the user class loader that should used in priority.
-
-
-
Field Detail
-
DESCRIPTOR
public static final java.lang.String DESCRIPTOR
- See Also:
- Constant Field Values
-
DESCRIPTOR_AUTHENTICATOR
public static final java.lang.String DESCRIPTOR_AUTHENTICATOR
- See Also:
- Constant Field Values
-
DESCRIPTOR_AUTHENTICATOR_PATH
public static final java.lang.String DESCRIPTOR_AUTHENTICATOR_PATH
- See Also:
- Constant Field Values
-
DESCRIPTOR_CLIENT
public static final java.lang.String DESCRIPTOR_CLIENT
- See Also:
- Constant Field Values
-
DESCRIPTOR_CLIENT_PATH
public static final java.lang.String DESCRIPTOR_CLIENT_PATH
- See Also:
- Constant Field Values
-
DESCRIPTOR_CONVERTER
public static final java.lang.String DESCRIPTOR_CONVERTER
- See Also:
- Constant Field Values
-
DESCRIPTOR_CONVERTER_PATH
public static final java.lang.String DESCRIPTOR_CONVERTER_PATH
- See Also:
- Constant Field Values
-
DESCRIPTOR_PROTOCOL
public static final java.lang.String DESCRIPTOR_PROTOCOL
- See Also:
- Constant Field Values
-
DESCRIPTOR_PROTOCOL_PATH
public static final java.lang.String DESCRIPTOR_PROTOCOL_PATH
- See Also:
- Constant Field Values
-
DESCRIPTOR_SERVER
public static final java.lang.String DESCRIPTOR_SERVER
- See Also:
- Constant Field Values
-
DESCRIPTOR_SERVER_PATH
public static final java.lang.String DESCRIPTOR_SERVER_PATH
- See Also:
- Constant Field Values
-
MAJOR_NUMBER
public static final java.lang.String MAJOR_NUMBER
Major version number.- See Also:
- Constant Field Values
-
MINOR_NUMBER
public static final java.lang.String MINOR_NUMBER
Minor version number.- See Also:
- Constant Field Values
-
RELEASE_NUMBER
public static final java.lang.String RELEASE_NUMBER
Release number.- See Also:
- Constant Field Values
-
VERSION
public static final java.lang.String VERSION
Complete version.- See Also:
- Constant Field Values
-
VERSION_HEADER
public static final java.lang.String VERSION_HEADER
Complete version header.- See Also:
- Constant Field Values
-
-
Method Detail
-
clear
public static void clear()
Clears the current Restlet Engine altogether.
-
createThreadWithLocalVariables
public static java.lang.Thread createThreadWithLocalVariables(java.lang.Runnable runnable, java.lang.String name)
Creates a new standalone thread with local Restlet thread variable properly set.- Parameters:
runnable
- The runnable task to execute.name
- The thread name.- Returns:
- The thread with proper variables ready to run the given runnable task.
-
clearThreadLocalVariables
public static void clearThreadLocalVariables()
Clears the thread local variables set by the Restlet API and engine.
-
getAnonymousLogger
public static java.util.logging.Logger getAnonymousLogger()
Returns an anonymous logger. By default it callsgetLogger(String)
with a "" name.- Returns:
- The logger.
-
getInstance
public static Engine getInstance()
Returns the registered Restlet engine.- Returns:
- The registered Restlet engine.
-
getLogger
public static java.util.logging.Logger getLogger(java.lang.Class<?> clazz)
Returns a logger based on the class name of the given object.- Parameters:
clazz
- The parent class.- Returns:
- The logger.
-
getLogger
public static java.util.logging.Logger getLogger(java.lang.Class<?> clazz, java.lang.String defaultLoggerName)
Returns a logger based on the class name of the given object.- Parameters:
clazz
- The parent class.defaultLoggerName
- The default logger name to use if no one can be inferred from the class.- Returns:
- The logger.
-
getLogger
public static java.util.logging.Logger getLogger(java.lang.Object object, java.lang.String defaultLoggerName)
Returns a logger based on the class name of the given object.- Parameters:
object
- The parent object.defaultLoggerName
- The default logger name to use if no one can be inferred from the object class.- Returns:
- The logger.
-
getLogger
public static java.util.logging.Logger getLogger(java.lang.String loggerName)
Returns a logger based on the given logger name.- Parameters:
loggerName
- The logger name.- Returns:
- The logger.
-
getResource
public static java.net.URL getResource(java.lang.String name)
Returns the classloader resource for a given name/path.- Parameters:
name
- The name/path to lookup.- Returns:
- The resource URL.
-
loadClass
public static java.lang.Class<?> loadClass(java.lang.String className) throws java.lang.ClassNotFoundException
Returns the class object for the given name using the engine classloader.- Parameters:
className
- The class name to lookup.- Returns:
- The class object or null if the class was not found.
- Throws:
java.lang.ClassNotFoundException
- See Also:
getClassLoader()
-
register
public static Engine register()
Registers a new Restlet Engine.- Returns:
- The registered engine.
-
register
public static Engine register(boolean discoverPlugins)
Registers a new Restlet Engine.- Parameters:
discoverPlugins
- True if plug-ins should be automatically discovered.- Returns:
- The registered engine.
-
createClassLoader
protected java.lang.ClassLoader createClassLoader()
Creates a new class loader. By default, it returns an instance ofEngineClassLoader
.- Returns:
- A new class loader.
-
createHelper
public ConnectorHelper<org.restlet.Client> createHelper(org.restlet.Client client, java.lang.String helperClass)
Creates a new helper for a given client connector.- Parameters:
client
- The client to help.helperClass
- Optional helper class name.- Returns:
- The new helper.
-
createHelper
public ConnectorHelper<org.restlet.Server> createHelper(org.restlet.Server server, java.lang.String helperClass)
Creates a new helper for a given server connector.- Parameters:
server
- The server to help.helperClass
- Optional helper class name.- Returns:
- The new helper.
-
findHelper
public ConverterHelper findHelper()
Finds the converter helper supporting the given conversion.- Returns:
- The converter helper or null.
-
findHelper
public AuthenticatorHelper findHelper(org.restlet.data.ChallengeScheme challengeScheme, boolean clientSide, boolean serverSide)
Finds the authenticator helper supporting the given scheme.- Parameters:
challengeScheme
- The challenge scheme to match.clientSide
- Indicates if client side support is required.serverSide
- Indicates if server side support is required.- Returns:
- The authenticator helper or null.
-
getClassLoader
public java.lang.ClassLoader getClassLoader()
Returns the class loader. It uses the delegation model with the Engine class's class loader as a parent. If this parent doesn't find a class or resource, it then tries the user class loader (viagetUserClassLoader()
and finally theThread.getContextClassLoader()
.- Returns:
- The engine class loader.
- See Also:
EngineClassLoader
-
getLoggerFacade
public LoggerFacade getLoggerFacade()
Returns the logger facade to use.- Returns:
- The logger facade to use.
-
getRegisteredAuthenticators
public java.util.List<AuthenticatorHelper> getRegisteredAuthenticators()
Returns the list of available authentication helpers.- Returns:
- The list of available authentication helpers.
-
getRegisteredClients
public java.util.List<ConnectorHelper<org.restlet.Client>> getRegisteredClients()
Returns the list of available client connectors.- Returns:
- The list of available client connectors.
-
getRegisteredConverters
public java.util.List<ConverterHelper> getRegisteredConverters()
Returns the list of available converters.- Returns:
- The list of available converters.
-
getRegisteredProtocols
public java.util.List<ProtocolHelper> getRegisteredProtocols()
Returns the list of available protocol connectors.- Returns:
- The list of available protocol connectors.
-
getRegisteredServers
public java.util.List<ConnectorHelper<org.restlet.Server>> getRegisteredServers()
Returns the list of available server connectors.- Returns:
- The list of available server connectors.
-
getUserClassLoader
public java.lang.ClassLoader getUserClassLoader()
Returns the class loader specified by the user and that should be used in priority.- Returns:
- The user class loader
-
registerDefaultAuthentications
public void registerDefaultAuthentications()
Registers the default authentication helpers.
-
registerDefaultConnectors
public void registerDefaultConnectors()
Registers the default client and server connectors.
-
registerDefaultConverters
public void registerDefaultConverters()
Registers the default converters.
-
registerDefaultProtocols
public void registerDefaultProtocols()
Registers the default protocols.
-
registerHelper
public void registerHelper(java.lang.ClassLoader classLoader, java.lang.String provider, java.util.List helpers, java.lang.Class constructorClass)
Registers a helper.- Parameters:
classLoader
- The classloader to use.provider
- Bynary name of the helper's class.helpers
- The list of helpers to update.constructorClass
- The constructor parameter class to look for.
-
registerHelpers
public void registerHelpers(java.lang.ClassLoader classLoader, java.net.URL configUrl, java.util.List<?> helpers, java.lang.Class<?> constructorClass)
Registers a helper.- Parameters:
classLoader
- The classloader to use.configUrl
- Configuration URL to parsehelpers
- The list of helpers to update.constructorClass
- The constructor parameter class to look for.
-
registerHelpers
public void registerHelpers(java.lang.String descriptorPath, java.util.List<?> helpers, java.lang.Class<?> constructorClass) throws java.io.IOException
Registers a list of helpers.- Parameters:
descriptorPath
- Classpath to the descriptor file.helpers
- The list of helpers to update.constructorClass
- The constructor parameter class to look for.- Throws:
java.io.IOException
-
registerUrlFactory
public void registerUrlFactory()
Registers a factory that is used by the URL class to create theURLConnection
instances when theURL.openConnection()
orURL.openStream()
methods are invoked.The implementation is based on the client dispatcher of the current context, as provided by
Context.getCurrent()
method.
-
setClassLoader
public void setClassLoader(java.lang.ClassLoader newClassLoader)
Sets the engine class loader.- Parameters:
newClassLoader
- The new user class loader to use.
-
setLoggerFacade
public void setLoggerFacade(LoggerFacade loggerFacade)
Sets the logger facade to use.- Parameters:
loggerFacade
- The logger facade to use.
-
setRegisteredAuthenticators
public void setRegisteredAuthenticators(java.util.List<AuthenticatorHelper> registeredAuthenticators)
Sets the list of available authentication helpers.- Parameters:
registeredAuthenticators
- The list of available authentication helpers.
-
setRegisteredClients
public void setRegisteredClients(java.util.List<ConnectorHelper<org.restlet.Client>> registeredClients)
Sets the list of available client helpers.- Parameters:
registeredClients
- The list of available client helpers.
-
setRegisteredConverters
public void setRegisteredConverters(java.util.List<ConverterHelper> registeredConverters)
Sets the list of available converter helpers.- Parameters:
registeredConverters
- The list of available converter helpers.
-
setRegisteredProtocols
public void setRegisteredProtocols(java.util.List<ProtocolHelper> registeredProtocols)
Sets the list of available protocol helpers.- Parameters:
registeredProtocols
- The list of available protocol helpers.
-
setRegisteredServers
public void setRegisteredServers(java.util.List<ConnectorHelper<org.restlet.Server>> registeredServers)
Sets the list of available server helpers.- Parameters:
registeredServers
- The list of available server helpers.
-
setUserClassLoader
public void setUserClassLoader(java.lang.ClassLoader newClassLoader)
Sets the user class loader that should used in priority.- Parameters:
newClassLoader
- The new user class loader to use.
-
-