Skip to content

Commit

Permalink
MID-7484: Transport.init() renamed to configure() and javadoc added
Browse files Browse the repository at this point in the history
  • Loading branch information
virgo47 committed Feb 21, 2022
1 parent 110e601 commit 7cb4669
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public String debugDump(int indent) {
}

@Override
public void init(@NotNull GeneralTransportConfigurationType configuration, @NotNull TransportSupport transportSupport) {
public void configure(@NotNull GeneralTransportConfigurationType configuration, @NotNull TransportSupport transportSupport) {
// not called for legacy transport component
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
*/
public interface Transport<C extends GeneralTransportConfigurationType> {

/**
* Configures transport instance - this must be fast and exception free.
* This is not the place to start any connections or sessions; this is called after sysconfig is changed.
*
* @param configuration portion of the configuration relevant to this transport
* @param transportSupport support object with dependencies
*/
void configure(@NotNull C configuration, @NotNull TransportSupport transportSupport);

/**
* Sends the message via this transport.
*
Expand All @@ -41,6 +50,4 @@ public interface Transport<C extends GeneralTransportConfigurationType> {

// not-null for new transports, but legacy transports return null (remove after 4.6 cleanup if that happens)
C getConfiguration();

void init(@NotNull C configuration, @NotNull TransportSupport transportSupport);
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public class CustomMessageTransport implements Transport<CustomTransportConfigur
private TransportSupport transportSupport;

@Override
public void init(@NotNull CustomTransportConfigurationType configuration, @NotNull TransportSupport transportSupport) {
public void configure(
@NotNull CustomTransportConfigurationType configuration,
@NotNull TransportSupport transportSupport) {
this.configuration = Objects.requireNonNull(configuration);
name = Objects.requireNonNull(configuration.getName());
this.transportSupport = Objects.requireNonNull(transportSupport);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import static com.evolveum.midpoint.transport.impl.TransportUtil.formatToFileNew;

import java.util.Objects;

import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.notifications.api.events.Event;
Expand Down Expand Up @@ -36,9 +38,11 @@ public class FileMessageTransport implements Transport<FileTransportConfiguratio
private FileTransportConfigurationType configuration;

@Override
public void init(@NotNull FileTransportConfigurationType configuration, @NotNull TransportSupport transportSupport) {
this.configuration = java.util.Objects.requireNonNull(configuration);
name = java.util.Objects.requireNonNull(configuration.getName());
public void configure(
@NotNull FileTransportConfigurationType configuration,
@NotNull TransportSupport transportSupport) {
this.configuration = Objects.requireNonNull(configuration);
name = Objects.requireNonNull(configuration.getName());
// transportSupport not needed here
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import java.util.Objects;
import java.util.*;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
Expand Down Expand Up @@ -61,9 +59,11 @@ public class MailMessageTransport implements Transport<MailTransportConfiguratio
private TransportSupport transportSupport;

@Override
public void init(@NotNull MailTransportConfigurationType configuration, @NotNull TransportSupport transportSupport) {
this.configuration = java.util.Objects.requireNonNull(configuration);
name = java.util.Objects.requireNonNull(configuration.getName());
public void configure(
@NotNull MailTransportConfigurationType configuration,
@NotNull TransportSupport transportSupport) {
this.configuration = Objects.requireNonNull(configuration);
name = Objects.requireNonNull(configuration.getName());
this.transportSupport = transportSupport;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import javax.xml.namespace.QName;

Expand Down Expand Up @@ -75,9 +76,11 @@ public class SmsMessageTransport implements Transport<SmsTransportConfigurationT
private TransportSupport transportSupport;

@Override
public void init(@NotNull SmsTransportConfigurationType configuration, @NotNull TransportSupport transportSupport) {
this.configuration = java.util.Objects.requireNonNull(configuration);
name = java.util.Objects.requireNonNull(configuration.getName());
public void configure(
@NotNull SmsTransportConfigurationType configuration,
@NotNull TransportSupport transportSupport) {
this.configuration = Objects.requireNonNull(configuration);
name = Objects.requireNonNull(configuration.getName());
this.transportSupport = transportSupport;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private void createCustomTransport(CustomTransportConfigurationType customConfig
Transport<CustomTransportConfigurationType> transport = className != null
? (Transport<CustomTransportConfigurationType>) Class.forName(className).getConstructor().newInstance()
: new CustomMessageTransport();
transport.init(customConfig, transportSupport);
transport.configure(customConfig, transportSupport);
registerTransport(transport);
transportsFromSysConfig.add(transport.getName());
} catch (ReflectiveOperationException | ClassCastException e) {
Expand All @@ -202,7 +202,7 @@ private <C extends GeneralTransportConfigurationType> void createTransport(
return;
}
Transport<C> transport = transportSupplier.get();
transport.init(transportConfig, transportSupport);
transport.configure(transportConfig, transportSupport);
registerTransport(transport);
transportsFromSysConfig.add(transport.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public String getName() {
}

@Override
public void init(@NotNull GeneralTransportConfigurationType configuration, @NotNull TransportSupport transportSupport) {
public void configure(@NotNull GeneralTransportConfigurationType configuration, @NotNull TransportSupport transportSupport) {
// not called for legacy transport component
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public String getName() {
}

@Override
public void init(@NotNull GeneralTransportConfigurationType configuration, @NotNull TransportSupport transportSupport) {
public void configure(@NotNull GeneralTransportConfigurationType configuration, @NotNull TransportSupport transportSupport) {
// not called for legacy transport component
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public String getName() {
}

@Override
public void init(@NotNull GeneralTransportConfigurationType configuration, @NotNull TransportSupport transportSupport) {
public void configure(@NotNull GeneralTransportConfigurationType configuration, @NotNull TransportSupport transportSupport) {
// not called for legacy transport component
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ public String getName() {
}

@Override
public void init(@NotNull GeneralTransportConfigurationType configuration, @NotNull TransportSupport transportSupport) {
public void configure(@NotNull GeneralTransportConfigurationType configuration, @NotNull TransportSupport transportSupport) {
// not called for legacy transport component
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* This is only useful for the simplest cases without using system configuration.
* * Specifying its class name for custom transport and calling sysconfig modify.
* In this case the change will cause transport service to register the transport
* and its {@link #init} method will be called.
* and its {@link #configure} method will be called.
* The instance then can be obtained by {@link TransportService#getTransport}.
*
* Afterwards, use {@link #getMessages()} and {@link #clearMessages()} as needed.
Expand Down Expand Up @@ -84,7 +84,7 @@ public String getName() {
}

@Override
public void init(@NotNull CustomTransportConfigurationType configuration, @NotNull TransportSupport transportSupport) {
public void configure(@NotNull CustomTransportConfigurationType configuration, @NotNull TransportSupport transportSupport) {
this.configuration = configuration;
name = configuration.getName();
}
Expand Down

0 comments on commit 7cb4669

Please sign in to comment.