@Override public void initialise() throws InitialisationException { if (ironManConfig != null) { locator.find(Location.builder().globalName(ironManConfig).build()) .orElseThrow(() -> new IllegalArgumentException("No bean with name " + ironManConfig)); } }
private void removeFromComponentLocator(List<String> locations) { locations.forEach(location -> { componentLocator.removeComponent(builderFromStringRepresentation(location).build()); }); }
/** * {@inheritDoc} */ @Override public Optional<Component> find(Location location) { if (isTemplateLocationFunction.apply(location.getGlobalName())) { return empty(); } return ofNullable(componentsMap.get(location.toString())); }
/** * Utility method that given a {@link Location} creates a new one but ignoring the last part of it. */ public static Location deleteLastPartFromLocation(Location location) { Location.Builder builder = Location.builder(); List<String> parts = location.getParts(); builder = builder.globalName(location.getGlobalName()); for (int i = 0; i < parts.size() - 1; i++) { builder = builder.addPart(parts.get(i)); } return builder.build(); }
/** * Introspect a {@link Location} and indicates if this one is pointing or not to a Connection * * @param location The given {@link Location} to introspect * @return a boolean indicating if the {@link Location} is pointing or not to a Connection */ public static boolean isConnection(Location location) { return !location.getParts().isEmpty() && location.getParts().get(location.getParts().size() - 1).equals(CONNECTION); } }
private void assertConnection(String configName, boolean isSuccess, Matcher<Exception> exceptionMatcher, Matcher<ErrorType> codeMatcher) { ConnectivityTestingService testingService = registry.<ConnectivityTestingService>lookupByName(CONNECTIVITY_TESTING_SERVICE_KEY).get(); ConnectionValidationResult validationResult = testingService.testConnection(builder().globalName(configName).build()); assertThat(validationResult.isValid(), is(isSuccess)); if (!isSuccess) { assertThat(validationResult.getException(), exceptionMatcher); assertThat(validationResult.getErrorType().orElse(null), codeMatcher); } } }
@Override public void onStart(SourceCallback<InputStream, Void> sourceCallback) throws MuleException { if (nextOperationReference != null) { Component proc = locator.find(builderFromStringRepresentation(location.getParts().get(0).getPartPath()).addProcessorsPart() .addIndexPart(0).build()) .orElseThrow(() -> new IllegalArgumentException("Missing processor after this source")); Map<String, Object> parameters = (Map<String, Object>) proc.getAnnotation(ANNOTATION_PARAMETERS); if (!parameters.get("name").equals(nextOperationReference)) { throw new IllegalArgumentException(String.format("Next processor %s does not match the expected operation %s", parameters.get("name"), nextOperationReference)); } } scheduler = schedulerService.cpuLightScheduler(); sourceCallbackHandleTask = scheduler.scheduleAtFixedRate(() -> sourceCallback.handle(Result.<InputStream, Void>builder() .output(new ByteArrayInputStream(getSpellBytes(spell))) .build()), 0, castFrequencyInMillis, MILLISECONDS); }
protected ComponentModel findRequiredComponentModel(Location location) { final Reference<ComponentModel> foundComponentModelReference = new Reference<>(); Optional<ComponentModel> globalComponent = applicationModel.findTopLevelNamedComponent(location.getGlobalName()); globalComponent.ifPresent(componentModel -> findComponentWithLocation(componentModel, location) .ifPresent(foundComponentModel -> foundComponentModelReference.set(foundComponentModel))); if (foundComponentModelReference.get() == null) { throw new NoSuchComponentModelException(createStaticMessage("No object found at location " + location.toString())); } return foundComponentModelReference.get(); }
private Optional<MetadataCacheId> getHashedGlobal(String name) { if (!isBlank(name)) { return locator.get(Location.builder().globalName(name).build()) .map(global -> getIdForComponentMetadata(global).orElse(null)); } return empty(); }
private void assertStrategy(String flowName, BackPressureStrategy expected) { MessageSource source = (MessageSource) componentLocator.find(builderFromStringRepresentation(flowName + "/source").build()).get(); assertThat(source.getBackPressureStrategy(), is(expected)); } }
/** * {@inheritDoc} */ @Override public Optional<Component> find(Location location) { if (isTemplateLocationFunction.apply(location.getGlobalName())) { return empty(); } return ofNullable(componentsMap.get(location.toString())); }
@Override protected Map<String, Object> getStartUpRegistryObjects() { when(componentLocator.find(Location.builder().globalName(APPLE_FLOW).build())).thenReturn(of(mock(Flow.class))); when(configurationProperties.resolveBooleanProperty(MULE_LAZY_INIT_DEPLOYMENT_PROPERTY)).thenReturn(Optional.of(false)); Map<String, Object> registryObjects = new HashMap<>(); registryObjects.put(REGISTRY_KEY, componentLocator); registryObjects.put("_configurationProperties", configurationProperties); return registryObjects; }
private void removeFromComponentLocator(List<String> locations) { locations.forEach(location -> { componentLocator.removeComponent(builderFromStringRepresentation(location).build()); }); }
/** * Triggers the forced execution of the polling message processor ignoring the configured scheduler. */ private void poll() { boolean execute = false; synchronized (this) { if (disallowConcurrentExecution && executing) { execute = false; } else { execute = true; executing = true; } } if (execute) { Message request = of(null); pollWith(request); } else { LOGGER.info("Flow '{}' is already running and 'disallowConcurrentExecution' is set to 'true'. Execution skipped.", flowConstruct.getRootContainerLocation().getGlobalName()); } }
@Override protected Map<String, Object> getStartUpRegistryObjects() { when(componentLocator.find(Location.builder().globalName(APPLE_FLOW).build())).thenReturn(of(mock(Flow.class))); return singletonMap(REGISTRY_KEY, componentLocator); }
private void assertStrategy(String flowName, BackPressureStrategy expected) { MessageSource source = (MessageSource) componentLocator.find(builderFromStringRepresentation(flowName + "/source").build()).get(); assertThat(source.getBackPressureStrategy(), is(expected)); } }
protected ComponentModel findRequiredComponentModel(Location location) { final Reference<ComponentModel> foundComponentModelReference = new Reference<>(); Optional<ComponentModel> globalComponent = applicationModel.findTopLevelNamedComponent(location.getGlobalName()); globalComponent.ifPresent(componentModel -> findComponentWithLocation(componentModel, location) .ifPresent(foundComponentModel -> foundComponentModelReference.set(foundComponentModel))); if (foundComponentModelReference.get() == null) { throw new NoSuchComponentModelException(createStaticMessage("No object found at location " + location.toString())); } return foundComponentModelReference.get(); }
@Stereotype(ReferableOperationStereotypeDefinition.class) public void withFlowReference(@Config DrStrange dr, @Optional @FlowReference String flowRef, @ComponentId String name) { if (!StringUtils.isBlank(flowRef)) { if (!locator.find(Location.builder().globalName(flowRef).build()).isPresent()) { throw new IllegalArgumentException("The referenced flow does not exist in this application"); } } }
@Test public void obtainDisconnectedSourceConfigParameters() throws Exception { Component element = locator.find(Location.builder().globalName("source").addSourcePart().build()).get(); assertThat(element, is(instanceOf(ConfiguredComponent.class))); final ConfigurationInstance configurationInstance = ((ConfiguredComponent) element).getConfigurationInstance().get(); ConfigurationState configurationState = configurationInstance.getState(); assertThat(configurationState.getConfigParameters().size(), is(0)); assertThat(configurationState.getConnectionParameters().size(), is(0)); }
@Before public void setUp() throws Exception { String flowName = "root"; when(completeMessageProcessTemplateAndContext.getMessageSource().getRootContainerLocation()) .thenReturn(Location.builder().globalName(flowName).build()); when(completeMessageProcessTemplateAndContext.getOriginalMessage()).thenReturn(""); when(completeMessageProcessTemplateAndContext.getEvent()).thenReturn(mockEvent); when(registry.lookupByName(flowName)).thenReturn(of(flowConstruct)); when(mockMuleContext.getErrorTypeRepository()).thenReturn(createDefaultErrorTypeRepository()); when(completeMessageProcessTemplateAndContext.getTransactionConfig()).thenReturn(empty()); }