Fasel/fasel-jfx/src/main/java/de/vanitasvitae/fasel/xmpp/XmppConnectionService.java

48 lines
1.5 KiB
Java

package de.vanitasvitae.fasel.xmpp;
import java.io.IOException;
import java.util.Map;
import java.util.WeakHashMap;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import de.vanitasvitae.fasel.db.entity.Account;
import org.jxmpp.stringprep.XmppStringprepException;
public final class XmppConnectionService {
private final XMPPTCPConnection connection;
private static final Map<Account, XmppConnectionService> CONNECTIONS = new WeakHashMap<>();
public static XmppConnectionService connectionForAccount(Account account) throws XmppStringprepException {
XmppConnectionService connection = CONNECTIONS.get(account);
if (connection == null) {
connection = new XmppConnectionService(account.getUsername(), account.getServiceAddress(), account.getPassword());
CONNECTIONS.put(account, connection);
}
return connection;
}
private XmppConnectionService(String username, String serverAddress, String password)
throws XmppStringprepException {
connection = new XMPPTCPConnection(username, password, serverAddress);
}
public XMPPConnection getConnection() {
return connection;
}
public void login() throws InterruptedException, IOException, SmackException, XMPPException {
connection.connect();
connection.login();
}
public void attachDatabase() {
}
}