Record Management System from entry into one of the proficient series

zhaozj2021-02-16  48

Record Management System is an important subsystem for J2ME, with a purpose of implementing the persistent storage of application local data. The mobile information device currently supporting the file system is also limited, so the Record Management System is the preferred way for J2ME developers to achieve local data storage. The purpose of this paper is to fully introduce the knowledge of Record Management System.

As the name suggests that Record Management System is a system for managing data, Record is the most important entity in the system. The mobile device storage is not a field, but an array of bytes. What kind of data is not specified in the Mobile Infomation Device Profile (MIDP) specification to be stored as records, in fact, the record is any data that can be represented by byte arrays, such as pictures, text, and the like. Record Management System's root is to store and uniquely identify records, and the task of indicating data is done by the application, so J2ME developers tend to take more energy to process data in the storage space. The purpose of this is to simplify the implementation of MIDP, so that J2ME subsystem is small and flexible. After all, the storage space of mobile information equipment and the ability of the processor is limited.

The Record Store is a series of recorded ordered sets, and the record is unable to exist alone and must belong to the Record Store. The Record Store guarantees that the read and write operations recorded are atoms, and the data will not be destroyed. In the API, the Record Store is implemented by javax.microedition.rms.RecordStore, and the specific operation of RecordStore will have a detailed introduction in the next article.

The MIDP specification illustrates the mobile information device to provide a non-volatile storage space to the application to implement data persistence storage. However, the space provided by different devices is not the same. If the MIDlet Suite uses the Record Management System, it must be in the Manifest file and JAD files to clear the minimum data storage space it needs by setting MIDlet-data-size, the unit is byte, such as MIDlet-data-size: 8192. If your value exceeds the maximum value specified by the mobile device, then your application will not be installed correctly. This value is not the storage space of the mobile device to truly provide the maximum RECORD Management System of the application, often more, so developers should avoid excessive storage of the minimum storage space required by the application, should refer to related equipment when necessary Description Manual. Reading and writing data in non-volatile storage is often slower, so it is best to provide performance for frequently accessible data to provide a cache. The read and write operation of the Record Management System is thread secure, but because the Record Store is shared by the entire MIDlet Suite, if the thread running on a different MIDLET runs the RECORD Store, we should make the necessary thread synchronization, avoid data being destroyed .

MIDP 1.0 and MIDP 2.0 About Record Management System Some different, MIDlets in the same MIDlet Suite can access each other's Record Store. However, in the implementation of MIDP 1.0, there is no mechanism to share the Record Store between different MIDlet Suite. The new API provided in MIDP2.0 to solve the problem of sharing the Record Store between different MIDlet Suite. When you create the Record Store, you will use the authorization mode and read and write control parameters to manage the management of sharing mechanisms. Detailed introduction in the article.

The best way to strengthen the understanding of Record Management System is to conduct actual development. I found that the MIDP implementation of all mobile devices is accurate in the development. When I use the getSizeavaliable () method to query the NOKIA6108's available Record Store space, the value gets more than 1M bytes, but when I write 40K data, I appear RecordStoreFullexception Exception, so I wrote an automatic test phone RECORD. Software for the largest storage space. The principle is to write 1k byte of data to the Record Store, for example, 100-500 milliseconds, and the maximum value can be obtained when the storage space is full, and the exact unit is K byte. Below is the source code of the program and the content of the JAD file. The development platform is Eclipse3.0RC2 EclipseMe0.4.1 WTK2.1 J2SDK1.4.2._03, and the test is passed on the real machine NOKIA 6108 and the maximum value is 31K. (Please do not test on the simulator, the result is meaningless) Summary: This article only leads the reader's understanding of the Record Management System, although the article is finally provided with an application. But there is no in-depth analysis how to use the Record Management System. In the next article we will in depth in the javax.microedition.rms package, the focus is how to use the RecordStore class.

//RMSAnalyzer.javaimport javax.microedition.lcdui.Alert; import javax.microedition.lcdui.AlertType; import javax.microedition.lcdui.Display; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; import Javax.microedition.rms.RecordstoreException;

/ * * Created on 2004-6-21 * * Todo to change the template for this generated file go to * window - preferences - java - code style - code templates * /

/ ** * @Author ming * * Todo to change the template for this generated type comment Go to window - * preferences - java - code style - code templates * / public class rmsanalyzer extends MIDlet {

Private Display Display; Private Countercanvas Countercanvas; Private Alert Alert

/ * * (Non-javadoc) * * @see javax.microedition.midlet.midlet # startapp () * / protected void startapp () throws midletStateChangeException {// Todo auto-generated method stub

display = Display.getDisplay (RMSAnalyzer.this); alert = new Alert ( "error"); try {String interval = this.getAppProperty ( "INTER"); int t = Integer.parseInt (interval); counterCanvas = new CounterCanvas (T, 1, this);} catch (recordstoreExcection e) {this.showalerterror (E.GetMessage ());} display.setcurrent (countercanvas);} public display getDisplay () {Return Display;}

