本文整理汇总了Java中rocks.xmpp.core.stanza.model.client.Presence类的典型用法代码示例。如果您正苦于以下问题:Java Presence类的具体用法?Java Presence怎么用?Java Presence使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Presence类属于rocks.xmpp.core.stanza.model.client包,在下文中一共展示了Presence类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: die
import rocks.xmpp.core.stanza.model.client.Presence; //导入依赖的package包/类
private void die(String reason) {
log.info("died:" + reason == null ? "" : reason);
try {
if (xmppSession.isConnected()) {
xmppSession.send(new Presence(Presence.Type.UNAVAILABLE));
}
xmppSession.close();
} catch (XmppException e) {
log.error("failed to die cleanly", e);
throw new IllegalStateException("failed to die cleanly (with presence)");
}
}
示例2: activate
import rocks.xmpp.core.stanza.model.client.Presence; //导入依赖的package包/类
public void activate(final Router router) throws XmppException, InterruptedException, SuspendExecution {
// connect to xmpp
XmppSessionConfiguration configuration = XmppSessionConfiguration.builder().build();
xmppSession = new XmppSession("chat.hipchat.com", configuration);
xmppSession.connect();
xmppSession.login(username, password);
xmppSession.send(new Presence());
// join the rooms
joinRooms(this.rooms);
// send a welcome message
joinedRooms.values().stream()
.forEach(cr -> {
String peeps = String.join(", ", cr.getOccupants().stream()
.filter(x -> !x.isSelf())
.map(Occupant::getNick)
.collect(Collectors.toList()));
cr.sendMessage("Hey " + peeps);
});
log.info("Joined room(s) " + String.join(", ", joinedRooms.keySet()));
// reconnect listener
xmppSession.addSessionStatusListener(e -> {
if (e.getStatus() == XmppSession.Status.AUTHENTICATED) {
try {
joinRooms(this.rooms);
} catch (XmppException e1) {
e1.printStackTrace();
}
} else {
log.info("Received unhandled session status: " + e.getStatus());
}
});
selectMessageLoop(router);
}