predicate java_Java Predicate类代码示例

import org.jivesoftware.smack.sm.predicates.Predicate; //导入依赖的package包/类

@Override

protected synchronized void loginInternal(String username, String password, Resourcepart resource) throws XMPPException,

SmackException, IOException, InterruptedException {

// Authenticate using SASL

SSLSession sslSession = secureSocket != null ? secureSocket.getSession() : null;

saslAuthentication.authenticate(username, password, config.getAuthzid(), sslSession);

// If compression is enabled then request the server to use stream compression. XEP-170

// recommends to perform stream compression before resource binding.

maybeEnableCompression();

if (isSmResumptionPossible()) {

smResumedSyncPoint.sendAndWaitForResponse(new Resume(clientHandledStanzasCount, smSessionId));

if (smResumedSyncPoint.wasSuccessful()) {

// We successfully resumed the stream, be done here

afterSuccessfulLogin(true);

return;

}

// SM resumption failed, what Smack does here is to report success of

// lastFeaturesReceived in case of sm resumption was answered with 'failed' so that

// normal resource binding can be tried.

LOGGER.fine("Stream resumption failed, continuing with normal stream establishment process");

}

List previouslyUnackedStanzas = new LinkedList();

if (unacknowledgedStanzas != null) {

// There was a previous connection with SM enabled but that was either not resumable or

// failed to resume. Make sure that we (re-)send the unacknowledged stanzas.

unacknowledgedStanzas.drainTo(previouslyUnackedStanzas);

// Reset unacknowledged stanzas to 'null' to signal that we never send 'enable' in this

// XMPP session (There maybe was an enabled in a previous XMPP session of this

// connection instance though). This is used in writePackets to decide if stanzas should

// be added to the unacknowledged stanzas queue, because they have to be added right

// after the 'enable' stream element has been sent.

dropSmState();

}

// Now bind the resource. It is important to do this *after* we dropped an eventually

// existing Stream Management state. As otherwise and may end up in

// unacknowledgedStanzas and become duplicated on reconnect. See SMACK-706.

bindResourceAndEstablishSession(resource);

if (isSmAvailable() && useSm) {

// Remove what is maybe left from previously stream managed sessions

serverHandledStanzasCount = 0;

// XEP-198 3. Enabling Stream Management. If the server response to 'Enable' is 'Failed'

// then this is a non recoverable error and we therefore throw an exception.

smEnabledSyncPoint.sendAndWaitForResponseOrThrow(new Enable(useSmResumption, smClientMaxResumptionTime));

synchronized (requestAckPredicates) {

if (requestAckPredicates.isEmpty()) {

// Assure that we have at lest one predicate set up that so that we request acks

// for the server and eventually flush some stanzas from the unacknowledged

// stanza queue

requestAckPredicates.add(Predicate.forMessagesOrAfter5Stanzas());

}

}

}

// (Re-)send the stanzas *after* we tried to enable SM

for (Stanza stanza : previouslyUnackedStanzas) {

sendStanzaInternal(stanza);

}

afterSuccessfulLogin(false);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值