在我们的Scala/Play应用程序中,我们使用activiti.(也尝试使用camunda)用户可以创建工作流程(如图所示http://camunda.com/).对这些外部工作流引擎的所有调用都包含在Scala Future中(activiti和camunda API都是Java阻塞API).
是否有任何库实现工作流程完全使用Akka/Actors避免像activiti/camunda这样的重型工具包?或者想法如何最好地使用Akka与activiti/camunda?
我有第三次或第四次这个问题,重新启动我的Mac(优胜美地和以前的OSX版本相同)postgres服务器无法启动.我在这个链接后安装了我的postgres .知道为什么每次重启后这种情况一直发生吗?
打字psql就给了
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Run Code Online (Sandbox Code Playgroud) 这更像是一个设计和最佳实践问题.我正在转换应用程序以使用Actors和Futures.目前这些是层(在Akka混合之前).
Play Controller -> Service layer -> (Slick) DAOs
Run Code Online (Sandbox Code Playgroud)
现在想拥有类似的东西
Play Controller -> Actors ->Services (Now they'll return Futures) ->DAO
Run Code Online (Sandbox Code Playgroud)
在这样做时,我发现由于原始服务层具有所有具有所需业务逻辑的方法,因此Actors层看起来就像一个中介.想知道是否可以(从设计的角度来看)摆脱服务层现在一切都将通过Actors?
Play controller->Actors (with business methods) -> business methods calling into DAO (which Service methods were doing before)
Run Code Online (Sandbox Code Playgroud)
或者继续使用现有的Service层并仅使用Akka Actors中的那些方法?保持服务层原样的风险是,所有服务方法都将保持公开,并且可以从其他任何地方自由调用(如果有人直接在控制器中调用Service方法(通过传递Actors)或其他东西,则打破模式).
这可能有点鸡和鸡蛋的问题,但这是情况,我想听听你的意见.
有一个简单的case class例子
case class Person(id:Option[Int],firstName:Option[String] ...)
Run Code Online (Sandbox Code Playgroud)
现在Slick Table类看起来如下
class Person(tag: Tag) extends Table[Person](tag, "person") {
def * = (id?, firstName) <> ((Person.apply _).tupled, Person.unapply)
def id = column[Int]("id", O.AutoInc, O.PrimaryKey)
Run Code Online (Sandbox Code Playgroud)
现在之所以将id其定义为Optiona,case class是因为Person在app中的其他位置使用了相同的类.例如JSON,在控制器层中序列化/反序列化.当请求进入创建新记录时,显然id不会在传入中传递JSON.同时,当一个人试图从案例类中检索值时Option,id可能会误导,id因为那不是一个可选字段.IMO,当我看到Option类型我认为这可能有None或Some但在这种情况下它总是有一个值,来自Slick/db,所以定义它Option是误导性的.
我可以将它定义为case class Person(id : SOME_CONST_NUM, firstName :Option[String] ..)每当你将其传递给Slick进行插入时,Slick将插入一个PK值.从Person您Person.id那里检索数据总是可以获得Slick为您提供的价值.用法明智,这是明确和更合适的.但是,这个硬编码的默认设置 …
我正在使用 Java 客户端 API 来恢复聚合。以下是我正在处理的结构。
aggregations
top_models
buckets
key : "BMW"
doc_count : 3
top_models
buckets
key : "X5"
doc_count : 2
top_hits
source
model : X5
color : Red
source
model:X5
color : White
key : "X3"
doc_count : 1
top_hits
source
model : X3
color : Red
key : "Mercedes"
doc_count : 2
top_models
buckets
key : "Benz"
doc_count : 1
top_hits
source
model : Benz
color : Red
key : "ML"
doc_count : 1
top_hits
source
model …Run Code Online (Sandbox Code Playgroud) 我在一个游戏项目中使用 WartRemover。我想从 Wartremover 扫描中排除路由文件(从中生成的代码)。我添加了以下内容,但它仍然扫描播放routes生成的代码。
wartremoverExcluded ++= Seq("com.xxx.controllers.ReverseMyController","com.xxx.controllers.javascript.ReverseMyController","com.xxx.controllers.ref.ReverseMyController")
Run Code Online (Sandbox Code Playgroud)
它仍然显示routes播放文件生成的代码中的疣错误。例如
warn] /xxx/conf/routes:23: Inferred type containing Nothing
warn] PUT /service/myendpoint com.xxx.controllers.MyController.postMyData
Run Code Online (Sandbox Code Playgroud)
对于路由文件中定义的更多路由也是如此。
如何从 wartremover 扫描中排除路由?
如果我有以下方法; 是一个Calendar.getInstance()线程安全的调用?
public Date currentTime() {
Date d = null;
synchronized(this){
d = Calendar.getInstance().getTime();
}
return d;
}
Run Code Online (Sandbox Code Playgroud)
我的理解是Calendar.getInstance()不是线程安全的,所以下面的方法不能是线程安全的.这是对的吗?
public Date currentTime() {
return Calendar.getInstance().getTime();
}
Run Code Online (Sandbox Code Playgroud)
我知道Joda-Time被提升为日期时间API的最佳实践,但在这里我坚持使用标准的java.util.Date/Calendar类.
是否可以在ScalaTest(混合使用Checkers for ScalaCheck属性)中创建一个自定义任意生成器,它正在测试Java代码?例如,以下是forAll中每个测试所需的步骤
val fund = new Fund()
val fundAccount = new Account(Account.RETIREMENT)
val consumer = new Consumer("John")
.createAccount(fundAccount)
fund.addConsumer(consumer)
fundAccount.deposit(amount)
Run Code Online (Sandbox Code Playgroud)
以上是断言结果等之前的准备代码
我有一个现有的API返回Future.现在介绍Actor其中一个用例并尝试继续使用相同的服务API.从下面你可以看到MyService.saveValues回归的未来.
object MyActor {
implicit val ec = scala.concurrent.ExecutionContext.Implicits.global
implicit val timeout = Timeout(1 second)
case class SampleMessage(list: List[String])
val actorSystem = //get actorSystem that was created at the startup
def saveMessage(list: List[String]) ={
val res = (actorSystem.actorOf(Props[MyActor]) ? SaveMyMessage(list) ).mapTo[Future[\/[Throwable,String]]
//res map{ r=>
//}
}
}
class MyActor extends Actor {
import MyActor._
def receive = {
case SaveMyMessage(list) =>
val originalSender = sender
val res : Future[\/[Throwable,String] ] …Run Code Online (Sandbox Code Playgroud) 偶然发现我正在查看的现有代码库中的代码.还有其他类似的调用,将"设置"值设置为"myService"等.确认后续部分不是线程安全的,因为myService不是"本地",两个线程同时进入createUser并同时调用"myService.newUser"时间会破坏后续的persona.firstName和persona.lastName等.这种理解是否正确?
object WFService {
lazy private val myService = engine.getMyService
def createUser(persona: Persona): String = {
val user = myService.newUser(persona.id.toString)
persona.firstName.map(n => user.setFirstName(n))
persona.lastName.map(n => user.setLastName(n))
Run Code Online (Sandbox Code Playgroud) 如果我有
val incomingIds : List[Int] = ....
val existingIds : List[Int] = //this makes db calls and find existing records (only interested in returning ids)
Run Code Online (Sandbox Code Playgroud)
接下来我想incomingIds用existingIds以下方式进行比较
说我有
val incomingIds : List[Int] = List(2,3,4,5)
val existingIds : List[Int] = List(1,2,3,6)
Run Code Online (Sandbox Code Playgroud)
上面的示例建议我的API应该能够找到ids要删除的内容(存在于incomingIds但不存在的内容existingIds).在这个样本中existingIds有1,4,5但是它们不存在应该进入的incomingIds手段1,4,5
val idsForDeletion :List[Int]
Run Code Online (Sandbox Code Playgroud)
并会有另一个列表调用它
val idsForInsertion :List[Int].
Run Code Online (Sandbox Code Playgroud)
所以6应该进入idsForInsertion清单.
是否有一种简单的方法来分区列表这样的方式?
scala ×9
akka ×3
java ×2
scalaz ×2
activiti ×1
calendar ×1
camunda ×1
collections ×1
datetime ×1
list ×1
macos ×1
postgresql ×1
scalacheck ×1
scalatest ×1
slick ×1