Framework Versions

The mBS framework has two versions. Separation in two versions comes from the opportunity for bundles to work with data files in two ways. In Standard Version, standard I/O facilities from the java.io package for working with files are used. In Connector Version, the OSGi IO Connector service is used for operations with data files.

Contents:


Standard Version

In Standard Version, bundles store their data files by using the facilities for working with files from the java.io package (by using RandomAccessFile, FileInputStream and FileOutputStream).

Figure 1 shows the modules involved in the Standard Version of the framework: bundles which work with data files through the API in the java.io package; and the used storage implementation - storage on top of java.io.


Figure 1: Modules involved in the Standard Version of the framework.

Framework JAR

The JARs from the lib directory of the Framework Professional Edition Package which hold the components of the Standard Version are:

Storage Type

This version uses storage on top of java.io, whose implementation class is com.prosyst.mbs.impl.framework.module.storage.file.StorageImpl.

Working with Data Files

You work with data files with the means of the java.io API when you are using the Standard Version of the framework.

You call the getDataFile method of the org.osgi.framework.BundleContext object for your bundle. Then to manipulate the file, call FileInputStream, FileOutputStream and RandomAccessFile on the returned File object.

Note: Only bundles whose symbolic names are included in the mbs.storage.allowroot system property, are able to access the root directory of the framework storage by using the getDataFile method.

Listing 1 shows how a bundle creates a file called example.txt in its storage area and writes a simple string.

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileInputStream;
public class FileTester implements BundleActivator {
  public void start(BundleContext bc) throws Exception {
String fName = "example.txt"; File f = bc.getDataFile(fName); FileOutputStream os = new FileOutputStream(f); os.write("This is just an example\n".getBytes()); os.flush(); os.close(); FileInputStream is = new FileInputStream(f); byte[] buff = new byte[512]; int read = 0; while ((read = is.read(buff, 0, buff.length)) > 0) { System.out.print(new String(buff, 0, buff.length)); } is.close();
}
  public void stop(BundleContext bc) throws Exception {}
}
Listing 1: Working with files in Standard Version.

Connector Version

When the Connector Version of the framework is used, bundles store data through the OSGi IO Connector service. For more information about the usage of this service, refer to the description of the Connector Service Bundle.

Figure 2 shows the modules involved in the Connector Version of the framework: bundles that use the OSGi IO Connector service to work with files; and the used storage implementation, which can be storage on top of java.io with Connector support or storage on top of MMFS with Connector support.


Figure 2: Modules involved in the Connector Version of the framework.

Framework JAR

The JARs from the lib directory of the Framework Professional Edition Package which contain the Connector Version of the framework for a specific JVM are:

Storage Type

This framework version uses:

Working with Data Files

When working with data files in the Connector Version:

  1. Call the getDataFile of the org.osgi.framework.BundleContext object for your bundle.
  2. Construct a URI by using the returned File object. The URI has the following syntax:

    file:/<pathname>[;<param>=<value>;<param>=<value>. . .]

  3. Open a connection by passing this URI. You can directly open an input or output stream as well.

Note: Only bundles whose symbolic names are included in the mbs.storage.allowroot system property, are able to access the root directory of the framework storage by using the getDataFile method.

Listing 2 creates a file example.txt in the default storage area of an arbitrary bundle. First a line is written in the file and afterwards the content of the file is read and printed in the system output.

  import java.io.File;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.ServiceReference;
import org.osgi.service.io.ConnectorService;
  public class ConnectionFactoryTest implements BundleActivator {
String outputPath;
String inputPath;
    public void start(BundleContext bc) {
InputStream is = null;
OutputStream os = null;
ServiceReference connRef = null;
try {
connRef = bc.getServiceReference(ConnectorService.class.getName());
if (connRef != null) {
ConnectorService connector = (ConnectorService) bc.getService(connRef);
File f = bc.getDataFile("example.txt");
outputPath = "file:/" + f.getPath() + ";connection_type=output";
os = connector.openOutputStream(outputPath);
os.write("This is just an example\n".getBytes());
os.flush();
os.close();
inputPath = "file:/" + f.getPath() + ";connection_type=input";
is = connector.openInputStream(inputPath);
byte[] buff = new byte[512];
int read = 0;
while ((read = is.read(buff, 0, buff.length)) > 0) {
System.out.print(new String(buff, 0, buff.length));
}
is.close();
bc.ungetService(connRef);
}
} catch(Exception e) {
if (is != null) {
try {
is.close();
} catch(IOException ignore) {}
}
if (os != null) {
try {
os.close();
} catch(IOException ignore) {}
}
}
if (connRef != null)
bc.ungetService(connRef);
}
    public void stop(BundleContext bc) {}
}
Listing 2: Working with files in Connector Version.

Troubleshooting when using storage on top of MMFS: If you use java.io facitilities, for example new FileInputStream or new FileOutputStream to write/read data from the File object received from the getDataFile of BundleContext, then the operations will not be executed properly because of the underlying abstraction used by MMFS.

ProSyst Bundles for Connector Version

mBS bundles intended to operate on the Connector Version have the mio suffix added to their archive names, for example db.jar - for Standard version and dbmio.jar - for Connector Version. These bundles import additionally the org.osgi.service.io package. Some of them also import the javax.microedition.io and/or org.mbs.services.io packages. Bundle developers may use the same naming convention for bundles working with data files in the Connector Version of the framework.


Framework Concepts