• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala Ack类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中monix.execution.Ack的典型用法代码示例。如果您正苦于以下问题:Scala Ack类的具体用法?Scala Ack怎么用?Scala Ack使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Ack类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: TestObserver

//设置package包名称以及导入依赖的类
package walfie.gbf.raidfinder.util

import monix.execution.Ack
import monix.reactive.Observer
import scala.concurrent.Future

class TestObserver[T] extends Observer[T] {
  var received = Vector.empty[T]
  var errorsReceived = Vector.empty[Throwable]
  var isComplete: Boolean = false

  def onNext(elem: T): Future[Ack] = {
    received = received :+ elem
    Ack.Continue
  }

  def onError(e: Throwable): Unit = {
    errorsReceived = errorsReceived :+ e
  }

  def onComplete(): Unit = {
    isComplete = true
  }
} 
开发者ID:walfie,项目名称:gbf-raidfinder,代码行数:25,代码来源:TestObserver.scala


示例2: MyObserver

//设置package包名称以及导入依赖的类
package my.samples.observers

import akka.actor.ActorRef
import monix.execution.Ack.Continue
import monix.execution.{ Ack, Scheduler }
import monix.reactive.observers.Subscriber
import my.samples.models.MyMessages
import my.samples.models.MyMessages.Tick
import org.slf4j.LoggerFactory

import scala.concurrent.Future

class MyObserver(actorRef: ActorRef, sourceName: String)(implicit s: Scheduler) extends Subscriber[Long] {

  private[this] def logger = LoggerFactory.getLogger(this.getClass)

  override implicit def scheduler: Scheduler = s

  override def onError(ex: Throwable): Unit =
    logger.error(s"error happened when processing the stream: error message << ${ex.getMessage} >>")

  override def onComplete(): Unit =
    logger.info("stream completed")

  override def onNext(elem: Long): Future[Ack] = {
    logger.info(s"message received from source $sourceName --> $elem")
    actorRef ! Tick(sourceName, elem)
    Continue
  }
}
object MyObserver {
  def apply(actorRef: ActorRef, sourceName: String)(implicit s: Scheduler) = {
    new MyObserver(actorRef, sourceName)(s)
  }
} 
开发者ID:joesan,项目名称:monix-samples,代码行数:36,代码来源:MyObserver.scala


示例3: SubjectSubscription

//设置package包名称以及导入依赖的类
package com.hypertino.hyperbus.util

import com.hypertino.hyperbus.transport.api.matchers.RequestMatcher
import monix.eval.Task
import monix.execution.Ack.Stop
import monix.execution.{Ack, Cancelable, Scheduler}
import monix.reactive.{Observable, Observer}
import monix.reactive.observers.Subscriber
import monix.reactive.subjects.{ConcurrentSubject, Subject}

import scala.util.Success

abstract class SubjectSubscription[T](implicit val scheduler: Scheduler) extends FuzzyMatcher {
  type eventType = T

  // FyzzyIndex properties
  def requestMatcher: RequestMatcher
  override def indexProperties: Seq[FuzzyIndexItemMetaInfo] = requestMatcher.indexProperties
  override def matches(other: Any): Boolean = requestMatcher.matches(other)

  // Subject properties
  protected val subject: Subject[eventType, eventType]
  def cancel(): Unit = {
    remove()
    subject.onComplete()
  }

  def publish(t: eventType): Task[Ack] = {
    Task.fromFuture(subject.onNext(t).andThen {
      case Success(Stop) ? remove()
    })
  }

  private def cancel_1() = cancel()

  val observable: Observable[eventType] = new Observable[eventType] {
    override def unsafeSubscribeFn(subscriber: Subscriber[eventType]): Cancelable = {
      val original: Cancelable = subject.unsafeSubscribeFn(subscriber)
      add()
      new Cancelable {
        override def cancel(): Unit = {
          cancel_1()
          original.cancel()
        }
      }
    }
  }

  protected def remove(): Unit
  protected def add(): Unit
} 
开发者ID:hypertino,项目名称:hyperbus,代码行数:52,代码来源:SubjectSubscription.scala


示例4: TopicErrorException

