use of org.mule.runtime.api.lifecycle.InitialisationException in project mule by mulesoft.
the class ExtensionPluginMetadataGenerator method createExtensionManager.
/**
* Creates a {@link ExtensionManager} needed for generating the metadata for an extension. It would be later discarded due to
* the manager would have references to classes loaded with the launcher class loader instead of the hierarchical class loaders
* created as result of the classification process.
*
* @return an {@link ExtensionManager} that would be used to register the extensions.
*/
private ExtensionManager createExtensionManager() {
DefaultExtensionManager extensionManager = new DefaultExtensionManager();
extensionManager.setMuleContext(new DefaultMuleContext() {
private ErrorTypeRepository errorTypeRepository = createDefaultErrorTypeRepository();
private ErrorTypeLocator errorTypeLocator = createDefaultErrorTypeLocator(errorTypeRepository);
@Override
public MuleRegistry getRegistry() {
return new MuleRegistryHelper(new DefaultRegistryBroker(this, new MuleLifecycleInterceptor()), this);
}
@Override
public ErrorTypeLocator getErrorTypeLocator() {
return errorTypeLocator;
}
@Override
public ErrorTypeRepository getErrorTypeRepository() {
return errorTypeRepository;
}
});
try {
extensionManager.initialise();
} catch (InitialisationException e) {
throw new RuntimeException("Error while initialising the extension manager", e);
}
return extensionManager;
}
use of org.mule.runtime.api.lifecycle.InitialisationException in project mule by mulesoft.
the class ParametersResolver method resolveParameters.
/**
* {@inheritDoc}
*/
@Override
public void resolveParameters(ObjectType objectType, DefaultObjectBuilder builder) {
final Class<?> objectClass = getType(objectType);
final boolean isParameterGroup = isFlattenedParameterGroup(objectType);
objectType.getFields().forEach(field -> {
final String key = getLocalPart(field);
ValueResolver<?> valueResolver = null;
Field objectField = getField(objectClass, key);
if (parameters.containsKey(key)) {
valueResolver = toValueResolver(parameters.get(key));
} else if (!isParameterGroup) {
valueResolver = getDefaultValue(field).isPresent() ? getFieldDefaultValueValueResolver(field, muleContext) : null;
}
Optional<NullSafeTypeAnnotation> nullSafe = field.getAnnotation(NullSafeTypeAnnotation.class);
if (nullSafe.isPresent()) {
ValueResolver<?> delegate = valueResolver != null ? valueResolver : new StaticValueResolver<>(null);
MetadataType type = getMetadataType(nullSafe.get().getType(), ExtensionsTypeLoaderFactory.getDefault().createTypeLoader());
valueResolver = NullSafeValueResolverWrapper.of(delegate, type, reflectionCache, muleContext, this);
}
if (field.getAnnotation(ConfigOverrideTypeAnnotation.class).isPresent()) {
valueResolver = ConfigOverrideValueResolverWrapper.of(valueResolver != null ? valueResolver : new StaticValueResolver<>(null), key, reflectionCache, muleContext);
}
if (valueResolver != null) {
try {
initialiseIfNeeded(valueResolver, true, muleContext);
builder.addPropertyResolver(objectField.getName(), valueResolver);
} catch (InitialisationException e) {
throw new MuleRuntimeException(e);
}
} else if (field.isRequired() && !isFlattenedParameterGroup(field) && !lazyInitEnabled) {
throw new RequiredParameterNotSetException(objectField.getName());
}
});
}
use of org.mule.runtime.api.lifecycle.InitialisationException in project mule by mulesoft.
the class FunctionalTestProcessor method initialise.
@Override
public void initialise() throws InitialisationException {
if (enableMessageHistory) {
messageHistory = new CopyOnWriteArrayList<>();
}
for (LifecycleCallback callback : lifecycleCallbacks) {
callback.onTransition(id, Initialisable.PHASE_NAME);
}
if (processorClass != null) {
try {
processor = (Processor) instantiateClass(processorClass);
initialiseIfNeeded(processor, true, muleContext);
} catch (Exception e) {
throw new InitialisationException(e, this);
}
}
}
use of org.mule.runtime.api.lifecycle.InitialisationException in project mule by mulesoft.
the class DefaultExtensionManagerFactory method create.
/**
* {@inheritDoc}
*/
@Override
public ExtensionManager create(MuleContext muleContext) {
ExtensionManager extensionManager = new DefaultExtensionManager();
muleContext.setExtensionManager(extensionManager);
try {
initialiseIfNeeded(extensionManager, false, muleContext);
} catch (InitialisationException e) {
throw new MuleRuntimeException(createStaticMessage("Could not initialise extension manager"), e);
}
return extensionManager;
}
use of org.mule.runtime.api.lifecycle.InitialisationException in project mule by mulesoft.
the class ServerNotificationManagerConfigurator method populateNotificationTypeMappings.
public ServerNotificationManager populateNotificationTypeMappings(Map<String, Class<? extends Notification>> eventMap, Map<String, Class<? extends NotificationListener>> interfaceMap) throws InitialisationException {
Map<String, NotificationsProvider> providersMap = new HashMap<>();
for (NotificationsProvider provider : registry.lookupAllByType(NotificationsProvider.class)) {
for (Entry<String, Pair<Class<? extends Notification>, Class<? extends NotificationListener>>> entry : provider.getEventListenerMapping().entrySet()) {
final String notificationType = entry.getKey();
if (!notificationType.matches("[a-zA-Z]+:[A-Z\\-]+")) {
throw new InitialisationException(createStaticMessage("Notification '%s' declared in '%s' doesn't comply with the '[artifactID]:[NOTIFICATION-ID]' format", notificationType, provider.toString()), this);
}
if (eventMap.containsKey(notificationType)) {
throw new InitialisationException(createStaticMessage("Notification '%s' declared in '%s' is already declared for another artifact in provider '%s'.", notificationType, provider.toString(), eventMap.get(notificationType)), this);
}
eventMap.put(notificationType, entry.getValue().getFirst());
interfaceMap.put(notificationType, entry.getValue().getSecond());
providersMap.put(notificationType, provider);
}
}
ServerNotificationManager notificationManager = muleContext.getNotificationManager();
if (dynamic != null) {
notificationManager.setNotificationDynamic(dynamic.booleanValue());
}
return notificationManager;
}
Aggregations