⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 activityflow.html

📁 Concurrent Programming in Java
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<html><!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><html> <head><title>Activity Flow</title></head><BODY bgcolor=#ffffee vlink=#0000aa link=#cc0000><h1>Activity Flow</h1>Activity flow designs extend ``two-party'' (client/server) designs tothose for larger collections of objects all engaged in some commonfunctionality.Activity flows can be thought of as the computational versions of``use cases'', ``scenarios'', ``scripts'', and related concepts fromObject-Oriented Analysis.  (For brief summaries, see for example <ahref="javascript:if(confirm('http://www.iconcomp.com/papers  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.iconcomp.com/papers'" tppabs="http://www.iconcomp.com/papers">Icon's papers on OOA/Dmethods</a>.)<p>Multithreaded programs often support one or more distinct kinds ofactivity flows -- series of connected steps or stages with adistinct beginning and end. Three broad categories are:<ul>  <li> <strong>Control Systems</strong>, where an external sensor input       ultimately causes the system to generate a particular       effector output.       As seen in <a href="javascript:if(confirm('http://g.oswego.edu/dl/acs/acs/acs.html  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://g.oswego.edu/dl/acs/acs/acs.html'" tppabs="http://g.oswego.edu/dl/acs/acs/acs.html">Avionics Control Systems</a>, there can be dozens of kinds of inputs       and outputs. For a plainer example, consider a skeletal       thermostatic heater control:<pre>     +------------+    +------------+    +------------+  -> | TempSensor | -> | Comparator | -> | HeatSwitch |     +------------+    +------------+    +------------+</pre>  <li> <strong>Assembly Systems</strong>, where newly created      objects undergo a series of changes and/or become      integrated with other new objects, before finally      being used for some particular purpose. For example      an assembly line for Cartons:<pre>    +---------------+    +-------+    +-----+    +------+    +---------+ -> | MakeCardboard | -> | Paint | -> | Cut | -> | Fold | -> | Use ... |    +---------------+    +-------+    +-----+    +------+    +---------+</pre>  <li> <strong>Workflow Systems</strong>, where each stage represents an      action that needs to be performed according to some set      of business policies or other requirements. For example      a simple Payment system:<pre>     +-----------------+    +-----------------+    +------------+  -> | incomingInvoice | -> | ManagerApproval | -> | IssueCheck |     +-----------------+    +-----------------+    +------------+</pre>      <p> Such flows can also include      <a href="#secNonLin"> ``non-linear''</a> forms --      branches, merges and loops, in addition to pure linear linkages.</ul>Most differences among these categories are just superficial: ControlSystems pass information from stage to stage, Assembly systems passobjects to be transformed or used, and Workflow systems passresponsibility for actions on objects. In all other respects, theirbasic structure and dynamics take the same general form.<h2>Structure</h2>Activity flow patterns generally consist of the following kinds ofcomponents:<dl>  <dt> <strong>Representational components.</strong>  <dd> Families of values or objects that represent the things that       the flow pattern is all about. For example, temperatures, cardboard       sheets, invoices. These are the basic kinds of values and       objects that are passed around across connected stages. Often,       these components are interesting objects       in their own right, that can perform services, communicate       with other objects, and so on. But when viewed as the       raw material for activity flow, they are       most often treated as mere passive       representations, providing information rather than behavior.  <dt> <strong>Transformational components (stages).</strong>  <dd> Objects that can serve as stages within a flow. To serve       as a stage, a component must be able to accept and/or       issue messages that serve as instructions about what to       do with representational components.  <dt> <strong>Control components.</strong>   <dd> Coordinators linking together       transformational components to fullfill the goals of a       particular activity flow,       and perhaps monitoring them during the courses       of activities.  <dt> <strong>Scripting.</strong>  <dd> At the highest levels, the creation of control components can      be treated as a form of scripting in the usual sense of the word      -- semi-automated programming of the control code ``glueing      together'' instances of existing object types; the kind of      programming associated with languages like JavaScript,      VisualBasic, and FlowMark (a workflow tool).  Development of a      scripting tool, or integration with an existing one is an      optional step in building systems based around activity flows.      This is analogous to the case of GUI builders consisting of      a base set of Widgets,      packers and layout managers, code to instantiate a particular      UI, and a visual scripter that helps set all this up.</dl><h2>Dynamics</h2>Activity flow design in multithreaded programs is a much more variedand central task than it typically is in purely sequential programs.Most of the design issues surrounding especially those systemssupporting multiple activity flows stem from considerations about howresponsibility and control is managed among the stages.  There arethree basic forms of control, <em>pull</em>, <em>push</em>, and<em>buffered</em>:<p><IMG SRC="pushpull.gif" tppabs="http://www.foi.hr/~dpavlin/java/mirrors/g.oswego.edu/dl/pats/pushpull.gif"><h3>Pull-Style</h3>In non-concurrent programs, activity flows are often restricted toa simple procedural/functional form. For example, imagine writingcascaded procedure calls corresponding to our initial examples:<pre>heaterSwitch.set(                 comparator.lessThanDesired(                                            TempSensor.currentValue()                                            )                );cartonUser.use(               folder.fold(                           cutter.cut(                                      painter.paint(                                                    new CardboardSheet()                                                   )                                     )                           )               );issuer.issueCheckFor(                     manager.approve(                                     reader.readInvoice(invoiceInputStream)                                    )                     );</pre>Or in a more object-oriented style for the Heater example:<pre>  class TempSensor { ...    float currentValue() { ... return currentlySensedValue_; }  }  class Comparator { ...    private TempSensor tempSensor_;    boolean currentLessThanDesired() { ...      return (tempSensor_.currentValue() < desired)    }  }  class Heater {    private Comparator comparator_;    void set() { ...      if (comparator_.currentLessThanDesired()) turnOn();    }  }</pre>An activity in a multithreaded program can take this form too, inwhich case it is often called a <em>Pull</em>-based design: Theultimate consumer (<em>sink</em>) of the set of activities ``pulls'' resultsfrom its predecessors, and in turn from their predecessors,and so on.<h3>Push-Style</h3>An alternative control strategy is for the ultimate <em>source</em>of an activity to initiate the flow to its successors, via(conceptually) asynchronous triggering messages. For example:<pre>  class TempSensor { ...    void detectChange() { ... comparator.compareTo(currentTemp_); }  }  class Comparator { ...     void compareTo(float t) { ...if (t < desired) heater.turnOn(); }  }  class Heater {     void turnOn() { ... }  }    </pre>A very common variant of Push-style control is the <ahref="early.html#secSubj" tppabs="http://www.foi.hr/~dpavlin/java/mirrors/g.oswego.edu/dl/pats/early.html#secSubj">Subject/Observer</a> protocol seen inseveral different guises in this set of patterns. When viewed within acontrol flow setting, the subject/observer protocol has a very simple<em>push</em> component in which a source stage (subject) informs itssuccessor stage (observer) that some action needs to be performed; thesuccessor then (perhaps later) <em>pulls</em> particular informationfrom the source to find out the specific action to be taken.<h3>Buffered</h3>A third form of control is for pairs or sets of stages to work off ashared <a href="synchDesign.html" tppabs="http://www.foi.hr/~dpavlin/java/mirrors/g.oswego.edu/dl/pats/synchDesign.html">buffer</a> of some sort. (Particularforms are called blackboards, <a href="javascript:if(confirm('http://www.cs.yale.edu/HTML/YALE/CS/Linda/linda.html  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.cs.yale.edu/HTML/YALE/CS/Linda/linda.html'" tppabs="http://www.cs.yale.edu/HTML/YALE/CS/Linda/linda.html">tuple spaces</a>, buses, but they are all variants of the samenotion.) Producer objects <em>push</em> commands in the buffer, andConsumer objects <em>pull</em> them. For example:<pre>  class TempSensor { ...    void detectChange() { ... temperatureBuffer.put(currentTemp_); }  }  class Comparator { ...    void compare() { ...      t = temperatureBuffer.take();      if (t < desired)  heaterBuffer.put(true);    }  }  class Heater { ...    void set() { ...      v = heaterBuffer.take();      if (v) turnOn(); else turnOff();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -