Search in sources :

Example 1 with MuleRegistry

use of org.mule.runtime.core.internal.registry.MuleRegistry in project mule by mulesoft.

the class TransformDiscoveryTestCase method testSimpleDiscovery.

@Test
public void testSimpleDiscovery() throws Exception {
    MuleRegistry registry = ((MuleContextWithRegistries) muleContext).getRegistry();
    Transformer t = registry.lookupTransformer(DataType.STRING, DataType.fromType(Apple.class));
    assertNotNull(t);
    assertEquals(StringToApple.class, t.getClass());
    t = registry.lookupTransformer(DataType.STRING, DataType.fromType(Orange.class));
    assertNotNull(t);
    assertEquals(StringToOrange.class, t.getClass());
    try {
        registry.lookupTransformer(DataType.STRING, DataType.fromType(Banana.class));
        fail("There is no transformer to go from String to Banana");
    } catch (TransformerException e) {
    // expected
    }
    registry.registerTransformer(new StringToRedApple());
    t = registry.lookupTransformer(DataType.STRING, DataType.fromType(RedApple.class));
    assertNotNull(t);
    assertEquals(StringToRedApple.class, t.getClass());
}
Also used : Apple(org.mule.tck.testmodels.fruit.Apple) RedApple(org.mule.tck.testmodels.fruit.RedApple) Transformer(org.mule.runtime.core.api.transformer.Transformer) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) MuleRegistry(org.mule.runtime.core.internal.registry.MuleRegistry) TransformerException(org.mule.runtime.core.api.transformer.TransformerException) Banana(org.mule.tck.testmodels.fruit.Banana) Test(org.junit.Test)

Example 2 with MuleRegistry

use of org.mule.runtime.core.internal.registry.MuleRegistry in project mule by mulesoft.

the class DefaultPolicyManager method initialise.

@Override
public void initialise() throws InitialisationException {
    operationPolicyProcessorFactory = new DefaultOperationPolicyProcessorFactory(policyStateHandler);
    sourcePolicyProcessorFactory = new DefaultSourcePolicyProcessorFactory(policyStateHandler);
    MuleRegistry registry = ((MuleContextWithRegistries) muleContext).getRegistry();
    policyProvider = registry.lookupLocalObjects(PolicyProvider.class).stream().findFirst().orElse(new NullPolicyProvider());
    sourcePolicyParametersTransformerCollection = registry.lookupObjects(SourcePolicyParametersTransformer.class);
    operationPolicyParametersTransformerCollection = registry.lookupObjects(OperationPolicyParametersTransformer.class);
    policyPointcutParametersManager = new PolicyPointcutParametersManager(registry.lookupObjects(SourcePolicyPointcutParametersFactory.class), registry.lookupObjects(OperationPolicyPointcutParametersFactory.class));
}
Also used : OperationPolicyParametersTransformer(org.mule.runtime.core.api.policy.OperationPolicyParametersTransformer) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) MuleRegistry(org.mule.runtime.core.internal.registry.MuleRegistry) SourcePolicyParametersTransformer(org.mule.runtime.core.api.policy.SourcePolicyParametersTransformer)

Example 3 with MuleRegistry

use of org.mule.runtime.core.internal.registry.MuleRegistry in project mule by mulesoft.

the class DefaultsConfigurationBuilder method doConfigure.

