DRCL JavaSim API

drcl.comp.queue
Class QLogic

java.lang.Object
  |
  +--drcl.DrclObj
        |
        +--drcl.comp.queue.QLogic
All Implemented Interfaces:
java.lang.Cloneable, ObjectDuplicable, java.io.Serializable
Direct Known Subclasses:
RED, SRED

public class QLogic
extends DrclObj

This class is the base class for queue logic. The purpose of this class is to separate the logic of deciding whether or not to enqueue an object, from the actual actions of enqueuing/discarding/dequeuing an object. It makes it possible to construct a complex queue structure where one can plug in different logic to form a specific queue implementation.

This class defines the interfaces of that decision logic. Specifically, a subclass must implement adviceOn(data_, size_). The method returns null if it is ok to enqueue the data of the specified size. It returns a non-null string (advice) if it advices to discard the data. The caller may or may not take the advice. But regardless of which action to take, the caller must call the corresponding event handlers (dropHandler(), enqueueHandler() and dequeueHandler()) of this queue logic so that this queue logic can maintain the appropriate picture of what the real queue (the caller maintains) is like in order to give correct advices later on.

This class implements a simple limited-capacity queue logic.

See Also:
Serialized Form

Field Summary
 int capacity
          The capacity of the queue.
protected static java.lang.String DEFAULT_ADVICE
          Default advice for replying in adviceOn(Object, int) when the host's garbage flag is not on (for better performance).
static java.lang.String EVENT_QSIZE
          Name of the instant queue size change event.
protected  Component host
          The host component who owns this object.
 int qlen
          The current queue length (# of objects in the queue).
 int qsize
          The current queue size (each object in the queue may have different size).
protected  Port qSizePort
          Port that exports the instant queue size change events.
 
Constructor Summary
QLogic()
           
QLogic(Component host_)
           
QLogic(Component host_, java.lang.String qpid_)
           
 
Method Summary
 java.lang.String adviceOn(java.lang.Object obj_, int size_)
          Advices the host component for deciding whether or not to drop the (arriving) object.
 void dequeueHandler(java.lang.Object obj_, int size_)
          Handles the event of dequeuing the object of the given size.
 void dropHandler(java.lang.Object obj_, int size_)
          Handles the event of dropping the object of the given size.
 void duplicate(java.lang.Object source_)
          Duplicates the content of the source object to this object.
 void enqueueHandler(java.lang.Object obj_, int size_)
          Handles the event of enqueuing the object of the given size.
 int getCapacity()
          Returns the capacity of the queue.
 int getCurrentQLength()
          Returns the current length of the queue.
 int getCurrentQSize()
          Returns the current size of the queue.
 Component getHost()
           
 java.lang.String info()
          Prints the content (states) of this queue management instance.
 java.lang.String info(java.lang.String prefix_)
          Prints the content (states) of this queue management instance.
 boolean isEmpty()
          Returns true if the queue is empty.
 boolean isFull()
          Returns true if the queue is full.
 void reset()
          Resets this object to the initial state.
 void set(Component host_, java.lang.String pid_)
           
 void setCapacity(int capacity_)
          Sets the capacity of the queue.
 void setHost(Component host_)
           
 void setQSizePort(java.lang.String pid_)
           
 
Methods inherited from class drcl.DrclObj
clone, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EVENT_QSIZE

public static final java.lang.String EVENT_QSIZE
Name of the instant queue size change event.

DEFAULT_ADVICE

protected static final java.lang.String DEFAULT_ADVICE
Default advice for replying in adviceOn(Object, int) when the host's garbage flag is not on (for better performance).

qSizePort

protected Port qSizePort
Port that exports the instant queue size change events.

host

protected Component host
The host component who owns this object.

capacity

public int capacity
The capacity of the queue.

qsize

public int qsize
The current queue size (each object in the queue may have different size).

qlen

public int qlen
The current queue length (# of objects in the queue).
Constructor Detail

QLogic

public QLogic()

QLogic

public QLogic(Component host_)

QLogic

public QLogic(Component host_,
              java.lang.String qpid_)
Method Detail

reset

public void reset()
Resets this object to the initial state. Subclasses must call super.reset() when overriding this method.

duplicate

public void duplicate(java.lang.Object source_)
Duplicates the content of the source object to this object. If the host component is already set, this method also creates the queue size change event port of the same ID as that in source_. Subclasses must call super.duplicate() when overriding this method.
Overrides:
duplicate in class DrclObj

info

public java.lang.String info()
Prints the content (states) of this queue management instance. It is equivalent to calling info(null).

info

public java.lang.String info(java.lang.String prefix_)
Prints the content (states) of this queue management instance.
Parameters:
prefix_ - prefix of each line in the printout.

adviceOn

public java.lang.String adviceOn(java.lang.Object obj_,
                                 int size_)
Advices the host component for deciding whether or not to drop the (arriving) object.
Returns:
the advice; null if advicing not to drop the object.

dropHandler

public void dropHandler(java.lang.Object obj_,
                        int size_)
Handles the event of dropping the object of the given size.

enqueueHandler

public void enqueueHandler(java.lang.Object obj_,
                           int size_)
Handles the event of enqueuing the object of the given size.

dequeueHandler

public void dequeueHandler(java.lang.Object obj_,
                           int size_)
Handles the event of dequeuing the object of the given size.

setCapacity

public void setCapacity(int capacity_)
Sets the capacity of the queue.

getCapacity

public int getCapacity()
Returns the capacity of the queue.

getCurrentQSize

public int getCurrentQSize()
Returns the current size of the queue.

getCurrentQLength

public int getCurrentQLength()
Returns the current length of the queue.

isFull

public boolean isFull()
Returns true if the queue is full.

isEmpty

public boolean isEmpty()
Returns true if the queue is empty.

setHost

public void setHost(Component host_)

getHost

public Component getHost()

setQSizePort

public void setQSizePort(java.lang.String pid_)
Parameters:
pid_ - ID of the port.

set

public void set(Component host_,
                java.lang.String pid_)
Parameters:
pid_ - ID of the port.

DRCL JavaSim API

Copyright © 2001 - DRCL, OSU     ~ Back to JavaSim Home ~