[New] Added ExecutionPolicy.runAsAgentWithResult()
This commit is contained in:
parent
15db21b45e
commit
844bb670b4
|
@ -15,6 +15,7 @@ import li.strolch.privilege.model.Certificate;
|
|||
import li.strolch.privilege.model.PrivilegeContext;
|
||||
import li.strolch.runtime.StrolchConstants;
|
||||
import li.strolch.runtime.privilege.PrivilegedRunnable;
|
||||
import li.strolch.runtime.privilege.PrivilegedRunnableWithResult;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -92,8 +93,8 @@ public abstract class ExecutionPolicy extends StrolchPolicy {
|
|||
public abstract void toExecuted(Action action);
|
||||
|
||||
/**
|
||||
* Stops the execution of this {@link Action} without completing its execution, i.e. sets the state to
|
||||
* {@link State#STOPPED}
|
||||
* Stops the execution of this {@link Action} without completing its execution, i.e. sets the state to {@link
|
||||
* State#STOPPED}
|
||||
*
|
||||
* @param action
|
||||
* the action to stop execution for
|
||||
|
@ -101,8 +102,8 @@ public abstract class ExecutionPolicy extends StrolchPolicy {
|
|||
public abstract void toStopped(Action action);
|
||||
|
||||
/**
|
||||
* Sets this {@link Action} which should be in execution to an error state, i.e. sets the state to
|
||||
* {@link State#ERROR}
|
||||
* Sets this {@link Action} which should be in execution to an error state, i.e. sets the state to {@link
|
||||
* State#ERROR}
|
||||
*
|
||||
* @param action
|
||||
* the action to set to error state
|
||||
|
@ -110,8 +111,8 @@ public abstract class ExecutionPolicy extends StrolchPolicy {
|
|||
public abstract void toError(Action action);
|
||||
|
||||
/**
|
||||
* Sets this {@link Action} which should be in execution to a warning state, i.e. sets the state to
|
||||
* {@link State#WARNING}
|
||||
* Sets this {@link Action} which should be in execution to a warning state, i.e. sets the state to {@link
|
||||
* State#WARNING}
|
||||
*
|
||||
* @param action
|
||||
* the action to set to warning state
|
||||
|
@ -151,9 +152,8 @@ public abstract class ExecutionPolicy extends StrolchPolicy {
|
|||
}
|
||||
|
||||
/**
|
||||
* Opens a {@link StrolchTransaction} where the realm retrieved using
|
||||
* {@link ComponentContainer#getRealm(Certificate)}. This transaction should be used in a try-with-resource clause
|
||||
* so it is properly closed.
|
||||
* Opens a {@link StrolchTransaction} where the realm retrieved using {@link ComponentContainer#getRealm(Certificate)}.
|
||||
* This transaction should be used in a try-with-resource clause so it is properly closed.
|
||||
*
|
||||
* @return the open {@link StrolchTransaction}
|
||||
*
|
||||
|
@ -174,9 +174,26 @@ public abstract class ExecutionPolicy extends StrolchPolicy {
|
|||
* @param runnable
|
||||
* the runnable to perform
|
||||
*
|
||||
* @throws PrivilegeException if the agent is missing the privilege
|
||||
* @throws PrivilegeException
|
||||
* if the agent is missing the privilege
|
||||
*/
|
||||
protected void runAsAgent(PrivilegedRunnable runnable) throws PrivilegeException {
|
||||
getContainer().getPrivilegeHandler().runAs(StrolchConstants.SYSTEM_USER_AGENT, runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the given {@link PrivilegedRunnableWithResult} as the system user {@link
|
||||
* StrolchConstants#SYSTEM_USER_AGENT}
|
||||
*
|
||||
* @param runnable
|
||||
* the runnable to perform
|
||||
*
|
||||
* @return the result of the operation
|
||||
*
|
||||
* @throws PrivilegeException
|
||||
* if the agent is missing the privilege
|
||||
*/
|
||||
protected <T> T runAsAgentWithResult(PrivilegedRunnableWithResult<T> runnable) throws PrivilegeException {
|
||||
return getContainer().getPrivilegeHandler().runWithResult(StrolchConstants.SYSTEM_USER_AGENT, runnable);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue