NCSAHabanero

[ Previous ] [ Index ] [ Next ]

-------------------------------------------------------------------
How to decide on the fly whether to share an event
-------------------------------------------------------------------

Shipping Decision Function

Background Information

Simple Event Handling taught you how to declare whole classes of events as shared. However, sometimes you need to share some events of a class, but not every single one.

This pattern tells you how to decide on the fly which events to share, so that you do not have to share all the events of a class.

How does this work?

Instead of registering the class in startInFrame() with addSharedEventType(), implement the interface ncsa.habanero.ShippingDecisionFunction(). For example, if you only want to share typing when the "share typing" check box is checked, you could have ship() return the status of the "share typing" check box.
 
Example of using shipping decision functions.
class FredListener implements ActionListener, ShippingDecisionFunction  
 
  // other code 

  public boolean ship(java.awt.AWTEvent event)  
  { boolean shareThisEvent;  

    {code to decide on whether to share this event or not}  
         return (shareThisEvent}  
    }  

  // other code

 
ship() returns true if you want to share the event and false otherwise.


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. NCSA
The National Center for Supercomputing Applications

University of Illinois at Urbana-Champaign

Contacts page