Building a Distributed Spreadsheet in Modula-3

Mr. Kominek introduces us to the Modula-3 language and shows us how it can be used for cross-platform programming.
Step 5: Distributed Deployment

The netobj daemon acts like a bulletin board. First, the server posts a note saying, “I've got a spreadsheet object for sale.” Then the client comes along and says, “I'll buy that.” The server exports; the client imports; the daemon mediates. In the nomenclature of CORBA, the daemon is an object request broker. Once the sale is complete, the client and server talk to each other directly. Code details are found in Listing 4.

Listing 4 will work when the server and client are located on the same machine. Suppose instead that the server runs on some Linux box—eggnog.cmu.edu—and that the clients are elsewhere. Ensure that netobjd is running on eggnog and change one line in the client program.

address := NetObj.Locate( "eggnog.cmu.edu" );

With that, our programs now talk over the Net.

Step 6: Cell Range Locking

Because Modula-3 comes ready-made with thread support, it also provides mutexes (mutual exclusion semaphores) so that parallel operations on the same datum are serialized. In our discussion so far, the Money.T type has been left unspecified. It might actually be something like this:

INTERFACE Money;
TYPE
  T = MUTEX OBJECT
    cents: INTEGER;
  END;
END Money.

Mutexes protect data so that client B does not modify values before client A is finished. Granted, protecting each cell separately is overkill. A more elegant approach is to protect ranges of cells, with the lock initiated by user action.

Figure 2 shows a spreadsheet from the point of view of user A (Alice). She is working on the cell range tinted red. User B (Bob) cannot modify these cells. He is working on the blue cells, indicating to Alice that to her they are read only.

Figure 2. Simple Multiuser Spreadsheet

Step 7: Porting Procedure

To port our user interface program from Linux to Windows NT, do the following:

  1. Archive the client source code by using the tar command.

  2. Copy the tar file to your Windows machine.

  3. Unarchive the file using tar. Convert end-of-line markers.

  4. At the command line, type m3build.

Assuming there are no stunts of low-level programming, all the Modula-3 code in this example—including the GUI—is transparently portable. Differing path name conventions, for example, are hidden behind OS-independent interfaces. There's not an #ifdef in sight.

Conclusion

In this article I've highlighted the creation of a multi-platform, distributed spreadsheet using Modula-3. The key step is to wrap the spreadsheet into a network object. In this way, remote objects may be invoked with exactly the same syntax as local objects. Most of the hard work is done for you.

Modula-3 is not the only means for creating distributed applications, but in my mind it strikes an optimal balance between simplicity and power. By its very intent, it is a language for building large, solid systems in order for you to get your work done.

Clearly, my discussion has omitted many details. To help fill this gap, a companion tutorial is available on the Web (see the sidebar “Getting Started”.) Full source code is available for experimentation and invention.

John Kominek holds a master's degree in Computer Science from the University of Waterloo, and is currently a graduate student at CMU. When pressed, he admits to pronouncing Linux to rhyme with Linus. He can be reached via e-mail at jkominek@cs.cmu.edu.

______________________

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState