private void onReconnectionSuccessful() { if (LOGGER.isDebugEnabled()) { LOGGER.warn("Message source '{}' on root component '{}' successfully reconnected", sourceAdapter.getName(), getLocation().getRootContainerName()); } }
private void onReconnectionFailed(Throwable exception) { LOGGER.error(format("Message source '%s' on root component '%s' could not be reconnected. Will be shutdown. %s", sourceAdapter.getName(), getLocation().getRootContainerName(), exception.getMessage()), exception); shutdown(); }
private void doCallback(byte[] startData, long startDataSize, byte[] endData, long endDataSize, long endRingPointer, long streamLength, CoreEvent event) throws Exception { // make a nice summary of the data StringBuilder result = new StringBuilder("Received stream"); result.append("; length: "); result.append(streamLength); result.append("; '"); for (long i = 0; i < startDataSize; ++i) { result.append((char) startData[(int) i]); } long endSize = Math.min(endDataSize, STREAM_SAMPLE_SIZE); if (endSize > 0) { result.append("..."); for (long i = 0; i < endSize; ++i) { result.append((char) endData[(int) ((endRingPointer + i) % STREAM_SAMPLE_SIZE)]); } } result.append("'"); summary = result.toString(); String msg = getBoilerPlate("Message Received in service: " + this.getLocation().getRootContainerName() + ". " + summary + "\n callback: " + eventCallback, '*', 80); logger.info(msg); if (eventCallback != null) { eventCallback.eventReceived(event, this, muleContext); } }
protected FunctionalTestNotification buildEventReceivedNotification(final Message message, CoreEvent replyMessage) throws TransformerException { return new FunctionalTestNotification(message, getLocation().getRootContainerName(), replyMessage, EVENT_RECEIVED); }
private void shutdown() { try { stopIfNeeded(this); } catch (Exception e) { LOGGER .error(format("Failed to stop source '%s' on flow '%s'", sourceAdapter.getName(), getLocation().getRootContainerName()), e); } disposeIfNeeded(this, LOGGER); }
private void restart() throws MuleException { synchronized (started) { if (started.get()) { stopSource(); disposeSource(); startSource(); } else { LOGGER.warn(format("Message source '%s' on root component '%s' is stopped. Not doing restart", sourceAdapter.getName(), getLocation().getRootContainerName())); } } }
/** * @param event a {@link CoreEvent} * @return a configuration instance for the current component with a given {@link CoreEvent} */ protected Optional<ConfigurationInstance> getConfiguration(CoreEvent event) { if (!requiresConfig.get()) { return empty(); } if (isConfigurationSpecified()) { return of(configurationProvider.get()) .map(provider -> ofNullable(provider.get(event))) .orElseThrow(() -> new IllegalModelDefinitionException(format( "Root component '%s' contains a reference to config '%s' but it doesn't exists", getLocation().getRootContainerName(), configurationProvider))); } return getDefaultConfiguraiton(event); }
private void stopSource() throws MuleException { if (sourceAdapter != null) { try { sourceAdapter.stop(); } catch (Exception e) { throw new DefaultMuleException(format("Found exception stopping source '%s' of root component '%s'", sourceAdapter.getName(), getLocation().getRootContainerName()), e); } } }
protected boolean isTargetPresent() { if (isBlank(target)) { return false; } if (muleContext.getExpressionManager().isExpression(target)) { throw new IllegalOperationException(format(INVALID_TARGET_MESSAGE, getLocation().getRootContainerName(), componentModel.getName(), "an expression", TARGET_PARAMETER_NAME)); } else if (!muleContext.getExpressionManager().isExpression(targetValue)) { throw new IllegalOperationException(format(INVALID_TARGET_MESSAGE, getLocation().getRootContainerName(), componentModel.getName(), "something that is not an expression", TARGET_VALUE_PARAMETER_NAME)); } return true; }
private void setConnection() throws MuleException { if (!connectionSetter.isPresent()) { return; } FieldSetter<Object, ConnectionProvider> setter = connectionSetter.get(); ConfigurationInstance config = configurationInstance.orElseThrow(() -> new DefaultMuleException(createStaticMessage( "Message Source on root component '%s' requires a connection but it doesn't point to any configuration. Please review your " + "application", component .getLocation() .getRootContainerName()))); if (!config.getConnectionProvider().isPresent()) { throw new DefaultMuleException(createStaticMessage(format( "Message Source on root component '%s' requires a connection, but points to config '%s' which doesn't specify any. " + "Please review your application", component.getLocation().getRootContainerName(), config.getName()))); } ConnectionProvider<Object> connectionProvider = new SourceConnectionProvider(connectionManager, config); setter.set(sourceInvokationTarget.get(), connectionProvider); }
@Override public void start() throws InitialisationException { super.start(); ValidationResult result = this.expressionManager.validate(responseExpression); if (!result.isSuccess()) { throw new InvalidExpressionException(expression, result.errorMessage().orElse("Invalid expression")); } responseLatch = new CountDownLatch(responseCount); addAssertion(getLocation().getRootContainerName(), this); }
private void validateConfigurationProviderIsNotExpression() throws InitialisationException { if (isConfigurationSpecified() && expressionParser.isContainsTemplate(configurationProvider.get().getName())) { throw new InitialisationException( createStaticMessage( format("Root component '%s' defines component '%s' which specifies the expression '%s' as a config-ref. " + "Expressions are not allowed as config references", getLocation().getRootContainerName(), hyphenize(componentModel.getName()), configurationProvider)), this); } }
@Override public void doDispose() { try { safeLifecycle(() -> lifecycleManager.fireDisposePhase((phase, o) -> { disposeSource(); stopIfNeeded(retryPolicyTemplate); disposeIfNeeded(retryPolicyTemplate, LOGGER); stopSchedulers(); })); } catch (MuleException e) { LOGGER.warn(format("Failed to dispose message source at root element '%s'. %s", getLocation().getRootContainerName(), e.getMessage()), e); } }
@Before public void before() { when(notificationManager.isNotificationEnabled(any(Class.class))).thenReturn(true); when(muleContext.getNotificationManager()).thenReturn(notificationManager); phase.setMuleContext(muleContext); Registry registry = mock(Registry.class); when(registry.lookupByName(any())).thenReturn(of(this.flowConstruct)); phase.setRegistry(registry); ComponentLocation mockComponentLocation = mock(ComponentLocation.class); when(mockComponentLocation.getRootContainerName()).thenReturn("root"); when(messageSource.getLocation()).thenReturn(mockComponentLocation); when(mockContext.getTransactionConfig()).thenReturn(empty()); when(mockContext.getMessageSource()).thenReturn(messageSource); }
private String getRootContainerName() { String rootContainerName = (String) getAnnotation(ROOT_CONTAINER_NAME_KEY); if (rootContainerName == null) { rootContainerName = getLocation().getRootContainerName(); } return rootContainerName; }
/** * Validates if the current source is valid for the set configuration. In case that the validation fails, the method will throw * a {@link IllegalSourceException} */ @Override protected void validateOperationConfiguration(ConfigurationProvider configurationProvider) { ConfigurationModel configurationModel = configurationProvider.getConfigurationModel(); if (!configurationModel.getSourceModel(sourceModel.getName()).isPresent() && !configurationProvider.getExtensionModel().getSourceModel(sourceModel.getName()).isPresent()) { throw new IllegalSourceException(format( "Root component '%s' defines an usage of operation '%s' which points to configuration '%s'. " + "The selected config does not support that operation.", getLocation().getRootContainerName(), sourceModel.getName(), configurationProvider.getName())); } }
/** * Validates that the {@link #componentModel} is valid for the given {@code configurationProvider} * * @throws IllegalOperationException If the validation fails */ @Override protected void validateOperationConfiguration(ConfigurationProvider configurationProvider) { ConfigurationModel configurationModel = configurationProvider.getConfigurationModel(); if (!configurationModel.getOperationModel(componentModel.getName()).isPresent() && !configurationProvider.getExtensionModel().getOperationModel(componentModel.getName()).isPresent()) { throw new IllegalOperationException(format( "Root component '%s' defines an usage of operation '%s' which points to configuration '%s'. " + "The selected config does not support that operation.", getLocation().getRootContainerName(), componentModel.getName(), configurationProvider.getName())); } }
getLocation().getRootContainerName(), exception.getMessage())), exception); sourceAdapter.getName(), getLocation().getRootContainerName()), exception);
@Test public void injectedComponentLocation() throws Exception { new PollingProber(5000, 50) .check(new JUnitLambdaProbe(() -> { ComponentLocation location = SentientSource.capturedLocation; assertThat(location, is(notNullValue())); assertThat(location.getRootContainerName(), equalTo("sentient")); return true; })); }
@Override public void onStart(SourceCallback<T, A> sourceCallback) throws MuleException { delegate.onStart(sourceCallback); flowName = componentLocation.getRootContainerName(); keyPrefix = "_pollingSource_" + flowName + "/"; inflightIdsObjectStore = objectStoreManager.getOrCreateObjectStore(formatKey("inflight-ids"), ObjectStoreSettings.builder() .persistent(false) .maxEntries(1000) .entryTtl(60000L) .expirationInterval(20000L) .build()); recentlyProcessedIds = objectStoreManager.getOrCreateObjectStore(formatKey("recently-processed-ids"), unmanagedPersistent()); idsOnUpdatedWatermark = objectStoreManager.getOrCreateObjectStore(formatKey("ids-on-updated-watermark"), unmanagedPersistent()); watermarkObjectStore = objectStoreManager.getOrCreateObjectStore(formatKey("watermark"), unmanagedPersistent()); executor = schedulerService.customScheduler(SchedulerConfig.config() .withMaxConcurrentTasks(1) .withWaitAllowed(true) .withName(formatKey("executor"))); stopRequested.set(false); scheduler.schedule(executor, () -> poll(sourceCallback)); }