Counter.java

Go to the documentation of this file.
00001 
00008 package counter;
00009 
00010 import jvn.JvnException;
00011 import jvn.JvnObject;
00012 import jvn.JvnServerImpl;
00013 
00018 public class Counter {
00019 
00024         public static void main(String[] args) {
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         }
00061 }
00062 

Generated on Wed Jan 2 10:15:54 2008 for Javanaise by  doxygen 1.5.4