Habanero® Developer
Frequently Asked Questions


Arbitrators

Locks and Keys

 

Q: What arbitrators are provided in the habanero framework?

A: There are a few arbitrators provided in the habanero framework. They include the CentralArbitrator, the DynamicArbitrator, the LimitArbitrator, and the TurnTakerArbitrator.


 
Q: How do you select an arbitrator?

A: When creating the request for the new collaborative object inside the client program, you can specify the name of the tool and arbitrator in the habanero.rsc/toolsDir file. Below is an example of the Whiteboard's toolsDir file.

tool.name= WhiteBoard
tool.picture=WhiteBoard.gif
tool.classname=WhiteBoard.WhiteBoard
tool.arbitrator=ncsa.habanero.LimitArbitrator
tool.version=v1.0
tool.help=http://www.ncsa.uiuc.edu/SDG/Software/Habanero/Tools/
tool.useOwnStream=true

The tool.arbitrator property specifies which arbitrator the tool should use. The default arbitrator is the CentralArbitrator and puts no restrictions on the types of objects that can be sent to all collaborative objects.

In this example, we use the LimitArbitrator, but you can specify the name of any arbitrator that you have created.


 
Q: What do you need to do to limit an action?

A: The first step is to direct the server to use a different arbitrator. The default arbitrator is the CentralArbitrator, which allows any action to be performed. Instead, you need to use the LimitArbitrator or an arbitrator of your own design. Defining an arbitrator for your application is discussed in the How do you select an arbitrator for your program? FAQ.

The second step is to request a key to a lock. Locks are a limitation on the types of actions that can be performed. To get a lock, you determine what type of limitation you will need, and request the arbitrator give you permission to do these types of actions. The arbitrator returns the key. To learn more about locks, look at:


 
Q: How do you get a key?

A: To get a key, you first must create a lock that describes what you will do. Then you need to ask the arbitrator for a key. The tricky part then is getting the arbitrator. The arbitrator can be retrieved from the frame. The frame is input to the procedure startInFrame.

For this example, let's assume that you have saved the frame from startInFrame in the variable frame. Then you can get a key to a MyLock object using the following code:

      Arbitrator arbitrator = (frame.getCollobject()).arbitrator(); 
      kyNewKey = arbitrator.getLock (new MyLock (), Key.NoKey); 

This lock doesn't require any previous permissions, so the Key that is passed to getLock is Key.NoKey.


 
Q: How do you make a lock?

A: There are seven procedures that you must write to create a lock. These are:

allows

Before an action is sent to all other participants, the arbitrator calls the lock's allows routine. The lock can then check to see if the action that is about to occur matches with the actions that it allows.

blocks

The next routine that you need to write is called blocks. The LimitArbitrator forces almost every action that is performed to have a Key. We have considered the possibility that you may not always want this to be true. So when an action arrives at a LimitArbitrator without a key, two things happen. First, only certain actions may operate without a key. Actions without a key are checked to see if the arbitrator will allow it to run at all. It proforms this check in the keylessAction method. If the action is permitted, then arbitrator checks the action against all the locks. The routine it uses to check the action is blocks. Each lock has its blocks method called with the possible action. If you don't override this method, it is assumed that the action is OK.

consistent

When a participant is requesting a key, and it needs to be sure that the new lock doesn't cause a conflict with a lock that already exists. If the participant doesn't have the key to this lock, the consistent procedure is called.

keyWorksWith

When a participant is requesting a key, and it needs to be sure that the new lock doesn't cause a conflict with a lock that already exists. If the participant has the key to this lock, the keyWorksWith procedure is called.

releaseAfterUsing

Some locks can be used many times, others only once. If a lock is to be used only once and then automatically released, then the releaseAfterUsing returns true. Otherwise it returns false.

If you return false from releaseAfterUsing you are responsible for releasing the lock when you are finished using the releaseLock method of the LimitArbitrator.


 
Q: What locks are provided with the Habanero framework?

A: The Habanero provides four locks are designed to be used with the TurnTakerArbitrator. These locks are:

ExclusiveLock

The exclusive lock is provided if only one action is allowed to occur at a time. An ExclusiveLock blocks all other participants from gaining any new locks, and stops any unkeyed actions. However, actions that match previously acquired locks are allowed to execute.

PlayerLock

To play a game or to participate in a system where people need to take turns, you first need to identify yourself to the arbitrator. A PlayerLock is taken to identify the user.

TurnLock

Once a player or a participant has been identified by taking a PlayerLock, the person can then take their turn with a TurnLock.

LimitPlayerLock

Some games have a limited number of players that are allowed to participate. The user who creates a session gets to decide how many others will be allowed to take turns in the actions. The LimitPlayerLock allows a participant to set this limit.

 


A Navigation Image Map. Use the links below.
[ Download ] [ User Docs ] [ FAQs ] [ Home ] [ Dev API ] [ Tools ] [ License ]

Habanero® is a registered trademark owned by The Board of Trustees of the University of Illinois. Copyright 1996-1998. All rights reserved.   Java(TM) is a proprietary trademark owned by Sun Microsystems, Inc.