blob: 15c19d0a821345130fe9547ead4ced8eb6635b4b [file] [log] [blame]
Ken Gilmer2c29a972011-10-13 05:01:42 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19package org.apache.felix.http.lightweight.server;
20
21/**
22 * This class implements a simple one-shot gate for threads. The gate
23 * starts closed and will block any threads that try to wait on it. Once
24 * opened, all waiting threads will be released. The gate cannot be reused.
25**/
26public class ThreadGate
27{
28 private boolean m_open = false;
29
30 /**
31 * Open the gate and release any waiting threads.
32 **/
33 public synchronized void open()
34 {
35 m_open = true;
36 notifyAll();
37 }
38
39 /**
40 * Wait for the gate to open.
41 * @throws java.lang.InterruptedException If the calling thread is interrupted;
42 * the gate still remains closed until opened.
43 **/
44 public synchronized void await() throws InterruptedException
45 {
46 while (!m_open)
47 {
48 wait();
49 }
50 }
51}