01: /*
02: * Copyright (C) The Spice Group. All rights reserved.
03: *
04: * This software is published under the terms of the Spice
05: * Software License version 1.1, a copy of which has been included
06: * with this distribution in the LICENSE.txt file.
07: */
08: package org.codehaus.spice.netserve.connection.impl;
09:
10: import java.io.IOException;
11: import java.net.ServerSocket;
12: import java.net.Socket;
13:
14: /**
15: *
16: * @author Peter Donald
17: * @version $Revision: 1.2 $ $Date: 2004/03/21 23:42:59 $
18: */
19: class BlockingServerSocket extends ServerSocket {
20: static final Socket SOCKET = new Socket();
21:
22: private int m_lockCount;
23: private int m_acceptCount;
24:
25: public BlockingServerSocket() throws IOException {
26: }
27:
28: public Socket accept() throws IOException {
29: m_acceptCount++;
30: while (true) {
31: synchronized (this ) {
32: if (m_acceptCount <= m_lockCount) {
33: break;
34: }
35: try {
36: wait(100);
37: } catch (InterruptedException e) {
38: }
39: notifyAll();
40: }
41: }
42: return SOCKET;
43: }
44:
45: synchronized void unlock() {
46: m_lockCount++;
47: notifyAll();
48: }
49: }
|