Search in sources :

Example 1 with StreamingManager

use of org.mule.runtime.core.api.streaming.StreamingManager in project mule by mulesoft.

the class DefaultPolicyManager method createOperationPolicy.

@Override
public OperationPolicy createOperationPolicy(Component operation, CoreEvent event, Map<String, Object> operationParameters, OperationExecutionFunction operationExecutionFunction) {
    PolicyPointcutParameters operationPointcutParameters = policyPointcutParametersManager.createOperationPointcutParameters(operation, event, operationParameters);
    List<Policy> parameterizedPolicies = policyProvider.findOperationParameterizedPolicies(operationPointcutParameters);
    if (parameterizedPolicies.isEmpty()) {
        return (operationEvent) -> operationExecutionFunction.execute(operationParameters, operationEvent);
    }
    return new CompositeOperationPolicy(parameterizedPolicies, lookupOperationParametersTransformer(operation.getLocation().getComponentIdentifier().getIdentifier()), operationPolicyProcessorFactory, () -> operationParameters, operationExecutionFunction, streamingManager);
}
Also used : Policy(org.mule.runtime.core.api.policy.Policy) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) Processor(org.mule.runtime.core.api.processor.Processor) StreamingManager(org.mule.runtime.core.api.streaming.StreamingManager) Inject(javax.inject.Inject) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) MuleContext(org.mule.runtime.core.api.MuleContext) MessageProcessors.process(org.mule.runtime.core.privileged.processor.MessageProcessors.process) Component(org.mule.runtime.api.component.Component) Map(java.util.Map) Mono.from(reactor.core.publisher.Mono.from) Mono.just(reactor.core.publisher.Mono.just) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) SourcePolicyPointcutParametersFactory(org.mule.runtime.policy.api.SourcePolicyPointcutParametersFactory) PolicyStateHandler(org.mule.runtime.core.api.policy.PolicyStateHandler) SourcePolicyParametersTransformer(org.mule.runtime.core.api.policy.SourcePolicyParametersTransformer) Collections.emptyList(java.util.Collections.emptyList) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Message.of(org.mule.runtime.api.message.Message.of) Initialisable(org.mule.runtime.api.lifecycle.Initialisable) OperationPolicyParametersTransformer(org.mule.runtime.core.api.policy.OperationPolicyParametersTransformer) Either.right(org.mule.runtime.core.api.functional.Either.right) Either(org.mule.runtime.core.api.functional.Either) PolicyProvider(org.mule.runtime.core.api.policy.PolicyProvider) List(java.util.List) Policy(org.mule.runtime.core.api.policy.Policy) PolicyPointcutParameters(org.mule.runtime.policy.api.PolicyPointcutParameters) Optional(java.util.Optional) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) MuleRegistry(org.mule.runtime.core.internal.registry.MuleRegistry) OperationPolicyPointcutParametersFactory(org.mule.runtime.policy.api.OperationPolicyPointcutParametersFactory) PolicyPointcutParameters(org.mule.runtime.policy.api.PolicyPointcutParameters)

Example 2 with StreamingManager

use of org.mule.runtime.core.api.streaming.StreamingManager 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 3 with StreamingManager

use of org.mule.runtime.core.api.streaming.StreamingManager in project mule by mulesoft.

the class MuleContextUtils method mockMuleContext.

public static MuleContextWithRegistries mockMuleContext() {
    final MuleContextWithRegistries muleContext = mock(DefaultMuleContext.class, withSettings().defaultAnswer(RETURNS_DEEP_STUBS).extraInterfaces(PrivilegedMuleContext.class));
    when(muleContext.getUniqueIdString()).thenReturn(UUID.getUUID());
    when(muleContext.getDefaultErrorHandler(empty())).thenReturn(new OnErrorPropagateHandler());
    StreamingManager streamingManager = mock(StreamingManager.class, RETURNS_DEEP_STUBS);
    try {
        MuleRegistry registry = mock(MuleRegistry.class);
        when(muleContext.getRegistry()).thenReturn(registry);
        ComponentInitialStateManager componentInitialStateManager = mock(ComponentInitialStateManager.class);
        when(componentInitialStateManager.mustStartMessageSource(any())).thenReturn(true);
        when(registry.lookupObject(ComponentInitialStateManager.SERVICE_ID)).thenReturn(componentInitialStateManager);
        doReturn(streamingManager).when(registry).lookupObject(StreamingManager.class);
        doReturn(mock(NotificationDispatcher.class)).when(registry).lookupObject(NotificationDispatcher.class);
        doReturn(mock(ObjectStoreManager.class, RETURNS_DEEP_STUBS)).when(registry).lookupObject(OBJECT_STORE_MANAGER);
    } catch (RegistrationException e) {
        throw new RuntimeException(e);
    }
    return muleContext;
}
Also used : ComponentInitialStateManager(org.mule.runtime.api.deployment.management.ComponentInitialStateManager) RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) ObjectStoreManager(org.mule.runtime.api.store.ObjectStoreManager) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) StreamingManager(org.mule.runtime.core.api.streaming.StreamingManager) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) NotificationDispatcher(org.mule.runtime.api.notification.NotificationDispatcher) MuleRegistry(org.mule.runtime.core.internal.registry.MuleRegistry) OnErrorPropagateHandler(org.mule.runtime.core.internal.exception.OnErrorPropagateHandler) PrivilegedMuleContext(org.mule.runtime.core.privileged.PrivilegedMuleContext)

