我正在创建一个CompositeUserTypein Hibernate来映射EAST和NORTH字段到Coordinate对象.目前我的Coordinate对象是不可变的,如果可能的话我想保持这种方式.
我写了我的nullSafeGet,从ResultSet中拉出坐标并调用构造函数:
@Override
public Object nullSafeGet(ResultSet rs, String[] names,
SessionImplementor session, Object owner)
throws HibernateException, SQLException {
Integer easting = (Integer)Hibernate.INTEGER.nullSafeGet(rs, names[0]);
Integer northing = (Integer)Hibernate.INTEGER.nullSafeGet(rs, names[1]);
if(easting==null || northing==null)
return null;
return new Coordinate(easting, northing);
}
Run Code Online (Sandbox Code Playgroud)
我不知道该怎么做setPropertyValue,似乎想要一次设置一个坐标.可以实例化一个不可变对象CompositeUserType,或者我试图做不可能的事情?
(还试图弄清楚如何处理Hibernate.INTEGER被弃用,但一次只有一件事......)
如何检查我通过actorFor获得actorRef的远程actor是否还活着?任何对文档的引用都将不胜感激.我正在使用Scala的Akka.
我已经看到了对主管和死亡计时器的参考,但我并不觉得我的用例需要这么重的机器.我只想让我的客户端检查主服务器是否使用已知路径,以及是否发送消息介绍自己.如果主机未启动,则应等待一段时间再重试.
更新2: 建议我只是使用乒乓询问测试来查看它是否还活着.我明白这就像是
implicit val timeout = Timeout(5 seconds)
val future = actor ? AreYouAlive
try{
Await.result(future, timeout.duration)
}catch{
case e:AskTimeoutException => println("It's not there: "+e)
}
Run Code Online (Sandbox Code Playgroud)
我想我已经对日志中存在例外情况感到困惑,现在它们仍然存在.例如
也许这就是它的工作方式,我必须接受日志中的错误/警告,而不是试图防止它们?
我在Scala中有一些琐碎的火花项目,并且想使用logback,但是spark/hadoop似乎强迫我使用log4j.
这似乎与我对slf4j的目的的理解不一致; 这不是对spark/hadoop的疏忽吗?
我是否必须放弃logback并使用log4j,还是有解决方法?
在build.sbt中,我尝试了排除...
"org.apache.spark" %% "spark-core" % "1.4.1" excludeAll(
ExclusionRule(name = "log4j"),
ExclusionRule(name = "slf4j-log4j12")
),
"org.slf4j" % "slf4j-api" % "1.7.12",
"ch.qos.logback" % "logback-core" % "1.1.3",
"ch.qos.logback" % "logback-classic" % "1.1.3"
Run Code Online (Sandbox Code Playgroud)
......但这会导致异常......
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Level
at org.apache.hadoop.mapred.JobConf.<clinit>(JobConf.java:354)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:344)
at org.apache.hadoop.conf.Configuration.getClassByNameOrNull(Configuration.java:1659)
at org.apache.hadoop.util.ReflectionUtils.setJobConf(ReflectionUtils.java:91)
at org.apache.hadoop.util.ReflectionUtils.setConf(ReflectionUtils.java:75)
at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:133)
at org.apache.hadoop.security.Groups.<init>(Groups.java:55)
at org.apache.hadoop.security.Groups.getUserToGroupsMappingService(Groups.java:182)
at org.apache.hadoop.security.UserGroupInformation.initialize(UserGroupInformation.java:235)
at org.apache.hadoop.security.UserGroupInformation.ensureInitialized(UserGroupInformation.java:214)
at org.apache.hadoop.security.UserGroupInformation.getLoginUser(UserGroupInformation.java:669)
at org.apache.hadoop.security.UserGroupInformation.getCurrentUser(UserGroupInformation.java:571)
at org.apache.spark.util.Utils$$anonfun$getCurrentUserName$1.apply(Utils.scala:2162)
at org.apache.spark.util.Utils$$anonfun$getCurrentUserName$1.apply(Utils.scala:2162)
at scala.Option.getOrElse(Option.scala:120)
at org.apache.spark.util.Utils$.getCurrentUserName(Utils.scala:2162)
at org.apache.spark.SparkContext.<init>(SparkContext.scala:301)
at spike.HelloSpark$.main(HelloSpark.scala:19)
at …Run Code Online (Sandbox Code Playgroud) 我在Windows XP机器上使用共享文件夹在VMWare Player中运行Ubuntu Lucid来宾. git status虚拟机速度慢(24秒)但主机速度快(0.06秒)任何想法为什么?
更多细节:
du -hs .在客户操作系统中获得)git gc像这里描述的那样运行,但没有区别:计数对象:3604,完成.
压缩对象:100%(1069/1069),
完成.书写对象:100%
(3604/3604),完成了.总计3604(delta 2143),重用3604(delta 2143)
删除重复的对象:100%
(256/256),完成了.
PortableGit-1.7.2.3-preview20100911nosmp noapic nolapic描述这里.在Java Eclipse项目中进行严格的重构时,我经常会破坏构建,但是要集中精力让一次测试通过.在运行测试时,Eclipse警告项目无法编译,但它仍将运行可编译的测试.
现在我正在使用SBT,并希望通过'仅测试'实现相同的功能,但它尝试编译整个项目,失败,并且不运行测试.我怎么能告诉它只是编译它可以运行测试的位.
我有一个简单的类,自然分为两部分,所以我重构为
class Refactored extends PartOne with PartTwo
Run Code Online (Sandbox Code Playgroud)
然后单元测试开始失败.
下面是尝试重现问题.所有三个示例的功能都相同,但第三个测试失败并显示NullPointerException.什么是使用导致mockito问题的特征?
编辑: Mockito是Scala的最佳选择吗?我使用的是错误的工具吗?
import org.scalatest.junit.JUnitSuite
import org.scalatest.mock.MockitoSugar
import org.mockito.Mockito.when
import org.junit.Test
import org.junit.Before
class A(val b:B)
class B(val c:Int)
class First(){
def getSomething(a:A) = a.b.c
}
class Second_A extends Second_B
class Second_B{
def getSomething(a:A) = a.b.c
}
class Third_A extends Third_B
trait Third_B{
// Will get a NullPointerException here
// since a.b will be null
def getSomething(a:A) = a.b.c
}
class Mocking extends JUnitSuite with MockitoSugar{
var mockA:A = _
@Before def …Run Code Online (Sandbox Code Playgroud) 这篇伟大的每日Scala文章描述了如何克服匹配中的类型擦除.我正在尝试应用该技术来转换参数化类型的IndexesSeq,但匹配失败.为什么会这样,我该如何解决?
object Example extends App{
class TableColumn[T](
val values: IndexedSeq[T],
val name: Option[String] = None
)(implicit val m: Manifest[T])
class Def[C](implicit desired : Manifest[C]) {
def unapply[X](c : X)(implicit m : Manifest[X]) : Option[C] = {
//println("m.toString+", "+desired.toString)
def sameArgs = desired.typeArguments.zip(m.typeArguments).forall {
case (desired,actual) => desired >:> actual
}
if (desired >:> m && sameArgs) Some(c.asInstanceOf[C])
else None
}
}
val IntTableColumn = new Def[TableColumn[Int]]
val DoubleTableColumn = new Def[TableColumn[Double]]
class Analysis(data: IndexedSeq[TableColumn[_]]){
val transformedData = data.map{_ match{ …Run Code Online (Sandbox Code Playgroud) 我的问题涉及JVM应用程序可以在多大程度上利用主机的NUMA布局.
我有一个Akka应用程序,其中actor通过将传入数据与已加载到不可变(Scala)对象的"公共"数据相结合来同时处理请求.该应用程序使用许多双核VM在云中很好地扩展,但在单个64核计算机上表现不佳.我认为这是因为公共数据对象驻留在一个NUMA单元中,并且从其他单元同时访问的许多线程对于互连来说太多了.
如果我运行64个单独的JVM应用程序,每个应用程序包含1个actor,那么性能再次良好.一个更温和的方法可能是运行与NUMA单元一样多的JVM应用程序(在我的情况下为8),使主机操作系统有机会将线程和内存保持在一起?
但是有没有更聪明的方法在单个JVM中实现相同的效果?例如,如果我用一个案例类的几个实例替换我的公共数据对象,那么JVM是否有能力将它们放在最佳NUMA单元上?
更新:
我正在使用Oracle JDK 1.7.0_05和Akka 2.1.4
我现在尝试使用UseNUMA和UseParallelGC JVM选项.当使用一个或几个JVM时,似乎都没有对性能降低产生任何重大影响.我也尝试过使用PinnedDispatcher和thre-pool-executor,但没有效果.我不确定配置是否有效,因为启动日志中似乎没有什么不同.
当我为每个工人使用一个JVM(~50)时,最大的改进仍然存在.然而,问题似乎是在FailureDector注册Akka集群JVM之间成功交换"第一个心跳"之前存在很长的延迟(最多几分钟).我怀疑还有其他问题,我还没有发现.我已经不得不增加ulimit -u,因为我达到了默认的最大进程数(1024).
只是为了澄清,我并没有尝试获得大量的消息,只是试图让许多独立的actor同时访问一个不可变的对象.
我正试着用鱼壳跑步.
#!/usr/local/bin/fish
java -Xmx512M -jar (dirname (status -f))/sbt-launch-0.7.4.jar "$argv"
Run Code Online (Sandbox Code Playgroud)
当我打电话给我时,我得到以下内容
[info] Building project MyProject 1.0 against Scala 2.8.1
[info] using MyProject with sbt 0.7.4 and Scala 2.7.7
[info]
[info] Total session time: 1 s, completed Dec 19, 2010 4:29:46 PM
[success] Build completed successfully.
Run Code Online (Sandbox Code Playgroud)
然后sbt退出.为什么?它不应该等待命令吗?
在一个可能相关的说明中,我确信当我使用bash时,我不习惯在第一行做#![shell].改变了什么?
更新:当编写使用bash的等效脚本时,一切正常,sbt不进行构建然后退出
#!/bin/bash
java -Xmx512M -jar `dirname $0`/sbt-launch-0.7.4.jar "$@"
Run Code Online (Sandbox Code Playgroud) 以下代码导致最后一行出现StackOverflowError.
object StackTest extends App{
@tailrec def incrementValues(acc: Map[String, Int], inc: Int): Map[String, Int] = {
if(inc == 0) acc
else incrementValues(acc.mapValues(_ + 1), inc - 1)
}
val myMap = incrementValues(Map("key" -> 0), 10000)
myMap.foreach(println)
}
Run Code Online (Sandbox Code Playgroud)
在Scala 2.11.2中:
Exception in thread "main" java.lang.StackOverflowError
at scala.collection.MapLike$MappedValues.foreach(MapLike.scala:245)
at scala.collection.TraversableLike$WithFilter.foreach(TraversableLike.scala:777)
at scala.collection.MapLike$MappedValues.foreach(MapLike.scala:245)
at scala.collection.TraversableLike$WithFilter.foreach(TraversableLike.scala:777)
at scala.collection.MapLike$MappedValues.foreach(MapLike.scala:245)
...
Run Code Online (Sandbox Code Playgroud)
看看MapLike的源代码,我可以看到它使用MappedValues对象,它看起来像一个视图:
protected class MappedValues[C](f: B => C) extends AbstractMap[A, C] with DefaultMap[A, C] {
override def foreach[D](g: ((A, C)) => D): Unit = for ((k, …Run Code Online (Sandbox Code Playgroud)