我想在一个程序中使用actor,我会对某些演员有一些限制,好像他们是队列一样.例如,假设我有一些应用了更改事件的外部系统,还有一些外部系统数据的缓存.所以我有两个演员:
ChangeApplicationActorCacheActor作为一部分ChangeApplicationActor,当我将更改应用于X外部系统中的某个实体时,我想发送一些事件来告诉CacheActor同步:
val changeApplicationActor = actor {
loop {
react {
case ChangeInstruction(x) =>
externalSystem.applyChange(x)
cacheActor ! Sync(x)
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我现在有两个要求:
CacheActor具有内部状态和理想,我想它来处理其Sync指令顺序CacheActor包含两个Sync(x)相同值的指令的收件箱x,那么我想忽略第二个Sync指令(即我应该只有一个挂起的指令用于任何给定的值x)有没有办法强迫演员单线程?有什么方法可以访问演员的邮箱并删除任何重复的事件?难道我不能避免实施CacheActoras,嗯,不是演员吗?
我的应用程序布局基于左侧的treeView和右侧的面板.该面板托管一个不同的TForm类,具体取决于所选的树节点(一种'形式浏览器').一次只显示一个表单,该表单公开存储在别处的基础数据,并在每个新的树节点点击时创建和销毁表单实例.
除了以下场景外,这一切都正常.单击表单上的一个按钮,该按钮启动需要一秒左右的操作.在此操作期间,可能会调用Application.ProcessMessages.现在,在此操作实际完成之前,用户单击一个新的树节点.处理此wmMousedown消息,导致表单立即释放.然后,操作代码返回到表单代码,以查找自己已更改并导致AV.
我的问题是,在我允许表单被释放之前,有没有办法知道表单的消息已经全部处理完毕?单击关闭按钮时,模态窗体似乎会执行此操作,因为如果忙,它们会在关闭之前暂停...
谢谢Brian
任何人都可以帮我指出我的程序中的错误是什么?
在此先感谢,kingsmasher1
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <string.h>
#include <errno.h>
typedef struct msgbuf {
long mtype; /* message type, must be > 0 */
char mtext[15]; /* message data */
} msgbuf;
int main() {
key_t key;
int msqid, pid, length;
msgbuf buf;
msqid=msgget(IPC_PRIVATE,IPC_CREAT);
if(msqid==-1){
perror("msgget failed");
return;
}
else {
printf("msgget succeeded. ID:%u",msqid);
}
pid=fork();
if(pid==-1) {
perror("fork failed\n");
}
buf.mtype=1;
strcpy(buf.mtext, "This is a test message");
length=sizeof(buf.mtext);
if(msgsnd(msqid,&buf,length,0)!=0) {
perror("msgsnd failed:\n");
} …Run Code Online (Sandbox Code Playgroud) 我正在使用ActiveMQ使用C#应用程序发送和接收消息.但是我在队列中计算消息时遇到了一些困难.这是我的代码:
public int GetMessageCount()
{
int messageCount = 0;
Uri connecturi = new Uri(this.ActiveMQUri);
IConnectionFactory factory = new NMSConnectionFactory(connecturi);
using (IConnection connection = factory.CreateConnection())
using (ISession session = connection.CreateSession())
{
IDestination requestDestination = SessionUtil.GetDestination(session, this.QueueRequestUri);
IQueueBrowser queueBrowser = session.CreateBrowser((IQueue)requestDestination);
IEnumerator messages = queueBrowser.GetEnumerator();
while(messages.MoveNext())
{
messageCount++;
}
connection.Close();
session.Close();
connection.Close();
}
return messageCount;
}
Run Code Online (Sandbox Code Playgroud)
我以为我可以使用QueueBrowser来获取计数,但它返回的IEnumerator总是为空.我从这个页面得到了使用QueueBrowser的想法,但也许还有另一种方法我应该这样做?
更新:
我通过枚举器找到的"无限循环"问题的解决方案是通过访问当前消息来解决的.它现在只经过一次循环(这是正确的,因为队列中只有一条消息).
新的while循环是:
while(messages.MoveNext())
{
IMessage message = (IMessage)messages.Current;
messageCount++;
}
Run Code Online (Sandbox Code Playgroud) 清除WebSphere MQ中的队列时,使用clear命令和mqget API调用之间的区别是什么?
我正在使用Windows Azure消息队列.我想知道是否有一种方法可以在我得到它们时锁定队列中的消息?
我已经减少了一个问题,我需要以下示例代码:
var inQueue = ".\private$\testqueue";
using (var ts = new TransactionScope())
{
using (var q = new MessageQueue(inQueue, QueueAccessMode.Send))
{
for (var i = 0; i < 100000; ++i)
{
var msg = new Message(i);
q.Send(msg, MessageQueueTransactionType.Automatic);
}
}
ts.Complete();
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,它使用TransactionScope模式将100,000个整数写入(事务性,本地)队列.我的理解是这种类型的操作不会升级为DTC交易.
但是,如果我在运行时打开组件服务,我可以在本地DTC>事务列表中看到该事务.这意味着交易已经升级,对吧?
为什么会这样?我在另一个程序中因性能不佳而被提示,并且看起来使用DTC进行这样一个简单的事务可能是一个因素.无论如何,我只想了解原因.
任何帮助,将不胜感激.
当我试图减少POSIX消息队列中的消息数量时,它保持最大值为10.是否可以减少或增加POSIX消息队列中的消息数量?
以下代码将消息发送到POSIX消息队列.我将最大消息(MQ_MAX_NUM_OF_MESSAGES)设置为5,但它发送10条消息
send.c
#include <stdio.h>
#include <mqueue.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <string.h>
#define MSGQOBJ_NAME "/myqueue123"
#define MAX_MSG_LEN 70
#define MQ_MESSAGE_MAX_LENGTH 70
#define MQ_MAX_NUM_OF_MESSAGES 5
struct mq_attr attr;
int main(int argc, char *argv[])
{
mqd_t msgq_id;
unsigned int msgprio = 0;
pid_t my_pid = getpid();
char msgcontent[MAX_MSG_LEN];
int create_queue = 0;
char ch; /* for getopt() */
time_t currtime;
attr.mq_flags = 0;
attr.mq_maxmsg = MQ_MAX_NUM_OF_MESSAGES;
attr.mq_msgsize = MQ_MESSAGE_MAX_LENGTH;
attr.mq_curmsgs = 0;
while ((ch = getopt(argc, argv, …Run Code Online (Sandbox Code Playgroud) 在下面(可编译的)示例中,我正在尝试在普通控制台应用程序中侦听Windows消息队列,以便接收有关正在连接/断开的USB设备的通知.我从这里获取了示例代码:在C++非GUI应用程序中检测USB插入/删除
然而,呼吁GetMessage在while-clause永远不会返回,因为obviuously Windows不发送任何消息给我的队列.我究竟做错了什么?这与UIPI有什么关系吗?
我不经常使用MFC/WinAPI,所以请详细说明你的答案.
#define ANSI
#define WIN32_LEAN_AND_MEAN
#define _WIN32_WINNT 0x0501
#include <windows.h>
#include <winuser.h>
#include <Dbt.h>
#include <string>
#include <iostream>
#include <stdexcept>
#define HID_CLASSGUID {0x4d1e55b2, 0xf16f, 0x11cf,{ 0x88, 0xcb, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30}}
#define CLS_NAME "DUMMY_CLASS"
#define HWND_MESSAGE ((HWND)-3)
LRESULT message_handler(HWND__* hwnd, UINT uint, WPARAM wparam, LPARAM lparam)
{
switch (uint)
{
case WM_NCCREATE: // before window creation
return true;
break;
case WM_CREATE: // the actual creation of the window
{
// …Run Code Online (Sandbox Code Playgroud) 我尝试访问Windows消息队列的消息:
var activeQueue = new MessageQueue("\\myhost\\private$\\just.a.queue", QueueAccessMode.Receive);
foreach(message in _activeQueue.GetAllMessages().ToList()) {
Console.WriteLine(message.Body);
}
Run Code Online (Sandbox Code Playgroud)
我在尝试访问时收到InvalidOperationException message.Body(并且几乎除Id之外的所有其他属性 - 字段).