Example 4 with StreamingManager

use of org.mule.runtime.core.api.streaming.StreamingManager in project mule by mulesoft.

the class CompositeOperationPolicyTestCase method singlePolicy.

@Test
public void singlePolicy() throws Exception {
    compositeOperationPolicy = new CompositeOperationPolicy(asList(firstPolicy), operationPolicyParametersTransformer, operationPolicyProcessorFactory, operationParametersProcessor, operationExecutionFunction, streamingManager);
    CoreEvent result = from(compositeOperationPolicy.process(initialEvent)).doOnNext(event1 -> System.out.println("FINAL " + event1.getMessage().getPayload().getValue())).block();
    assertThat(result.getMessage(), is(nextProcessResultEvent.getMessage()));
    verify(operationExecutionFunction).execute(any(), same(initialEvent));
    verify(operationPolicyProcessorFactory).createOperationPolicy(same(firstPolicy), any());
    verify(firstPolicyOperationPolicyProcessor).apply(any());
}
Also used : Matchers.same(org.mockito.Matchers.same) Message(org.mule.runtime.api.message.Message) Optional.of(java.util.Optional.of) Processor(org.mule.runtime.core.api.processor.Processor) StreamingManager(org.mule.runtime.core.api.streaming.StreamingManager) Assert.assertThat(org.junit.Assert.assertThat) AbstractMuleTestCase(org.mule.tck.junit4.AbstractMuleTestCase) MuleException(org.mule.runtime.api.exception.MuleException) Arrays.asList(java.util.Arrays.asList) Is.is(org.hamcrest.core.Is.is) ExpectedException.none(org.junit.rules.ExpectedException.none) Mono.from(reactor.core.publisher.Mono.from) Mono.just(reactor.core.publisher.Mono.just) RETURNS_DEEP_STUBS(org.mockito.Mockito.RETURNS_DEEP_STUBS) Mono.error(reactor.core.publisher.Mono.error) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) Collections.emptyList(java.util.Collections.emptyList) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) EventContextFactory.create(org.mule.runtime.core.api.event.EventContextFactory.create) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) OperationPolicyParametersTransformer(org.mule.runtime.core.api.policy.OperationPolicyParametersTransformer) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) Rule(org.junit.Rule) Exceptions.rxExceptionToMuleException(org.mule.runtime.core.api.rx.Exceptions.rxExceptionToMuleException) Policy(org.mule.runtime.core.api.policy.Policy) Optional(java.util.Optional) DefaultComponentLocation.fromSingleComponent(org.mule.runtime.dsl.api.component.config.DefaultComponentLocation.fromSingleComponent) FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) Mockito.mock(org.mockito.Mockito.mock) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Test(org.junit.Test)

Aggregations

StreamingManager (org.mule.runtime.core.api.streaming.StreamingManager)4 MuleContextWithRegistries (org.mule.runtime.core.internal.context.MuleContextWithRegistries)3 MuleRegistry (org.mule.runtime.core.internal.registry.MuleRegistry)3 Collections.emptyList (java.util.Collections.emptyList)2 Optional (java.util.Optional)2 Component (org.mule.runtime.api.component.Component)2 ComponentInitialStateManager (org.mule.runtime.api.deployment.management.ComponentInitialStateManager)2 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)2 OperationPolicyParametersTransformer (org.mule.runtime.core.api.policy.OperationPolicyParametersTransformer)2 Policy (org.mule.runtime.core.api.policy.Policy)2 Processor (org.mule.runtime.core.api.processor.Processor)2 Arrays.asList (java.util.Arrays.asList)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Optional.of (java.util.Optional.of)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Inject (javax.inject.Inject)1 Is.is (org.hamcrest.core.Is.is)1 Assert.assertThat (org.junit.Assert.assertThat)1