io.camunda.zeebe.transport.TransportFactory Maven / Gradle / Ivy
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under
* one or more contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright ownership.
* Licensed under the Camunda License 1.0. You may not use this file
* except in compliance with the Camunda License 1.0.
*/
package io.camunda.zeebe.transport;
import io.atomix.cluster.messaging.ClusterCommunicationService;
import io.atomix.cluster.messaging.MessagingService;
import io.camunda.zeebe.scheduler.ActorSchedulingService;
import io.camunda.zeebe.transport.impl.AtomixClientTransportAdapter;
import io.camunda.zeebe.transport.impl.AtomixServerTransport;
import io.camunda.zeebe.transport.stream.api.ClientStreamMetrics;
import io.camunda.zeebe.transport.stream.api.ClientStreamService;
import io.camunda.zeebe.transport.stream.api.RemoteStreamErrorHandler;
import io.camunda.zeebe.transport.stream.api.RemoteStreamMetrics;
import io.camunda.zeebe.transport.stream.api.RemoteStreamService;
import io.camunda.zeebe.transport.stream.impl.ClientStreamServiceImpl;
import io.camunda.zeebe.transport.stream.impl.RemoteStreamApiHandler;
import io.camunda.zeebe.transport.stream.impl.RemoteStreamRegistry;
import io.camunda.zeebe.transport.stream.impl.RemoteStreamServiceImpl;
import io.camunda.zeebe.transport.stream.impl.RemoteStreamTransport;
import io.camunda.zeebe.transport.stream.impl.RemoteStreamerImpl;
import io.camunda.zeebe.util.buffer.BufferWriter;
import java.util.function.Function;
import org.agrona.DirectBuffer;
import org.agrona.concurrent.IdGenerator;
public final class TransportFactory {
private final ActorSchedulingService actorSchedulingService;
public TransportFactory(final ActorSchedulingService actorSchedulingService) {
this.actorSchedulingService = actorSchedulingService;
}
public ServerTransport createServerTransport(
final MessagingService messagingService, final IdGenerator requestIdGenerator) {
final var atomixServerTransport =
new AtomixServerTransport(messagingService, requestIdGenerator);
actorSchedulingService.submitActor(atomixServerTransport);
return atomixServerTransport;
}
public ClientTransport createClientTransport(final MessagingService messagingService) {
final var atomixClientTransportAdapter = new AtomixClientTransportAdapter(messagingService);
actorSchedulingService.submitActor(atomixClientTransportAdapter);
return atomixClientTransportAdapter;
}
public RemoteStreamService createRemoteStreamServer(
final ClusterCommunicationService clusterCommunicationService,
final Function metadataFactory,
final RemoteStreamErrorHandler errorHandler,
final RemoteStreamMetrics metrics) {
final RemoteStreamRegistry registry = new RemoteStreamRegistry<>(metrics);
return new RemoteStreamServiceImpl<>(
new RemoteStreamerImpl<>(clusterCommunicationService, registry, errorHandler, metrics),
new RemoteStreamTransport<>(
clusterCommunicationService, new RemoteStreamApiHandler<>(registry, metadataFactory)),
registry);
}
public ClientStreamService createRemoteStreamClient(
final ClusterCommunicationService clusterCommunicationService,
final ClientStreamMetrics metrics) {
return new ClientStreamServiceImpl<>(clusterCommunicationService, metrics);
}
}