~ifolder-dev/simias/trunk-packaging

« back to all changes in this revision

Viewing changes to src/core/NU-SimiasAspService/.svn/text-base/BaseRequestBroker.cs.svn-base

  • Committer: Jorge O. Castro
  • Date: 2007-12-03 06:56:46 UTC
  • Revision ID: jorge@ubuntu.com-20071203065646-mupcnjcwgm5mnhyt
* Remove a bunch of .svn directories we no longer need.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
 |
3
 
 | Copyright (c) 2007 Novell, Inc.
4
 
 | All Rights Reserved.
5
 
 |
6
 
 | This program is free software; you can redistribute it and/or
7
 
 | modify it under the terms of version 2 of the GNU General Public License as
8
 
 | published by the Free Software Foundation.
9
 
 |
10
 
 | This program is distributed in the hope that it will be useful,
11
 
 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 | GNU General Public License for more details.
14
 
 |
15
 
 | You should have received a copy of the GNU General Public License
16
 
 | along with this program; if not, contact Novell, Inc.
17
 
 |
18
 
 | To contact Novell about this file by physical or electronic mail,
19
 
 | you may find current contact information at www.novell.com 
20
 
 |
21
 
 |
22
 
 | Mono.ASPNET.BaseRequestBroker
23
 
 |
24
 
 | Authors:
25
 
 |      Gonzalo Paniagua Javier (gonzalo@ximian.com)
26
 
 |      Lluis Sanchez Gual (lluis@ximian.com)
27
 
 |      
28
 
 |***************************************************************************/
29
 
 
30
 
 
31
 
using System;
32
 
using System.Collections;
33
 
 
34
 
namespace Mono.ASPNET
35
 
{
36
 
        public class BaseRequestBroker: MarshalByRefObject, IRequestBroker
37
 
        {
38
 
                ArrayList requests = new ArrayList ();
39
 
                Queue freeSlots = new Queue ();
40
 
                
41
 
                internal int RegisterRequest (IWorker worker)
42
 
                {
43
 
                        lock (requests)
44
 
                        {
45
 
                                if (freeSlots.Count == 0)
46
 
                                        return requests.Add (worker);
47
 
                                
48
 
                                int freeSlot = (int)freeSlots.Dequeue ();
49
 
                                requests [freeSlot] = worker;
50
 
                                return freeSlot;
51
 
                        }
52
 
                }
53
 
                
54
 
                internal void UnregisterRequest (int id)
55
 
                {
56
 
                        lock (requests)
57
 
                        {
58
 
                                requests [id] = null;
59
 
                                freeSlots.Enqueue (id);
60
 
                        }
61
 
                }
62
 
                
63
 
                public int Read (int requestId, int size, out byte[] buffer)
64
 
                {
65
 
                        buffer = new byte[size];
66
 
                        IWorker w;
67
 
                        lock (requests) {
68
 
                                w = (IWorker) requests [requestId];
69
 
                        }
70
 
                        int nread = w.Read (buffer, 0, size);
71
 
                        return nread;
72
 
                }
73
 
                
74
 
                public IWorker GetWorker (int requestId)
75
 
                {
76
 
                        lock (requests) {
77
 
                                return (IWorker) requests [requestId];
78
 
                        }
79
 
                }
80
 
                
81
 
                public void Write (int requestId, byte[] buffer, int position, int size)
82
 
                {
83
 
                        GetWorker (requestId).Write (buffer, position, size);
84
 
                }
85
 
                
86
 
                public void Close (int requestId)
87
 
                {
88
 
                        GetWorker (requestId).Close ();
89
 
                }
90
 
                
91
 
                public void Flush (int requestId)
92
 
                {
93
 
                        GetWorker (requestId).Flush ();
94
 
                }
95
 
 
96
 
                public override object InitializeLifetimeService ()
97
 
                {
98
 
                        return null;
99
 
                }
100
 
        }
101
 
}