
_Distributed Active Objects_
by Marc H. Brown and Marc A. Najork

Listing One
(HBox
  (Numeric %num1)
  (Text "+")
  (Numeric %num2)
  (Text "=")
  (Text %sum "0"))

Listing Two
let doAdd =
  proc (fv)
    let n1 = form_getInt (fv, "num1");
    let n2 = form_getInt (fv, "num2");
    form_putText (fv, "sum", fmt_int (n1+n2))
  end;
    let oblet = {

      vbt => form_fromURL (BaseURL & "adder.fv"),
      run =>
        meth (self)
          form_attach (self.vbt, "num1", doAdd);
          form_attach (self.vbt, "num2", doAdd);
        end
    };

Listing Three
    let oblet = {
      vbt    => form_fromURL (BaseURL & "tic-tac-toe.fv"),
      symbol => ok,
      opp    => ok,
      reset =>
        meth (self)
          for i = 1 to 9 do
            form_putText (self.vbt, "lab" & fmt_int(i), "");
          end;
        end,
      move =>
        meth (self, label, symbol)
          form_putText (self.vbt, label, symbol);
          let other = if symbol is "X" then "O" else "X" end;
          form_putText (self.vbt, "status", other & " is next");
          if form_getReactivity(self.vbt, "board") is "active" then
            form_putReactivity(self.vbt, "board", "dormant");
          else
            form_putReactivity(self.vbt, "board", "active");
          end;
        end,
      run =>
        meth (self)
          try
            self.opp := net_import ("TicTacToe", "ash.pa.dec.com");
            self.opp.opp := self;
            self.symbol := "X";
          except net_failure =>
            net_export ("TicTacToe", "ash.pa.dec.com", self);
            form_putReactivity (self.vbt, "board", "dormant");
            self.symbol := "O";
          end;
          let doReset =
            proc(fv)
              self.reset ();
              self.opp.reset ();
            end;
          let doPress =
            proc (m)
              let label = "lab" & fmt_int(m);
              if form_getText (self.vbt, label) is "" then
                self.move (label, self.symbol);
                self.opp.move (label, self.symbol);
              end;
            end;
          form_attach (self.vbt, "reset", doReset);

          for i = 1 to 9 do
            let p = proc(fv) doPress(i) end;
            form_attach (self.vbt, "btn" & fmt_int(i), p)
          end;
        end
    };

Listing Four
    (Rim (Pen 10)
      (VBox
        (Text %floorWith "The floor is free right now")
        (Glue 10)
        (Shape (Width 300) (Height 200)
          (Frame Lowered
             (Filter Passive
               (TextEdit (BgColor "White") %mainEditor))))
        (Glue 10)
        (HBox
          (Text "Your Name:")
          (Frame Lowered (TypeIn (BgColor "White") %myName))
          Fill
          (Button %grabFloor "Grab Floor"))))

Listing Five
    let ProtoConfControl = {
      oblets => [],
      onFloor => ok,
      contents => "",
      register =>
        meth (self, oblet)
          self.oblets := self.oblets @ [oblet];
          oblet.updateText (self.contents);
          if self.onFloor isnot ok then
            oblet.transferFloor (self.onFloor);
          end;
        end,
      transferFloor =>
        meth (self, name)
          self.onFloor := name;
          foreach o in self.oblets do
            o.transferFloor (name);
          end;
        end,
      updateText =>
        meth (self, contents)
          self.contents := contents;
          foreach o in self.oblets do
            o.updateText (contents);
          end;
        end
    };

Listing Six
    let oblet = {
      vbt => form_fromURL (BaseURL & "chatroom.fv"),

      transferFloor =>
        meth (self, name)
          form_putReactivity (self.vbt, "mainEditor", "passive");
          form_putBgColor (self.vbt, "mainEditor", color_named("white"));
          form_putText (self.vbt, "floorWith", "The floor is with " & name);
        end,
      updateText =>
        meth (self, contents)
          form_putText (self.vbt, "mainEditor", contents);
        end,
      run =>
        meth (self)
          var confControl = ok;
          try
            confControl := net_import("ConfControl", "ash.pa.dec.com");
          except net_failure =>
            confControl := ProtoConfControl;
            net_export("ConfControl", "ash.pa.dec.com", confControl);
          end;
          let doGrabFloor =
            proc (fv)
              confControl.transferFloor (form_getText (fv, "myName"));
              form_putReactivity (fv, "mainEditor", "active");
              form_putBgColor (fv, "mainEditor", color_named("pink"));
            end;
          let doKeyEvent =
            proc (fv)
              confControl.updateText (form_getText (fv, "mainEditor"));
            end;
          confControl.register (self);
          form_attach (self.vbt, "grabFloor", doGrabFloor);
          form_attach (self.vbt, "mainEditor", doKeyEvent);
        end
    };

Listing Seven
    let z = {
      views => [],
      ...
      probe =>
        meth (self,w,b,amt)
          let threads =
            foreach v in self.views map
              let closure = proc() v.probe(w,b,amt) end;
              thread_fork(closure)
            end;
          foreach t in threads do
            thread_join(t)
          end;
        end;
        ...



