org.nlab.smtp.transport.strategy.ConnectionStrategyFactory Maven / Gradle / Ivy
Show all versions of smtp-connection-pool Show documentation
package org.nlab.smtp.transport.strategy;
import jakarta.mail.MessagingException;
import jakarta.mail.Transport;
/**
* {@link Transport} supports actually 4 types of connections which are handled by this connection strategy factory
*
* - {@link Transport#connect()} => {@link #newConnectionStrategy()}
* - {@link Transport#connect(String, String)} ()} => {@link #newConnectionStrategy(String, String)}
* - {@link Transport#connect(String, String, String)} ()} => {@link #newConnectionStrategy(String, String, String)}
* - {@link Transport#connect(String, int, String, String)} ()} => {@link #newConnectionStrategy(String, int, String, String)}
*
*
* Created by nlabrot on 04/06/15.
*/
public class ConnectionStrategyFactory {
public static ConnectionStrategy newConnectionStrategy() {
return new ConnectionStrategy() {
@Override
public void connect(Transport transport) throws MessagingException {
transport.connect();
}
};
}
public static ConnectionStrategy newConnectionStrategy(final String username, final String password) {
return new ConnectionStrategy() {
@Override
public void connect(Transport transport) throws MessagingException {
transport.connect(username, password);
}
@Override
public String toString() {
return "ConnectionStrategy{" +
"username=" + username +
'}';
}
};
}
public static ConnectionStrategy newConnectionStrategy(final String host, final String username, final String password) {
return new ConnectionStrategy() {
@Override
public void connect(Transport transport) throws MessagingException {
transport.connect(host, username, password);
}
@Override
public String toString() {
return "ConnectionStrategy{" +
"host=" + host +
", username=" + username +
'}';
}
};
}
public static ConnectionStrategy newConnectionStrategy(final String host, final int port, final String username, final String password) {
return new ConnectionStrategy() {
@Override
public void connect(Transport transport) throws MessagingException {
transport.connect(host, port, username, password);
}
@Override
public String toString() {
return "ConnectionStrategy{" +
"host=" + host +
", port=" + port +
", username=" + username +
'}';
}
};
}
}