xref: /AOO41X/main/jurt/com/sun/star/lib/uno/protocols/urp/PendingRequests.java (revision 2be432768a66cc90838f6a32e76ec156f587e741)
1*2be43276SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2be43276SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2be43276SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2be43276SAndrew Rist  * distributed with this work for additional information
6*2be43276SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2be43276SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2be43276SAndrew Rist  * "License"); you may not use this file except in compliance
9*2be43276SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*2be43276SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*2be43276SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2be43276SAndrew Rist  * software distributed under the License is distributed on an
15*2be43276SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2be43276SAndrew Rist  * KIND, either express or implied.  See the License for the
17*2be43276SAndrew Rist  * specific language governing permissions and limitations
18*2be43276SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*2be43276SAndrew Rist  *************************************************************/
21*2be43276SAndrew Rist 
22*2be43276SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package com.sun.star.lib.uno.protocols.urp;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import com.sun.star.lib.uno.environments.remote.ThreadId;
27cdf0e10cSrcweir import com.sun.star.uno.IMethodDescription;
28cdf0e10cSrcweir import java.util.HashMap;
29cdf0e10cSrcweir import java.util.Stack;
30cdf0e10cSrcweir 
31cdf0e10cSrcweir final class PendingRequests {
PendingRequests()32cdf0e10cSrcweir     public PendingRequests() {}
33cdf0e10cSrcweir 
push(ThreadId tid, Item item)34cdf0e10cSrcweir     public synchronized void push(ThreadId tid, Item item) {
35cdf0e10cSrcweir         Stack s = (Stack) map.get(tid);
36cdf0e10cSrcweir         if (s == null) {
37cdf0e10cSrcweir             s = new Stack();
38cdf0e10cSrcweir             map.put(tid, s);
39cdf0e10cSrcweir         }
40cdf0e10cSrcweir         s.push(item);
41cdf0e10cSrcweir     }
42cdf0e10cSrcweir 
pop(ThreadId tid)43cdf0e10cSrcweir     public synchronized Item pop(ThreadId tid) {
44cdf0e10cSrcweir         Stack s = (Stack) map.get(tid);
45cdf0e10cSrcweir         Item i = (Item) s.pop();
46cdf0e10cSrcweir         if (s.empty()) {
47cdf0e10cSrcweir             map.remove(tid);
48cdf0e10cSrcweir         }
49cdf0e10cSrcweir         return i;
50cdf0e10cSrcweir     }
51cdf0e10cSrcweir 
52cdf0e10cSrcweir     public static final class Item {
Item( boolean internal, IMethodDescription function, Object[] arguments)53cdf0e10cSrcweir         public Item(
54cdf0e10cSrcweir             boolean internal, IMethodDescription function, Object[] arguments)
55cdf0e10cSrcweir         {
56cdf0e10cSrcweir             this.internal = internal;
57cdf0e10cSrcweir             this.function = function;
58cdf0e10cSrcweir             this.arguments = arguments;
59cdf0e10cSrcweir         }
60cdf0e10cSrcweir 
61cdf0e10cSrcweir         public final boolean internal;
62cdf0e10cSrcweir         public final IMethodDescription function;
63cdf0e10cSrcweir         public final Object[] arguments;
64cdf0e10cSrcweir     }
65cdf0e10cSrcweir 
66cdf0e10cSrcweir     private final HashMap map = new HashMap(); // from ThreadId to Stack of Item
67cdf0e10cSrcweir }
68