私は単純なメッセージマネージャを作成しようとしていますが、私のメッセージはキューに表示されません。Message Managerが壊れています
それが呼び出すコード:
public class MessageManager implements Runnable {
PriorityQueue<Message> messagesQueue = new PriorityQueue<Message>();
public void EnqueueMessage(Message message)
{
messagesQueue.add(message);
}
@Override
public void run() {
// TODO Auto-generated method stub
while (true)
{
//pull message from queue
if (!messagesQueue.isEmpty())
{
CJournal.Journal(MessageManager.class, "Found a message");
Message message = messagesQueue.remove();
//dispatch messages according to their type
switch(message.mflag)
{
case EM_BOOTSTRAP:
CJournal.Journal(MessageManager.class, "Messaging system working properly.");
default:
CJournal.Journal(MessageManager.class, "Dispatch Message Trashed");
}
}
}
}
そして、デバッグ出力は次のとおりです:
//initialize message manager
CJournal.Journal(Main.class, "Initializing message manager");
MessageManager messageManager = new MessageManager();
messageManager.run();
//send bootstrap message
CJournal.Journal(Main.class, "Testing messanger: ending bootstrapping message to messagemanager");
Message boot_strap_message = new Message();
boot_strap_message.mflag = EEventMachine.EM_BOOTSTRAP;
messageManager.EnqueueMessage(boot_strap_message);
とメッセージマネージャのコードがある
13 In Class::class Sampler.Main Journal Entry:Testing Event Manager
14 In Class::class Sampler.Main Journal Entry:Created dummy CEvent. Pushing to event manager.
15 In Class::class Sampler.Main Journal Entry:Initializing message manager
私が取得する必要があり、 「メッセージングシステムが正常に動作しています」
アイデア?
--------------------------------------------------------------
O`11 In Class::class SchedulingManager.Timer.CTimerManager Journal Entry:Creating a CTimer Object
12 In Class::class SchedulingManager.Timer.CTimerManager Journal Entry:Timer creation success. Adding CTimer object to internal list Of Timers
13 In Class::class Sampler.Main Journal Entry:Testing Event Manager
14 In Class::class Sampler.Main Journal Entry:Created dummy CEvent. Pushing to event manager.
15 In Class::class Sampler.Main Journal Entry:Initializing message manager
16 In Class::class Sampler.Main Journal Entry:Testing messanger: ending bootstrapping message to messagemanager
Exception in thread "main" Exception in thread "Thread-4" java.lang.ClassCastException: MessageManagement.Message cannot be cast to java.lang.Comparable
at java.util.concurrent.PriorityBlockingQueue.siftUpComparable(Unknown Source)
at java.util.concurrent.PriorityBlockingQueue.offer(Unknown Source)
at java.util.concurrent.PriorityBlockingQueue.add(Unknown Source)
at MessageManagement.MessageManager.EnqueueMessage(MessageManager.java:69)
at Sampler.Main.main(Main.java:128)
java.util.NoSuchElementException
at java.util.AbstractQueue.remove(Unknown Source)
at MessageManagement.MessageManager.run(MessageManager.java:47)
そして、このコード:
`パブリッククラスMessageManagerはスレッド{
@Override
public void run() {
// TODO Auto-generated method stub
while (true)
{
if (!messagesQueue.isEmpty())
{
//pull message from queue
Message message = messagesQueue.remove();
//dispatch messages according to their type
switch(message.mflag)
{
case EM_BOOTSTRAP:
CJournal.Journal(MessageManager.class, "Messaging system working properly.");
default:
CJournal.Journal(MessageManager.class, "Dispatch Message Trashed");
}
}
}
}
public static PriorityBlockingQueue<Message> messagesQueue = new PriorityBlockingQueue<Message>();
public static void EnqueueMessage(Message message)
{
messagesQueue.add(message);
}
を拡張し、これは私が私のスレッドを宣言しています方法です:
MessageManager messageManager = new MessageManager();
messageManager.start();
//send bootstrap message
CJournal.Journal(Main.class, "Testing messanger: ending bootstrapping message to messagemanager");
Message boot_strap_message = new Message();
boot_strap_message.mflag = EEventMachine.EM_BOOTSTRAP;
messageManager.EnqueueMessage(boot_strap_message);
Loop loop = new Loop(); //hand over to game loop
私はありません何が問題なのか確かめてください。