use of org.apache.qpid.server.util.ServerScopedRuntimeException in project qpid-broker-j by apache.
the class BDBHARemoteReplicationNodeImpl method onDelete.
@Override
protected ListenableFuture<Void> onDelete() {
if (!_nodeLeft) {
SettableFuture<Void> future = SettableFuture.create();
String nodeName = getName();
boolean deletionAllowed;
try {
getEventLogger().message(_virtualHostNodeLogSubject, HighAvailabilityMessages.DELETED());
deletionAllowed = _replicatedEnvironmentFacade.removeNodeFromGroup(nodeName);
if (deletionAllowed) {
future.set(null);
} else {
future.setException(new IllegalStateTransitionException(String.format("Node '%s' cannot be deleted when role is a master", nodeName)));
}
} catch (ServerScopedRuntimeException e) {
future.setException(e);
throw e;
} catch (RuntimeException e) {
future.setException(new IllegalStateTransitionException(String.format("Unexpected exception on node '%s' deletion", nodeName), e));
}
return future;
} else {
return super.onDelete();
}
}
use of org.apache.qpid.server.util.ServerScopedRuntimeException in project qpid-broker-j by apache.
the class ConfiguredDerivedInjectedAttribute method getValue.
@Override
public T getValue(final C configuredObject) {
try {
Object[] params = new Object[1 + _staticParams.length];
params[0] = configuredObject;
for (int i = 0; i < _staticParams.length; i++) {
params[i + 1] = _staticParams[i];
}
return (T) _method.invoke(null, params);
} catch (IllegalAccessException e) {
throw new ServerScopedRuntimeException("Unable to get value for '" + getName() + "' from configured object of category " + configuredObject.getCategoryClass().getSimpleName(), e);
} catch (InvocationTargetException e) {
Throwable targetException = e.getTargetException();
if (targetException instanceof RuntimeException) {
throw (RuntimeException) targetException;
} else if (targetException instanceof Error) {
throw (Error) targetException;
} else {
// This should never happen as it would imply a getter which is declaring a checked exception
throw new ServerScopedRuntimeException("Unable to get value for '" + getName() + "' from configured object of category " + configuredObject.getCategoryClass().getSimpleName(), e);
}
}
}
use of org.apache.qpid.server.util.ServerScopedRuntimeException in project qpid-broker-j by apache.
the class ConfiguredObjectInjectedOperation method perform.
@Override
public Object perform(C subject, Map<String, Object> parameters) {
if (!_validator.appliesToType((Class<? extends ConfiguredObject<?>>) subject.getClass())) {
throw new IllegalArgumentException("Operation " + _operation.getName() + " cannot be used on an object of type " + subject.getClass().getSimpleName());
} else {
Set<String> providedNames = new HashSet<>(parameters.keySet());
providedNames.removeAll(_validNames);
if (!providedNames.isEmpty()) {
throw new IllegalArgumentException("Parameters " + providedNames + " are not accepted by " + getName());
}
Object[] paramValues = new Object[1 + _staticParams.length + _params.size()];
paramValues[0] = subject;
for (int i = 0; i < _staticParams.length; i++) {
paramValues[i + 1] = _staticParams[i];
}
for (int i = 0; i < _params.size(); i++) {
paramValues[i + 1 + _staticParams.length] = getParameterValue(subject, parameters, _params.get(i));
}
try {
return _operation.invoke(null, paramValues);
} catch (IllegalAccessException e) {
throw new ServerScopedRuntimeException(e);
} catch (InvocationTargetException e) {
if (e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
} else if (e.getCause() instanceof Error) {
throw (Error) e.getCause();
} else {
throw new ServerScopedRuntimeException(e);
}
}
}
}
use of org.apache.qpid.server.util.ServerScopedRuntimeException in project qpid-broker-j by apache.
the class ConfiguredObjectTypeRegistry method addStateTransitions.
private void addStateTransitions(final Class<? extends ConfiguredObject> clazz, final Map<State, Map<State, Method>> map) {
for (Method m : clazz.getDeclaredMethods()) {
if (m.isAnnotationPresent(StateTransition.class)) {
if (ListenableFuture.class.isAssignableFrom(m.getReturnType())) {
if (m.getParameterTypes().length == 0) {
m.setAccessible(true);
StateTransition annotation = m.getAnnotation(StateTransition.class);
for (State state : annotation.currentState()) {
addStateTransition(state, annotation.desiredState(), m, map);
}
} else {
throw new ServerScopedRuntimeException("A state transition method must have no arguments. Method " + m.getName() + " on " + clazz.getName() + " does not meet this criteria.");
}
} else {
throw new ServerScopedRuntimeException("A state transition method must return a ListenableFuture. Method " + m.getName() + " on " + clazz.getName() + " does not meet this criteria.");
}
}
}
}
use of org.apache.qpid.server.util.ServerScopedRuntimeException in project qpid-broker-j by apache.
the class ConfiguredObjectTypeRegistry method findField.
private AutomatedField findField(final ConfiguredObjectAttribute<?, ?> attr, Class<?> objClass) {
Class<?> clazz = objClass;
while (clazz != null) {
for (Field field : clazz.getDeclaredFields()) {
if (field.isAnnotationPresent(ManagedAttributeField.class) && field.getName().equals("_" + attr.getName().replace('.', '_'))) {
try {
ManagedAttributeField annotation = field.getAnnotation(ManagedAttributeField.class);
field.setAccessible(true);
Method beforeSet;
if (!"".equals(annotation.beforeSet())) {
beforeSet = clazz.getDeclaredMethod(annotation.beforeSet());
beforeSet.setAccessible(true);
} else {
beforeSet = null;
}
Method afterSet;
if (!"".equals(annotation.afterSet())) {
afterSet = clazz.getDeclaredMethod(annotation.afterSet());
afterSet.setAccessible(true);
} else {
afterSet = null;
}
return new AutomatedField(field, beforeSet, afterSet);
} catch (NoSuchMethodException e) {
throw new ServerScopedRuntimeException("Cannot find method referenced by annotation for pre/post setting action", e);
}
}
}
clazz = clazz.getSuperclass();
}
if (objClass.isInterface() || Modifier.isAbstract(objClass.getModifiers())) {
return null;
}
throw new ServerScopedRuntimeException("Unable to find field definition for automated field " + attr.getName() + " in class " + objClass.getName());
}
Aggregations