@Override
protected void doConfigure(MuleContext muleContext) throws Exception {
    MuleRegistry registry = ((MuleContextWithRegistries) muleContext).getRegistry();
    new SimpleRegistryBootstrap(APP, muleContext).initialise();
    configureQueueManager(muleContext);
    registry.registerObject(OBJECT_MULE_CONTEXT, muleContext);
    registerObject(OBJECT_SECURITY_MANAGER, new DefaultMuleSecurityManager(), muleContext);
    registerObject(BASE_IN_MEMORY_OBJECT_STORE_KEY, createDefaultInMemoryObjectStore(), muleContext);
    registerObject(BASE_PERSISTENT_OBJECT_STORE_KEY, createDefaultPersistentObjectStore(), muleContext);
    registerLocalObjectStoreManager(muleContext, registry);
    registerObject(OBJECT_SCHEDULER_POOLS_CONFIG, SchedulerContainerPoolsConfig.getInstance(), muleContext);
    registerObject(OBJECT_SCHEDULER_BASE_CONFIG, config().withPrefix(muleContext.getConfiguration().getId()).withShutdownTimeout(() -> muleContext.getConfiguration().getShutdownTimeout(), MILLISECONDS), muleContext);
    registerObject(OBJECT_STORE_MANAGER, new MuleObjectStoreManager(), muleContext);
    registerObject(OBJECT_DEFAULT_MESSAGE_PROCESSING_MANAGER, new MuleMessageProcessingManager(), muleContext);
    registerObject(OBJECT_MULE_STREAM_CLOSER_SERVICE, new DefaultStreamCloserService(), muleContext);
    registerObject(OBJECT_LOCK_PROVIDER, new SingleServerLockProvider(), muleContext);
    registerObject(OBJECT_LOCK_FACTORY, new MuleLockFactory(), muleContext);
    registerObject(OBJECT_PROCESSING_TIME_WATCHER, new DefaultProcessingTimeWatcher(), muleContext);
    registerObject(OBJECT_DEFAULT_RETRY_POLICY_TEMPLATE, new NoRetryPolicyTemplate(), muleContext);
    registerObject(OBJECT_CONVERTER_RESOLVER, new DynamicDataTypeConversionResolver(muleContext), muleContext);
    registerObject(DEFAULT_OBJECT_SERIALIZER_NAME, new JavaObjectSerializer(), muleContext);
    registerObject(OBJECT_EXPRESSION_LANGUAGE, new MVELExpressionLanguage(muleContext), muleContext);
    StreamingManager streamingManager = new DefaultStreamingManager();
    registerObject(OBJECT_STREAMING_MANAGER, streamingManager, muleContext);
    registerObject(OBJECT_EXPRESSION_MANAGER, new DefaultExpressionManager(), muleContext);
    registerObject(OBJECT_TIME_SUPPLIER, new LocalTimeSupplier(), muleContext);
    registerObject(OBJECT_CONNECTION_MANAGER, new DefaultConnectionManager(muleContext), muleContext);
    registerObject(METADATA_SERVICE_KEY, new MuleMetadataService(), muleContext);
    registerObject(VALUE_PROVIDER_SERVICE_KEY, new MuleValueProviderService(), muleContext);
    registerObject(PROCESSOR_INTERCEPTOR_MANAGER_REGISTRY_KEY, new DefaultProcessorInterceptorManager(), muleContext);
    registerObject(OBJECT_NOTIFICATION_DISPATCHER, new DefaultNotificationDispatcher(), muleContext);
    registerObject(NotificationListenerRegistry.REGISTRY_KEY, new DefaultNotificationListenerRegistry(), muleContext);
    registerObject(EventContextService.REGISTRY_KEY, new DefaultEventContextService(), muleContext);
    registerObject(OBJECT_TRANSACTION_FACTORY_LOCATOR, new TransactionFactoryLocator(), muleContext);
    registerObject(ComponentInitialStateManager.SERVICE_ID, new ComponentInitialStateManager() {

        @Override
        public boolean mustStartMessageSource(Component component) {
            return true;
        }
    }, muleContext);
}
Also used : TransactionFactoryLocator(org.mule.runtime.core.internal.transaction.TransactionFactoryLocator) DefaultEventContextService(org.mule.runtime.core.internal.event.DefaultEventContextService) DefaultConnectionManager(org.mule.runtime.core.internal.connection.DefaultConnectionManager) MuleMessageProcessingManager(org.mule.runtime.core.internal.execution.MuleMessageProcessingManager) DefaultNotificationDispatcher(org.mule.runtime.core.internal.context.notification.DefaultNotificationDispatcher) DefaultNotificationListenerRegistry(org.mule.runtime.core.internal.context.notification.DefaultNotificationListenerRegistry) NoRetryPolicyTemplate(org.mule.runtime.core.api.retry.policy.NoRetryPolicyTemplate) LocalTimeSupplier(org.mule.runtime.core.internal.time.LocalTimeSupplier) MuleMetadataService(org.mule.runtime.core.internal.metadata.MuleMetadataService) Component(org.mule.runtime.api.component.Component) DynamicDataTypeConversionResolver(org.mule.runtime.core.internal.transformer.DynamicDataTypeConversionResolver) MuleValueProviderService(org.mule.runtime.core.internal.value.MuleValueProviderService) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) MuleObjectStoreManager(org.mule.runtime.core.internal.util.store.MuleObjectStoreManager) SingleServerLockProvider(org.mule.runtime.core.internal.lock.SingleServerLockProvider) DefaultProcessingTimeWatcher(org.mule.runtime.core.internal.management.stats.DefaultProcessingTimeWatcher) MVELExpressionLanguage(org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage) JavaObjectSerializer(org.mule.runtime.core.internal.serialization.JavaObjectSerializer) MuleLockFactory(org.mule.runtime.core.internal.lock.MuleLockFactory) ComponentInitialStateManager(org.mule.runtime.api.deployment.management.ComponentInitialStateManager) DefaultMuleSecurityManager(org.mule.runtime.core.internal.security.DefaultMuleSecurityManager) DefaultExpressionManager(org.mule.runtime.core.internal.el.DefaultExpressionManager) DefaultProcessorInterceptorManager(org.mule.runtime.core.internal.processor.interceptor.DefaultProcessorInterceptorManager) DefaultStreamCloserService(org.mule.runtime.core.internal.util.DefaultStreamCloserService) StreamingManager(org.mule.runtime.core.api.streaming.StreamingManager) DefaultStreamingManager(org.mule.runtime.core.api.streaming.DefaultStreamingManager) MuleRegistry(org.mule.runtime.core.internal.registry.MuleRegistry) DefaultStreamingManager(org.mule.runtime.core.api.streaming.DefaultStreamingManager) SimpleRegistryBootstrap(org.mule.runtime.core.internal.config.bootstrap.SimpleRegistryBootstrap)

