Modifier and Type | Class and Description |
---|---|
protected static class |
Daemon.DaemonThread
Thread class used by the
startModule(Module) and
executeScheduledTask(Task) methods so that the returned object and the
exception thrown can be returned to calling class |
Modifier and Type | Field and Description |
---|---|
protected static String |
DAEMON_USER_UUID
The uuid defined for the daemon user object
|
protected static ThreadLocal<User> |
daemonThreadUser |
protected static ThreadLocal<Boolean> |
isDaemonThread |
Modifier | Constructor and Description |
---|---|
protected |
Daemon()
Protected constructor to override the default constructor to prevent it from being instantiated.
|
Modifier and Type | Method and Description |
---|---|
static User |
createUser(User user,
String password,
List<String> roleNames)
This method should not be called directly, only
ContextDAO.createUser(User, String, List) can
legally invoke createUser(User, String, List) . |
static void |
executeScheduledTask(Task task)
Executes the given task in a new thread that is authenticated as the daemon user.
|
static User |
getDaemonThreadUser() |
static String |
getDaemonUserUuid() |
static boolean |
isDaemonThread() |
static boolean |
isDaemonUser(User user)
Checks whether user is Daemon.
|
static Thread |
runInDaemonThread(Runnable runnable,
DaemonToken token)
Executes the given runnable in a new thread that is authenticated as the daemon user.
|
static void |
runInDaemonThreadAndWait(Runnable runnable,
DaemonToken token)
Executes the given runnable in a new thread that is authenticated as the daemon user and wait
for the thread to finish.
|
static Thread |
runInNewDaemonThread(Runnable runnable)
Call this method if you are inside a Daemon thread (for example in a Module activator or a
scheduled task) and you want to start up a new parallel Daemon thread.
|
static void |
runStartupForService(OpenmrsService service)
Calls the
OpenmrsService.onStartup() method, as a daemon, for an instance
implementing the OpenmrsService interface. |
static Module |
startModule(Module module) |
static Module |
startModule(Module module,
boolean isOpenmrsStartup,
org.springframework.context.support.AbstractRefreshableApplicationContext applicationContext)
This method should not be called directly.
|
protected static final String DAEMON_USER_UUID
protected static final ThreadLocal<Boolean> isDaemonThread
protected static final ThreadLocal<User> daemonThreadUser
protected Daemon()
public static Module startModule(Module module) throws ModuleException
public static Module startModule(Module module, boolean isOpenmrsStartup, org.springframework.context.support.AbstractRefreshableApplicationContext applicationContext) throws ModuleException
ModuleFactory.startModule(Module)
method uses this to start the given module in a new thread that is authenticated as the
daemon user. module
- the module to startisOpenmrsStartup
- Specifies whether this module is being started at application startup
or notapplicationContext
- the spring application context instance to refreshModuleFactory.startModuleInternal(Module)
ModuleException
public static User createUser(User user, String password, List<String> roleNames) throws Exception
ContextDAO.createUser(User, String, List)
can
legally invoke createUser(User, String, List)
.user
- A new user to be created.password
- The password to set for the new user.roleNames
- A list of role names to fetch the roles to add to the user.Exception
public static void executeScheduledTask(Task task) throws Exception
TimerSchedulerTask
during actual task executiontask
- the task to run
Should not be called from other methods other than TimerSchedulerTask
Should not throw error if called from a TimerSchedulerTask classException
public static Thread runInNewDaemonThread(Runnable runnable)
runnable
- what to run in a new threadThread
Should throw error if called from a non daemon thread
Should not throw error if called from a daemon threadpublic static boolean isDaemonThread()
Context.hasPrivilege(String)
public static void runStartupForService(OpenmrsService service) throws ModuleException
OpenmrsService.onStartup()
method, as a daemon, for an instance
implementing the OpenmrsService
interface.service
- instance implementing the OpenmrsService
interface.ModuleException
public static Thread runInDaemonThread(Runnable runnable, DaemonToken token)
public static void runInDaemonThreadAndWait(Runnable runnable, DaemonToken token)
runnable
- an object implementing the Runnable
interface.token
- the token required to run code as the daemon userpublic static boolean isDaemonUser(User user)
user
- user whom we are checking if daemonpublic static User getDaemonThreadUser()
public static String getDaemonUserUuid()
Copyright © 2024 OpenMRS Inc.. All rights reserved.