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.
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.
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.
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.
22
package org.jboss.remoting.callback;
24
import org.jboss.logging.Logger;
25
import org.jboss.remoting.SerializableStore;
27
import java.io.IOException;
28
import java.io.Serializable;
29
import java.util.ArrayList;
30
import java.util.List;
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>
42
public class BlockingCallbackStore implements SerializableStore
44
private Object lockObject = new Object();
46
private List callbacks = new ArrayList();
48
private static final Logger log = Logger.getLogger(BlockingCallbackStore.class);
51
* Gets the number of callbacks that are waiting
57
return callbacks.size();
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.
67
public Object getNext() throws IOException
69
Object callback = null;
71
synchronized(lockObject)
73
if(callbacks.size() > 0)
75
callback = callbacks.remove(0);
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.
89
public void add(Serializable object) throws IOException
91
if(log.isTraceEnabled())
93
log.trace("Adding " + object + " to blocking callback store. Calling thread " +
94
Thread.currentThread() + " will be held until getNext() is called");
97
synchronized(lockObject)
101
callbacks.add(object);
104
catch (InterruptedException e)
106
log.debug("InterruptedException received while waiting for thread (" +
107
Thread.currentThread() + ") to be released from BlockingCallbackStore.add(Serializable) call.");
116
public void setConfig(Map config)
124
public void start() throws Exception
139
public void create() throws Exception
146
public void destroy()
152
* @param purgeOnShutdown
154
public void setPurgeOnShutdown(boolean purgeOnShutdown)
159
* No op. Always returns false.
162
public boolean getPurgeOnShutdown()
170
public void purgeFiles()
b'\\ No newline at end of file'