io.advantageous.qbit.queue.Queue.receiveQueue()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(199)

本文整理了Java中io.advantageous.qbit.queue.Queue.receiveQueue方法的一些代码示例,展示了Queue.receiveQueue的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Queue.receiveQueue方法的具体详情如下:
包路径:io.advantageous.qbit.queue.Queue
类名称:Queue
方法名:receiveQueue

Queue.receiveQueue介绍

[英]This returns a thread safe receive queue. Pulling an item off of the queue makes it unavailable to other thread.
[中]这将返回一个线程安全的接收队列。从队列中拉出一个项目会使其他线程无法使用它。

代码示例

代码示例来源:origin: advantageous/qbit

@Override
public ReceiveQueue<Response<Object>> responses() {
  return responseQueue.receiveQueue();
}

代码示例来源:origin: advantageous/qbit

@Override
public ReceiveQueue<String> receiveQueue() {
  return stringQueue.receiveQueue();
}

代码示例来源:origin: advantageous/qbit

public ReceiveQueue<T> receiveQueue() {
  final ReceiveQueue<String> receiveQueue = queue.receiveQueue();

代码示例来源:origin: advantageous/qbit

private void initQueue() {
  /* Clean it up. */
  queue.ifPresent(actualQueue -> {
    try {
      actualQueue.stop();
    } catch (Exception ex) {
      logger.debug("Unable to stop queue", ex);
    }
  });
  receiveQueue.ifPresent(actualReceiveQueue -> {
    try {
      actualReceiveQueue.stop();
    } catch (Exception ex) {
      logger.debug("Unable to shut down receive queue", ex);
    }
  });
  try {
    this.queue = Optional.of(queueSupplier.get());
    this.queue.ifPresent(actualQueue -> receiveQueue = Optional.of(actualQueue.receiveQueue()));
  } catch (Exception ex) {
    logger.error("Unable to create queue with queue supplier", ex);
    this.queue = Optional.empty();
    this.receiveQueue = Optional.empty();
  }
}

代码示例来源:origin: advantageous/qbit

@Override
  public void run() {
    ReceiveQueue<String> receiveQueue = queue.receiveQueue();
    while (receiveQueue.poll() != null) {
      count[0]++;
    }
  }
});

代码示例来源:origin: advantageous/qbit

responseQueue.receiveQueue() : null;
eventQueue.receiveQueue();

代码示例来源:origin: advantageous/qbit

@Override
  public void run() {
    long cnt = 0;
    final ReceiveQueue<String> receiveQueue = queue.receiveQueue();
    String item = receiveQueue.take();
    while (item != null) {
      cnt++;
      puts(item);
      item = receiveQueue.take();
      if (cnt >= 900) {
        count.set(cnt);
        break;
      }
    }
  }
});

代码示例来源:origin: advantageous/qbit

final ReceiveQueue<String> receiveQueue = queue.receiveQueue();

代码示例来源:origin: advantageous/qbit

@Before
public void setUp() throws Exception {
  personQueue = JsonQueue.createMapQueue(String.class, Person.class, QueueBuilder.queueBuilder()
      .setName("FOO").build());
  personSendQueue = personQueue.sendQueue();
  personReceiveQueue = personQueue.receiveQueue();
  personSendQueue.shouldBatch();
  personSendQueue.name();
  personSendQueue.size();
  personQueue.name();
  personQueue.size();
}

代码示例来源:origin: advantageous/qbit

