use of org.apache.qpid.server.util.ServerScopedRuntimeException in project qpid-broker-j by apache.
the class AbstractQueue method addConsumer.
// ------ Manage Consumers
@Override
public <T extends ConsumerTarget<T>> QueueConsumerImpl<T> addConsumer(final T target, final FilterManager filters, final Class<? extends ServerMessage> messageClass, final String consumerName, final EnumSet<ConsumerOption> optionSet, final Integer priority) throws ExistingExclusiveConsumer, ExistingConsumerPreventsExclusive, ConsumerAccessRefused, QueueDeleted {
try {
final QueueConsumerImpl<T> queueConsumer = getTaskExecutor().run(new Task<QueueConsumerImpl<T>, Exception>() {
@Override
public QueueConsumerImpl<T> execute() throws Exception {
return addConsumerInternal(target, filters, messageClass, consumerName, optionSet, priority);
}
@Override
public String getObject() {
return AbstractQueue.this.toString();
}
@Override
public String getAction() {
return "add consumer";
}
@Override
public String getArguments() {
return "target=" + target + ", consumerName=" + consumerName + ", optionSet=" + optionSet;
}
});
target.consumerAdded(queueConsumer);
if (isEmpty()) {
target.noMessagesAvailable();
}
target.updateNotifyWorkDesired();
target.notifyWork();
return queueConsumer;
} catch (ExistingExclusiveConsumer | ConsumerAccessRefused | ExistingConsumerPreventsExclusive | QueueDeleted | RuntimeException e) {
throw e;
} catch (Exception e) {
// Should never happen
throw new ServerScopedRuntimeException(e);
}
}
use of org.apache.qpid.server.util.ServerScopedRuntimeException in project qpid-broker-j by apache.
the class FileTrustStoreImpl method validateTrustStore.
private static void validateTrustStore(FileTrustStore trustStore) {
KeyStore keyStore;
try {
keyStore = initializeKeyStore(trustStore);
} catch (Exception e) {
final String message;
if (e instanceof IOException && e.getCause() != null && e.getCause() instanceof UnrecoverableKeyException) {
message = "Check trust store password. Cannot instantiate trust store from '" + trustStore.getStoreUrl() + "'.";
} else {
message = "Cannot instantiate trust store from '" + trustStore.getStoreUrl() + "'.";
}
throw new IllegalConfigurationException(message, e);
}
try {
final Enumeration<String> aliasesEnum = keyStore.aliases();
boolean certificateFound = false;
while (aliasesEnum.hasMoreElements()) {
String alias = aliasesEnum.nextElement();
if (keyStore.isCertificateEntry(alias)) {
certificateFound = true;
break;
}
}
if (!certificateFound) {
throw new IllegalConfigurationException("Trust store must contain at least one certificate.");
}
} catch (KeyStoreException e) {
throw new ServerScopedRuntimeException("Trust store has not been initialized", e);
}
try {
TrustManagerFactory.getInstance(trustStore.getTrustManagerFactoryAlgorithm());
} catch (NoSuchAlgorithmException e) {
throw new IllegalConfigurationException("Unknown trustManagerFactoryAlgorithm: " + trustStore.getTrustManagerFactoryAlgorithm());
}
}
use of org.apache.qpid.server.util.ServerScopedRuntimeException in project qpid-broker-j by apache.
the class AbstractConfiguredObject method automatedSetValue.
private void automatedSetValue(final String name, Object value) {
try {
final ConfiguredAutomatedAttribute attribute = (ConfiguredAutomatedAttribute) _attributeTypes.get(name);
if (value == null && !"".equals(attribute.defaultValue())) {
value = attribute.defaultValue();
}
ConfiguredObjectTypeRegistry.AutomatedField field = _automatedFields.get(name);
if (field.getPreSettingAction() != null) {
field.getPreSettingAction().invoke(this);
}
Object desiredValue = attribute.convert(value, this);
field.getField().set(this, desiredValue);
if (field.getPostSettingAction() != null) {
field.getPostSettingAction().invoke(this);
}
} catch (IllegalAccessException e) {
throw new ServerScopedRuntimeException("Unable to set the automated attribute " + name + " on the configure object type " + getClass().getName(), e);
} catch (InvocationTargetException e) {
if (e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
}
throw new ServerScopedRuntimeException("Unable to set the automated attribute " + name + " on the configure object type " + getClass().getName(), e);
}
}
use of org.apache.qpid.server.util.ServerScopedRuntimeException in project qpid-broker-j by apache.
the class AbstractSystemConfig method makeActive.
protected ListenableFuture<Void> makeActive() {
final EventLogger eventLogger = _eventLogger;
final EventLogger startupLogger = initiateStartupLogging();
try {
final Container<?> container = initiateStoreAndRecovery();
container.setEventLogger(startupLogger);
final SettableFuture<Void> returnVal = SettableFuture.create();
addFutureCallback(container.openAsync(), new FutureCallback() {
@Override
public void onSuccess(final Object result) {
State state = container.getState();
if (state == State.ACTIVE) {
startupLogger.message(BrokerMessages.READY());
container.setEventLogger(eventLogger);
returnVal.set(null);
} else {
returnVal.setException(new ServerScopedRuntimeException("Broker failed reach ACTIVE state (state is " + state + ")"));
}
}
@Override
public void onFailure(final Throwable t) {
returnVal.setException(t);
}
}, getTaskExecutor());
return returnVal;
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}
use of org.apache.qpid.server.util.ServerScopedRuntimeException in project qpid-broker-j by apache.
the class ConfiguredObjectInjectedStatistic 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);
}
}
}
Aggregations