summaryrefslogtreecommitdiff
path: root/java/tests/ASX/MessageQueueTest.java
blob: 0dfc34283302393da8e55296ec4dd70ed406ac33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// ============================================================================
//
// = PACKAGE
//    tests.ASX
// 
// = FILENAME
//    MessageQueueTest.java
//
// = AUTHOR
//    Prashant Jain
// 
// ============================================================================
package tests.ASX;

import java.io.*;
import ACE.OS.*;
import ACE.ASX.*;

public class MessageQueueTest
{
  public static void main (String args[])
    {
      try
	{
	  MessageBlock conMb;
	  MessageQueue msgQueue = new MessageQueue ();
	  MessageBlock mb1 = new MessageBlock ("hello");
	  MessageBlock mb2 = new MessageBlock ("world");
	  mb1.msgPriority (5);
	  mb2.msgPriority (7);

	  // Enqueue in priority order.
	  if (msgQueue.enqueue (mb1) == -1)
	    ACE.ERROR ("put_next");

	  if (msgQueue.enqueue (mb2) == -1)
	    ACE.ERROR ("put_next");

	  // Now try to dequeue
	  if ((conMb = msgQueue.dequeueHead ()) == null)
	    ACE.ERROR ("dequeueHead");
	  else
	    ACE.DEBUG ("Consumer: removed item " + conMb.base () + " of priority " + conMb.msgPriority ());
	}
      catch (InterruptedException e)
	{
	}
    }
}