public void startReading(final ResponseReader<R> reader) {
   ApplicationManager.getApplication()
       .executeOnPooledThread(
           () -> {
             myThread = Thread.currentThread();
             try {
               while (true) {
                 final R r = reader.readResponse();
                 if (r == null) break;
                 if (r instanceof ResponseToRequest) {
                   final int requestId = ((ResponseToRequest) r).getRequestId();
                   processResponse(requestId, r);
                 } else {
                   processResponse(r);
                 }
               }
             } catch (InterruptedException ignored) {
             } catch (IOException e) {
               LOG.info(e);
             } finally {
               synchronized (myLock) {
                 myStopped = true;
               }
             }
           });
 }
  public void stopReading() {
    synchronized (myLock) {
      if (myStopped) return;
      myStopped = true;
    }

    if (myThread != null) {
      myThread.interrupt();
    }
  }