本文整理汇总了Java中org.igniterealtime.jbosh.BOSHClient类的典型用法代码示例。如果您正苦于以下问题:Java BOSHClient类的具体用法?Java BOSHClient怎么用?Java BOSHClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BOSHClient类属于org.igniterealtime.jbosh包,在下文中一共展示了BOSHClient类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkForIDRepeats
import org.igniterealtime.jbosh.BOSHClient; //导入依赖的package包/类
@Test(timeout=120000)
public void checkForIDRepeats() throws Exception {
final int iterations = 2500;
long repeats = 0;
logTestStart();
// Run a few thousand iterations and check for repeats
Set<Long> observed = new HashSet<Long>(iterations * 2);
BOSHClientConfig cfg = session.getBOSHClientConfig();
for (int i=0; i<iterations; i++) {
// Initiate a new session
BOSHClient sess = BOSHClient.create(cfg);
sess.send(ComposableBody.builder().build());
StubConnection conn = cm.awaitConnection();
AbstractBody req = conn.getRequest().getBody();
String rid = req.getAttribute(Attributes.RID);
conn.sendResponse(ComposableBody.builder()
.setAttribute(Attributes.TYPE, "terminate")
.setAttribute(Attributes.CONDITION, "item-not-found")
.build());
if (!observed.add(Long.valueOf(rid))) {
repeats++;
}
}
LOG.info("Repeated initial RID " + repeats + " time(s)");
if (repeats >= 2) {
fail("Initial RID repeated " + repeats + " times in "
+ iterations + " iterations");
}
}
示例2: scheduleMaxDelayTask
import org.igniterealtime.jbosh.BOSHClient; //导入依赖的package包/类
/**
* Validate that the maximum time delta does not expire before a new
* request is made.
*
* "In any case, if no requests are being held, the client MUST make a new
* request before the maximum inactivity period has expired."
*
* @param count current number of outstanding connections
*/
private void scheduleMaxDelayTask(final int count) {
if (count > 0) {
// Nothing to validate
return;
}
try {
BOSHClient session = client.get();
if (session == null) {
// Client not set
return;
}
CMSessionParams params = session.getCMSessionParams();
if (params == null) {
// Nothing to validate against
return;
}
AttrInactivity inactivity = params.getInactivityPeriod();
int max;
if (inactivity == null) {
max = 1;
} else {
max = inactivity.intValue();
}
LOG.finest("Scheduling inactivity timer");
inactivityRef.set(schedExec.schedule(
new InactivityChecker(max), max, TimeUnit.SECONDS));
} catch (Error err) {
toThrow.compareAndSet(null, err);
}
}
示例3: validateConnectionCount
import org.igniterealtime.jbosh.BOSHClient; //导入依赖的package包/类
/**
* Validate the concurrent connection count.
*
* @param count current number of outstanding connections
* @param conn current connection
*/
private void validateConnectionCount(
final int count, final StubConnection conn) {
try {
BOSHClient session = client.get();
int max = 2;
if (session != null) {
CMSessionParams params = session.getCMSessionParams();
if (params == null) {
max = 1;
} else {
AttrRequests requests = params.getRequests();
if (requests != null) {
max = requests.intValue();
}
}
}
AbstractBody msg = conn.getRequest().getBody();
int extra;
if (msg.getAttribute(Attributes.PAUSE) != null
|| "terminate".equals(msg.getAttribute(Attributes.TYPE))) {
extra = 1;
} else {
extra = 0;
}
assertTrue("concurrent connections must be 0 <= x <= " + max
+ "+" + extra + " (was: " + count + ")",
count >= 0 && count <= (max + extra));
} catch (Error err) {
toThrow.compareAndSet(null, err);
}
}
示例4: validateOveractivePolling
import org.igniterealtime.jbosh.BOSHClient; //导入依赖的package包/类
/**
* If the client sends two consecutive empty new requests (i.e. requests
* with incremented rid attributes, not repeat requests) within a period
* shorter than the number of seconds specified by the 'polling' attribute
* (the shortest allowable polling interval) in the session creation
* response, and if the connection manager's response to the first request
* contained no payloads, then upon reception of the second request the
* connection manager SHOULD terminate the HTTP session and return a
* 'policy-violation' terminal binding error to the client.
*
* @param index connection index
* @param conn current connection
* @pram previous previous connection
*/
private void validateOveractivePolling(
final int index,
final StubConnection conn,
final StubConnection previous) {
BOSHClient session = client.get();
if (session == null || previous == null) {
// No established session
return;
}
ComposableBody prevReq =
toComposableBody(previous.getRequest().getBody());
ComposableBody req =
toComposableBody(conn.getRequest().getBody());
String prevIDStr = prevReq.getAttribute(Attributes.RID);
String idStr = req.getAttribute(Attributes.RID);
long prevID = Long.parseLong(prevIDStr);
long id = Long.parseLong(idStr);
if (!(prevReq.getPayloadXML().isEmpty()
&& req.getPayloadXML().isEmpty())
&& (id - prevID != 1)) {
// Not two consecutive empty requests
return;
}
ComposableBody prevResp =
toComposableBody(previous.getResponse().getBody());
if (!prevResp.getPayloadXML().isEmpty()) {
// Previous response was not empty
return;
}
CMSessionParams params = session.getCMSessionParams();
if (params == null) {
// Nothing to validate against
return;
}
AttrPolling polling = params.getPollingInterval();
if (polling == null) {
// Nothing to check against
return;
}
long prevTime = previous.getRequest().getRequestTime();
long connTime = conn.getRequest().getRequestTime();
long delta = connTime - prevTime;
if (delta < polling.getInMilliseconds() ) {
fail("Polling session overactivity policy violation in "
+ "connection #" + index + " (" + delta + " < "
+ polling.getInMilliseconds() + ")");
}
}
示例5: setBOSHClient
import org.igniterealtime.jbosh.BOSHClient; //导入依赖的package包/类
/**
* Set the BOSH session that this validator is monitoring.
*
* @param session client session
*/
void setBOSHClient(final BOSHClient session) {
client.set(session);
}