/** * Sends the packet and provides the expected reply <br> * * @param request the request sended * @param filter identifies expected reply packet object * @param timeout limits the wait time, 0 for infinite wait * @return the reply packet object * @throws IOException */ public Packet sendSynchronous(Packet request, Predicate<Packet> filter, long timeout) throws IOException { SynchronousListener listener = new SynchronousListener(filter); addListener(listener); send(request); listener.waitForReply(timeout); removeListener(listener); Packet reply = listener.getReplyPacket(); if (reply == null) throw new NoReplyException(); return reply; }
public R sync(boolean canInterrupt) throws Exception { SynchronousListener<R> syncListener = new SynchronousListener<R>(); this.addListener(syncListener); return syncListener.sync(canInterrupt); }
@Override public R sync() throws Exception { SynchronousListener<R> syncListener = new SynchronousListener<R>(); this.addListener(syncListener); return syncListener.sync(); }