我正在寻找比这更清洁的解决方案:
import scala.collection.mutable.ListBuffer
val y = Array(1,2,3,4)
val z = new ListBuffer[Int]()
y.foreach(elem => z += elem)
Run Code Online (Sandbox Code Playgroud) 对于可以相当简洁地表达的Actors,必须添加块({...})以便我可以添加日志命令是令人沮丧的.我想在处理消息之前记录我的内部状态,然后在处理消息之后 - 这可能吗?
def receive = {
// I want to log here instead and remove the non-critical logs from below
// e.g. log.debug(s"Received $message")
// log.debug(s"Internal state is $subscriptions")
case RegisterChannel(name, owner) => {
getChannel(name) match {
case Some(deadChannel: DeadChannel) => {
subscriptions += (RealChannel(name, Server(owner)) -> subscriptions(deadChannel))
subscriptions -= deadChannel
context.watch(owner)
log.debug(s"Replaced $deadChannel with a real channel $channels")
}
case Some(realChannel: RealChannel) =>
log.error(s"Refusing to use RegisterChannel($name, $owner) due to $realChannel")
case None => {
subscriptions …Run Code Online (Sandbox Code Playgroud) 我看到多个广播(例如ACTION_TIME_TICK)无法在清单中注册,必须通过显式注册Context.registerReceiver().我在使用ACTION_USER_PRESENT广播意图时遇到问题.具体来说,我在模拟器上测试,我的应用程序保持强制关闭错误:
08-30 09:44:23.397: ERROR/AndroidRuntime(290): java.lang.RuntimeException: Unable to start receiver me.turnerha.RegisterListeners: java.lang.IllegalArgumentException: Receiver not registered: me.turnerha.RegisterListeners@43d05690
Run Code Online (Sandbox Code Playgroud)
这是由
08-30 09:44:23.397: ERROR/AndroidRuntime(290): Caused by: java.lang.IllegalArgumentException: Receiver not registered: me.turnerha.RegisterListeners@43d05690
Run Code Online (Sandbox Code Playgroud)
我的清单很简单:
<receiver android:name=".RegisterListeners">
<intent-filter>
<action android:name="android.intent.action.SCREEN_ON" />
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?我本质上是在创建一个在安装应用程序后尽快唤醒的Receiver.第一次被唤醒时,它会注册一些监听器,然后它会自动取消注册,因此它永远不会再被调用.(我真的希望在您的应用程序安装后立即触发一个意图,以允许一点点设置:))
我很好奇为什么在JLayeredPane上调用setBackground(Color)似乎并没有真正设置背景颜色.我猜它与JLayeredPane有某种关系因为某些原因必须有透明背景?无论如何,这里有一些显示问题的代码.这是在Mac上,所以我相信它正在使用OSX LAF.此图像显示了此结果.
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
public class Main {
public static void main(String[] args) {
// This should be done with Swing Utilities, but I wanted to keep this
// simple...
JFrame foo = new JFrame();
foo.setSize(new Dimension(500, 500));
JLayeredPane bar = new JLayeredPane();
bar.setPreferredSize(new Dimension(200, 200));
bar.setBackground(Color.red);
// If you comment out the following line, you don't see any indication
// the JLayeredPane is actually being …Run Code Online (Sandbox Code Playgroud) 我在Scala中有许多无状态对象,我想将它们组合成一个API - 一种外观如下:
object tools {
// List all methods in toolA
// List all methods in toolB
// List all methods in toolC
}
object ToolA { ... }
object ToolB { ... }
object ToolC { ... }
Run Code Online (Sandbox Code Playgroud)
显然,这是烦人在维护列表tools中的方法ToolA,ToolB和ToolC正在改变很多.A/B/C中没有状态,也没有设置参数.
有什么要说的途径...... "使tools包含集合中的所有的方法中ToolA,ToolB和ToolC"?
有没有办法在不必手动定义日志记录方法的情况下执行以下操作def error:
object FooBar {
lazy val log = LoggerFactory.getLogger("AndroidProxy")
def error(msg: String) = log.error(msg)
def my_method(): Unit = {
error("This is an error!")
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用reshape2格式化这个90-observation dstat数据,以便我可以以合理的方式绘制它,但我无法弄清楚如何将所有foo.5列转换为我可以使用ggplot2轻松绘制的内容.
> library(RCurl)
> x <- getURL("https://gist.githubusercontent.com/hamiltont/27d9f93ad53d8978bccd/raw/ec6118805b9ab8606a303dc81450a6f760864cf9/dstat.csv")
> dstat = read.csv(file="stats", skip=6, header=TRUE)
> names(dstat)
[1] "usr" "sys" "idl" "wai" "hiq"
[6] "siq" "usr.1" "sys.1" "idl.1" "wai.1"
[11] "hiq.1" "siq.1" "usr.2" "sys.2" "idl.2"
[16] "wai.2" "hiq.2" "siq.2" "usr.3" "sys.3"
[21] "idl.3" "wai.3" "hiq.3" "siq.3" "usr.4"
[26] "sys.4" "idl.4" "wai.4" "hiq.4" "siq.4"
[31] "usr.5" "sys.5" "idl.5" "wai.5" "hiq.5"
[36] "siq.5" "usr.6" "sys.6" "idl.6" "wai.6"
[41] "hiq.6" "siq.6" "usr.7" "sys.7" "idl.7"
[46] "wai.7" "hiq.7" "siq.7" "usr.8" …Run Code Online (Sandbox Code Playgroud) 我正在尝试调试为什么null null在记录$rs $rr使用以下kamailio配置的值时得到的原因。
内部request_route:
if (is_method("REGISTER")) {
t_on_reply("REGISTER_FROM_USER");
# In case of a failure, do a failover:
t_on_failure("FAILURE_TO_REGISTRAR");
}
Run Code Online (Sandbox Code Playgroud)
在failure_route内部:
failure_route[FAILURE_TO_REGISTRAR] {
xlog("L_INFO","Registrar replied (failure): $rs $rr\n");
Run Code Online (Sandbox Code Playgroud)
输出:
Registrar replied (failure): <null> <null>
Run Code Online (Sandbox Code Playgroud) 我看了很多例子,我仍然感到困惑.我从这里编译了一个简单的延迟检查程序,它在一台主机上运行完美,但是当我尝试在两台主机上运行时,它会挂起.但是,运行像hostname运行良好的东西:
[hamiltont@4 latency]$ mpirun --report-bindings --hostfile hostfile --rankfile rankfile -np 2 hostname
[4:16622] [[5908,0],0] odls:default:fork binding child [[5908,1],0] to slot_list 0
4
[5:12661] [[5908,0],1] odls:default:fork binding child [[5908,1],1] to slot_list 0
5
Run Code Online (Sandbox Code Playgroud)
但这是编译的延迟程序:
[hamiltont@4 latency]$ mpirun --report-bindings --hostfile hostfile --rankfile rankfile -np 2 latency
[4:16543] [[5989,0],0] odls:default:fork binding child [[5989,1],0] to slot_list 0
[5:12582] [[5989,0],1] odls:default:fork binding child [[5989,1],1] to slot_list 0
[4][[5989,1],0][btl_tcp_endpoint.c:638:mca_btl_tcp_endpoint_complete_connect] connect() to 10.0.2.5 failed: Connection timed out (110)
Run Code Online (Sandbox Code Playgroud)
我目前的猜测是我的防火墙规则有问题(例如主机名不在主机之间通信,但延迟程序会这样做).
[hamiltont@4 latency]$ cat rankfile …Run Code Online (Sandbox Code Playgroud) 此代码导致编译错误could not find implicit value for parameter marshaller:
spray.httpx.marshalling.ToResponseMarshaller[List[akka.actor.ActorRef]].
我不认为问题是ActorRef,因为改变它.mapTo[List[String]]显示相同的编译错误
一般来说,喷雾如何编组与所有暗示有点混淆 - 有没有办法使这个明确,例如ListProtocol.marshal(value)?
import akka.actor.Actor
import spray.http.HttpResponse
import spray.http.HttpRequest
import spray.http.Uri
import spray.http._
import spray.routing._
import HttpMethods._
import akka.actor.ActorRef
import akka.pattern.ask
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.Success
import scala.util.Failure
import spray.http.StatusCodes.InternalServerError
import spray.json.DefaultJsonProtocol
import spray.httpx.SprayJsonSupport._
import spray.httpx.marshalling._
import spray.http._
class HttpApi(val manager: ActorRef) extends HttpServiceActor {
def receive = runRoute {
path("nodes") {
get {
onComplete(manager.ask(NodeList())(3.seconds).mapTo[List[ActorRef]]) {
case Success(value) => {
// …Run Code Online (Sandbox Code Playgroud) 我似乎无法弄清楚如何将这些功能链接在一起,任何帮助或建议都将不胜感激。
// Generic approach to adding flags to a command string
trait UpdateCommandString {
def update[T](option: Option[T], flagName: String)(implicit command: String): String = {
if (option.isEmpty)
command
else if (option.get.isInstanceOf[Boolean]) {
if (option.get.asInstanceOf[Boolean])
s"$command $flagName"
command
} else
s"$command $flagName ${option.get.asInstanceOf[String]}"
}
}
// One example of flags (the program I'm using has literally 50+ flags
// so there will be a number of case classes that group them into related
// sets)
case class Flags(cache: Option[String] = None,
errorlog: …Run Code Online (Sandbox Code Playgroud) 对于一个副项目,我正在阅读一些 systemd 源代码。我发现里面__pure__函数的用法很混乱。具体来说,为什么变量会存在于函数中?它存储结果但似乎从未真正使用过,并且该函数没有我可以看到的副作用。endswithcg_get_root_pathecg_get_root_pathendswithendswith
char *endswith(const char *s, const char *postfix) _pure_;
int cg_get_root_path(char **path) {
char *p, *e;
int r;
assert(path);
r = cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, 1, &p);
if (r < 0)
return r;
e = endswith(p, "/" SPECIAL_INIT_SCOPE);
if (!e)
e = endswith(p, "/" SPECIAL_SYSTEM_SLICE); /* legacy */
if (!e)
e = endswith(p, "/system"); /* even more legacy */
if (e)
*e = 0;
*path = p;
return 0;
}
char* endswith(const char …Run Code Online (Sandbox Code Playgroud)