public class Restarter extends Object
The Restarter should be initialized
early to ensure that
classes are loaded multiple times. Mostly the RestartApplicationListener
can be
relied upon to perform initialization, however, you may need to call
initialize(String[])
directly if your SpringApplication arguments are not
identical to your main method arguments.
By default, applications running in an IDE (i.e. those not packaged as "fat jars") will automatically detect URLs that can change. It's also possible to manually configure URLs or class file updates for remote restart scenarios.
RestartApplicationListener
,
initialize(String[])
,
getInstance()
,
restart()
Modifier | Constructor and Description |
---|---|
protected |
Restarter(Thread thread,
String[] args,
boolean forceReferenceCleanup,
RestartInitializer initializer)
Internal constructor to create a new
Restarter instance. |
Modifier and Type | Method and Description |
---|---|
void |
addClassLoaderFiles(ClassLoaderFiles classLoaderFiles)
Add additional
ClassLoaderFiles to be included in the next restart. |
void |
addUrls(Collection<URL> urls)
Add additional URLs to be includes in the next restart.
|
static void |
clearInstance()
Clear the instance.
|
static void |
disable()
Initialize and disable restart support.
|
URL[] |
getInitialUrls()
Return the initial set of URLs as configured by the
RestartInitializer . |
static Restarter |
getInstance()
Return the active
Restarter instance. |
Object |
getOrAddAttribute(String name,
ObjectFactory<?> objectFactory) |
ThreadFactory |
getThreadFactory()
Return a
ThreadFactory that can be used to create leak safe threads. |
protected void |
initialize(boolean restartOnInitialize) |
static void |
initialize(String[] args)
Initialize restart support.
|
static void |
initialize(String[] args,
boolean forceReferenceCleanup)
Initialize restart support.
|
static void |
initialize(String[] args,
boolean forceReferenceCleanup,
RestartInitializer initializer)
Initialize restart support.
|
static void |
initialize(String[] args,
boolean forceReferenceCleanup,
RestartInitializer initializer,
boolean restartOnInitialize)
Initialize restart support for the current application.
|
static void |
initialize(String[] args,
RestartInitializer initializer)
Initialize restart support.
|
protected Throwable |
relaunch(ClassLoader classLoader)
Relaunch the application using the specified classloader.
|
Object |
removeAttribute(String name) |
void |
restart()
Restart the running application.
|
void |
restart(FailureHandler failureHandler)
Restart the running application.
|
protected void |
start(FailureHandler failureHandler)
Start the application.
|
protected void |
stop()
Stop the application.
|
protected Restarter(Thread thread, String[] args, boolean forceReferenceCleanup, RestartInitializer initializer)
Restarter
instance.thread
- the source threadargs
- the application argumentsforceReferenceCleanup
- if soft/weak reference cleanup should be forcedinitializer
- the restart initializerinitialize(String[])
protected void initialize(boolean restartOnInitialize)
public void addUrls(Collection<URL> urls)
urls
- the urls to addpublic void addClassLoaderFiles(ClassLoaderFiles classLoaderFiles)
ClassLoaderFiles
to be included in the next restart.classLoaderFiles
- the files to addpublic ThreadFactory getThreadFactory()
ThreadFactory
that can be used to create leak safe threads.public void restart()
public void restart(FailureHandler failureHandler)
failureHandler
- a failure handler to deal with application that doesn't startprotected void start(FailureHandler failureHandler) throws Exception
failureHandler
- a failure handler for application that won't startException
- in case of errorsprotected Throwable relaunch(ClassLoader classLoader) throws Exception
classLoader
- the classloader to usenull
Exception
- in case of errorsprotected void stop() throws Exception
Exception
- in case of errorspublic Object getOrAddAttribute(String name, ObjectFactory<?> objectFactory)
public URL[] getInitialUrls()
RestartInitializer
.null
public static void disable()
public static void initialize(String[] args)
initialize(String[], boolean, RestartInitializer)
for details.args
- main application argumentsinitialize(String[], boolean, RestartInitializer)
public static void initialize(String[] args, RestartInitializer initializer)
initialize(String[], boolean, RestartInitializer)
for details.args
- main application argumentsinitializer
- the restart initializerinitialize(String[], boolean, RestartInitializer)
public static void initialize(String[] args, boolean forceReferenceCleanup)
initialize(String[], boolean, RestartInitializer)
for details.args
- main application argumentsforceReferenceCleanup
- if forcing of soft/weak reference should happen oninitialize(String[], boolean, RestartInitializer)
public static void initialize(String[] args, boolean forceReferenceCleanup, RestartInitializer initializer)
initialize(String[], boolean, RestartInitializer)
for details.args
- main application argumentsforceReferenceCleanup
- if forcing of soft/weak reference should happen oninitializer
- the restart initializerinitialize(String[], boolean, RestartInitializer)
public static void initialize(String[] args, boolean forceReferenceCleanup, RestartInitializer initializer, boolean restartOnInitialize)
RestartApplicationListener
but can also be called directly if main
application arguments are not the same as those passed to the
SpringApplication
.args
- main application argumentsforceReferenceCleanup
- if forcing of soft/weak reference should happen on
each restart. This will slow down restarts and is intended primarily for testinginitializer
- the restart initializerrestartOnInitialize
- if the restarter should be restarted immediately when
the RestartInitializer
returns non null
resultspublic static Restarter getInstance()
Restarter
instance. Cannot be called before
initialization
.public static void clearInstance()
Copyright © 2017 Pivotal Software, Inc.. All rights reserved.