counter.Counter Class Reference

List of all members.

Static Public Member Functions

static void main (String[] args)


Detailed Description

This class defines a stress test for the Javanaise system. Different instances will try to count, without skipping any number.

Definition at line 18 of file Counter.java.


Member Function Documentation

static void counter.Counter.main ( String[]  args  )  [static]

Main class. Will create a shared integer object and start counting.

Parameters:
args 

Definition at line 24 of file Counter.java.

References jvn.JvnException.getMessage(), jvn.JvnServerImpl.jvnCreateObject(), jvn.JvnObject.jvnGetObjectState(), jvn.JvnObject.jvnLockRead(), jvn.JvnObject.jvnLockWrite(), jvn.JvnServerImpl.jvnLookupObject(), jvn.JvnServerImpl.jvnRegisterObject(), and jvn.JvnObject.jvnUnLock().

00024                                                {
00025                 try {
00026                         // initialize JVN
00027                         JvnServerImpl js = JvnServerImpl.jvnGetServer();
00028 
00029                         if (js == null) {
00030                                 System.out.println("Counter stress test problem : cannot create server!");
00031                         }
00032                         else {
00033                                 // look up the IRC object in the JVN server
00034                                 // if not found, create it, and register it in the JVN server
00035                                 JvnObject jo = js.jvnLookupObject("Counter",JvnObject.class);
00036                                 if (jo == null) {
00037                                         jo = js.jvnCreateObject(new IntegerWrapper());
00038                                         // after creation, I have a write lock on the object
00039                                         jo.jvnUnLock();
00040                                         js.jvnRegisterObject("Counter", jo);
00041                                 }
00042                                 while(true) {
00043                                         try {
00044                                                 // jo.jvnLockWrite(); // Egoistic read.
00045                                                 jo.jvnLockRead();
00046                                                 int number = ((IntegerWrapper) jo.jvnGetObjectState()).read();
00047                                                 jo.jvnUnLock();
00048                                                 System.out.println("Current number is "+number+", next number shall be "+(++number));
00049                                                 jo.jvnLockWrite();
00050                                                 ((IntegerWrapper) jo.jvnGetObjectState()).write(number);
00051                                                 jo.jvnUnLock();
00052                                         } catch (JvnException je) {
00053                                                 System.out.println("Counter stress test problem : " + je.getMessage());
00054                                         }
00055                                 }
00056                         }
00057                 } catch (JvnException je) {
00058                         System.out.println("Counter stress test problem : " + je.getMessage());
00059                 }
00060         }

Here is the call graph for this function:


The documentation for this class was generated from the following file:
Generated on Wed Jan 2 10:15:56 2008 for Javanaise by  doxygen 1.5.4