Example 4 with MuleRegistry

use of org.mule.runtime.core.internal.registry.MuleRegistry in project mule by mulesoft.

the class DefaultExtensionManagerTestCase method getOperationExecutorThroughImplicitConfigurationConcurrently.

@Test
public void getOperationExecutorThroughImplicitConfigurationConcurrently() throws Exception {
    final int threadCount = 2;
    final CountDownLatch joinerLatch = new CountDownLatch(threadCount);
    MuleRegistry registry = muleContext.getRegistry();
    when(extension1ConfigurationModel.getModelProperty(ParameterGroupModelProperty.class)).thenReturn(empty());
    doAnswer(invocation -> {
        registerIntoMockContext(muleContext, getImplicitConfigurationProviderName(extensionModel1, extension1ConfigurationModel), extension1ConfigurationProvider);
        new Thread(() -> extensionsManager.getConfiguration(extensionModel1, extension1OperationModel, event)).start();
        joinerLatch.countDown();
        return null;
    }).when(registry).registerObject(anyString(), anyObject());
    Optional<ConfigurationInstance> configurationInstance = extensionsManager.getConfiguration(extensionModel1, extension1OperationModel, event);
    joinerLatch.countDown();
    assertThat(configurationInstance.isPresent(), is(true));
    assertThat(joinerLatch.await(5, TimeUnit.SECONDS), is(true));
    assertThat(configurationInstance.get().getValue(), is(sameInstance(configInstance)));
}
Also used : MuleRegistry(org.mule.runtime.core.internal.registry.MuleRegistry) CountDownLatch(java.util.concurrent.CountDownLatch) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance) ExtensionsTestUtils.mockConfigurationInstance(org.mule.test.module.extension.internal.util.ExtensionsTestUtils.mockConfigurationInstance) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 5 with MuleRegistry

use of org.mule.runtime.core.internal.registry.MuleRegistry in project mule by mulesoft.

the class MuleTestUtils method createAndRegisterFlow.

/**
 * Creates a new flow and registers it in the given {@code mockComponentLocator}
 *
 * @param mockComponentLocator a {@link Mockito#mock(Class)} {@link ConfigurationComponentLocator}
 */
public static Flow createAndRegisterFlow(MuleContext context, String flowName, ConfigurationComponentLocator mockComponentLocator) throws MuleException {
    Flow flow = createFlow(context, flowName);
    MuleRegistry registry = ((MuleContextWithRegistries) context).getRegistry();
    if (registry != null) {
        registry.registerFlowConstruct(flow);
    }
    when(mockComponentLocator.find(Location.builder().globalName(flowName).build())).thenReturn(Optional.of(flow));
    return flow;
}
Also used : MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) MuleRegistry(org.mule.runtime.core.internal.registry.MuleRegistry) Flow(org.mule.runtime.core.api.construct.Flow)

Aggregations

MuleRegistry (org.mule.runtime.core.internal.registry.MuleRegistry)11 MuleContextWithRegistries (org.mule.runtime.core.internal.context.MuleContextWithRegistries)8 Test (org.junit.Test)3 NotificationDispatcher (org.mule.runtime.api.notification.NotificationDispatcher)3 StreamingManager (org.mule.runtime.core.api.streaming.StreamingManager)3 RegistrationException (org.mule.runtime.core.privileged.registry.RegistrationException)3 ComponentInitialStateManager (org.mule.runtime.api.deployment.management.ComponentInitialStateManager)2 ErrorTypeRepository (org.mule.runtime.api.exception.ErrorTypeRepository)2 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)2 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)2 Transformer (org.mule.runtime.core.api.transformer.Transformer)2 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Component (org.mule.runtime.api.component.Component)1 ComponentIdentifier (org.mule.runtime.api.component.ComponentIdentifier)1 ConfigurationProperties (org.mule.runtime.api.component.ConfigurationProperties)1 ConfigurationComponentLocator (org.mule.runtime.api.component.location.ConfigurationComponentLocator)1 Location (org.mule.runtime.api.component.location.Location)1 DefaultExpressionLanguageFactoryService (org.mule.runtime.api.el.DefaultExpressionLanguageFactoryService)1