KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > spice > netserve > connection > impl > BlockingServerSocket


1 /*
2  * Copyright (C) The Spice Group. All rights reserved.
3  *
4  * This software is published under the terms of the Spice
5  * Software License version 1.1, a copy of which has been included
6  * with this distribution in the LICENSE.txt file.
7  */

8 package org.codehaus.spice.netserve.connection.impl;
9
10 import java.io.IOException JavaDoc;
11 import java.net.ServerSocket JavaDoc;
12 import java.net.Socket JavaDoc;
13
14 /**
15  *
16  * @author Peter Donald
17  * @version $Revision: 1.2 $ $Date: 2004/03/21 23:42:59 $
18  */

19 class BlockingServerSocket
20    extends ServerSocket JavaDoc
21 {
22    static final Socket JavaDoc SOCKET = new Socket JavaDoc();
23
24    private int m_lockCount;
25    private int m_acceptCount;
26
27    public BlockingServerSocket()
28       throws IOException JavaDoc
29    {
30    }
31
32    public Socket JavaDoc accept()
33       throws IOException JavaDoc
34    {
35       m_acceptCount++;
36       while ( true )
37       {
38          synchronized ( this )
39          {
40             if ( m_acceptCount <= m_lockCount )
41             {
42                break;
43             }
44             try
45             {
46                wait( 100 );
47             }
48             catch ( InterruptedException JavaDoc e )
49             {
50             }
51             notifyAll();
52          }
53       }
54       return SOCKET;
55    }
56
57    synchronized void unlock()
58    {
59       m_lockCount++;
60       notifyAll();
61    }
62 }
63
Popular Tags