@Test
public void testWithBundleUsingObjectName() {
  final ServiceBundle serviceBundle = new ServiceBundleBuilder().setAddress("/services").buildAndStart();
  serviceBundle.addService(new TodoService());
  Todo todoItem = new Todo("call mom", "give mom a call", new Date());
  MethodCall<Object> addMethodCall = QBit.factory().createMethodCallByNames("add", "/services/todo-manager", "call1:localhost", todoItem, null);
  serviceBundle.call(addMethodCall);
  MethodCall<Object> listMethodCall = QBit.factory().createMethodCallByNames("list", "/services/todo-manager", "call2:localhost", todoItem, null);
  serviceBundle.call(listMethodCall);
  serviceBundle.flush();
  Sys.sleep(100);
  ReceiveQueue<Response<Object>> responses = serviceBundle.responses().receiveQueue();
  Response<Object> response = responses.take();
  Object body = response.body();
  if (body instanceof List) {
    @SuppressWarnings("unchecked") List<Todo> items = (List) body;
    ok = items.size() > 0 || die("items should have one todo in it");
    Todo todoItem1 = items.get(0);
    ok = todoItem.equals(todoItem1) || die("TodoItem ", todoItem, todoItem1);
  } else {
    die("Response was not a list", body);
  }
}

代码示例来源:origin: advantageous/qbit

@Before
public void setup() {
  final QueueBuilder queueBuilder = QueueBuilder.queueBuilder();
  queue = queueBuilder.setArrayBlockingQueue().setBatchSize(10)
      .setCheckEvery(5).setCheckIfBusy(false)
      .setName("Queue test").setPollTimeUnit(TimeUnit.MILLISECONDS)
      .setPollWait(50).build();
  receiveQueue = queue.receiveQueue();
  sendQueue = queue.sendQueue();
}

代码示例来源:origin: advantageous/qbit

@Before
public void setUp() throws Exception {
  personQueue = JsonQueue.createListQueue(Person.class, QueueBuilder.queueBuilder()
      .setName("FOO").build());
  personSendQueue = personQueue.sendQueue();
  personReceiveQueue = personQueue.receiveQueue();
  personSendQueue.shouldBatch();
  personSendQueue.name();
  personSendQueue.size();
  personQueue.name();
  personQueue.size();
}

代码示例来源:origin: advantageous/qbit

@Before
public void setup() {
  final QueueBuilder queueBuilder = QueueBuilder.queueBuilder();
  queue = queueBuilder.setLinkTransferQueue().setBatchSize(50)
      .setCheckEvery(5).setCheckIfBusy(true)
      .setName("Queue test").setPollTimeUnit(TimeUnit.MILLISECONDS)
      .setPollWait(50).build();
  receiveQueue = queue.receiveQueue();
  sendQueue = queue.sendQueue();
}

代码示例来源:origin: advantageous/qbit

@Before
public void setUp() throws Exception {
  personQueue = new JsonQueue<>(Person.class, QueueBuilder.queueBuilder()
      .setName("FOO").build());
  personSendQueue = personQueue.sendQueue();
  personReceiveQueue = personQueue.receiveQueue();
  personSendQueue.shouldBatch();
  personSendQueue.name();
  personSendQueue.size();
  personQueue.name();
  personQueue.size();
}

代码示例来源:origin: advantageous/qbit

@Before
public void setup() {
  final QueueBuilder queueBuilder = QueueBuilder.queueBuilder();
  queue = queueBuilder.setLinkTransferQueue().setBatchSize(50)
      .setCheckEvery(5).setCheckIfBusy(true).setTryTransfer(true)
      .setName("Queue test").setPollTimeUnit(TimeUnit.MILLISECONDS)
      .setPollWait(50).build();
  receiveQueue = queue.receiveQueue();
  sendQueue = queue.sendQueue();
}

代码示例来源:origin: advantageous/qbit

@Before
public void setup() {
  final QueueBuilder queueBuilder = QueueBuilder.queueBuilder();
  queue = queueBuilder.setArrayBlockingQueue().setBatchSize(50)
      .setCheckEvery(5).setCheckIfBusy(true)
      .setEnqueueTimeoutTimeUnit(null).setEnqueueTimeout(0)
      .setName("Queue test").setPollTimeUnit(TimeUnit.MILLISECONDS)
      .setPollWait(50).build();
  receiveQueue = queue.receiveQueue();
  sendQueue = queue.sendQueue();
}

代码示例来源:origin: advantageous/qbit

