當前位置: 首頁>>代碼示例>>Java>>正文


Java SubscribeOptionsBuilder類代碼示例

本文整理匯總了Java中com.ibm.mqlight.api.SubscribeOptions.SubscribeOptionsBuilder的典型用法代碼示例。如果您正苦於以下問題:Java SubscribeOptionsBuilder類的具體用法?Java SubscribeOptionsBuilder怎麽用?Java SubscribeOptionsBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SubscribeOptionsBuilder類屬於com.ibm.mqlight.api.SubscribeOptions包,在下文中一共展示了SubscribeOptionsBuilder類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getSubscribeOptions

import com.ibm.mqlight.api.SubscribeOptions.SubscribeOptionsBuilder; //導入依賴的package包/類
/**
 * @return
 */
public SubscribeOptions getSubscribeOptions() {
	SubscribeOptionsBuilder sob = SubscribeOptions.builder();
	if (autoConfirm != null) sob.setAutoConfirm(autoConfirm == AUTO_CONFIRM.AUTO);
	if (linkCredit != null) sob.setCredit(linkCredit);
	if (qos != null) sob.setQos(qos);
	if (shareName != null) sob.setShare(shareName);
	if (ttl != null) sob.setTtl(ttl);
	return sob.build();
}
 
開發者ID:ot4i,項目名稱:perf-harness,代碼行數:13,代碼來源:BlockingJavaClient.java

示例2: unsubscribeFromWithinMessageCallbackTemplate

import com.ibm.mqlight.api.SubscribeOptions.SubscribeOptionsBuilder; //導入依賴的package包/類
private void unsubscribeFromWithinMessageCallbackTemplate(QOS qos, final boolean shared, boolean autoConfirm,
        final boolean confirmBeforeUnsubscribe, final boolean confirmAfterUnsubscribe) throws Exception {
    MockComponent engine = new MockComponent();
    MockNonBlockingClientListener listener = new MockNonBlockingClientListener(false);
    final NonBlockingClientImpl client = openCommon(engine, listener);
    EngineConnection engineConnection = new EngineConnection();

    OpenRequest openRequest = (OpenRequest)engine.getMessages().get(0);
    client.tell(new OpenResponse(openRequest, engineConnection), engine);

    SubscribeOptionsBuilder subOptsBuilder = SubscribeOptions.builder();
    subOptsBuilder.setQos(qos);
    if (qos == QOS.AT_LEAST_ONCE) {
        subOptsBuilder.setAutoConfirm(autoConfirm);
    }
    if (shared) {
        subOptsBuilder.setShare("share");
    }
    SubscribeOptions subOpts = subOptsBuilder.build();

    final Semaphore done = new Semaphore(0);
    final MockCompletionListener subscribeListener = new MockCompletionListener();
    final MockCompletionListener unsubscribeListener = new MockCompletionListener();
    client.subscribe("/kittens", subOpts, new DestinationAdapter<Void>() {
        @Override
        public void onMessage(NonBlockingClient client2, Void context, Delivery delivery) {
            if (confirmBeforeUnsubscribe) {
                delivery.confirm();
            }
            if (shared) {
                client.unsubscribe("/kittens", "share", unsubscribeListener, null);
            } else {
                client.unsubscribe("/kittens", unsubscribeListener, null);
            }
            if (confirmAfterUnsubscribe) {
                delivery.confirm();
            }
            done.release();
        }
    }, subscribeListener, null);

    client.tell(new SubscribeResponse(engineConnection, new SubscriptionTopic("/kittens", shared ? "share" : null)), engine);
    subscribeListener.assertSuccess();

    byte[] amqpMessageData = TestDestinationListenerWrapper.createSerializedProtonMessage(
            new AmqpValue(new Binary(new byte[]{1})), "/kittens", 0, null, null, null);
    client.tell(new DeliveryRequest(amqpMessageData, qos,
            shared ? "share:share:/kittens" : "private:/kittens", null, null), engine);
    assertTrue("Client failed to receive message within timeout. ", done.tryAcquire(4, TimeUnit.SECONDS));

    LinkedList<Message> messages = engine.getMessages();
    boolean notConfirmed = (qos == QOS.AT_LEAST_ONCE) && !autoConfirm && !confirmBeforeUnsubscribe && !confirmAfterUnsubscribe;
    assertEquals("Engine received wrong number of events", notConfirmed ? 3 : 4, messages.size());
    int i = 0;
    assertEquals("Event #" + (i + 1) + " should have been OpenRequest", OpenRequest.class, messages.get(i++).getClass());
    assertEquals("Event #" + (i + 1) + " should have been SubscribeRequest", SubscribeRequest.class, messages.get(i++).getClass());
    if (!notConfirmed) {
        assertEquals("Event #" + (i + 1) + " should have been DeliveryResponse", DeliveryResponse.class, messages.get(i++).getClass());
    }
    assertEquals("Event #" + (i + 1) + " should have been UnsubscribeRequest", UnsubscribeRequest.class, messages.get(i++).getClass());

    client.tell(messages.get(2), engine);
    client.tell(new UnsubscribeResponse(engineConnection, new SubscriptionTopic("/kittens", shared ? "share" : null), null), engine);
    unsubscribeListener.assertSuccess();
}
 
開發者ID:mqlight,項目名稱:java-mqlight,代碼行數:66,代碼來源:TestNonBlockingClientImpl.java


注:本文中的com.ibm.mqlight.api.SubscribeOptions.SubscribeOptionsBuilder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。