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

« back to all changes in this revision

Viewing changes to src/main/org/jboss/remoting/samples/chat/utility/ShutDownGate.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
package org.jboss.remoting.samples.chat.utility;
 
2
 
 
3
/**
 
4
 * <p>Title: Chat4</p>
 
5
 * <p>Description: </p>
 
6
 * <p>Copyright: Copyright (c) 2003</p>
 
7
 * <p>Company: </p>
 
8
 * @author not attributable
 
9
 * @version 1.0
 
10
 */
 
11
 
 
12
import java.io.Serializable;
 
13
 
 
14
import org.jboss.remoting.samples.chat.exceptions.ShuttingDownException;
 
15
 
 
16
public class ShutDownGate implements Serializable {
 
17
 
 
18
    private static final long serialVersionUID = 2;
 
19
 
 
20
    private int numberOfUsers;
 
21
    private boolean shuttingDown;
 
22
 
 
23
    public ShutDownGate()
 
24
    {
 
25
      reset();
 
26
    }
 
27
 
 
28
    public void reset()
 
29
    {
 
30
      numberOfUsers = 0;
 
31
      shuttingDown = false;
 
32
    }
 
33
 
 
34
    public synchronized void check() throws ShuttingDownException
 
35
    {
 
36
      if (shuttingDown == true)
 
37
        throw new ShuttingDownException();
 
38
    }
 
39
 
 
40
    public synchronized boolean isShuttingDown()
 
41
    {
 
42
      return shuttingDown;
 
43
    }
 
44
 
 
45
    public synchronized void enter() throws ShuttingDownException
 
46
    {
 
47
      if (shuttingDown == true)
 
48
        throw new ShuttingDownException();
 
49
      numberOfUsers++;
 
50
    }
 
51
 
 
52
    public synchronized void leave()
 
53
    {
 
54
      if (numberOfUsers <= 0)
 
55
        throw new Error("ShutDownGate: number of Users <= 0");
 
56
 
 
57
      if (--numberOfUsers == 0)
 
58
        notifyAll();
 
59
    }
 
60
 
 
61
    public synchronized void shutDown()
 
62
    {
 
63
      shuttingDown = true;
 
64
 
 
65
      while (numberOfUsers > 0) {
 
66
        try {
 
67
          System.out.println("shutdown(): numberOfUsers == " + numberOfUsers);
 
68
          wait();
 
69
        }
 
70
        catch (InterruptedException ie) {}
 
71
      }
 
72
    }
 
73
 
 
74
  }
 
 
b'\\ No newline at end of file'