Java Reference
In-Depth Information
to restart the
JVM
. To see this in action, you first need to revert the
setColor()
method
of the local
DefaultShape
class back once again to the broken implementation:
public void setColor(Color color) {
m_shape.setColor(color);
}
Next, completely rebuild the example:
$
ant clean dist
This time, you won't use a debugger. Also, add your command shell to the current set
of bundles, so you can ask the framework to update the fixed bundle later:
$
ant add_shell_bundles
$
java -jar launcher.jar bundles
First, confirm that you have the broken implementation installed by attempting to
paint a shape (you should see an exception). Then, in another operating system shell,
fix the
setColor()
method of the
DefaultShape
class using the code from listing 8.2,
and rebuild the paint frame bundle in a new window:
$
cd chapter08/debugging-bundles/org.foo.paint
$
ant
You can now try updating your fixed bundle. Go back to the
OSG
i console, and type
the following:
->
update 6
Here, 6 is the
ID
of the paint frame bundle, as reported by the
bundles
command. When
you issue the
update
command, the framework updates the bundle content by reload-
ing the bundle
JAR
file from its original install location. It also stops and restarts the paint
frame bundle, so you should see the paint frame window disappear and reappear. The
paint example is now using the fixed code, which means you can paint multicolored
shapes as shown in figure 8.8. Notice that you didn't need to follow the update with a
refresh. This is because the paint frame bundle doesn't export any packages, so you
know there are no other bundles hanging onto old revisions of the
DefaultShape
code.
Unlike
JR
ebel, the
OSG
i update process doesn't depend on a special
JVM
agent. It
also doesn't have any significant effect on performance. These reasons together mean
you can use the
OSG
i update process in a production environment. The downside is
that you have to update and restart the entire bundle, potentially destroying the cur-
rent state, rather than redefine a single class. If you wanted to keep any previously
drawn shapes, you would need to persist them somehow when stopping and restore
them when restarting.
Yo u ' v e j u s t s e e n h o w y o u c a n d e b u g a n d f i x p r o b l e m s i n
OSG
i applications using every-
day development tools such as jdb and Eclipse. You looked at more advanced techniques,
such as HotSwap and
JR
ebel, and finally used the tried-and-tested
OSG
i update process
to fix a broken bundle. We hope these examples made you feel more comfortable about