当前位置: 首页>>代码示例>>Java>>正文


Java Presence类代码示例

本文整理汇总了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)");
        }
    }
 
开发者ID:ninjabear,项目名称:marissa-java,代码行数:18,代码来源:Marissa.java

示例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);

    }
 
开发者ID:ninjabear,项目名称:marissa-java,代码行数:52,代码来源:Marissa.java


注:本文中的rocks.xmpp.core.stanza.model.client.Presence类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。