1

Following is the code to update counter.

kvList contains List[(key, value to add)]

def counter(kvList: List[(String, Long)]) = {
  try {`enter code here`
   if (kvList!=null && kvList.nonEmpty) {
    Observable.from(kvList).flatMap(kv => {
     val bucketObservableAsync =
     rx.lang.scala.JavaConversions.toScalaObservable(
         bucket.async().counter(kv._1, kv._2, kv._2, ttl)
     )

    def errorOccurred(t: Throwable): Unit = {
      log.error("ReportingService observable error occurred", t)
    }

    bucketObservableAsync.doOnError(errorOccurred)
    bucketObservableAsync
    }).last.toBlocking.single
    } else {
      log.info("ReportingService no keys to update")
    }
  } catch {
    case e: Throwable =>
    log.error("ReportingService error occurred ", e)
  }
}

I'm using couchbase java-client-2.1.3 and I could see 2 issues over here:

The errorOccurred is not getting called

Instead of (1) I'm getting the following exception sometimes:

ReportingService error occurred
com.couchbase.client.core.CouchbaseException: NOT_EXISTS
    at com.couchbase.client.java.CouchbaseAsyncBucket$26.call(CouchbaseAsyncBucket.java:950)
    at com.couchbase.client.java.CouchbaseAsyncBucket$26.call(CouchbaseAsyncBucket.java:932)
    at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:69)
    at rx.internal.producers.SingleProducer.request(SingleProducer.java:65)
    at rx.Subscriber.setProducer(Subscriber.java:211)
    at rx.internal.operators.OnSubscribeMap$MapSubscriber.setProducer(OnSubscribeMap.java:102)
    at rx.subjects.AsyncSubject.onCompleted(AsyncSubject.java:105)
    at com.couchbase.client.core.endpoint.AbstractGenericHandler$1.call(AbstractGenericHandler.java:199)
    at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
Matthew Groves
  • 25,181
  • 9
  • 71
  • 121
KaliCharan
  • 1,215
  • 2
  • 8
  • 12
  • I [edited your question](https://stackoverflow.com/help/editing), improving either its formatting, or [its quality](https://stackoverflow.blog/2011/02/05/suggested-edits-and-edit-review/) to help people understanding your question, and to help you to get an appropriate answer. But you still may need to add further information for your question to become fully solvable. – Bsquare ℬℬ Dec 21 '18 at 10:28
  • What further info is required? – KaliCharan Dec 21 '18 at 11:48
  • Expert of this topic (whose I'm not myself) will tell you, if further info is needed. – Bsquare ℬℬ Dec 21 '18 at 13:43

0 Answers0