One of the record management systems from entry to entry

Source: Internet
Author: User

The record management system is an important sub-system of j2m2. it aims to achieve persistent storage of local data of applications. Currently, mobile information devices that support file systems are limited. Therefore, the record management system is the first choice for developers to implement local data storage. The purpose of this article is to fully introduce the knowledge of record management system.

As the name suggests, record management system is a data management system, and record is the most important entity in the system. In the bucket of a mobile device, the storage space is not a field, but a byte array. The mobile infomation device profile (MIDP) specification does not specify what data can be stored as a record. In fact, the record is any data, sample, text, and so on that can be represented by byte arrays. The record management system stores and uniquely identifies records, and indicates that data tasks are completed by applications, therefore, developers of j2s often need to spend more energy to process data in buckets. The purpose of this operation is to simplify the implementation of MIDP, so that the sub-system of j2-based architecture can be as small and flexible as possible. After all, the storage space and processor capabilities of mobile information devices are limited.

A record store is an ordered set of records. A record cannot exist independently and must belong to a record store. Record store ensures that the read and write operations of records are atomic and data is not damaged. In the API, record store is implemented by javax. microedition. RMS. recordstore. The detailed operations on recordstore will be described in the following article.

The MIDP specification specifies that mobile information devices must provide at least 8 KB of non-volatile storage space to applications for persistent data storage. However, different devices provide different spaces. If the MIDlet suite uses the record management system, it must set the MIDlet-data-size in the manifest and Jad files to describe the minimum data storage space it needs, the Unit is byte, for example, MIDlet-data-size: 8192. If your value exceeds the maximum value specified by the mobile device, your application cannot be correctly installed. This value is not the storage space of the maximum record management system actually provided to applications by mobile devices. It is usually larger, therefore, developers should avoid setting the minimum storage space required by applications too large. If necessary, refer to the instruction manual for related devices. Reading and writing data in a non-volatile bucket is often slow. Therefore, it is best to provide a caching mechanism for frequently accessed data to provide performance. The read and write operations of the record management system are thread-safe, but because the record store is shared by the entire MIDlet suite, if the threads running on different MIDlet operate on the record store, we should perform necessary thread synchronization to avoid data corruption.

The implementation of record management system in midp1.0 and midp2.0 is somewhat different. The midlets in the same MIDlet suite can access each other's record store. However, the midp1.0 implementation does not provide a mechanism to share the record store between different MIDlet suites. The new API provided in midp2.0 solves the problem of sharing record store between different MIDlet suites, when creating a record store, you can manage the sharing mechanism through the authorization mode and read/write control parameters. I will introduce it in detail in the next article.

The best way to enhance understanding of the record management system is to conduct actual development. During Development, I found that not all mobile devices have correct MIDP implementations. When I use the getsizeavaliable () method to query the available record store space of nokia6108, the value obtained exceeds 1 MB. However, when I write 40 kb of data, a recordstorefullexception exception occurs, so I wrote a software that automatically tests the maximum storage space of the phone record store. The principle is to write 1 K bytes of data to the record store at a certain time, for example,-milliseconds. When an exception occurs when the storage space is full, the maximum value is obtained. The exact unit is K bytes. The following 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. It passes the test on Nokia 6108 and shows that the maximum value is 31 K. (Do not perform tests on the simulator. The results do not make sense)

Summary: This article only gives readers a general understanding of the record management system, although an application is provided at the end of the article. However, we have not thoroughly analyzed how to use the record management system. In the next article, we will analyze the classes in the javax. microedition. RMS package in depth, focusing on how to use the recordstore class.

// Rmsanalyzer. Java
Import 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
* 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;
Private countercanvas;
Private 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 prompt ");
Try
{
String interval = This. getappproperty ("Inter ");
Int T = integer. parseint (interval );
Countercanvas = new countercanvas (T, 1, this );
}
Catch (recordstoreexception 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. Java
Import 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
* 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;
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 = 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 = 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 (1, 128,128,255 );
}
Arg0.fillrect (screen_width/10, screen_height/2, counter, 10 );
If (! Go)
Arg0.drawstring ("maximum value:" + counter + "K Bytes", 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. policydestroyed ();
} 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;
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 <count; I ++)
{
Data [I] = 1;
}
Rs. addrecord (data, 0, count * k );
}

Public void deleterms ()
{
Try
{
Rs. closerecordstore ();
Recordstore. deleterecordstore (name );
} Catch (recordstoreexception E)
{
Rmsanalyzer. showalerterror (E. getmessage ());
}
}
}

Rmsanalyzer. Jad

MIDlet-jar-size: 5293
MIDlet-1: rmsanalyzer, rmsanalyzer
MIDlet-jar-URL: rmsanalyzer. Jar
Microedition-configuration: CLDC-1.0
MIDlet-version: 1.0.0
MIDlet-Name: rmsanalyzer
MIDlet-data-size: 8192
MIDlet-vendor: MIDlet suite vendor
Microedition-profile: MIDP-1.0
Inter: 100.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.