Class c2.framework.Component
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class c2.framework.Component

java.lang.Object
   |
   +----c2.framework.Brick
           |
           +----c2.framework.Component

public class Component
extends Brick
System functionality is encapsulated into components . Components communicate with one another by passing messages via connectors . Messages come in two flavors:

To declare a new component, inherit from Component and override the the handle() methods. Use send() to send Requests or Notifications to other components. Inherit from ComponentThread if you want the component to run in its own thread of control.

	class MyComponent extends Component {
	    protected void handle(Request r) {
		  // process a request
	    }
	    protected void handle(Notification n) {
		  // process a notification
	    }
	}
To use a component, create an instance of it and call the start() method:
	MyComponent c = new MyComponent("Test", FIFOPort.classType());
	c.start();
	...
See the Request and Notification classes for details on messages.

See Also:
Request, Notification, ComponentThread, start

Variable Index

 o bottom
 o top

Constructor Index

 o Component()
Creates an uninitialized instance of the component.
 o Component(String, Class)
Creates and initializes an instance of the component.

Method Index

 o bottomPort()
Returns the bottom port of the component
 o create(String, Class)
Initializes the component.
 o handle(Notification)
This method is invoked when the component receives a notification from a component below it.
 o handle(Request)
This method is invoked when the component receives a request from a component below it.
 o newMessage(Port)
This method is invoked when the component receives a new request or notification.
 o send(Notification)
Call this method to send a notification to a component below your component.
 o send(Request)
Call this method to send a request to a component above your component.
 o topPort()
Returns the top port of the component
 o toString()
Returns a String representation of the Component, including the component's type, name, top and bottom ports.

Variables

 o top
  protected Port top
 o bottom
  protected Port bottom

Constructors

 o Component
  public Component()
Creates an uninitialized instance of the component. Use the create() method to initialize the component. This constructor exists so that components can be dynamically loaded using Class.newInstance()
See Also:
Class
 o Component
  public Component(String name,
                   Class portClass)
Creates and initializes an instance of the component.

Parameters:
name - the name of the component
portClass - the Class of the port to use. The port processes all incomming and outgoing messages into and out of the component.
See Also:
Port

Methods

 o create
  public void create(String name,
                     Class portClass)
Initializes the component. NOTE: Only call this method once, and only if you used the empty constructor.

Parameters:
name - the name of the component
portClass - the Class of the port to use. The port processes all incomming and outgoing messages into and out of the component.
See Also:
Port
 o topPort
  public Port topPort()
Returns the top port of the component
 o bottomPort
  public Port bottomPort()
Returns the bottom port of the component
 o handle
  protected synchronized abstract void handle(Request r)
This method is invoked when the component receives a request from a component below it. Override this method to process requests.
Overrides:
handle in class Brick
 o handle
  protected synchronized abstract void handle(Notification n)
This method is invoked when the component receives a notification from a component below it. Override this method to process notifications.
Overrides:
handle in class Brick
 o send
  protected void send(Request r)
Call this method to send a request to a component above your component.
Overrides:
send in class Brick
See Also:
Request
 o send
  protected void send(Notification n)
Call this method to send a notification to a component below your component.
Overrides:
send in class Brick
See Also:
Notification
 o newMessage
  protected void newMessage(Port p)
This method is invoked when the component receives a new request or notification. By default, it invokes the appropriate handle() method. Override this function only if you need to do special processing on incomming messages.
Overrides:
newMessage in class Brick
See Also:
handle
 o toString
  public String toString()
Returns a String representation of the Component, including the component's type, name, top and bottom ports.
Overrides:
toString in class Brick

All Packages  Class Hierarchy  This Package  Previous  Next  Index