Java Reference
In-Depth Information
<<Listen>>
<<command>> <<args>>
TelnetBinding
Port
Parse and select
command implementation
Dispatch to command
implementation
CommandImpl
Figure 3.7 TelnetBinding overview
connection requests. It spawns a new thread for each connecting client. The client
sends command lines to its thread, where a command line consists of a command
name and the arguments for the command. The thread parses the command line,
selects the appropriate command, and invokes it with any specified arguments, as
shown in figure 3.7.
Commands process the arguments passed in to them. We won't discuss the imple-
mentation of the telnet binding and the connection thread, but full source code is
available in the companion code. We'll dissect the command implementations to illus-
trate how to use Bundle and BundleContext . Let's get the ball rolling by showing how
you configure the bundle.
3.3.1
Configuring bundles
The shell needs two configuration properties: one for the port and one for the maxi-
mum number of concurrent connections. In traditional Java programming, you'd use
the System.getProperty() method to retrieve them. When creating a bundle, you can
use the BundleContext object to retrieve configuration properties instead. The main
benefit of this approach is that it avoids the global aspect of System.getProperty()
and allows properties per framework instance.
The OSG i specification doesn't specify a user-oriented way to set bundle configura-
tion properties, so different frameworks handle this differently; typically, they provide
a configuration file where the properties are set. But the specification does require
bundle-configuration properties to be backed by system properties, so you can still use
system properties in a pinch. Retrieving bundle-configuration property values is stan-
dardized via the BundleContext.getProperty() method, as shown next.
Listing 3.4 Bundle configuration by example
package org.foo.shell;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
Search WWH ::




Custom Search