I m处理设立一个网络服务,接收通过XMPP发送信息的请求。 然而,所有电文都将从一个账户(服务器记录仪上向用户发送通知)发送。
问题何在——如何执行? 我正试图将XMPPConnection级作为单一州,但我 st忙地向包含东道名称、港口、JID等的建筑商提出论点。
页: 1 因此,我想到的是解决该问题如下(即某种工厂?):
public class XMPPConnectionSingleton
{
private volatile static XMPPConnectionSingleton anInstance;
private volatile static XMPPConnection connection;
public static XMPPConnectionSingleton getInstance() {
if(anInstance == null) {
synchronized (XMPPConnectionSingleton.class) {
if(anInstance == null)
anInstance = new XMPPConnectionSingleton();
}
}
return anInstance;
}
public void init(String server, int port, String jid, String password, String resource)
{
ConnectionConfiguration conf = new ConnectionConfiguration(server, port);
connection = new XMPPConnection(conf);
// logging in, etc.
}
}
Is it a good way to go? Or maybe it is better to make a wrapping class for XMPPConnection, accepting a constructor with no parameters?