我的bash脚本中有以下代码.现在我想在POSIX中使用它.那么如何转换呢?谢谢.
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null && pwd )"
Run Code Online (Sandbox Code Playgroud) 我想做的是:
1)在服务器上创建一个主actor,可以在10台不同的机器上动态创建10个远程actor
2)主人将任务分配给10个远程演员
3)当每个远程演员完成他们的工作时,他们将结果发送给主演员
4)主人关闭整个系统
我的问题是:
1)我不知道如何配置主演员,下面是我的服务器部分代码:
class MasterAppliation extends Bootable{
val hostname = InetAddress.getLocalHost.getHostName
val config = ConfigFactory.parseString(
s"""
akka{
actor{
provider = "akka.remote.RemoteActorRefProvider"
deployment {
/remotemaster {
router = "round-robin"
nr-of-instances = 10
target {
nodes = ["akka.tcp://remotesys@host1:2552", "akka.tcp://remotesys@host2:2552", ....... akka.tcp://remotesys@host10:2552"]
}
}
}
remote{
enabled-transports = ["akka.remote.netty.tcp"]
netty.tcp{
hostname = "$hostname"
port = 2552
}
}
}""")
val system = ActorSystem("master", ConfigFactory.load(config))
val master = system.actorOf(Props(new master), name = "master")
def dosomething = master ! Begin()
def …
Run Code Online (Sandbox Code Playgroud) 现在,我被要求在akka的演员中添加日志功能.
收到消息后,在处理消息之前,应将此消息写入日志.在发送消息之前,应首先记录此消息.
我想我应该覆盖Actor中的receive
和send
函数.假设我创建了一个actorlog
扩展的特征Actor
.课程myActor
延伸actorlog
.但在myActor
,我需要覆盖receive
功能(这似乎导致问题).所以我很困惑我该做什么.
PS.我知道akka提供日志记录.但现在我需要自己实现这个功能.
#include <iostream>
using namespace std;
void swap(int *a, int *b) {
*a = *a^*b;
*b = *a^*b;
*a = *a^*b;
}
int main()
{
int array[]={1,9,2,8,3,7};
for(int i=0; i<6; i++)
cout<<array[i];
cout<<endl;
swap(array[1], array[4]);
for(int i=0; i<6;i++)
cout<<array[i];
cout<<endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
以上是一个测试样本.我发现如果使用swap(array[1], array[4]);
它,它也会交换数组中两个位置的值.但这让我感到困惑,因为函数swap()
需要两个指针,而不是两个整数值.
谢谢你的帮助:)
c++ swap namespaces using-directives argument-dependent-lookup
我是python的新手。现在,我想创建一个计时器。超时后,将采取一些措施。但是,我可以中断此计时器并将其重置。伪代码如下所示:
def timeout()
print "time out!"
T.cancel() #reset timer T
T = Timer(60, timeout)
T.start()
T = Timer(60, timeout)
def interrupt()
T.cancel() #reset timer T
T = Timer(60, timeout)
T.start()
if __name__=='__main__'
T.start()
while true
if something is true
interrupt
Run Code Online (Sandbox Code Playgroud)
我想出的解决方案是取消函数中断中的计时器,然后创建一个新计时器。但是,似乎取消了计时器并创建了新的计时器,这不是高性能。任何的想法?
我使用ASM为while()语句生成字节代码.但是eclipse报道:
Exception in thread "main" java.lang.VerifyError: (class: show_cise_image, method: main signature: ([Ljava/lang/String;)V) Inconsistent stack height 2 != 1
at java.lang.Class.getDeclaredMethods0(Native Method)
..................
Run Code Online (Sandbox Code Playgroud)
我的字节码源代码:
show_cise_image {
boolean flag;
flag = true;
while(flag){
flag = false;
}
}
Run Code Online (Sandbox Code Playgroud)
生成上述代码的字节代码:
/ class version 51.0 (51)
// access flags 0x21
public class show_cise_image {
// access flags 0x8
static int v = 0
// access flags 0x8
static boolean flag = 0
// access flags 0x9
public static main(String[]) : void
L0
LINENUMBER 6 …
Run Code Online (Sandbox Code Playgroud) 我的测试代码如下:
main1.c:
#include <stdio.h>
extern struct tt ;
int main()
{
struct tt y;
y.a=255;
y.b=0;
printf("tt->a=%#x ,tt->b=%#x \n",y.a,y.b);
}
Run Code Online (Sandbox Code Playgroud)
main2.c:
#include<stdio.h>
struct tt
{
int a;
int b;
};
Run Code Online (Sandbox Code Playgroud)
生成文件:
main: main1.o
gcc -o main main1.o
main1.o: main2.c main1.c
Run Code Online (Sandbox Code Playgroud)
但编译器报告:
cc -c -o main1.o main1.c
main1.c:2: warning: useless storage class specifier in empty declaration
main1.c: In function ‘main’:
main1.c:5: error: storage size of ‘y’ isn’t known
make: *** [main1.o] Error 1
Run Code Online (Sandbox Code Playgroud)
如何在.c文件中编写代码使用另一个.c文件中定义的结构?
谢谢你的帮助!
现在,我想将数组转换为这样的字典:
dict = {'item0': arr[0], 'item1': arr[1], 'item2': arr[2]...}
Run Code Online (Sandbox Code Playgroud)
如何在python中优雅地解决这个问题?
public class test {
public static void main(String[] args) {
boolean flag=false;
char[] c=new char[5];
c[0]='e';
read(flag, c);
System.out.println(c[0]);
System.out.println(flag);
}
public static void read(boolean flag, char[] c){
flag=true;
c[0]='a';
}
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,我发现了一个有趣的问题:char[] c
已更改并正确打印结果,但布尔标志尚未更改!我不知道这是怎么回事?现在,我想改变旗帜,怎么做呢?谢谢你的帮助!
我正在使用scala 2.10和Akka 2.2.1在ubuntu 12.04下进行eclipse.
// A and B are derived from Node
val algorithm = if(args(0) > 1)()=> new A else ()=> new B
/* alternative:
val algorithm = if(args(0) > 1) (()=> system.actorOf(Props(new A), name ="A") )
else (()=> system.actorOf(Props(new B),name="B"))
*/
// alternative : class work(algorithm: ()=>ActorRef, num:Int) {
class work(algorithm: ()=> Node, num: Int){
val a = Array.fill(num)(algorithm) // here I wanna create an array with num slots
// and objects of A or B in it …
Run Code Online (Sandbox Code Playgroud) 现在我想要一个演员向其他演员发送消息,同时接收来自其他人的消息.看来我需要在Akka中使用多线程.以下是我的代码:
def receive = {
case Rumor => {
count+=1;
if ...
else self ! Sleep(FiniteDuration(20, "millis"))
}
case Sleep(duration) => {
case object WakeUp
context.system.scheduler.scheduleOnce(duration, self, WakeUp)
context.become(
{
case WakeUp => context.unbecome()
others ! Rumor
}, discardOld = false
)
}
case _=> .....
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:
1)我不确定我的代码是否会像我期望的那样工作.参考使用演员内部的Akka调度程序
2)我已经导入了
import scala.math._
import akka.actor._
import scala.util.Random
import scala.concurrent.duration._
Run Code Online (Sandbox Code Playgroud)
但编译器仍然报告错误:
error: Cannot find an implicit ExecutionContext, either require one yourself or import ExecutionContext.Implicits.global
context.system.scheduler.scheduleOnce(duration, self, WakeUp)
Run Code Online (Sandbox Code Playgroud) 我有这样的代码:
max32 = 0xffffffffL
print(sys.getsizeof(max32))
>>32
Run Code Online (Sandbox Code Playgroud)
这是用python 2编写的。
现在我需要确保这段代码在 python 3 中也兼容。但是 python3 中没有长整数。我怎么做?
akka ×4
scala ×4
python ×3
java ×2
bash ×1
c ×1
c++ ×1
distributed ×1
namespaces ×1
posix ×1
python-3.x ×1
sh ×1
swap ×1
timer ×1