2.3. Running the Bundle

We first launch the Java Embedded Server software by setting its classes on the CLASSPATH and loading the main class:

setenv CLASSPATH jes_path/lib/framework.jar
java com.sun.jes.impl.framework.Main

The following output will appear on your screen:

Java Embedded Server 2.0

Copyright 1998, 1999 and 2000 Sun Microsystems, Inc. All rights
   reserved.
Use is subject to license terms.

Type 'h[elp]' for a list of commands.
>

The user interface to the framework is an interactive command console. To install our bundle, use the install command:

> install /home/joe/bundles/home.jar

The bundle is installed when the prompt returns. Use the bundles command to examine the current status of the installed bundle:

> bundles
ID  STATE     LOCATION
--  --------- -------------------------
1   INSTALLED file:/home/joe/bundles/home.jar
>

Next, start the bundle:

> start 1
Home, sweet home

The number 1 is the bundle identification (ID) as reported by the bundles command. When the bundle is started, its activator's start method is invoked, and we see the expected message displayed. Try issuing the bundles command again to see the change of state:

> bundles
ID  STATE     LOCATION
--  --------- -------------------------
1   ACTIVE    file:/home/joe/bundles/home.jar
>

Now stop the bundle by issuing the stop command:

> stop 1
I'll be back

The bundle activator's stop method is invoked, which produces the expected message. You can start and stop the bundle multiple times, and check how the bundle status changes.

Finally, let's uninstall the bundle, then recheck the bundle status:

> uninstall 1
> bundles
>

The bundle is gone from the framework. You may use the shutdown command to exit the framework:

> shutdown
%

2.3.1. Getting Help

After launching the framework, type “help” at the prompt to see a list of commands, their abbreviations, and syntaxes:

 > help
b[undles]
e[xportedpackages]
debugon    <name> [,<option>,...]
debugoff   <name>
g[et]      <property_name>
h[elp]     [<command>]
i[nstall]  <bundle_url> [, ...]
m[anifest] <bundle_url | bundle_id>
r[un]      <filename | url>
se[t]       <property_name>=<property_value>
ser[vices]  [<filter>]
sh[utdown]
sta[rt]     <bundle_url | bundle_id> [, ...]
sto[p]      <bundle_url | bundle_id> [, ...]
tty
un[install] <bundle_url | bundle_id> [, ...]
up[date]    <bundle_url | bundle_id> [bundle_update_url] [, ...]

  <bundle_url> and <bundle_update_url> must be the URL of a bundle
  or be relative to the bundle base URL.
  .jar suffix will be appended if not specified.

JES cache directory:   /home/joe/jescache
						Bundle base URL:       file:/home/joe/jes2.0/bundles
Java 2 security support: No

To see a more detailed description of a command, specify the command after typing “help”:

> help install
Install the specified bundles.

The help feature also displays the current settings for the cache directory and the bundle base URL, which we describe next.

2.3.2. The Cache Directory

The Java Embedded Server software caches installed bundles loaded over the network and keeps track of their status, so that after the framework is shut down and restarted, the bundles are reinstalled, and those that used to be active are started again. A cache directory on the local file system is created for this purpose.

You can learn the whereabouts of the cache directory by using the help command. For example, the output in Section 2.3.1 shows that the cache directory is at /home/joe/jescache. By default, the cache directory is created in the user's home directory under the name of jescache. You can override that by setting the com.sun.jes.framework.cache.dir system property:

java -Dcom.sun.jes.framework.cache.dir=/tmp/mycache com.sun.jes .impl.framework.Main

If you want to start from a pristine state, remove the cache directory.

2.3.3. The Bundle Base URL

In the framework, bundles are identified either by an ID number or by a location string. The latter is usually a URL or a path on the local file system. For example,

> install c:mybundleshello.jar

installs a bundle from the local file system, whereas

> install http://myhost:8080/bundles/hello.jar

fetches the bundle remotely from an HTTP server and installs it in the framework.

If an absolute URL or path is specified, it is used directly to obtain the bundle. If a relative URL or path is specified, it is concatenated with the base URL to retrieve the bundle. By default, the base URL is the current directory.

You can set the com.sun.jes.framework.bundles.baseurl system property to point to the location of a pool of bundles. For example,

> set com.sun.jes.framework.bundles.baseurl=http://myhost:8080/
bundles
> install hello.jar

You can find the current setting for the bundle base URL from the help command output. For instance, the help display in Section 2.3.1 shows that the current bundle base URL is file:/home/joe/jes2.0/bundles.

Unlike the com.sun.jes.framework.cache.dir system property, which can only be set when the framework is launched, the com.sun.jes.framework.bundles.baseurl property can be modified at any time using the set command, and it takes effect immediately.

2.3.4. Brief Summary of the Major Commands

The framework command console allows you to control a bundle's life cycle. The following commands serve this functionality:

  • install installs a bundle from a URL.

  • start activates an installed bundle by its ID or location string.

  • stop deactivates a bundle by its ID or location string.

  • update updates a bundle to a newer version using its ID or location string.

  • uninstall uninstalls a bundle by its ID or location string.

The following commands report useful information about bundles and services in the framework:

  • bundles displays all bundles currently installed in the framework and their states.

  • services displays all services registered in the framework.

  • manifest displays headers defined in a bundle's manifest.

  • exportedpackages displays the exported packages as well as their exporters and importers.

The two following commands allow you to set or retrieve system properties in the Java virtual machine:

  • set sets a system property.

  • get displays the value of a system property.

Please consult the documentation located in the jes_path/docs directory for more details on how to use the framework console. We return to the command console often to see code in action as we delve into the intricacies of bundles and services.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.226.240