KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > dream > queue > PushPullQueueNotSynchronizedImpl


1 /**
2  * Dream
3  * Copyright (C) 2003 INRIA Rhone-Alpes
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library 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 GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: matthieu.leclercq@inrialpes.fr
20  *
21  * Initial developer(s): Matthieu Leclercq
22  * Contributor(s):
23  */

24
25 package org.objectweb.dream.queue;
26
27 import java.util.Map JavaDoc;
28
29 import org.objectweb.dream.AbstractComponent;
30 import org.objectweb.dream.Pull;
31 import org.objectweb.dream.Push;
32 import org.objectweb.dream.message.Message;
33 import org.objectweb.fractal.api.NoSuchInterfaceException;
34 import org.objectweb.fractal.api.control.IllegalBindingException;
35 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
36
37 /**
38  * High performance implementation of a Push/Pull queue. This queue is not
39  * thread safe and its <i>pull </i> interface is non blocking (return
40  * <code>null</code> if the buffer is empty).
41  */

42 public class PushPullQueueNotSynchronizedImpl extends AbstractComponent
43     implements
44       Push,
45       Pull,
46       PushQueuePrimitiveComponentAttributeController
47 {
48
49   protected List listItf;
50   protected int size = 0;
51
52   /**
53    * @see Push#push(Message, Map)
54    */

55   public void push(Message message, Map JavaDoc context)
56   {
57     size++;
58     listItf.add(message);
59   }
60
61   /**
62    * @see Pull#pull(Map)
63    */

64   public Message pull(Map JavaDoc context)
65   {
66     if (listItf.isEmpty())
67     {
68       return null;
69     }
70     else
71     {
72       size--;
73       return (Message) listItf.remove();
74     }
75   }
76
77   /**
78    * @see PushQueueAttributeController#getOverflowPolicy()
79    */

80   public String JavaDoc getOverflowPolicy()
81   {
82     return EXCEPTION_OVERFLOW_POLICY;
83   }
84
85   /**
86    * @see PushQueueAttributeController#setOverflowPolicy(String)
87    */

88   public void setOverflowPolicy(String JavaDoc policy)
89   {
90     // do nothing, no overflow in this queue
91
}
92
93   /**
94    * @see QueueAttributeController#getCurrentSize()
95    */

96   public int getCurrentSize()
97   {
98     return size;
99   }
100
101   /**
102    * @see QueueAttributeController#getMaxCapacity()
103    */

104   public int getMaxCapacity()
105   {
106     return 0;
107   }
108
109   /**
110    * @see QueueAttributeController#setMaxCapacity(int)
111    */

112   public void setMaxCapacity(int maxCapacity)
113   {
114     // do nothing no max capacity
115
}
116
117   // ---------------------------------------------------------------------------
118
// Implementation of BindingController interface
119
// ---------------------------------------------------------------------------
120

121   /**
122    * @see org.objectweb.fractal.api.control.BindingController#listFc()
123    */

124   public String JavaDoc[] listFc()
125   {
126     return new String JavaDoc[]{List.ITF_NAME};
127   }
128
129   /**
130    * @see org.objectweb.fractal.api.control.BindingController#bindFc(String,
131    * Object)
132    */

133   public void bindFc(String JavaDoc clientItfName, Object JavaDoc serverItf)
134       throws NoSuchInterfaceException, IllegalBindingException,
135       IllegalLifeCycleException
136   {
137     super.bindFc(clientItfName, serverItf);
138     if (clientItfName.equals(List.ITF_NAME))
139     {
140       listItf = (List) serverItf;
141     }
142   }
143 }
Popular Tags