Search in sources :

Example 1 with MutexFlag

use of soc.util.MutexFlag in project JSettlers2 by jdmonin.

the class SOCChannelList method createChannel.

/**
 * create a new channel.  If channel already exists, do nothing.
 *
 * @param chName  the name of the channel
 * @param chOwner the game owner/creator's player name (added in 1.1.10)
 * @throws NullPointerException if <tt>chOwner</tt> null
 */
public synchronized void createChannel(final String chName, final String chOwner) throws NullPointerException {
    if (!isChannel(chName)) {
        MutexFlag mutex = new MutexFlag();
        channelMutexes.put(chName, mutex);
        Vector<Connection> members = new Vector<Connection>();
        channelMembers.put(chName, members);
        // throws NullPointerException
        channelOwners.put(chName, chOwner);
    }
}
Also used : Connection(soc.server.genericServer.Connection) MutexFlag(soc.util.MutexFlag) Vector(java.util.Vector)

Example 2 with MutexFlag

use of soc.util.MutexFlag in project JSettlers2 by jdmonin.

the class SOCChannelList method takeMonitorForChannel.

/**
 * take the monitor for this channel
 *
 * @param channel  the name of the channel
 * @return false   if the channel has no mutex
 */
public boolean takeMonitorForChannel(String channel) {
    D.ebugPrintln("SOCChannelList : TAKE MONITOR FOR " + channel);
    MutexFlag mutex = channelMutexes.get(channel);
    if (mutex == null) {
        return false;
    }
    boolean done = false;
    while (!done) {
        mutex = channelMutexes.get(channel);
        if (mutex == null) {
            return false;
        }
        synchronized (mutex) {
            if (mutex.getState() == true) {
                try {
                    // timeout to help avoid deadlock
                    mutex.wait(1000);
                } catch (InterruptedException e) {
                    System.out.println("EXCEPTION IN takeMonitor() -- " + e);
                }
            } else {
                done = true;
            }
        }
    }
    mutex.setState(true);
    return true;
}
Also used : MutexFlag(soc.util.MutexFlag)

Example 3 with MutexFlag

use of soc.util.MutexFlag in project JSettlers2 by jdmonin.

the class SOCChannelList method releaseMonitorForChannel.

/**
 * release the monitor for this channel
 *
 * @param channel  the name of the channel
 * @return false if the channel has no mutex
 */
public boolean releaseMonitorForChannel(String channel) {
    D.ebugPrintln("SOCChannelList : RELEASE MONITOR FOR " + channel);
    MutexFlag mutex = channelMutexes.get(channel);
    if (mutex == null) {
        return false;
    }
    synchronized (mutex) {
        mutex.setState(false);
        mutex.notify();
    }
    return true;
}
Also used : MutexFlag(soc.util.MutexFlag)

Example 4 with MutexFlag

use of soc.util.MutexFlag in project JSettlers2 by jdmonin.

the class SOCChannelList method deleteChannel.

/**
 * remove the channel from the list
 *
 * @param chName  the name of the channel
 */
public synchronized void deleteChannel(String chName) {
    D.ebugPrintln("SOCChannelList : deleteChannel(" + chName + ")");
    channelMembers.remove(chName);
    MutexFlag mutex = channelMutexes.get(chName);
    channelMutexes.remove(chName);
    if (mutex != null) {
        synchronized (mutex) {
            mutex.notifyAll();
        }
    }
}
Also used : MutexFlag(soc.util.MutexFlag)

Aggregations

MutexFlag (soc.util.MutexFlag)4 Vector (java.util.Vector)1 Connection (soc.server.genericServer.Connection)1