io.openmessaging.FutureListener Java Examples
The following examples show how to use
io.openmessaging.FutureListener.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultPromise.java From rocketmq-4.3.0 with Apache License 2.0 | 6 votes |
@Override public void addListener(final FutureListener<V> listener) { if (listener == null) { throw new NullPointerException("FutureListener is null"); } boolean notifyNow = false; synchronized (lock) { if (!isDoing()) { notifyNow = true; } else { if (promiseListenerList == null) { promiseListenerList = new ArrayList<>(); } promiseListenerList.add(listener); } } if (notifyNow) { notifyListener(listener); } }
Example #2
Source File: DefaultPromise.java From rocketmq with Apache License 2.0 | 6 votes |
@Override public void addListener(final FutureListener<V> listener) { if (listener == null) { throw new NullPointerException("FutureListener is null"); } boolean notifyNow = false; synchronized (lock) { if (!isDoing()) { notifyNow = true; } else { if (promiseListenerList == null) { promiseListenerList = new ArrayList<>(); } promiseListenerList.add(listener); } } if (notifyNow) { notifyListener(listener); } }
Example #3
Source File: DefaultPromise.java From rocketmq-read with Apache License 2.0 | 6 votes |
@Override public void addListener(final FutureListener<V> listener) { if (listener == null) { throw new NullPointerException("FutureListener is null"); } boolean notifyNow = false; synchronized (lock) { if (!isDoing()) { notifyNow = true; } else { if (promiseListenerList == null) { promiseListenerList = new ArrayList<>(); } promiseListenerList.add(listener); } } if (notifyNow) { notifyListener(listener); } }
Example #4
Source File: DefaultPromiseTest.java From rocketmq with Apache License 2.0 | 5 votes |
@Test public void testAddListener_WithException() throws Exception { final Throwable exception = new OMSRuntimeException("-1", "Test Error"); promise.addListener(new FutureListener<String>() { @Override public void operationComplete(Future<String> future) { assertThat(promise.getThrowable()).isEqualTo(exception); } }); promise.setFailure(exception); }
Example #5
Source File: DefaultPromiseTest.java From rocketmq with Apache License 2.0 | 5 votes |
@Test public void testAddListener_WithException_ListenerAfterSet() throws Exception { final Throwable exception = new OMSRuntimeException("-1", "Test Error"); promise.setFailure(exception); promise.addListener(new FutureListener<String>() { @Override public void operationComplete(Future<String> future) { assertThat(promise.getThrowable()).isEqualTo(exception); } }); }
Example #6
Source File: DefaultPromiseTest.java From rocketmq with Apache License 2.0 | 5 votes |
@Test public void testAddListener_ListenerAfterSet() throws Exception { promise.set("Done"); promise.addListener(new FutureListener<String>() { @Override public void operationComplete(Future<String> future) { assertThat(future.get()).isEqualTo("Done"); } }); }
Example #7
Source File: DefaultPromiseTest.java From rocketmq with Apache License 2.0 | 5 votes |
@Test public void testAddListener() throws Exception { promise.addListener(new FutureListener<String>() { @Override public void operationComplete(Future<String> future) { assertThat(promise.get()).isEqualTo("Done"); } }); promise.set("Done"); }
Example #8
Source File: DefaultPromise.java From rocketmq with Apache License 2.0 | 5 votes |
private void notifyListener(final FutureListener<V> listener) { try { listener.operationComplete(this); } catch (Throwable t) { LOG.error("notifyListener {} Error:{}", listener.getClass().getSimpleName(), t); } }
Example #9
Source File: DefaultPromise.java From rocketmq with Apache License 2.0 | 5 votes |
private void notifyListeners() { if (promiseListenerList != null) { for (FutureListener<V> listener : promiseListenerList) { notifyListener(listener); } } }
Example #10
Source File: FutureAdapter.java From joyqueue with Apache License 2.0 | 5 votes |
@Override public void addListener(FutureListener listener) { this.listener = listener; if (isDone()) { listener.operationComplete(this); } }
Example #11
Source File: DefaultPromiseTest.java From rocketmq-read with Apache License 2.0 | 5 votes |
@Test public void testAddListener_WithException() throws Exception { final Throwable exception = new OMSRuntimeException("-1", "Test Error"); promise.addListener(new FutureListener<String>() { @Override public void operationComplete(Future<String> future) { assertThat(promise.getThrowable()).isEqualTo(exception); } }); promise.setFailure(exception); }
Example #12
Source File: DefaultPromiseTest.java From rocketmq-read with Apache License 2.0 | 5 votes |
@Test public void testAddListener_WithException_ListenerAfterSet() throws Exception { final Throwable exception = new OMSRuntimeException("-1", "Test Error"); promise.setFailure(exception); promise.addListener(new FutureListener<String>() { @Override public void operationComplete(Future<String> future) { assertThat(promise.getThrowable()).isEqualTo(exception); } }); }
Example #13
Source File: DefaultPromiseTest.java From rocketmq-read with Apache License 2.0 | 5 votes |
@Test public void testAddListener_ListenerAfterSet() throws Exception { promise.set("Done"); promise.addListener(new FutureListener<String>() { @Override public void operationComplete(Future<String> future) { assertThat(future.get()).isEqualTo("Done"); } }); }
Example #14
Source File: DefaultPromiseTest.java From rocketmq-read with Apache License 2.0 | 5 votes |
@Test public void testAddListener() throws Exception { promise.addListener(new FutureListener<String>() { @Override public void operationComplete(Future<String> future) { assertThat(promise.get()).isEqualTo("Done"); } }); promise.set("Done"); }
Example #15
Source File: DefaultPromise.java From rocketmq-read with Apache License 2.0 | 5 votes |
private void notifyListener(final FutureListener<V> listener) { try { listener.operationComplete(this); } catch (Throwable t) { LOG.error("notifyListener {} Error:{}", listener.getClass().getSimpleName(), t); } }
Example #16
Source File: DefaultPromise.java From rocketmq-read with Apache License 2.0 | 5 votes |
private void notifyListeners() { if (promiseListenerList != null) { for (FutureListener<V> listener : promiseListenerList) { notifyListener(listener); } } }
Example #17
Source File: DefaultPromiseTest.java From rocketmq-4.3.0 with Apache License 2.0 | 5 votes |
@Test public void testAddListener_WithException() throws Exception { final Throwable exception = new OMSRuntimeException("-1", "Test Error"); promise.addListener(new FutureListener<String>() { @Override public void operationComplete(Future<String> future) { assertThat(promise.getThrowable()).isEqualTo(exception); } }); promise.setFailure(exception); }
Example #18
Source File: DefaultPromiseTest.java From rocketmq-4.3.0 with Apache License 2.0 | 5 votes |
@Test public void testAddListener_WithException_ListenerAfterSet() throws Exception { final Throwable exception = new OMSRuntimeException("-1", "Test Error"); promise.setFailure(exception); promise.addListener(new FutureListener<String>() { @Override public void operationComplete(Future<String> future) { assertThat(promise.getThrowable()).isEqualTo(exception); } }); }
Example #19
Source File: DefaultPromiseTest.java From rocketmq-4.3.0 with Apache License 2.0 | 5 votes |
@Test public void testAddListener_ListenerAfterSet() throws Exception { promise.set("Done"); promise.addListener(new FutureListener<String>() { @Override public void operationComplete(Future<String> future) { assertThat(future.get()).isEqualTo("Done"); } }); }
Example #20
Source File: DefaultPromiseTest.java From rocketmq-4.3.0 with Apache License 2.0 | 5 votes |
@Test public void testAddListener() throws Exception { promise.addListener(new FutureListener<String>() { @Override public void operationComplete(Future<String> future) { assertThat(promise.get()).isEqualTo("Done"); } }); promise.set("Done"); }
Example #21
Source File: DefaultPromise.java From rocketmq-4.3.0 with Apache License 2.0 | 5 votes |
private void notifyListener(final FutureListener<V> listener) { try { listener.operationComplete(this); } catch (Throwable t) { LOG.error("notifyListener {} Error:{}", listener.getClass().getSimpleName(), t); } }
Example #22
Source File: DefaultPromise.java From rocketmq-4.3.0 with Apache License 2.0 | 5 votes |
private void notifyListeners() { if (promiseListenerList != null) { for (FutureListener<V> listener : promiseListenerList) { notifyListener(listener); } } }
Example #23
Source File: SimpleProducer.java From rocketmq-read with Apache License 2.0 | 4 votes |
public static void main(String[] args) { final MessagingAccessPoint messagingAccessPoint = OMS.getMessagingAccessPoint("oms:rocketmq://localhost:9876/default:default"); final Producer producer = messagingAccessPoint.createProducer(); messagingAccessPoint.startup(); System.out.printf("MessagingAccessPoint startup OK%n"); producer.startup(); System.out.printf("Producer startup OK%n"); { Message message = producer.createBytesMessage("OMS_HELLO_TOPIC", "OMS_HELLO_BODY".getBytes(Charset.forName("UTF-8"))); SendResult sendResult = producer.send(message); //final Void aVoid = result.get(3000L); System.out.printf("Send async message OK, msgId: %s%n", sendResult.messageId()); } final CountDownLatch countDownLatch = new CountDownLatch(1); { final Future<SendResult> result = producer.sendAsync(producer.createBytesMessage("OMS_HELLO_TOPIC", "OMS_HELLO_BODY".getBytes(Charset.forName("UTF-8")))); result.addListener(new FutureListener<SendResult>() { @Override public void operationComplete(Future<SendResult> future) { if (future.getThrowable() != null) { System.out.printf("Send async message Failed, error: %s%n", future.getThrowable().getMessage()); } else { System.out.printf("Send async message OK, msgId: %s%n", future.get().messageId()); } countDownLatch.countDown(); } }); } { producer.sendOneway(producer.createBytesMessage("OMS_HELLO_TOPIC", "OMS_HELLO_BODY".getBytes(Charset.forName("UTF-8")))); System.out.printf("Send oneway message OK%n"); } try { countDownLatch.await(); Thread.sleep(500); // Wait some time for one-way delivery. } catch (InterruptedException ignore) { } producer.shutdown(); }
Example #24
Source File: SimpleProducer.java From rocketmq with Apache License 2.0 | 4 votes |
public static void main(String[] args) { final MessagingAccessPoint messagingAccessPoint = OMS.getMessagingAccessPoint("oms:rocketmq://localhost:9876/default:default"); final Producer producer = messagingAccessPoint.createProducer(); messagingAccessPoint.startup(); System.out.printf("MessagingAccessPoint startup OK%n"); producer.startup(); System.out.printf("Producer startup OK%n"); { Message message = producer.createBytesMessage("OMS_HELLO_TOPIC", "OMS_HELLO_BODY".getBytes(Charset.forName("UTF-8"))); SendResult sendResult = producer.send(message); //final Void aVoid = result.get(3000L); System.out.printf("Send async message OK, msgId: %s%n", sendResult.messageId()); } final CountDownLatch countDownLatch = new CountDownLatch(1); { final Future<SendResult> result = producer.sendAsync(producer.createBytesMessage("OMS_HELLO_TOPIC", "OMS_HELLO_BODY".getBytes(Charset.forName("UTF-8")))); result.addListener(new FutureListener<SendResult>() { @Override public void operationComplete(Future<SendResult> future) { if (future.getThrowable() != null) { System.out.printf("Send async message Failed, error: %s%n", future.getThrowable().getMessage()); } else { System.out.printf("Send async message OK, msgId: %s%n", future.get().messageId()); } countDownLatch.countDown(); } }); } { producer.sendOneway(producer.createBytesMessage("OMS_HELLO_TOPIC", "OMS_HELLO_BODY".getBytes(Charset.forName("UTF-8")))); System.out.printf("Send oneway message OK%n"); } try { countDownLatch.await(); Thread.sleep(500); // Wait some time for one-way delivery. } catch (InterruptedException ignore) { } producer.shutdown(); }
Example #25
Source File: SimpleProducer.java From rocketmq-4.3.0 with Apache License 2.0 | 4 votes |
public static void main(String[] args) { final MessagingAccessPoint messagingAccessPoint = OMS.getMessagingAccessPoint("oms:rocketmq://localhost:9876/default:default"); final Producer producer = messagingAccessPoint.createProducer(); messagingAccessPoint.startup(); System.out.printf("MessagingAccessPoint startup OK%n"); producer.startup(); System.out.printf("Producer startup OK%n"); { Message message = producer.createBytesMessage("OMS_HELLO_TOPIC", "OMS_HELLO_BODY".getBytes(Charset.forName("UTF-8"))); SendResult sendResult = producer.send(message); //final Void aVoid = result.get(3000L); System.out.printf("Send async message OK, msgId: %s%n", sendResult.messageId()); } final CountDownLatch countDownLatch = new CountDownLatch(1); { final Future<SendResult> result = producer.sendAsync(producer.createBytesMessage("OMS_HELLO_TOPIC", "OMS_HELLO_BODY".getBytes(Charset.forName("UTF-8")))); result.addListener(new FutureListener<SendResult>() { @Override public void operationComplete(Future<SendResult> future) { if (future.getThrowable() != null) { System.out.printf("Send async message Failed, error: %s%n", future.getThrowable().getMessage()); } else { System.out.printf("Send async message OK, msgId: %s%n", future.get().messageId()); } countDownLatch.countDown(); } }); } { producer.sendOneway(producer.createBytesMessage("OMS_HELLO_TOPIC", "OMS_HELLO_BODY".getBytes(Charset.forName("UTF-8")))); System.out.printf("Send oneway message OK%n"); } try { countDownLatch.await(); Thread.sleep(500); // Wait some time for one-way delivery. } catch (InterruptedException ignore) { } producer.shutdown(); }