User: biorn_steedom
Date: 01/04/20 16:15:08
Added: src/main/org/jboss/util WaitSemaphore.java WaitSync.java
Log:
Extended Sync interface and Semaphore implementation.
Revision Changes Path
1.1 jboss/src/main/org/jboss/util/WaitSemaphore.java
Index: WaitSemaphore.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.util;
/**
* Wait exclusive semaphore with wait - notify primitives
*
* @author Simone Bordet ([EMAIL PROTECTED])
* @version $Revision: 1.1 $
*/
public class WaitSemaphore
extends Semaphore
implements WaitSync
{
// Constants -----------------------------------------------------
private final static int MAX_USERS_ALLOWED = 1;
// Attributes ----------------------------------------------------
private int m_waiters;
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
public WaitSemaphore()
{
super(MAX_USERS_ALLOWED);
}
// Public --------------------------------------------------------
public void doWait() throws InterruptedException
{
synchronized (this)
{
release();
++m_waiters;
waitImpl(this);
--m_waiters;
acquire();
}
}
public void doNotify() throws InterruptedException
{
synchronized (this)
{
if (getWaiters() > 0)
{
acquire();
notify();
release();
}
}
}
public int getWaiters()
{
synchronized (this)
{
return m_waiters;
}
}
// Object overrides ---------------------------------------------------
public String toString()
{
return super.toString() + " - " + m_waiters;
}
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
}
1.1 jboss/src/main/org/jboss/util/WaitSync.java
Index: WaitSync.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.util;
/**
* Interface that gives wait - notify primitives to implementors.
*
* @see Semaphore
* @author Simone Bordet ([EMAIL PROTECTED])
* @version $Revision: 1.1 $
*/
public interface WaitSync extends Sync
{
// Constants -----------------------------------------------------
// Static --------------------------------------------------------
// Public --------------------------------------------------------
/**
* Pone in wait status this sync, until {@link #doNotify} is called to wake it
up.
* @see #doNotify
*/
public void doWait() throws InterruptedException;
/**
* Wakes up this sync that has been posed in wait status by a {@link #doWait}
call.
* If this sync is not waiting, invoking this method should have no effect.
* @see #doWait
*/
public void doNotify() throws InterruptedException;
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development