/ * * (Non-javadoc) * * @see javax.microedition.midlet.midlet # Pauseapp () * / protected void Pauseapp () {// Todo auto-generated method stub

}

/ * * (Non-Javadoc) * * @see javax.microedition.midlet.MIDlet # destroyApp (boolean) * / protected void destroyApp (boolean arg0) throws MIDletStateChangeException {// TODO Auto-generated method stub

}

Public void showalerterror (String Message) {alert.setString (message); Alert.SetType (AlertType.Error); Alert.SetTimeout (3000); Display.SetCurrent (Alert);

}

}

//Countercanvas.javaimport java.util.timer; import java.util.timertask

import javax.microedition.lcdui.Canvas; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Graphics; import javax.microedition. MIDlet.midletStateChangeException; import javax.microedition.rms. *;

/ * * Created on 2004-6-21 * * Todo to change the template for this generated file go to * window - preferences - java - code style - code templates * /

/ ** * @author ming * * TODO To change the template for this generated type comment go to Window - * Preferences - Java - Code Style - Code Templates * / public class CounterCanvas extends Canvas implements CommandListener {private RMSModel model; private RMSAnalyzer RMSanalyzer ; private int interTime; private int counter; private boolean go = true; public static Command backCommand = new Command ( "exit", Command.EXIT, 3); public static final int INC = 1; public final Timer timer = new Timer ( );

public CounterCanvas (int interTime, int base, RMSAnalyzer rmsa) throws RecordStoreException {this.interTime = interTime; this.counter = base; this.RMSanalyzer = rmsa; model = new RMSModel (base, RMSanalyzer); this.addCommand (backCommand); This.SetCommandListener (this);

Timertask Timertask = New Timertask () {public void run () {

try {model.writeRecord (INC); counter ;} catch (RecordStoreFullException e) {go = false; model.deleteRMS (); timer.cancel ();} catch (RecordStoreException e) {model.deleteRMS (); RMSanalyzer.showAlertError (E.getMessage ()); Timer.cancel ();} repaint ();

}};

Timer.schedule (Timertask, 1000, Intertime);

}

/ ** * @Param counter * the counter to set. * / Public void setcounter (int counter) {this.counter = counter;

/ ** * @param interTime * The interTime to set * / public void setInterTime (int interTime) {this.interTime = interTime;}. / * * (Non-Javadoc) * * @see javax.microedition.lcdui.Displayable # paint (javax.microedition.lcdui.Graphics) * / protected void paint (Graphics arg0) {// TODO Auto-generated method stub int SCREEN_WIDTH = this.getWidth (); int SCREEN_HEIGHT = this.getHeight (); arg0.drawRect ( Screen_Width / 10, Screen_Height / 2, Screen_Width * 4/5, 10); if (rmsanalyzer.getdisplay (). IsColor ()) {Arg0.SetColor (128, 128, 255);} arg0.fillRect (Screen_Width / 10, Screen_Height / 2, Counter, 10); if (! Go) arg0.drawstring ("Max:" COUNTER "K byte", 0, 0, graphics.top | graphics.Left);

}

/ * * (Non-Javadoc) * * @see javax.microedition.lcdui.CommandListener # commandAction (javax.microedition.lcdui.Command, * javax.microedition.lcdui.Displayable) * / public void commandAction (Command arg0, Displayable arg1 ) {// TODO Auto-generated method stub if (arg0 == backCommand) {try {model.deleteRMS (); RMSanalyzer.destroyApp (false); RMSanalyzer.notifyDestroyed ();} catch (MIDletStateChangeException e) {

}

}

}

//Rmsmodel.java

Import javax.microedition.rms. *;

/ ** * @author ming * * TODO To change the template for this generated type comment go to Window - * Preferences - Java - Code Style - Code Templates * / public class RMSModel {public static final int K = 1024; private RecordStore rs ; private int baseCount; private RMSAnalyzer RMSanalyzer; public static final String name = "test"; public RMSModel (int baseCount, RMSAnalyzer rmsa) throws RecordStoreException {this.baseCount = baseCount; this.RMSanalyzer = rmsa; if (rs == null) {RS = RecordStore.OpenRecordStore (name, true); WriteRecord (basecount);}}

public void writeRecord (int count) throws RecordStoreException {byte [] data = new byte [count * K]; for (int i = 0; i

Public void deleterms () {r rclosecordStore (); RecordStore.deleteRecordStore (Name);} catch (replandstoreExcection e) {rmsanalyzer.showalerterror (E.GetMessage ());}}}

Rmsanalyzer.jad

MIDlet-Jar-Size: 5293MIDlet-1: RMSAnalyzer ,, RMSAnalyzerMIDlet-Jar-URL: RMSAnalyzer.jarMicroEdition-Configuration: CLDC-1.0MIDlet-Version: 1.0.0MIDlet-Name: RMSAnalyzerMIDlet-Data-Size: 8192MIDlet-Vendor: Midlet Suite VendormicRoEdition-Profile: MIDP-1.0Inter: 100

转载请注明原文地址:https://www.9cbs.com/read-21596.html

New Post(0)