Java Reference
In-Depth Information
One possibility is to store the information out-
side the framework, such as in a database or a file,
as shown in figure 3.13. The disadvantage of this
approach is that the state isn't managed by the
framework and may not be cleaned up when the
bundle is uninstalled.
Another possibility is for a bundle to give its
state to another bundle that isn't being stopped;
then, it can get the state back after it restarts, as
shown in figure 3.14. This is a workable approach,
and in some cases it makes the most sense.
For simplicity, it would be nice to be able to
use files, but have them managed by the frame-
work. Such a possibility exists. The framework
maintains a private data area in the file system for
each installed bundle.
The BundleContext.getDataFile() method
provides access to your bundle's private data area.
When using the private data area, you don't need to
worry about where it is on the file system because
the framework takes care of that for you, as well as
cleaning up in the event of your bundle being unin-
stalled (see figure 3.15). It may seem odd to not
directly use files to store your data; but if you did,
it would be impossible for your bundle to clean up
during an uninstall. This is because a bundle isn't
notified when it's uninstalled. Further, this method
simplifies running with security enabled, because
bundles can be granted permission to access their
private area by the framework.
For the shell example, you want to use the pri-
vate area to persistently save the command history. Here's how the history command
should work; it prints the commands issued via the shell in reverse order:
Framework
External
file
Bundle
External
database
Figure 3.13 Storing state externally
Framework
Bundle
Data stored
inside another
bundle
Bundle
Figure 3.14 Storing state with other
bundles
Framework
Bundle cache
File in
data area
of the
bundle
Bundle
Figure 3.15 Storing state internally
-> history
bundles
uninstall 2
bundles
update 2
bundles
stop 2
bundles
start 2
bundles
install file:foo.jar
bundles
 
Search WWH ::




Custom Search