@Test(expected = QueueException.class)
public void testTimeout() {
  final QueueBuilder queueBuilder = QueueBuilder.queueBuilder();
  queue = queueBuilder.setArrayBlockingQueue().setBatchSize(5).setSize(5)
      .setEnqueueTimeout(1).setEnqueueTimeoutTimeUnit(TimeUnit.SECONDS)
      .setName("Queue test").setPollTimeUnit(TimeUnit.MILLISECONDS)
      .setPollWait(50).build();
  receiveQueue = queue.receiveQueue();
  sendQueue = queue.sendQueue();
  for (int index = 0; index < 2000; index++) {
    sendQueue.send("" + index);
  }
}

代码示例来源:origin: advantageous/qbit

@Test
public void testResponses() throws Exception {
  call = MethodCallBuilder.methodCallBuilder().setAddress("/foo/adder").setName("add").setBody(Lists.list(1, 2)).build();
  serviceBundle.addServiceObject("/adder", adderService);
  serviceBundle.call(call);
  serviceBundle.flushSends();
  Sys.sleep(1000);
  responseReceiveQueue = serviceBundle.responses().receiveQueue();
  serviceBundle.flush();
  Sys.sleep(200);
  response = responseReceiveQueue.pollWait();
  responseBody = response.body();
  int sum = Conversions.toInt(responseBody);
  Assert.assertEquals("Sum should be 3", 3, sum);
  serviceBundle.stop();
}

代码示例来源:origin: advantageous/qbit

@Test
public void testWithBundleUsingAddress() {
  final ServiceBundle serviceBundle = new ServiceBundleBuilder().setAddress("/services").buildAndStart();
  serviceBundle.addService(new TodoService());
  Todo todoItem = new Todo("call mom", "give mom a call", new Date());
  MethodCall<Object> addMethod =
      MethodCallBuilder.methodCallBuilder().setAddress("/services/todo-manager").setName("add").setReturnAddress("client1").setBody(todoItem).build();
  serviceBundle.call(addMethod);
  MethodCall<Object> listMethod =
      MethodCallBuilder.methodCallBuilder().setAddress("/services/todo-manager").setName("list").setReturnAddress("client1").setBody(todoItem).build();
  serviceBundle.call(listMethod);
  serviceBundle.flush();
  Sys.sleep(100);
  ReceiveQueue<Response<Object>> responses = serviceBundle.responses().receiveQueue();
  Response<Object> response = responses.take();
  Object body = response.body();
  if (body instanceof List) {
    @SuppressWarnings("unchecked") List<Todo> items = (List) body;
    ok = items.size() > 0 || die("items should have one todo in it");
    Todo todoItem1 = items.get(0);
    ok = todoItem.equals(todoItem1) || die("TodoItem ", todoItem, todoItem1);
  } else {
    die("Response was not a list", body);
  }
}

代码示例来源:origin: advantageous/qbit

@Test //TODO fails sometimes during build but not always
public void callingActualServiceWithReturn() {
  @RequestMapping("myService")
  class MyServiceClass implements SomeInterface {
    @Override
    public void method1() {
    }
    @Override
    public void method2(String hi, int amount) {
    }
    @Override
    public String method3(String hi, int amount) {
      return "Hi" + hi + " " + amount;
    }
  }
  SomeInterface myService = new MyServiceClass();
  final ServiceBundle bundle = new ServiceBundleBuilder().setAddress("/root").buildAndStart();
  bundle.addService(myService);
  final ReceiveQueue<Response<Object>> responseReceiveQueue = bundle.responses().receiveQueue();
  final SomeInterface myServiceProxy = bundle.createLocalProxy(
      SomeInterface.class,
      "myService");
  myServiceProxy.method3("hi", 5);
  bundle.flush();
  Sys.sleep(1000);
  final Response<Object> objectResponse = responseReceiveQueue.pollWait();
  objectResponse.address();
  puts(objectResponse.body());
  ok = "Hihi 5".equals(objectResponse.body()) || die();
}

相关文章