@Override public <R extends OFMessage> ListenableFuture<R> writeRequest(OFRequest<R> request) { if (!isConnected()) { return Futures.immediateFailedFuture(new SwitchDisconnectedException(getDatapathId())); } DeliverableListenableFuture<R> future = new DeliverableListenableFuture<R>(); xidDeliverableMap.put(request.getXid(), future); listener.messageWritten(this, request); this.write(request); return future; }
@Override public <REPLY extends OFStatsReply> ListenableFuture<List<REPLY>> writeStatsRequest( OFStatsRequest<REPLY> request) { if (!isConnected()) { return Futures.immediateFailedFuture(new SwitchDisconnectedException(getDatapathId())); } final DeliverableListenableFuture<List<REPLY>> future = new DeliverableListenableFuture<List<REPLY>>(); Deliverable<REPLY> deliverable = new Deliverable<REPLY>() { private final List<REPLY> results = Collections .synchronizedList(new ArrayList<REPLY>()); @Override public void deliver(REPLY reply) { results.add(reply); if (!reply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { // done future.deliver(results); } } @Override public void deliverError(Throwable cause) { future.deliverError(cause); } @Override public boolean isDone() { return future.isDone(); } @Override public boolean cancel(boolean mayInterruptIfRunning) { return future.cancel(mayInterruptIfRunning); } }; registerDeliverable(request.getXid(), deliverable); this.write(request); return future; }