//设置package包名称以及导入依赖的类
package flumina.monix

import flumina.{KafkaResult, TopicPartitionValue}
import monix.eval.Task
import monix.execution.Ack
import scodec.Err

import scala.concurrent.Future
import scala.concurrent.duration.FiniteDuration

final class TopicErrorException(errors: List[TopicPartitionValue[KafkaResult]]) extends Exception

sealed trait ConsumptionStrategy

object ConsumptionStrategy {
  final case class Tail(delay: FiniteDuration) extends ConsumptionStrategy
  case object TerminateEndOfStream             extends ConsumptionStrategy
}

trait CodecErrorHandler {
  def handle(err: Err): Future[Ack]
}

object CodecErrorHandler {
  val stop: CodecErrorHandler = new CodecErrorHandler {
    override def handle(err: Err): Future[Ack] = Ack.Stop
  }
} 
开发者ID:vectos,项目名称:flumina,代码行数:29,代码来源:Types.scala


示例5: handle

//设置package包名称以及导入依赖的类
package de.m7w3.signal.events

import de.m7w3.signal.Logging
import monix.execution.Ack
import monix.execution.Ack.Continue
import monix.reactive.Observer

import scala.concurrent.Future

trait EventListener extends Observer[SignalDesktopEvent] {
  def handle: PartialFunction[SignalDesktopEvent, Unit]

  override def onNext(elem: SignalDesktopEvent): Future[Ack] = {
    if (handle.isDefinedAt(elem)) {
      handle.apply(elem)
    }
    Continue
  }
}


abstract class SimpleEventListener extends EventListener with Logging {

  override def onError(ex: Throwable): Unit = {
    logger.error(s"Error in event listener ${getClass.getSimpleName}", ex)
  }

  override def onComplete(): Unit = {
    logger.info(s"${getClass.getSimpleName} completed")
  }
}

object EventListener {
  def simple(onEvent: PartialFunction[SignalDesktopEvent, Unit]): EventListener = {
    new SimpleEventListener() {
      override def handle: PartialFunction[SignalDesktopEvent, Unit] = onEvent
    }
  }
} 
开发者ID:ayoub-benali,项目名称:signal-desktop-client,代码行数:40,代码来源:EventListener.scala


示例6: publishEvent

//设置package包名称以及导入依赖的类
package de.m7w3.signal.events

import de.m7w3.signal.Logging
import monix.execution.Ack.Stop
import monix.execution.Scheduler.Implicits.global
import monix.execution.atomic.{Atomic, AtomicBoolean}
import monix.execution.{Ack, Cancelable}
import monix.reactive.OverflowStrategy.DropOld
import monix.reactive.subjects.ConcurrentSubject

import scala.concurrent.Future


trait EventPublisher {
  
  def publishEvent(event: SignalDesktopEvent): Future[Ack]
}

trait EventDispatcher {
  def register(listener: EventListener): Cancelable
}

class SignalDesktopEventDispatcher extends EventPublisher with EventDispatcher with Logging {

  private val alive: AtomicBoolean = Atomic(true)
  private val bufferSize: Int = 1024
  private val overflowStrategy = DropOld(bufferSize)
  // ensures concurrency,safety
  // and backpressure by maintaining a buffer
  // in this subject that sits before any subscriber
  // but has the drawback that we might execute stuff asynchronously
  private val subject: ConcurrentSubject[SignalDesktopEvent, SignalDesktopEvent] =
    ConcurrentSubject.publish[SignalDesktopEvent](overflowStrategy)

  override def publishEvent(event: SignalDesktopEvent): Future[Ack] = {
    if (alive.get) {
       subject.onNext(event)
    } else {
      logger.warn(s"closed. ignoring event $event")
      Stop
    }
  }

  override def register(listener: EventListener): Cancelable = {
    subject.subscribe(listener)
  }

  def close(): Unit = {
    alive.set(false)
    subject.onComplete()
  }
} 
开发者ID:ayoub-benali,项目名称:signal-desktop-client,代码行数:53,代码来源:EventDispatcher.scala



注:本文中的monix.execution.Ack类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala BodyParser类代码示例发布时间:2022-05-23
下一篇:
Scala Cache类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap