[New] Added methods on StrolchTransaction and StrolchComponent

This commit is contained in:
Robert von Burg 2017-01-23 16:42:08 +01:00
parent 13a7c83d96
commit 6bf3ee1509
5 changed files with 66 additions and 4 deletions

View File

@ -180,6 +180,21 @@ public class StrolchComponent {
this.state = this.state.validateStateChange(ComponentState.DESTROYED);
}
/**
* Returns the reference to the {@link StrolchComponent} with the given name, if it exists. If it does not exist, an
* {@link IllegalArgumentException} is thrown
*
* @param clazz
*
* @return the component with the given name
*
* @throws IllegalArgumentException
* if the component does not exist
*/
protected <V> V getComponent(Class<V> clazz) {
return this.container.getComponent(clazz);
}
/**
* Performs the given {@link PrivilegedRunnable} as the given system user
*

View File

@ -130,6 +130,11 @@ public abstract class AbstractTransaction implements StrolchTransaction {
return this.txResult.getState();
}
@Override
public boolean isOpen() {
return this.txResult.getState().isOpen();
}
@Override
public boolean isRollingBack() {
return this.txResult.getState().isRollingBack();
@ -145,6 +150,16 @@ public abstract class AbstractTransaction implements StrolchTransaction {
return this.txResult.getState().isClosing();
}
@Override
public boolean isClosed() {
return this.txResult.getState().isClosed();
}
@Override
public boolean isFailed() {
return this.txResult.getState().isFailed();
}
@Override
public String getRealmName() {
return this.realm.getRealm();

View File

@ -234,6 +234,11 @@ public interface StrolchTransaction extends AutoCloseable {
*/
public TransactionState getState();
/**
* @return if the current state of the {@link StrolchTransaction} is {@link TransactionState#OPEN}
*/
public boolean isOpen();
/**
* @return if the current state of the {@link StrolchTransaction} is {@link TransactionState#ROLLING_BACK}
*/
@ -249,6 +254,16 @@ public interface StrolchTransaction extends AutoCloseable {
*/
public boolean isClosing();
/**
* @return if the current state of the {@link StrolchTransaction} is {@link TransactionState#CLOSED}
*/
public boolean isClosed();
/**
* @return if the current state of the {@link StrolchTransaction} is {@link TransactionState#FAILED}
*/
public boolean isFailed();
/**
* If the given argument is true, then no observer updates are performed
*

View File

@ -50,4 +50,25 @@ public enum TransactionState {
public boolean isClosing() {
return this == CLOSING;
}
/**
* @return true if this is {@link #OPEN}
*/
public boolean isOpen() {
return this == OPEN;
}
/**
* @return true if this is {@link #CLOSED}
*/
public boolean isClosed() {
return this == CLOSED;
}
/**
* @return true if this is {@link #FAILED}
*/
public boolean isFailed() {
return this == FAILED;
}
}

View File

@ -55,10 +55,6 @@ public class DefaultServiceHandler extends StrolchComponent implements ServiceHa
super.initialize(configuration);
}
public <T> T getComponent(Class<T> clazz) {
return getContainer().getComponent(clazz);
}
public RuntimeConfiguration getRuntimeConfiguration() {
return this.runtimeConfiguration;
}