summaryrefslogtreecommitdiff
path: root/java/demo/Ice/async/QueueI.java
blob: c6243869c4df7aa8952e2f0df17caea9277e946f (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
51
52
53
54
55
56
57
58
// **********************************************************************
//
// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

import Demo.*;

public class QueueI extends _QueueDisp
{
    synchronized public void
    get_async(AMD_Queue_get getCB, Ice.Current current)
    {
        if(_messageQueue.size() != 0)
	{
	    try
	    {
	        getCB.ice_response((String)_messageQueue.getFirst());
		_messageQueue.removeFirst();
	    }
	    catch(Ice.LocalException ex)
	    {
	        ex.printStackTrace();
	    }
	}
	else
	{
	    _requestQueue.add(getCB);
	}
    }

    synchronized public void
    add(String message, Ice.Current current)
    {
        if(_requestQueue.size() != 0)
	{
	    try
	    {
	        AMD_Queue_get cb = (AMD_Queue_get)_requestQueue.removeFirst();
		cb.ice_response(message);
	    }
	    catch(Ice.LocalException ex)
	    {
	        ex.printStackTrace();
	    }
	}
	else
	{
	    _messageQueue.add(message);
	}
    }

    private java.util.LinkedList _messageQueue = new java.util.LinkedList();
    private java.util.LinkedList _requestQueue = new java.util.LinkedList();
}