~ubuntu-branches/ubuntu/raring/libjboss-remoting-java/raring

« back to all changes in this revision

Viewing changes to src/main/org/jboss/remoting/callback/BlockingCallbackStore.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: package-import@ubuntu.com-20110909140103-o8ucrolqt5g25k57
Tags: upstream-2.5.3.SP1
ImportĀ upstreamĀ versionĀ 2.5.3.SP1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
* JBoss, Home of Professional Open Source
 
3
* Copyright 2005, JBoss Inc., and individual contributors as indicated
 
4
* by the @authors tag. See the copyright.txt in the distribution for a
 
5
* full listing of individual contributors.
 
6
*
 
7
* This is free software; you can redistribute it and/or modify it
 
8
* under the terms of the GNU Lesser General Public License as
 
9
* published by the Free Software Foundation; either version 2.1 of
 
10
* the License, or (at your option) any later version.
 
11
*
 
12
* This software is distributed in the hope that it will be useful,
 
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
15
* Lesser General Public License for more details.
 
16
*
 
17
* You should have received a copy of the GNU Lesser General Public
 
18
* License along with this software; if not, write to the Free
 
19
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 
20
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 
21
*/
 
22
package org.jboss.remoting.callback;
 
23
 
 
24
import org.jboss.logging.Logger;
 
25
import org.jboss.remoting.SerializableStore;
 
26
 
 
27
import java.io.IOException;
 
28
import java.io.Serializable;
 
29
import java.util.ArrayList;
 
30
import java.util.List;
 
31
import java.util.Map;
 
32
 
 
33
/**
 
34
 * This callback store does not persist callback messages when memory is
 
35
 * running low, but instead will block the thread making the handle callback
 
36
 * call from the server invoker.  The intention is that this will throttle the
 
37
 * server invoker from generating/sending any more callbacks until client as
 
38
 * called to get the in-memory callbacks that have already been collected and
 
39
 * memory has been released.
 
40
 * @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
 
41
 */
 
42
public class BlockingCallbackStore implements SerializableStore
 
43
{
 
44
   private Object lockObject = new Object();
 
45
 
 
46
   private List callbacks = new ArrayList();
 
47
 
 
48
   private static final Logger log = Logger.getLogger(BlockingCallbackStore.class);
 
49
 
 
50
   /**
 
51
    * Gets the number of callbacks that are waiting
 
52
    * to be processed.
 
53
    * @return
 
54
    */
 
55
   public int size()
 
56
   {
 
57
      return callbacks.size();
 
58
   }
 
59
 
 
60
   /**
 
61
    * Will get the first callback that are being held for the
 
62
    * client.  This will also release the lock that is holding
 
63
    * any threads that have called the add(Serializalbe) method.
 
64
    * @return
 
65
    * @throws IOException
 
66
    */
 
67
   public Object getNext() throws IOException
 
68
   {
 
69
      Object callback = null;
 
70
 
 
71
      synchronized(lockObject)
 
72
      {
 
73
         if(callbacks.size() > 0)
 
74
         {
 
75
            callback = callbacks.remove(0);
 
76
         }
 
77
         lockObject.notify();
 
78
      }
 
79
      return callback;
 
80
   }
 
81
 
 
82
   /**
 
83
    * To be used for adding a callback to the store.
 
84
    * The thread making the call will be held until the
 
85
    * getNext() method is called.
 
86
    * @param object
 
87
    * @throws IOException
 
88
    */
 
89
   public void add(Serializable object) throws IOException
 
90
   {
 
91
      if(log.isTraceEnabled())
 
92
      {
 
93
         log.trace("Adding " + object + " to blocking callback store.  Calling thread " +
 
94
                   Thread.currentThread() + " will be held until getNext() is called");
 
95
      }
 
96
 
 
97
      synchronized(lockObject)
 
98
      {
 
99
         try
 
100
         {
 
101
            callbacks.add(object);
 
102
            lockObject.wait();
 
103
         }
 
104
         catch (InterruptedException e)
 
105
         {
 
106
            log.debug("InterruptedException received while waiting for thread (" +
 
107
                      Thread.currentThread() + ") to be released from BlockingCallbackStore.add(Serializable) call.");
 
108
         }
 
109
      }
 
110
   }
 
111
 
 
112
   /**
 
113
    * No op
 
114
    * @param config
 
115
    */
 
116
   public void setConfig(Map config)
 
117
   {
 
118
   }
 
119
 
 
120
   /**
 
121
    * No op
 
122
    * @throws Exception
 
123
    */
 
124
   public void start() throws Exception
 
125
   {
 
126
   }
 
127
 
 
128
   /**
 
129
    * No op
 
130
    */
 
131
   public void stop()
 
132
   {
 
133
   }
 
134
 
 
135
   /**
 
136
    * No op
 
137
    * @throws Exception
 
138
    */
 
139
   public void create() throws Exception
 
140
   {
 
141
   }
 
142
 
 
143
   /**
 
144
    * No op
 
145
    */
 
146
   public void destroy()
 
147
   {
 
148
   }
 
149
 
 
150
   /**
 
151
    * No op
 
152
    * @param purgeOnShutdown
 
153
    */
 
154
   public void setPurgeOnShutdown(boolean purgeOnShutdown)
 
155
   {
 
156
   }
 
157
 
 
158
   /**
 
159
    * No op.  Always returns false.
 
160
    * @return
 
161
    */
 
162
   public boolean getPurgeOnShutdown()
 
163
   {
 
164
      return false;
 
165
   }
 
166
 
 
167
   /**
 
168
    * No op.
 
169
    */
 
170
   public void purgeFiles()
 
171
   {
 
172
   }
 
173
}
 
 
b'\\ No newline at end of file'