Java Reference
In-Depth Information
you examples of how to debug all these problems and suggest best practices based on
our collective experience of working with real-world OSG i applications in the field.
Let's kick off with something simple. Say you have an application composed of
many working bundles and one misbehaving bundle: how do you find the bad bundle
and debug it?
8.1
Debugging bundles
Applications continue to grow over time—more features get built on top of existing
functionality, and each code change can introduce errors, expose latent bugs, or
break original assumptions. In a properly modularized OSG i application, this should
only lead to a few misbehaving bundles rather than a completely broken application.
If you can identify these bundles, you can decide whether to remove or replace them,
potentially fixing the application without having to restart it. But first, you need to
find out which bundles are broken!
Take the paint example you've worked on in previous chapters. Imagine that you
get a request to allow users to pick the colors of shapes. Your first step might be to add
a setColor() method to the SimpleShape interface:
/**
* Change the color used to shade the shape.
*
* @param color The color used to shade the shape.
**/
public void setColor(Color color);
You probably think adding a method to an API is a minor, backward-compatible
change, but in this case the interface is implemented by various client bundles that
you may not have control over. In order to compile against the new SimpleShape API ,
they need to implement this method; so from their perspective, this is a major change.
You should therefore increment the API version in the main paint example build.xml
file to reflect this. The last version you used was 5.0, so the new version is
<property name="version" value="6.0"/>
You now need to implement the setColor() method in each of the three shape bun-
dles. Here's the updated implementation for the triangle shape bundle.
Listing 8.1 Implementing the setColor() method for the triangle shape
public class Triangle implements SimpleShape {
Color m_color = Color.GREEN;
Remembers
assigned color
public void draw(Graphics2D g2, Point p) {
int x = p.x - 25;
int y = p.y - 25;
GradientPaint gradient =
new GradientPaint(x, y, m_color, x + 50, y, Color.WHITE);
g2.setPaint(gradient);
int[] xcoords = { x + 25, x, x + 50 };
int[] ycoords = { y, y + 50, y + 50 };
Applies color to
gradient
 
Search WWH ::




Custom Search