One of the new and interesting technologies developed using Java is the Castanet product for automating the distribution of Web applications and software. Castanet, developed by Marimba, Inc., consists of a client/server publishing system that automatically updates users' computers with Web applications and software that are made available over specific distribution channels. Castanet's paradigm for Web publishing has since been adopted by both Netscape and Microsoft. The Netcaster component of Netscape Communicator incorporates Castanet technology, as well as more general channel capabilities. Microsoft and Marimba collaborated on the Channel Definition Format used by Internet Explorer 4.0.
In this chapter, you'll be introduced to Castanet and learn how the Castanet Transmitter and Tuner are used to publish applets and other executable content. You'll also learn about the channel publishing support provided by Netcaster and Active Channels. When you finish this chapter, you'll be able to use channels to publish your own Java applets.
Castanet is a new paradigm for distributing Web applications and software that was developed by Marimba, Inc. (http://www.marimba.com), a company that was started by four of the original members of the Java team. Marimba provides three main products that are used to implement Castanet:
All three of these Marimba products were developed in Java. They are available for Windows 95, Windows NT, and Solaris platforms. Ports of these products are also available for Linux and other operating system platforms.
NOTE: Version 2.1 of Castanet only supports the Java Development Kit 1.1.5. Applications written using the newer JDK 1.2 API do not work with this version of Castanet.
Castanet also provides repeater and proxy products. Repeaters are used to add supplementary transmission capabilities. Proxies are used to support transmission through a firewall.
Castanet uses the analogy of radio and television broadcasting. Web applications are published using Castanet Publish, a component of Castanet Transmitter. These applications may consist of simple HTML files, Java applets, presentations developed using Bongo, or Java applications. The applications are published to a Castanet Transmitter and are associated with a named channel. The Castanet Transmitter is analogous to a Web server. A channel is analogous to a Web site. For example, Marimba provides a transmitter on the host trans.marimba.com. This transmitter provides access to a number of channels, ranging from Castanet documentation to a couple of interesting games.
The Castanet Tuner is a client that is run by users in order to access Castanet channels. The tuner allows users to subscribe to a particular Castanet Transmitter and channel. When a user subscribes to a channel, the tuner contacts the transmitter responsible for that channel and downloads all of the files published on that channel to a directory on the user's computer. It then allows the user to execute these applications locally. The tuner also periodically checks back with the transmitter to see if the application files have been updated, and if so, downloads any changes to the user's computer. In this way, the user is ensured of having the latest information that is published on a channel available locally on his computer.
Figure 49.1 summarizes how Castanet works. A content developer creates HTML files, Java applets and applications, and Bongo presentations that he wants to publish. He organizes these files into three channels: A, B, and C. For example, A could be news and weather, B could be art and literature, and C could be games. He uses Castanet Publisher to publish these files to a transmitter. Different users subscribe to these channels using their tuner clients. The tuners download the files for the subscribed channels and store them on the users' hard drives. The users execute the application files locally using the tuner. The tuner also periodically checks back with the transmitter and updates the locally stored application files after they have been updated and republished by the content developer.
FIGURE 49.1. How Castanet works.
As you can see from Figure 49.1, Castanet uses a much different approach than most other Internet client/server systems, in which the interaction between a client and server is limited to a single transaction or a single group of transactions. For example, when a Web browser fetches a Web page from a Web server, the interaction between the browser and the server is complete. The user may never go back to that Web page again. In Castanet, once you subscribe to a channel, your tuner periodically checks back with the transmitter to make sure that you have the latest content published on the channel. If new information is published on the channel, the tuner automatically downloads it to the user's hard drive. This is a great benefit to the user, allowing him to keep abreast of the latest information of interest without having to continually check back with the server. The tuner does all the legwork for him.
Another advantage of the Castanet approach is that the tuner maintains the information that is published on a channel locally on the user's hard disk. This means that the user does not have to be connected to the Internet to access this information. For example, suppose you were using a notebook computer. You could dial in to your Internet service provider and use your tuner to subscribe to a channel. Your tuner would download the channel's content and store it on your hard drive. You could then take your notebook computer on a plane and access the channel's content while you were flying away to a distant location. When you arrived at your destination, you could call into your ISP and get an update of any new content that was added to the channel.
Castanet is especially helpful to users who have low-bandwidth Internet connections. Because the tuner works in the background to update your channels, it can be checking on your favorite channels while you are running other applications or doing other things. You can leave your computer running overnight and when you wake up the next day, it will be automatically updated with the latest channel content.
As mentioned earlier, Castanet channels support HTML, Java applets and applications, and Bongo presentations. Bongo presentations are a scripted hybrid of applets and applications. Think of them as Java applets or applications that are implemented using scripts rather than byte code.
When HTML files are published over a channel, the tuner executes them by invoking your default browser. You must configure your browser to use Castanet as a local proxy for accessing the Web. Castanet works with both Netscape Navigator and Microsoft Internet Explorer, as well as other popular browsers. The main advantage of Castanet when used for HTML publishing is that it maintains the HTML files on your system. When you need to access them, they're there. You don't have to worry about accessing the Internet or whether the destination Web server is down.
When Java applets are published over a channel, the tuner executes the applet in much the same way as the appletviewer tool of the JDK. The tuner provides the applet with all of the capabilities that it would have if it were executed via a browser. For example, an applet can retrieve and display images and play audio files. Castanet is an advantage for applet developers and users because it maintains the applet and the files used by the applet on users' computers, so the applet developer can use more bandwidth-consuming audio, image, and video files. When users access the applet, they don't have to wait for the multimedia files to be downloaded. They're waiting for them on their hard disks. Most applets can be used with Castanet without modification.
When Java applications are published over a channel, the tuner executes the application locally on your machine. However, the tuner implements a security manager that prevents the application from causing any damage to your system. The security manager confines all application disk I/O to a specific directory on your hard disk, prevents applications from making network connections to any host other than the transmitter, and keeps applications from executing local programs or dynamic link libraries. Castanet facilitates the installation and execution of Java applications, while limiting the exposure of users to accidental or deliberate damage.
The Castanet Tuner is freely available for download from Marimba's Web site. It is supported on Windows 95, Windows NT, Macintosh, and Solaris platforms. It has also been ported to Linux and other operating systems. The Linux version is available from the Java Linux Web site at http://www.blackdown.org/java-linux/Products.html. The Windows 95 version of Castanet Tuner is distributed as a self-extracting executable file that installs quickly and easily on your system. Go ahead and download and install Castanet Tuner. When you have finished, select Castanet Tuner from the Start menu to run it.
Figure 49.2 shows how the tuner appears when you execute it. It provides four tabs that are used to access various parts of the application. The Marimba tab displays the Marimba logo and copyright information.
NOTE: When you first run the tuner, it will connect to Marimba's transmitter and update itself with the latest version of the tuner software. This may take a few minutes.
FIGURE 49.2. The Castanet Tuner.
The Channels tab lists the channels that you are currently subscribed to and allows you to execute these channels by double-clicking on them (see Figure 49.3).
FIGURE 49.3. The Channels tab lists the channels that you've subscribed.
The Listing tab allows you to list all of the channels that are available from a particular transmitter, as shown in Figure 49.4. Just enter the host name of the transmitter and click on the List button. You can subscribe to a channel by double-clicking on it.
FIGURE 49.4. The Listings tab lists the channels of a transmitter.
The Configure tab, shown in Figure 49.5, allows you to configure your tuner. It contains the Updates, User, Network, and Options subtabs. The Updates subtab lets you control how frequently the tuner contacts transmitters. The User subtab allows you to enter name and address information. The Network subtab is used to configure a firewall proxy. The Options subtab is used to configure your network connection.
FIGURE 49.5. The Configure tab lets you configure your tuner.
We'll subscribe to a transmitter and channel to show you how it works. Click on the Listing tab, enter trans.marimba.com in the pull-down text field, and click on the List button. A listing of the Marimba channels is displayed, as shown in Figure 49.4. Double-click on the SameGame channel to subscribe to it. The SameGame application is downloaded and then executed, as shown in Figure 49.6. You can play the game by clicking twice on groups of two or more squares of the same color. The objective is to remove all of the squares.
When you are finished with the SameGame channel, close it and return to the Listing tab. Enter gday.bloke.com:81 and click the List button. The channels for the gday.bloke.com transmitter are listed. Double-click on the WhatsNew channel to subscribe to it. This channel provides a great starting place to learn about other channels.
FIGURE 49.6. The SameGame channel.
WARNING: When using Castanet tuner to access transmitter channels, remember that it stores all channel content locally on your hard disk. If you are not vigilant about your channel usage, you'll find yourself running out of hard disk storage space.
The Castanet Transmitter is a product of Marimba, Inc. It is not freeware or shareware. However, Marimba makes evaluation copies available for download from its Web site. Castanet Transmitter also comes in Windows 95, Windows NT, and Solaris versions. The Windows 95 version is distributed as a self-extracting executable installation program.
NOTE: To run the examples later in this chapter, you'll need to download and install Castanet Transmitter.
Castanet Transmitter allows you to create your own channels for distributing executable content and HTML files over the Internet. It consists of two products: the transmitter itself and Castanet Publisher. The transmitter is self-installing and provides excellent help support. Castanet Publisher is covered in the next section.
You use Castanet Publisher to publish your executable content to a transmitter. Castanet Publisher doesn't provide any Web content development capabilities. You develop your Java and HTML files using your normal development tools. All Castanet Publisher does is move your files from your development directory to a directory on the transmitter and configure your transmitter to make the files available over a particular channel.
Castanet comes with a few demo channels. These channels are contained in the C:\Program Files\Marimba\Castanet Publisher\developers\channels directory. I'll show you how to publish one so that you'll learn how Castanet Publisher works. If you do not have your transmitter running, now is a good time to start it. I use the C:\Channels directory as my transmitter channels directory.
WARNING: You cannot circumvent Castanet Publisher by copying files directly to your transmitter. Castanet Publisher must copy your files so that it can properly configure them on a channel.
Open Castanet Publisher from the Start menu. It displays the window shown in Figure 49.7.
FIGURE 49.7. The Castanet Publisher opening window.
Click on the Channels button to go to the Channels Under Development window, shown in Figure 49.8.
FIGURE 49.8. The Channels Under Devel-opment window.
Click the Add button to go to the Directory Finder dialog box, shown in Figure 49.9.
FIGURE 49.9. The Directory Finder dialog box.
Enter C:\Program Files\Marimba\Castanet Publisher\developers\channels\ Crossword and click the Add button. The channel is added to the Channels under Development window, as shown in Figure 49.10.
Now click the Edit button. The nine-tabbed window, shown in Figure 49.11, is displayed. You can use these tabs to configure your channel before publishing it. These tabs are described in the following paragraphs:
FIGURE 49.10. The channel is added to the Channels Under Development window.
FIGURE 49.11. The channel configuration tabs.
Now that you've taken a brief tour through Castanet Publisher, click the Publisher button to publish the Crossword channel.
Click the Done button twice and then the Quit button to exit Castanet Publisher.
FIGURE 49.12. Publishing the Crossword channel.
Now that you've published the Crossword channel to your transmitter, you can use your tuner to execute it. Open your tuner and turn to the Listing tab. Enter the host name of your transmitter and click the List button. The Crossword channel is displayed under your transmitter, as shown in Figure 49.13. Double-click on the Crossword channel to execute it.
FIGURE 49.13. Listing the Crossword channel on your transmitter.
Figure 49.14 shows the Crossword channel. It displays a crossword puzzle that you can complete.
FIGURE 49.14. Executing the Crossword channel.
Although we haven't covered all of Castanet's features or capabilities, you now know enough to develop an applet and publish it using Castanet. Listing 49.1 shows the Gallery applet, which is contained in the ch49\publish directory.
After you compile the Gallery applet, the ch49\publish directory contains the following files:
The image.jpg file contains a photographic image. The audio.au file contains an audio description of the photo.
Now use Castanet Publisher to distribute the applet and its supporting files via a channel. When you open Castanet Publisher, click the Channels button to go to the Channels Under Development window. Then click the Add button. Type c:\jdk1.2\ju\ch49\publish in the Path field (as shown in Figure 49.15), and then click the OK button.
FIGURE 49.15. Specifying the channel's source directory.
Now click on the Edit button in the Channels Under Development window. The channel configuration window is displayed. Click on the General tab. Set the Name field to Daily Photo Gallery. Set the Type field to Applet. Set the Code field to Gallery. Set the Width field to 500 and the Height field to 450 (see Figure 49.16).
FIGURE 49.16. Specifying the channel's name and type.
Click on the Update tab and then set the Update Frequency for an Inactive application to Daily. Then click the Publisher button. The Gallery channel is published to your transmitter. Castanet Publisher displays a confirmation, as shown in Figure 49.17. Go ahead and exit Castanet Publisher.
FIGURE 49.17. Confirming the channel's publication.
Start your tuner and click on the Listing tab. Enter the host name of your transmitter and click the List button. The name of the new channel is displayed, as shown in Figure 49.18.
FIGURE 49.18. Listing the new channel under your transmitter.
Double-click on the Daily Photo Gallery channel and the Gallery applet is executed, as shown in Figure 49.19. You can click the Audio Description button to find out information about the photograph that is displayed. Close the applet and the tuner.
FIGURE 49.19. The Daily Photo Gallery channel.
The previous example shows how easy it is to publish an applet using Castanet. In this section, I'll show you how easy it is to update the information displayed by the applet. In your ch49 directory are files named image2.jpg and audio2.au. These files contain a new image and audio description. Copy these files over the image.jpg and audio.au files contained in the publish subdirectory.
You've just updated the Daily Photo Gallery's source directory. Now let's publish the new information to the transmitter. Open Castanet Publisher and click the Channels button. Select the channel and click the Edit button. Now click the Publisher button to republish the channel. That's all you need to do to update your channel. You can exit from Castanet Publish.
Because your channel specified a daily update frequency, all channel tuners will check back with your transmitter in about a day to get the updated channel information. Let's check out the new information that you published. Open your tuner and click on the Channels tab. Now double-click on the Daily Photo Gallery channel. The same photo that was displayed in Figure 49.19 is displayed. That's because your tuner didn't check in with your transmitter yet.
Close the Daily Photo Gallery channel, but keep it selected in the Channels tab of your tuner. Select Update from the Channel pull-down menu to force your tuner to check back with the transmitter. Now double-click on the Daily Photo Gallery channel again. This time it displays the photo shown in Figure 49.20.
FIGURE 49.20. The Daily Photo Gallery channel.
Up to this point, we've been focusing on how Castanet works. In this section we'll describe how the Gallery applet works. It creates two field variables named image and audio to refer to the image that is displayed and its associated audio description. The init() method invokes the getCodeBase() method of the Applet class to retrieve the URL associated with the applet's code base. This URL is used to read the image and audio files that are located in the same directory as the applet. Even though the applet, image file, and audio file are executed by a tuner from the user's hard disk, we can still use getCodeBase() to refer to their location. The getImage() and getAudioClip() methods retrieve the image and audio files. The rest of init() consists of applet layout.
The stop() method simply stops the playing of the audio file.
The actionPerformed() method of the ButtonHandler class handles the clicking of the button by playing the audio file.
The MyCanvas class is used to display the image in the middle of the applet window. The paint() method calculates the difference between the canvas size and the image size and adjusts the image to the center of the canvas.
import java.applet.*; import java.awt.*; import java.awt.event.*; import java.net.*; public class Gallery extends Applet { AudioClip audio; Image image; public void init() { try { URL base = getCodeBase(); image = getImage(base,"image.jpg"); audio = getAudioClip(base,"audio.au"); setLayout(new BorderLayout()); add("Center",new MyCanvas(image)); Button button = new Button("Audio Description"); button.addActionListener(new ButtonHandler()); add("South",button); }catch (Exception ex) { } } public void stop() { audio.stop(); } class ButtonHandler implements ActionListener { public void actionPerformed(ActionEvent event) { audio.play(); } } } class MyCanvas extends Canvas { Image image; public MyCanvas(Image image) { this.image = image; } public void paint(Graphics g) { Dimension canvasSize = getSize(); int imageHeight = image.getHeight(this); int imageWidth = image.getWidth(this); int x = (canvasSize.width - imageWidth)/2; int y = (canvasSize.height - imageHeight)/2; if(x<0) x=0; if(y<0) y=0; g.drawImage(image,x,y,this); } }
OTHER CASTANET PUBLISHING CAPABILITIES
So far, you have seen how easy it is to publish applets with Castanet. However, Castanet provides many more capabilities than we've covered here. Some of these capabilities are as follows:
The use of these capabilities in channels is a book in itself. For more information, I suggest that you subscribe to the Castanet Developer Docs channel that is published by trans.marimba.com.
The Castanet approach to delivering Web content was adopted by Netscape in Netscape Communicator 4.0. The Netcaster component of Communicator 4.0 supports the push delivery of Web content and includes support for Java and JavaScript. Netcaster provides direct support for Castanet channels. However, Netcaster does not support Microsoft's Channel Definition Format (CDF).
Netcaster, like Castanet, is channel-oriented. The user subscribes to certain channels that are delivered to the user as a background or foreground operation. Netcaster implements push in the same way as Castanet by having the client download data from the server and store it on the user's local computer. Netcaster supports the notion of a "Webtop" as a channel that is anchored to the user's desktop. The Webtop channels are similar to the Active Channels supported by Microsoft's Internet Explorer 4.0.
Netcaster supports offline browsing, which is implemented by downloading Web sites to the user's hard disk. The user browses local files instead of going out to the Web.
One of the major advantages of Netcaster is that it works with the existing HTML, Java, and JavaScript infrastructure of the Web. No special transmitter or server-side publishing is required. Existing Web sites do not need to be reconfigured to work with Netcaster. All the user needs to do is identify the URL of a Web site, the number of levels of links to download, and an update period. Netcaster takes care of the rest.
Castanet support is embedded in Netcaster. Netcaster can be used to access Castanet channels by simply identifying the URL of the Castanet transmitter. Castanet URLs begin with castanet:// and are followed by the name of the host, port, and channel to be accessed. Netcaster provides the best of both worlds--support of Castanet channels and general HTTP, Java, and JavaScript support.
There are no special requirements for developing Netcaster channels. For basic channel support, all you have to do is publish your HTML files, scripts, and Java .class files to your Web site. If you want to publish Castanet channels for use with Netcaster, you can use the Castanet publishing tools covered earlier in this chapter. Castanet channels require the use of a Castanet transmitter.
Active Channels are Microsoft's answer to pushing Web content. They are based on the Channel Definition Format (CDF), which is a channel specification developed by Microsoft and Marimba. The CDF has been submitted to the World Wide Web Consortium for international standardization. Active Channels are incorporated into Internet Explorer 4.0.
Active Channels are similar to Castanet channels in that channel content is loaded in the background, at regular intervals, by the user's client program. Internet Explorer 4.0 is the Active Channel client. Active Channels are also similar to the Netcaster Webtop in that Active Channels can be integrated within the Windows 95, 98, and NT desktop. Since Active Channels are targeted toward Windows platforms, Active Channels provide tighter desktop integration. This is a major feature of Windows 98.
Active Channel content consists of anything that you could publish to a Web site: HTML files, scripts, Java applets, and ActiveX controls. Active Channels are implemented in the same manner as Netcaster channels. However, special testing of Active Channels is required because ActiveX controls and some Java applets may not work correctly in the channel's offline mode. This generally occurs when the control or applet needs access to network resources.
Unlike Netcaster channels, Active Channels require the use of a separate CDF file. The CDF file is used to specify the channel content, its structure, and information about the scheduling of channel updates. CDF files are syntactically similar to HTML files in that they use HTML-like tags. CDF files also specify the URLs of the channel files, the structure of the channel pages, and scheduling options.
CDF is an application of the eXtensible Markup Language (XML). Its syntax is covered in the Channel Definition Format specification, which is available at http://www.microsoft.com/standards/cdf-f.htm. A CDF file begins with a line that identifies the XML version being used:
<?XML Version="1.0"?>
This is then followed by a CHANNEL tag that identifies the channel's main page:
<CHANNEL HREF="url">
In the preceding statement, url is replaced by the URL of the channel's main HTML page.
ABSTRACT and TITLE tags can be used to specify an abstract and title for the channel:
<ABSTRACT>This is a summary of what my channel is all about.</ABSTRACT> <TITLE>This is my channel's title</TITLE>
The LOGO tag may be used to specify a logo for a channel:
<LOGO HREF="url" STYLE="iconType" />
The url identifies the location of the channel's logo (a GIF file). The iconType identifies the type of icon. Three icon types are supported: icon, image, or image-wide. These icons are placed on the Channel Bar and Active Desktop.
A series of ITEM tags follow the LOGO tags. The ITEM tags are used to specify the subpages (other pages) of a channel. ITEM tags are used as follows:
<ITEM HREF="url"> <ABSTRACT>Abstract of subpage.</ABSTRACT> <TITLE>Title of subpage</TITLE> </ITEM>
The url refers to the URL of the subpage. The ABSTRACT and TITLE tags are used to provide additional information about the subpage.
The closing CHANNEL tag follows the last ITEM tag and marks the end of the CDF file.
</CHANNEL>
Listing 49.2 provides an example CDF file. This file identifies the URL of the main page as http://www.jaworski.com/ju/ch49/hello.htm. Listing 49.3 displays the contents of the hello.htm file. An abstract and title are provided for the main page. However, I skipped the logos. The channel contains a single subpage--the HelloChannel applet. Listing 49.4 shows the source code for HelloChannel. This applet just displays the text Hello Channel! to the applet display area.
I've put the hello.htm and HelloChannel.class files on my Web server. To view the channel with Internet Explorer 4.0, simply open the example.cdf file. Figure 49.21 shows how the channel is displayed by Internet Explorer.
As you can see, Active Channels are easy to create. Basically, you create a Web site as you normally would and then specify the channel's contents using a CDF file. Active Channels are equal in capability to basic Netcaster channels, but they are far less sophisticated than Castanet channels. Active Channels have a significant disadvantage in that they require the creation of a separate CDF file.
FIGURE 49.21. Displaying the example Active Channel.
<?XML Version="1.0"?> <CHANNEL HREF="http://www.jaworski.com/ju/ch49/hello.htm"> <ABSTRACT>This is a example Active Channel.</ABSTRACT> <TITLE>Example Active Channel</TITLE> <ITEM HREF="http://www.jaworski.com/ju/ch49/HelloChannel.class"> <ABSTRACT>HelloChannel applet.</ABSTRACT> <TITLE>HelloChannel</TITLE> </ITEM> </CHANNEL>
<HTML> <HEAD> <TITLE>Example Active Channel</TITLE> </HEAD> <BODY> <H1>An applet that is part of this channel:</H1> <APPLET CODE="HelloChannel.class" HEIGHT=300 WIDTH=300> </APPLET> </BODY> </HTML>
import java.applet.*; import java.awt.*; public class HelloChannel extends Applet { public void paint(Graphics g) { g.setFont(new Font("TimesRoman",Font.BOLD+Font.ITALIC,36)); g.drawString("Hello Channel!",50,50); } }
In this chapter, you were introduced to Castanet and learned how the Castanet Transmitter and Tuner are used to publish applets and other executable content. You also learned about the channel publishing support provided by Netcaster and Active Channels. In the next chapter, you'll learn about the electronic commerce capabilities supported by the Java Commerce and JavaCard APIs.
© Copyright, Macmillan Computer Publishing. All rights reserved.