Package org.restlet.engine
Class Engine
java.lang.Object
org.restlet.engine.Engine
Engine supporting the Restlet API. The engine acts as a registry of various
Note that by default the JULI logging mechanism is used but it is possible to replace it by providing an alternate
Helper types: AuthenticatorHelper
, ClientHelper,
ConverterHelper and
ServerHelper classes.Note that by default the JULI logging mechanism is used but it is possible to replace it by providing an alternate
LoggerFacade 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
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringMajor version number.static final StringMinor version number.static final StringRelease number.static final StringComplete version.static final StringComplete version header. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidclear()Clears the current Restlet Engine altogether.static voidClears the thread local variables set by the Restlet API and engine.static voidUpdates the global log configuration of the JVM programmatically.protected ClassLoaderCreates a new class loader.createHelper(Client client, String helperClass) Creates a new helper for a given client connector.createHelper(Server server, String helperClass) Creates a new helper for a given server connector.static ThreadcreateThreadWithLocalVariables(Runnable runnable, String name) Creates a new standalone thread with local Restlet thread variable properly set.Finds the converter helper supporting the given conversion.findHelper(ChallengeScheme challengeScheme, boolean clientSide, boolean serverSide) Finds the authenticator helper supporting the given scheme.static LoggerReturns an anonymous logger.Returns the class loader.static EngineReturns the registered Restlet engine.Returns the general log formatter.static LoggerReturns a logger based on the class name of the given object.static LoggerReturns a logger based on the class name of the given object.static LoggerReturns a logger based on the class name of the given object.static LoggerReturns a logger based on the given logger name.Returns the logger facade to use.static LevelReturns the general log level.Returns the list of available authentication helpers.Returns the list of available client connectors.Returns the list of available converters.Returns the list of available protocol connectors.Returns the list of available server connectors.static URLgetResource(String name) Returns the classloader resource for a given name/path.static LevelReturns the Restlet log level.Returns the class loader specified by the user and that should be used in priority.static Class<?>Returns the class object for the given name using the engine classloader.static Engineregister()Registers a new Restlet Engine.static Engineregister(boolean discoverPlugins) Registers a new Restlet Engine.voidRegisters the default authentication helpers.voidRegisters the default client and server connectors.voidRegisters the default converters.voidRegisters the default protocols.voidregisterHelper(ClassLoader classLoader, String provider, List helpers, Class constructorClass) Registers a helper.voidregisterHelpers(ClassLoader classLoader, URL configUrl, List<?> helpers, Class<?> constructorClass) Registers a helper.voidregisterHelpers(String descriptorPath, List<?> helpers, Class<?> constructorClass) Registers a list of helpers.voidRegisters a factory that is used by the URL class to create theURLConnectioninstances when theURL.openConnection()orURL.openStream()methods are invoked.voidsetClassLoader(ClassLoader newClassLoader) Sets the engine class loader.static voidsetLogFormatter(Class<? extends Formatter> logFormatter) Sets the general log formatter.voidsetLoggerFacade(LoggerFacade loggerFacade) Sets the logger facade to use.static voidsetLogLevel(Level logLevel) Sets the general log level.voidsetRegisteredAuthenticators(List<AuthenticatorHelper> registeredAuthenticators) Sets the list of available authentication helpers.voidsetRegisteredClients(List<ConnectorHelper<Client>> registeredClients) Sets the list of available client helpers.voidsetRegisteredConverters(List<ConverterHelper> registeredConverters) Sets the list of available converter helpers.voidsetRegisteredProtocols(List<ProtocolHelper> registeredProtocols) Sets the list of available protocol helpers.voidsetRegisteredServers(List<ConnectorHelper<Server>> registeredServers) Sets the list of available server helpers.static voidsetRestletLogLevel(Level restletLogLevel) Sets the Restlet log level.voidsetUserClassLoader(ClassLoader newClassLoader) Sets the user class loader that should used in priority.
-
Field Details
-
DESCRIPTOR
- See Also:
-
DESCRIPTOR_AUTHENTICATOR
- See Also:
-
DESCRIPTOR_AUTHENTICATOR_PATH
- See Also:
-
DESCRIPTOR_CLIENT
- See Also:
-
DESCRIPTOR_CLIENT_PATH
- See Also:
-
DESCRIPTOR_CONVERTER
- See Also:
-
DESCRIPTOR_CONVERTER_PATH
- See Also:
-
DESCRIPTOR_PROTOCOL
- See Also:
-
DESCRIPTOR_PROTOCOL_PATH
- See Also:
-
DESCRIPTOR_SERVER
- See Also:
-
DESCRIPTOR_SERVER_PATH
- See Also:
-
MAJOR_NUMBER
Major version number.- See Also:
-
MINOR_NUMBER
Minor version number.- See Also:
-
RELEASE_NUMBER
Release number.- See Also:
-
VERSION
Complete version.- See Also:
-
VERSION_HEADER
Complete version header.- See Also:
-
-
Constructor Details
-
Engine
public Engine()Constructor that will automatically attempt to discover connectors. -
Engine
public Engine(boolean discoverHelpers) Constructor.- Parameters:
discoverHelpers- True if helpers should be automatically discovered.
-
-
Method Details
-
clear
public static void clear()Clears the current Restlet Engine altogether. -
createThreadWithLocalVariables
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. -
configureLog
public static void configureLog()Updates the global log configuration of the JVM programmatically. -
getAnonymousLogger
Returns an anonymous logger. By default, it callsgetLogger(String)with a "" name.- Returns:
- The logger.
-
getInstance
Returns the registered Restlet engine.- Returns:
- The registered Restlet engine.
-
getLogFormatter
Returns the general log formatter.- Returns:
- The general log formatter.
-
getLogger
Returns a logger based on the class name of the given object.- Parameters:
clazz- The parent class.- Returns:
- The logger.
-
getLogger
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
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
Returns a logger based on the given logger name.- Parameters:
loggerName- The logger name.- Returns:
- The logger.
-
getLogLevel
Returns the general log level.- Returns:
- The general log level.
-
getResource
Returns the classloader resource for a given name/path.- Parameters:
name- The name/path to lookup.- Returns:
- The resource URL.
-
getRestletLogLevel
Returns the Restlet log level. For loggers with a name starting with "org.restlet".- Returns:
- The Restlet log level.
-
loadClass
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:
ClassNotFoundException- See Also:
-
register
Registers a new Restlet Engine.- Returns:
- The registered engine.
-
register
Registers a new Restlet Engine.- Parameters:
discoverPlugins- True if plug-ins should be automatically discovered.- Returns:
- The registered engine.
-
setLogFormatter
Sets the general log formatter.- Parameters:
logFormatter- The general log formatter.
-
setLogLevel
Sets the general log level. Modifies the global JVM'sLogManager.- Parameters:
logLevel- The general log level.
-
setRestletLogLevel
Sets the Restlet log level. For loggers with a name starting with "org.restlet".- Parameters:
restletLogLevel- The Restlet log level.
-
createClassLoader
Creates a new class loader. By default, it returns an instance ofEngineClassLoader.- Returns:
- A new class loader.
-
createHelper
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
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
Finds the converter helper supporting the given conversion.- Returns:
- The converter helper or null.
-
findHelper
public AuthenticatorHelper findHelper(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
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:
-
getLoggerFacade
Returns the logger facade to use.- Returns:
- The logger facade to use.
-
getRegisteredAuthenticators
Returns the list of available authentication helpers.- Returns:
- The list of available authentication helpers.
-
getRegisteredClients
Returns the list of available client connectors.- Returns:
- The list of available client connectors.
-
getRegisteredConverters
Returns the list of available converters.- Returns:
- The list of available converters.
-
getRegisteredProtocols
Returns the list of available protocol connectors.- Returns:
- The list of available protocol connectors.
-
getRegisteredServers
Returns the list of available server connectors.- Returns:
- The list of available server connectors.
-
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(ClassLoader classLoader, String provider, List helpers, 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(ClassLoader classLoader, URL configUrl, List<?> helpers, 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(String descriptorPath, List<?> helpers, Class<?> constructorClass) throws 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:
IOException
-
registerUrlFactory
public void registerUrlFactory()Registers a factory that is used by the URL class to create theURLConnectioninstances 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
Sets the engine class loader.- Parameters:
newClassLoader- The new user class loader to use.
-
setLoggerFacade
Sets the logger facade to use.- Parameters:
loggerFacade- The logger facade to use.
-
setRegisteredAuthenticators
Sets the list of available authentication helpers.- Parameters:
registeredAuthenticators- The list of available authentication helpers.
-
setRegisteredClients
Sets the list of available client helpers.- Parameters:
registeredClients- The list of available client helpers.
-
setRegisteredConverters
Sets the list of available converter helpers.- Parameters:
registeredConverters- The list of available converter helpers.
-
setRegisteredProtocols
Sets the list of available protocol helpers.- Parameters:
registeredProtocols- The list of available protocol helpers.
-
setRegisteredServers
Sets the list of available server helpers.- Parameters:
registeredServers- The list of available server helpers.
-
setUserClassLoader
Sets the user class loader that should used in priority.- Parameters:
newClassLoader- The new user class loader to use.
-