io.camunda.zeebe.spring.client.jobhandling.JobHandlerInvokingSpringBeans Maven / Gradle / Ivy
/*
* Copyright © 2017 camunda services GmbH ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.camunda.zeebe.spring.client.jobhandling;
import io.camunda.zeebe.client.api.command.CompleteJobCommandStep1;
import io.camunda.zeebe.client.api.command.FinalCommandStep;
import io.camunda.zeebe.client.api.command.ThrowErrorCommandStep1.ThrowErrorCommandStep2;
import io.camunda.zeebe.client.api.response.ActivatedJob;
import io.camunda.zeebe.client.api.worker.JobClient;
import io.camunda.zeebe.client.api.worker.JobHandler;
import io.camunda.zeebe.client.impl.Loggers;
import io.camunda.zeebe.spring.client.annotation.value.ZeebeWorkerValue;
import io.camunda.zeebe.spring.client.jobhandling.parameter.ParameterResolver;
import io.camunda.zeebe.spring.client.jobhandling.parameter.ParameterResolverStrategy;
import io.camunda.zeebe.spring.client.jobhandling.result.ResultProcessor;
import io.camunda.zeebe.spring.client.jobhandling.result.ResultProcessorStrategy;
import io.camunda.zeebe.spring.client.metrics.MetricsRecorder;
import io.camunda.zeebe.spring.common.exception.ZeebeBpmnError;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
/** Zeebe JobHandler that invokes a Spring bean */
public class JobHandlerInvokingSpringBeans implements JobHandler {
private static final Logger LOG = Loggers.JOB_WORKER_LOGGER;
private final ZeebeWorkerValue workerValue;
private final CommandExceptionHandlingStrategy commandExceptionHandlingStrategy;
private final MetricsRecorder metricsRecorder;
private final List parameterResolvers;
private final ResultProcessor resultProcessor;
public JobHandlerInvokingSpringBeans(
final ZeebeWorkerValue workerValue,
final CommandExceptionHandlingStrategy commandExceptionHandlingStrategy,
final MetricsRecorder metricsRecorder,
final ParameterResolverStrategy parameterResolverStrategy,
final ResultProcessorStrategy resultProcessorStrategy) {
this.workerValue = workerValue;
this.commandExceptionHandlingStrategy = commandExceptionHandlingStrategy;
this.metricsRecorder = metricsRecorder;
parameterResolvers = createParameterResolvers(parameterResolverStrategy);
resultProcessor = createResultProcessor(resultProcessorStrategy);
}
private List createParameterResolvers(
final ParameterResolverStrategy parameterResolverStrategy) {
return workerValue.getMethodInfo().getParameters().stream()
.map(parameterResolverStrategy::createResolver)
.toList();
}
private ResultProcessor createResultProcessor(
final ResultProcessorStrategy resultProcessorStrategy) {
return resultProcessorStrategy.createProcessor(workerValue.getMethodInfo().getReturnType());
}
@Override
public void handle(final JobClient jobClient, final ActivatedJob job) throws Exception {
final List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy