diff options
author | Bernard Normier <bernard@zeroc.com> | 2007-02-01 17:09:49 +0000 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2007-02-01 17:09:49 +0000 |
commit | abada90e3f84dc703b8ddc9efcbed8a946fadead (patch) | |
tree | 2c6f9dccd510ea97cb927a7bd635422efaae547a /java/demo/Freeze | |
parent | removing trace message (diff) | |
download | ice-abada90e3f84dc703b8ddc9efcbed8a946fadead.tar.bz2 ice-abada90e3f84dc703b8ddc9efcbed8a946fadead.tar.xz ice-abada90e3f84dc703b8ddc9efcbed8a946fadead.zip |
Expanded tabs into spaces
Diffstat (limited to 'java/demo/Freeze')
25 files changed, 2404 insertions, 2404 deletions
diff --git a/java/demo/Freeze/bench/Client.java b/java/demo/Freeze/bench/Client.java index 1cb54c3730b..b068da7e429 100644 --- a/java/demo/Freeze/bench/Client.java +++ b/java/demo/Freeze/bench/Client.java @@ -13,390 +13,390 @@ class TestApp extends Ice.Application { TestApp(String envName) { - _envName = envName; + _envName = envName; } void IntIntMapTest(Freeze.Map m, boolean fast) { - // - // Populate the database. - // - _watch.start(); - Freeze.Transaction tx = _connection.beginTransaction(); - if(fast) - { - for(int i = 0; i < _repetitions; ++i) - { - m.fastPut(new Integer(i), new Integer(i)); - } - } - else - { - for(int i = 0; i < _repetitions; ++i) - { - m.put(new Integer(i), new Integer(i)); - } - } - tx.commit(); - - double total = _watch.stop(); + // + // Populate the database. + // + _watch.start(); + Freeze.Transaction tx = _connection.beginTransaction(); + if(fast) + { + for(int i = 0; i < _repetitions; ++i) + { + m.fastPut(new Integer(i), new Integer(i)); + } + } + else + { + for(int i = 0; i < _repetitions; ++i) + { + m.put(new Integer(i), new Integer(i)); + } + } + tx.commit(); + + double total = _watch.stop(); double perRecord = total / _repetitions; System.out.println("\ttime for " + _repetitions + " " + ((fast) ? "fast " : "") + "writes: " + total + "ms"); System.out.println("\ttime per write: " + perRecord + "ms"); - // - // Read each record. - // - _watch.start(); - for(int i = 0; i < _repetitions; ++i) - { - Integer n = (Integer)m.get(new Integer(i)); - test(n.intValue() == i); - } + // + // Read each record. + // + _watch.start(); + for(int i = 0; i < _repetitions; ++i) + { + Integer n = (Integer)m.get(new Integer(i)); + test(n.intValue() == i); + } total = _watch.stop(); perRecord = total / _repetitions; System.out.println("\ttime for " + _repetitions + " reads: " + total + "ms"); System.out.println("\ttime per read: " + perRecord + "ms"); - if(m instanceof IndexedIntIntMap) - { - IndexedIntIntMap indexedM = (IndexedIntIntMap)m; - // - // Read each record using the index - // - _watch.start(); - for(int i = 0; i < _repetitions; ++i) - { - java.util.Iterator p = indexedM.findByValue(i); - test(p.hasNext()); - java.util.Map.Entry e = (java.util.Map.Entry)p.next(); - test(((Integer)e.getKey()).intValue() == i); - m.closeAllIterators(); - } - total = _watch.stop(); - perRecord = total / _repetitions; - - System.out.println("\ttime for " + _repetitions + " indexed reads: " + total + "ms"); - System.out.println("\ttime per indexed read: " + perRecord + "ms"); - } - - - // - // Remove each record. - // - _watch.start(); - tx = _connection.beginTransaction(); - if(fast) - { - for(int i = 0; i < _repetitions; ++i) - { - test(m.fastRemove(new Integer(i))); - } - } - else - { - for(int i = 0; i < _repetitions; ++i) - { - Integer n = (Integer)m.remove(new Integer(i)); - test(n.intValue() == i); - } - } - tx.commit(); - total = _watch.stop(); + if(m instanceof IndexedIntIntMap) + { + IndexedIntIntMap indexedM = (IndexedIntIntMap)m; + // + // Read each record using the index + // + _watch.start(); + for(int i = 0; i < _repetitions; ++i) + { + java.util.Iterator p = indexedM.findByValue(i); + test(p.hasNext()); + java.util.Map.Entry e = (java.util.Map.Entry)p.next(); + test(((Integer)e.getKey()).intValue() == i); + m.closeAllIterators(); + } + total = _watch.stop(); + perRecord = total / _repetitions; + + System.out.println("\ttime for " + _repetitions + " indexed reads: " + total + "ms"); + System.out.println("\ttime per indexed read: " + perRecord + "ms"); + } + + + // + // Remove each record. + // + _watch.start(); + tx = _connection.beginTransaction(); + if(fast) + { + for(int i = 0; i < _repetitions; ++i) + { + test(m.fastRemove(new Integer(i))); + } + } + else + { + for(int i = 0; i < _repetitions; ++i) + { + Integer n = (Integer)m.remove(new Integer(i)); + test(n.intValue() == i); + } + } + tx.commit(); + total = _watch.stop(); perRecord = total / _repetitions; System.out.println("\ttime for " + _repetitions + " " + ((fast) ? "fast " : "") + "removes: " + total + "ms"); System.out.println("\ttime per remove: " + perRecord + "ms"); - m.close(); + m.close(); } interface Generator { - int next(); - String toString(); + int next(); + String toString(); } static class RandomGenerator implements Generator { - RandomGenerator(int seed, int max) - { - _r = new java.util.Random(0); - _max = max; - } - - public int - next() - { - return _r.nextInt(_max); - } - - public String - toString() - { - return "random(" + _max + ")"; - } - - private java.util.Random _r; - private int _max; + RandomGenerator(int seed, int max) + { + _r = new java.util.Random(0); + _max = max; + } + + public int + next() + { + return _r.nextInt(_max); + } + + public String + toString() + { + return "random(" + _max + ")"; + } + + private java.util.Random _r; + private int _max; } static class SequentialGenerator implements Generator { - SequentialGenerator(int min, int max) - { - _min = min; - _max = max; - _current = _min; - } - - public int - next() - { - int n = _current; - ++_current; - if(_current > _max) - { - _current = _min; - } - return n; - } - - public String - toString() - { - return new Integer((_max - _min)+1).toString(); - } - - private int _min; - private int _max; - private int _current; + SequentialGenerator(int min, int max) + { + _min = min; + _max = max; + _current = _min; + } + + public int + next() + { + int n = _current; + ++_current; + if(_current > _max) + { + _current = _min; + } + return n; + } + + public String + toString() + { + return new Integer((_max - _min)+1).toString(); + } + + private int _min; + private int _max; + private int _current; } void generatedRead(Freeze.Map m, int reads, Generator gen) { - _watch.start(); - for(int i = 0; i < reads; ++i) - { - int key = gen.next(); - Integer n = (Integer)m.get(new Integer(key)); - test(n.intValue() == key); - } + _watch.start(); + for(int i = 0; i < reads; ++i) + { + int key = gen.next(); + Integer n = (Integer)m.get(new Integer(key)); + test(n.intValue() == key); + } double total = _watch.stop(); double perRecord = total / reads; System.out.println("\ttime for " + reads + " reads of " + gen + " records: " + - total + "ms"); - System.out.println("\ttime per read: " + perRecord + "ms"); - - if(m instanceof IndexedIntIntMap) - { - IndexedIntIntMap indexedM = (IndexedIntIntMap)m; - _watch.start(); - for(int i = 0; i < reads; ++i) - { - int val = gen.next(); - java.util.Iterator p = indexedM.findByValue(val); - test(p.hasNext()); - java.util.Map.Entry e = (java.util.Map.Entry)p.next(); - test(((Integer)e.getKey()).intValue() == val); - m.closeAllIterators(); - } - total = _watch.stop(); - perRecord = total / reads; - - System.out.println("\ttime for " + reads + " reverse (indexed) reads of " + gen + " records: " + - total + "ms"); - System.out.println("\ttime per reverse (indexed) read: " + perRecord + "ms"); - } + total + "ms"); + System.out.println("\ttime per read: " + perRecord + "ms"); + + if(m instanceof IndexedIntIntMap) + { + IndexedIntIntMap indexedM = (IndexedIntIntMap)m; + _watch.start(); + for(int i = 0; i < reads; ++i) + { + int val = gen.next(); + java.util.Iterator p = indexedM.findByValue(val); + test(p.hasNext()); + java.util.Map.Entry e = (java.util.Map.Entry)p.next(); + test(((Integer)e.getKey()).intValue() == val); + m.closeAllIterators(); + } + total = _watch.stop(); + perRecord = total / reads; + + System.out.println("\ttime for " + reads + " reverse (indexed) reads of " + gen + " records: " + + total + "ms"); + System.out.println("\ttime per reverse (indexed) read: " + perRecord + "ms"); + } } void IntIntMapReadTest(Freeze.Map m) { - // - // Populate the database. - // - _watch.start(); - Freeze.Transaction tx = _connection.beginTransaction(); - for(int i = 0; i < _repetitions; ++i) - { - m.fastPut(new Integer(i), new Integer(i)); - } - tx.commit(); - double total = _watch.stop(); + // + // Populate the database. + // + _watch.start(); + Freeze.Transaction tx = _connection.beginTransaction(); + for(int i = 0; i < _repetitions; ++i) + { + m.fastPut(new Integer(i), new Integer(i)); + } + tx.commit(); + double total = _watch.stop(); double perRecord = total / _repetitions; System.out.println("\ttime for " + _repetitions + " writes: " + total + "ms"); System.out.println("\ttime per write: " + perRecord + "ms"); - // - // Do some read tests. - // - generatedRead(m, _repetitions, new SequentialGenerator(1000, 1000)); - generatedRead(m, _repetitions, new SequentialGenerator(2000, 2009)); - generatedRead(m, _repetitions, new SequentialGenerator(3000, 3099)); - generatedRead(m, _repetitions, new SequentialGenerator(4000, 4999)); - - // - // Do a random read test. - // - generatedRead(m, _repetitions, new RandomGenerator(0, 10000)); - - // - // Remove each record. - // + // + // Do some read tests. + // + generatedRead(m, _repetitions, new SequentialGenerator(1000, 1000)); + generatedRead(m, _repetitions, new SequentialGenerator(2000, 2009)); + generatedRead(m, _repetitions, new SequentialGenerator(3000, 3099)); + generatedRead(m, _repetitions, new SequentialGenerator(4000, 4999)); + + // + // Do a random read test. + // + generatedRead(m, _repetitions, new RandomGenerator(0, 10000)); + + // + // Remove each record. + // /* * For this test I don't want to remove the records because I * want to examine the cache stats for the database. * - _watch.start(); - for(int i = 0; i < _repetitions; ++i) - { - test(m.fastRemove(new Integer(i))); - } - total = _watch.stop(); + _watch.start(); + for(int i = 0; i < _repetitions; ++i) + { + test(m.fastRemove(new Integer(i))); + } + total = _watch.stop(); perRecord = total / _repetitions; System.out.println("\ttime for " + _repetitions + " removes: " + total + "ms"); System.out.println("\ttime per remove: " + perRecord + "ms"); */ - m.close(); + m.close(); } void Struct1Struct2MapTest(Freeze.Map m) { - // - // Populate the database. - // - Struct1 s1 = new Struct1(); - Struct2 s2 = new Struct2(); - _watch.start(); - Freeze.Transaction tx = _connection.beginTransaction(); - for(int i = 0; i < _repetitions; ++i) - { - s1.l = i; - s2.s = new Integer(i).toString(); - s2.s1 = s1; - m.fastPut(s1, s2); - } - tx.commit(); - double total = _watch.stop(); + // + // Populate the database. + // + Struct1 s1 = new Struct1(); + Struct2 s2 = new Struct2(); + _watch.start(); + Freeze.Transaction tx = _connection.beginTransaction(); + for(int i = 0; i < _repetitions; ++i) + { + s1.l = i; + s2.s = new Integer(i).toString(); + s2.s1 = s1; + m.fastPut(s1, s2); + } + tx.commit(); + double total = _watch.stop(); double perRecord = total / _repetitions; System.out.println("\ttime for " + _repetitions + " writes: " + total + "ms"); System.out.println("\ttime per write: " + perRecord + "ms"); - // - // Read each record. - // - _watch.start(); - for(int i = 0; i < _repetitions; ++i) - { - s1.l = i; - Struct2 ns2 = (Struct2)m.get(s1); - test(ns2.s.equals(new Integer(i).toString())); - } + // + // Read each record. + // + _watch.start(); + for(int i = 0; i < _repetitions; ++i) + { + s1.l = i; + Struct2 ns2 = (Struct2)m.get(s1); + test(ns2.s.equals(new Integer(i).toString())); + } total = _watch.stop(); perRecord = total / _repetitions; System.out.println("\ttime for " + _repetitions + " reads: " + total + "ms"); System.out.println("\ttime per read: " + perRecord + "ms"); - - // - // Optional index test - // - - if(m instanceof IndexedStruct1Struct2Map) - { - IndexedStruct1Struct2Map indexedM = (IndexedStruct1Struct2Map)m; - _watch.start(); - for(int i = 0; i < _repetitions; ++i) - { - String s = (new Integer(i)).toString(); - java.util.Iterator p = indexedM.findByS(s); - test(p.hasNext()); - java.util.Map.Entry e = (java.util.Map.Entry)p.next(); - test(((Struct1)e.getKey()).l == i); - m.closeAllIterators(); - } - - for(int i = 0; i < _repetitions; ++i) - { - s1.l = i; - java.util.Iterator p = indexedM.findByS1(s1); - test(p.hasNext()); - java.util.Map.Entry e = (java.util.Map.Entry)p.next(); - test(((Struct1)e.getKey()).l == i); - m.closeAllIterators(); - } - total = _watch.stop(); - perRecord = total / (2 * _repetitions); - - System.out.println("\ttime for " + 2 * _repetitions + " indexed reads: " + total + "ms"); - System.out.println("\ttime per indexed read: " + perRecord + "ms"); - } - - // - // Remove each record. - // - _watch.start(); - tx = _connection.beginTransaction(); - for(int i = 0; i < _repetitions; ++i) - { - s1.l = i; - test(m.fastRemove(s1)); - } - tx.commit(); - total = _watch.stop(); + + // + // Optional index test + // + + if(m instanceof IndexedStruct1Struct2Map) + { + IndexedStruct1Struct2Map indexedM = (IndexedStruct1Struct2Map)m; + _watch.start(); + for(int i = 0; i < _repetitions; ++i) + { + String s = (new Integer(i)).toString(); + java.util.Iterator p = indexedM.findByS(s); + test(p.hasNext()); + java.util.Map.Entry e = (java.util.Map.Entry)p.next(); + test(((Struct1)e.getKey()).l == i); + m.closeAllIterators(); + } + + for(int i = 0; i < _repetitions; ++i) + { + s1.l = i; + java.util.Iterator p = indexedM.findByS1(s1); + test(p.hasNext()); + java.util.Map.Entry e = (java.util.Map.Entry)p.next(); + test(((Struct1)e.getKey()).l == i); + m.closeAllIterators(); + } + total = _watch.stop(); + perRecord = total / (2 * _repetitions); + + System.out.println("\ttime for " + 2 * _repetitions + " indexed reads: " + total + "ms"); + System.out.println("\ttime per indexed read: " + perRecord + "ms"); + } + + // + // Remove each record. + // + _watch.start(); + tx = _connection.beginTransaction(); + for(int i = 0; i < _repetitions; ++i) + { + s1.l = i; + test(m.fastRemove(s1)); + } + tx.commit(); + total = _watch.stop(); perRecord = total / _repetitions; System.out.println("\ttime for " + _repetitions + " removes: " + total + "ms"); System.out.println("\ttime per remove: " + perRecord + "ms"); - m.close(); + m.close(); } void Struct1Class1MapTest(Freeze.Map m) { - // - // Populate the database. - // - Struct1 s1 = new Struct1(); - Class1 c1 = new Class1(); - _watch.start(); - Freeze.Transaction tx = _connection.beginTransaction(); - for(int i = 0; i < _repetitions; ++i) - { - s1.l = i; - c1.s = new Integer(i).toString(); - m.fastPut(s1, c1); - } - tx.commit(); - double total = _watch.stop(); + // + // Populate the database. + // + Struct1 s1 = new Struct1(); + Class1 c1 = new Class1(); + _watch.start(); + Freeze.Transaction tx = _connection.beginTransaction(); + for(int i = 0; i < _repetitions; ++i) + { + s1.l = i; + c1.s = new Integer(i).toString(); + m.fastPut(s1, c1); + } + tx.commit(); + double total = _watch.stop(); double perRecord = total / _repetitions; System.out.println("\ttime for " + _repetitions + " writes: " + total + "ms"); System.out.println("\ttime per write: " + perRecord + "ms"); - // - // Read each record. - // - _watch.start(); - for(int i = 0; i < _repetitions; ++i) - { - s1.l = i; - Class1 nc1 = (Class1)m.get(s1); - test(nc1.s.equals(new Integer(i).toString())); - } + // + // Read each record. + // + _watch.start(); + for(int i = 0; i < _repetitions; ++i) + { + s1.l = i; + Class1 nc1 = (Class1)m.get(s1); + test(nc1.s.equals(new Integer(i).toString())); + } total = _watch.stop(); perRecord = total / _repetitions; @@ -404,180 +404,180 @@ class TestApp extends Ice.Application System.out.println("\ttime per read: " + perRecord + "ms"); - // - // Optional index test - // - - if(m instanceof IndexedStruct1Class1Map) - { - IndexedStruct1Class1Map indexedM = (IndexedStruct1Class1Map)m; - _watch.start(); - for(int i = 0; i < _repetitions; ++i) - { - String s = (new Integer(i)).toString(); - java.util.Iterator p = indexedM.findByS(s); - test(p.hasNext()); - java.util.Map.Entry e = (java.util.Map.Entry)p.next(); - test(((Struct1)e.getKey()).l == i); - m.closeAllIterators(); - } - - total = _watch.stop(); - perRecord = total / _repetitions; - - System.out.println("\ttime for " + _repetitions + " indexed reads: " + total + "ms"); - System.out.println("\ttime per indexed read: " + perRecord + "ms"); - } - - // - // Remove each record. - // - _watch.start(); - tx = _connection.beginTransaction(); - for(int i = 0; i < _repetitions; ++i) - { - s1.l = i; - test(m.fastRemove(s1)); - } - tx.commit(); - total = _watch.stop(); + // + // Optional index test + // + + if(m instanceof IndexedStruct1Class1Map) + { + IndexedStruct1Class1Map indexedM = (IndexedStruct1Class1Map)m; + _watch.start(); + for(int i = 0; i < _repetitions; ++i) + { + String s = (new Integer(i)).toString(); + java.util.Iterator p = indexedM.findByS(s); + test(p.hasNext()); + java.util.Map.Entry e = (java.util.Map.Entry)p.next(); + test(((Struct1)e.getKey()).l == i); + m.closeAllIterators(); + } + + total = _watch.stop(); + perRecord = total / _repetitions; + + System.out.println("\ttime for " + _repetitions + " indexed reads: " + total + "ms"); + System.out.println("\ttime per indexed read: " + perRecord + "ms"); + } + + // + // Remove each record. + // + _watch.start(); + tx = _connection.beginTransaction(); + for(int i = 0; i < _repetitions; ++i) + { + s1.l = i; + test(m.fastRemove(s1)); + } + tx.commit(); + total = _watch.stop(); perRecord = total / _repetitions; System.out.println("\ttime for " + _repetitions + " removes: " + total + "ms"); System.out.println("\ttime per remove: " + perRecord + "ms"); - m.close(); + m.close(); } void Struct1ObjectMapTest(Freeze.Map m) { - // - // Populate the database. - // - Struct1 s1 = new Struct1(); - Class1 c1 = new Class1(); - Class2 c2 = new Class2(); - c2.rec = c2; - c2.obj = c1; - _watch.start(); - Freeze.Transaction tx = _connection.beginTransaction(); - for(int i = 0; i < _repetitions; ++i) - { - s1.l = i; - Object o; - if((i % 2) == 0) - { - o = c2; - } - else - { - o = c1; - } - c1.s = new Integer(i).toString(); - - m.fastPut(s1, o); - } - tx.commit(); - - double total = _watch.stop(); + // + // Populate the database. + // + Struct1 s1 = new Struct1(); + Class1 c1 = new Class1(); + Class2 c2 = new Class2(); + c2.rec = c2; + c2.obj = c1; + _watch.start(); + Freeze.Transaction tx = _connection.beginTransaction(); + for(int i = 0; i < _repetitions; ++i) + { + s1.l = i; + Object o; + if((i % 2) == 0) + { + o = c2; + } + else + { + o = c1; + } + c1.s = new Integer(i).toString(); + + m.fastPut(s1, o); + } + tx.commit(); + + double total = _watch.stop(); double perRecord = total / _repetitions; System.out.println("\ttime for " + _repetitions + " writes: " + total + "ms"); System.out.println("\ttime per write: " + perRecord + "ms"); - // - // Read each record. - // - _watch.start(); - for(int i = 0; i < _repetitions; ++i) - { - s1.l = i; - - Object o = m.get(s1); - - Class1 nc1; - if((i % 2) == 0) - { - Class2 nc2 = (Class2)o; - test(nc2.rec == nc2); - nc1 = (Class1)nc2.obj; - } - else - { - nc1 = (Class1)o; - } - - test(nc1.s.equals(new Integer(i).toString())); - } + // + // Read each record. + // + _watch.start(); + for(int i = 0; i < _repetitions; ++i) + { + s1.l = i; + + Object o = m.get(s1); + + Class1 nc1; + if((i % 2) == 0) + { + Class2 nc2 = (Class2)o; + test(nc2.rec == nc2); + nc1 = (Class1)nc2.obj; + } + else + { + nc1 = (Class1)o; + } + + test(nc1.s.equals(new Integer(i).toString())); + } total = _watch.stop(); perRecord = total / _repetitions; System.out.println("\ttime for " + _repetitions + " reads: " + total + "ms"); System.out.println("\ttime per read: " + perRecord + "ms"); - // - // Remove each record. - // - _watch.start(); - tx = _connection.beginTransaction(); - for(int i = 0; i < _repetitions; ++i) - { - s1.l = i; - test(m.fastRemove(s1)); - } - tx.commit(); - total = _watch.stop(); + // + // Remove each record. + // + _watch.start(); + tx = _connection.beginTransaction(); + for(int i = 0; i < _repetitions; ++i) + { + s1.l = i; + test(m.fastRemove(s1)); + } + tx.commit(); + total = _watch.stop(); perRecord = total / _repetitions; System.out.println("\ttime for " + _repetitions + " removes: " + total + "ms"); System.out.println("\ttime per remove: " + perRecord + "ms"); - m.close(); + m.close(); } public int run(String[] args) { - _connection = Freeze.Util.createConnection(communicator(), _envName); + _connection = Freeze.Util.createConnection(communicator(), _envName); - System.out.println("IntIntMap (Collections API)"); - IntIntMapTest(new IntIntMap(_connection, "IntIntMap", true), false); + System.out.println("IntIntMap (Collections API)"); + IntIntMapTest(new IntIntMap(_connection, "IntIntMap", true), false); - System.out.println("IntIntMap (Fast API)"); - IntIntMapTest(new IntIntMap(_connection, "IntIntMap.fast", true), true); + System.out.println("IntIntMap (Fast API)"); + IntIntMapTest(new IntIntMap(_connection, "IntIntMap.fast", true), true); - System.out.println("IntIntMap with index (Collections API)"); - IntIntMapTest(new IndexedIntIntMap(_connection, "IndexedIntIntMap", true), false); + System.out.println("IntIntMap with index (Collections API)"); + IntIntMapTest(new IndexedIntIntMap(_connection, "IndexedIntIntMap", true), false); - System.out.println("IntIntMap with index (Fast API)"); - IntIntMapTest(new IndexedIntIntMap(_connection, "IndexedIntIntMap.fast", true), true); + System.out.println("IntIntMap with index (Fast API)"); + IntIntMapTest(new IndexedIntIntMap(_connection, "IndexedIntIntMap.fast", true), true); - System.out.println("Struct1Struct2Map"); - Struct1Struct2MapTest(new Struct1Struct2Map(_connection, "Struct1Struct2", true)); + System.out.println("Struct1Struct2Map"); + Struct1Struct2MapTest(new Struct1Struct2Map(_connection, "Struct1Struct2", true)); - System.out.println("Struct1Struct2Map with index"); - Struct1Struct2MapTest(new IndexedStruct1Struct2Map(_connection, "IndexedStruct1Struct2", true)); - - System.out.println("Struct1Class1Map"); - Struct1Class1MapTest(new Struct1Class1Map(_connection, "Struct1Class1", true)); + System.out.println("Struct1Struct2Map with index"); + Struct1Struct2MapTest(new IndexedStruct1Struct2Map(_connection, "IndexedStruct1Struct2", true)); + + System.out.println("Struct1Class1Map"); + Struct1Class1MapTest(new Struct1Class1Map(_connection, "Struct1Class1", true)); - System.out.println("Struct1Class1Map with index"); - Struct1Class1MapTest(new IndexedStruct1Class1Map(_connection, "IndexedStruct1Class1", true)); + System.out.println("Struct1Class1Map with index"); + Struct1Class1MapTest(new IndexedStruct1Class1Map(_connection, "IndexedStruct1Class1", true)); - System.out.println("IntIntMap (read test)"); - IntIntMapReadTest(new IntIntMap(_connection, "IntIntMap", true)); + System.out.println("IntIntMap (read test)"); + IntIntMapReadTest(new IntIntMap(_connection, "IntIntMap", true)); - System.out.println("IntIntMap (read test with index)"); - IntIntMapReadTest(new IndexedIntIntMap(_connection, "IndexedIntIntMap", true)); - + System.out.println("IntIntMap (read test with index)"); + IntIntMapReadTest(new IndexedIntIntMap(_connection, "IndexedIntIntMap", true)); + - System.out.println("Struct1ObjectMap"); - Struct1ObjectMapTest(new Struct1ObjectMap(_connection, "Struct1Object", true)); + System.out.println("Struct1ObjectMap"); + Struct1ObjectMapTest(new Struct1ObjectMap(_connection, "Struct1Object", true)); - _connection.close(); + _connection.close(); - return 0; + return 0; } private static void @@ -600,7 +600,7 @@ public class Client static public void main(String[] args) { - TestApp app = new TestApp("db"); - app.main("test.Freeze.bench.Client", args); + TestApp app = new TestApp("db"); + app.main("test.Freeze.bench.Client", args); } } diff --git a/java/demo/Freeze/bench/StopWatch.java b/java/demo/Freeze/bench/StopWatch.java index 079fa6d45bd..4a96e2fe66f 100644 --- a/java/demo/Freeze/bench/StopWatch.java +++ b/java/demo/Freeze/bench/StopWatch.java @@ -16,19 +16,19 @@ class StopWatch public void start() { - _stopped = false; - _start = System.currentTimeMillis(); + _stopped = false; + _start = System.currentTimeMillis(); } public long stop() { - if(!_stopped) - { - _stop = System.currentTimeMillis(); - _stopped = true; - } - return _stop - _start; + if(!_stopped) + { + _stop = System.currentTimeMillis(); + _stopped = true; + } + return _stop - _start; } private boolean _stopped; diff --git a/java/demo/Freeze/library/BookFactory.java b/java/demo/Freeze/library/BookFactory.java index c00b5812fe0..56f729549ee 100644 --- a/java/demo/Freeze/library/BookFactory.java +++ b/java/demo/Freeze/library/BookFactory.java @@ -12,8 +12,8 @@ class BookFactory extends Ice.LocalObjectImpl implements Ice.ObjectFactory public Ice.Object create(String type) { - assert(type.equals("::Demo::Book")); - return new BookI(_library); + assert(type.equals("::Demo::Book")); + return new BookI(_library); } public void @@ -23,7 +23,7 @@ class BookFactory extends Ice.LocalObjectImpl implements Ice.ObjectFactory BookFactory(LibraryI library) { - _library = library; + _library = library; } private LibraryI _library; diff --git a/java/demo/Freeze/library/BookI.java b/java/demo/Freeze/library/BookI.java index e7c51f7bdb2..74188b27b1f 100644 --- a/java/demo/Freeze/library/BookI.java +++ b/java/demo/Freeze/library/BookI.java @@ -24,63 +24,63 @@ class BookI extends Book throw new Ice.ObjectNotExistException(); } - // - // Immutable. - // - return description; + // + // Immutable. + // + return description; } synchronized public String getRenterName(Ice.Current current) - throws BookNotRentedException + throws BookNotRentedException { if(_destroyed) { throw new Ice.ObjectNotExistException(); } - if(rentalCustomerName.length() == 0) - { - throw new BookNotRentedException(); - } - return rentalCustomerName; + if(rentalCustomerName.length() == 0) + { + throw new BookNotRentedException(); + } + return rentalCustomerName; } synchronized public void rentBook(String name, Ice.Current current) - throws BookRentedException + throws BookRentedException { if(_destroyed) { throw new Ice.ObjectNotExistException(); } - if(rentalCustomerName.length() != 0) - { - throw new BookRentedException(); - } - rentalCustomerName = name; + if(rentalCustomerName.length() != 0) + { + throw new BookRentedException(); + } + rentalCustomerName = name; } synchronized public void returnBook(Ice.Current current) - throws BookNotRentedException + throws BookNotRentedException { if(_destroyed) { throw new Ice.ObjectNotExistException(); } - if(rentalCustomerName.length() == 0) - { - throw new BookNotRentedException(); - } - rentalCustomerName = new String();; + if(rentalCustomerName.length() == 0) + { + throw new BookNotRentedException(); + } + rentalCustomerName = new String();; } synchronized public void destroy(Ice.Current current) - throws DatabaseException + throws DatabaseException { if(_destroyed) { @@ -89,29 +89,29 @@ class BookI extends Book _destroyed = true; - try - { - _library.remove(description); - } - catch(Freeze.DatabaseException ex) - { - DatabaseException e = new DatabaseException(); - e.message = ex.message; - throw e; - } + try + { + _library.remove(description); + } + catch(Freeze.DatabaseException ex) + { + DatabaseException e = new DatabaseException(); + e.message = ex.message; + throw e; + } } BookI(LibraryI library) { - _library = library; + _library = library; _destroyed = false; - // - // This could be avoided by having two constructors (one for - // new creation of a book, and the other for restoring a - // previously saved book). - // - rentalCustomerName = new String(); + // + // This could be avoided by having two constructors (one for + // new creation of a book, and the other for restoring a + // previously saved book). + // + rentalCustomerName = new String(); } private LibraryI _library; diff --git a/java/demo/Freeze/library/Client.java b/java/demo/Freeze/library/Client.java index 802acd88954..b9fb2037097 100644 --- a/java/demo/Freeze/library/Client.java +++ b/java/demo/Freeze/library/Client.java @@ -11,37 +11,37 @@ public class Client extends Ice.Application { class ShutdownHook extends Thread { - public void - run() - { - try - { - communicator().destroy(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - } - } + public void + run() + { + try + { + communicator().destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + } } public int run(String[] args) { - // - // Since this is an interactive demo we want to clear the - // Application installed interrupt callback and install our - // own shutdown hook. + // + // Since this is an interactive demo we want to clear the + // Application installed interrupt callback and install our + // own shutdown hook. // - setInterruptHook(new ShutdownHook()); - - return RunParser.runParser(appName(), args, communicator()); + setInterruptHook(new ShutdownHook()); + + return RunParser.runParser(appName(), args, communicator()); } static public void main(String[] args) { - Client app = new Client(); - app.main("demo.Freeze.library.Client", args, "config.client"); + Client app = new Client(); + app.main("demo.Freeze.library.Client", args, "config.client"); } } diff --git a/java/demo/Freeze/library/Collocated.java b/java/demo/Freeze/library/Collocated.java index a5963b4e85a..0f5f93ccb14 100644 --- a/java/demo/Freeze/library/Collocated.java +++ b/java/demo/Freeze/library/Collocated.java @@ -11,74 +11,74 @@ class LibraryCollocated extends Ice.Application { class ShutdownHook extends Thread { - public void - run() - { - try - { - communicator().destroy(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - } - } + public void + run() + { + try + { + communicator().destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + } } public int run(String[] args) { - // - // Since this is an interactive demo we want to clear the - // Application installed interrupt callback and install our - // own shutdown hook. - // - setInterruptHook(new ShutdownHook()); + // + // Since this is an interactive demo we want to clear the + // Application installed interrupt callback and install our + // own shutdown hook. + // + setInterruptHook(new ShutdownHook()); - Ice.Properties properties = communicator().getProperties(); + Ice.Properties properties = communicator().getProperties(); - // - // Create an Object Adapter - // - Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Library"); + // + // Create an Object Adapter + // + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Library"); - // - // Create an Evictor for books. - // - Freeze.Evictor evictor = Freeze.Util.createEvictor(adapter, _envName, "books", null, null, true); - int evictorSize = properties.getPropertyAsInt("Library.EvictorSize"); - if(evictorSize > 0) - { - evictor.setSize(evictorSize); - } + // + // Create an Evictor for books. + // + Freeze.Evictor evictor = Freeze.Util.createEvictor(adapter, _envName, "books", null, null, true); + int evictorSize = properties.getPropertyAsInt("Library.EvictorSize"); + if(evictorSize > 0) + { + evictor.setSize(evictorSize); + } - adapter.addServantLocator(evictor, "book"); + adapter.addServantLocator(evictor, "book"); - // - // Create the library, and add it to the Object Adapter. - // - LibraryI library = new LibraryI(communicator(), _envName, "authors", evictor); - adapter.add(library, communicator().stringToIdentity("library")); + // + // Create the library, and add it to the Object Adapter. + // + LibraryI library = new LibraryI(communicator(), _envName, "authors", evictor); + adapter.add(library, communicator().stringToIdentity("library")); - // - // Create and install a factory and initializer for books. - // - Ice.ObjectFactory bookFactory = new BookFactory(library); - communicator().addObjectFactory(bookFactory, "::Demo::Book"); + // + // Create and install a factory and initializer for books. + // + Ice.ObjectFactory bookFactory = new BookFactory(library); + communicator().addObjectFactory(bookFactory, "::Demo::Book"); - // - // Everything ok, let's go. - // - int status = RunParser.runParser(appName(), args, communicator()); - adapter.destroy(); + // + // Everything ok, let's go. + // + int status = RunParser.runParser(appName(), args, communicator()); + adapter.destroy(); - library.close(); - return status; + library.close(); + return status; } LibraryCollocated(String envName) { - _envName = envName; + _envName = envName; } private String _envName; @@ -89,7 +89,7 @@ public class Collocated static public void main(String[] args) { - LibraryCollocated app = new LibraryCollocated("db"); - app.main("demo.Freeze.library.Collocated", args, "config.collocated"); + LibraryCollocated app = new LibraryCollocated("db"); + app.main("demo.Freeze.library.Collocated", args, "config.collocated"); } } diff --git a/java/demo/Freeze/library/Grammar.java b/java/demo/Freeze/library/Grammar.java index 43749b2d67a..5c3c68c1ab9 100644 --- a/java/demo/Freeze/library/Grammar.java +++ b/java/demo/Freeze/library/Grammar.java @@ -11,173 +11,173 @@ class Grammar { Grammar(Parser p) { - _parser = p; - _scanner = new Scanner(_parser); + _parser = p; + _scanner = new Scanner(_parser); } void parse() { - while(true) - { - try - { - _token = _scanner.nextToken(); - if(_token == null) - { - return; - } - else if(_token.type == Token.TOK_SEMI) - { - // Continue - } - else if(_token.type == Token.TOK_HELP) - { - _token = _scanner.nextToken(); - if(_token.type != Token.TOK_SEMI) - { - throw new ParseError("Expected ';'"); - } + while(true) + { + try + { + _token = _scanner.nextToken(); + if(_token == null) + { + return; + } + else if(_token.type == Token.TOK_SEMI) + { + // Continue + } + else if(_token.type == Token.TOK_HELP) + { + _token = _scanner.nextToken(); + if(_token.type != Token.TOK_SEMI) + { + throw new ParseError("Expected ';'"); + } - _parser.usage(); - } - else if(_token.type == Token.TOK_EXIT) - { - _token = _scanner.nextToken(); - if(_token.type != Token.TOK_SEMI) - { - throw new ParseError("Expected ';'"); - } + _parser.usage(); + } + else if(_token.type == Token.TOK_EXIT) + { + _token = _scanner.nextToken(); + if(_token.type != Token.TOK_SEMI) + { + throw new ParseError("Expected ';'"); + } - return; - } - else if(_token.type == Token.TOK_ADD_BOOK) - { - java.util.List s = strings(); - if(_token.type != Token.TOK_SEMI) - { - throw new ParseError("Expected ';'"); - } - _parser.addBook(s); - } - else if(_token.type == Token.TOK_FIND_ISBN) - { - java.util.List s = strings(); - if(_token.type != Token.TOK_SEMI) - { - throw new ParseError("Expected ';'"); - } - _parser.findIsbn(s); - } - else if(_token.type == Token.TOK_FIND_AUTHORS) - { - java.util.List s = strings(); - if(_token.type != Token.TOK_SEMI) - { - throw new ParseError("Expected ';'"); - } - _parser.findAuthors(s); - } - else if(_token.type == Token.TOK_NEXT_FOUND_BOOK) - { - _token = _scanner.nextToken(); - if(_token.type != Token.TOK_SEMI) - { - throw new ParseError("Expected ';'"); - } + return; + } + else if(_token.type == Token.TOK_ADD_BOOK) + { + java.util.List s = strings(); + if(_token.type != Token.TOK_SEMI) + { + throw new ParseError("Expected ';'"); + } + _parser.addBook(s); + } + else if(_token.type == Token.TOK_FIND_ISBN) + { + java.util.List s = strings(); + if(_token.type != Token.TOK_SEMI) + { + throw new ParseError("Expected ';'"); + } + _parser.findIsbn(s); + } + else if(_token.type == Token.TOK_FIND_AUTHORS) + { + java.util.List s = strings(); + if(_token.type != Token.TOK_SEMI) + { + throw new ParseError("Expected ';'"); + } + _parser.findAuthors(s); + } + else if(_token.type == Token.TOK_NEXT_FOUND_BOOK) + { + _token = _scanner.nextToken(); + if(_token.type != Token.TOK_SEMI) + { + throw new ParseError("Expected ';'"); + } - _parser.nextFoundBook(); - } - else if(_token.type == Token.TOK_PRINT_CURRENT) - { - _token = _scanner.nextToken(); - if(_token.type != Token.TOK_SEMI) - { - throw new ParseError("Expected ';'"); - } + _parser.nextFoundBook(); + } + else if(_token.type == Token.TOK_PRINT_CURRENT) + { + _token = _scanner.nextToken(); + if(_token.type != Token.TOK_SEMI) + { + throw new ParseError("Expected ';'"); + } - _parser.printCurrent(); - } - else if(_token.type == Token.TOK_RENT_BOOK) - { - java.util.List s = strings(); - if(_token.type != Token.TOK_SEMI) - { - throw new ParseError("Expected ';'"); - } - _parser.rentCurrent(s); - } - else if(_token.type == Token.TOK_RETURN_BOOK) - { - _token = _scanner.nextToken(); - if(_token.type != Token.TOK_SEMI) - { - throw new ParseError("Expected ';'"); - } - _parser.returnCurrent(); - } - else if(_token.type == Token.TOK_REMOVE_CURRENT) - { - _token = _scanner.nextToken(); - if(_token.type != Token.TOK_SEMI) - { - throw new ParseError("Expected ';'"); - } + _parser.printCurrent(); + } + else if(_token.type == Token.TOK_RENT_BOOK) + { + java.util.List s = strings(); + if(_token.type != Token.TOK_SEMI) + { + throw new ParseError("Expected ';'"); + } + _parser.rentCurrent(s); + } + else if(_token.type == Token.TOK_RETURN_BOOK) + { + _token = _scanner.nextToken(); + if(_token.type != Token.TOK_SEMI) + { + throw new ParseError("Expected ';'"); + } + _parser.returnCurrent(); + } + else if(_token.type == Token.TOK_REMOVE_CURRENT) + { + _token = _scanner.nextToken(); + if(_token.type != Token.TOK_SEMI) + { + throw new ParseError("Expected ';'"); + } - _parser.removeCurrent(); - } - else if(_token.type == Token.TOK_SET_EVICTOR_SIZE) - { - java.util.List s = strings(); - if(_token.type != Token.TOK_SEMI) - { - throw new ParseError("Expected ';'"); - } - _parser.setEvictorSize(s); - } - else if(_token.type == Token.TOK_SHUTDOWN) - { - _token = _scanner.nextToken(); - if(_token.type != Token.TOK_SEMI) - { - throw new ParseError("Expected ';'"); - } + _parser.removeCurrent(); + } + else if(_token.type == Token.TOK_SET_EVICTOR_SIZE) + { + java.util.List s = strings(); + if(_token.type != Token.TOK_SEMI) + { + throw new ParseError("Expected ';'"); + } + _parser.setEvictorSize(s); + } + else if(_token.type == Token.TOK_SHUTDOWN) + { + _token = _scanner.nextToken(); + if(_token.type != Token.TOK_SEMI) + { + throw new ParseError("Expected ';'"); + } - _parser.shutdown(); - } - else - { - _parser.error("parse error"); - } - } - catch(ParseError e) - { - _parser.error("Parse error: " + e.getMessage()); - } - } + _parser.shutdown(); + } + else + { + _parser.error("parse error"); + } + } + catch(ParseError e) + { + _parser.error("Parse error: " + e.getMessage()); + } + } } private java.util.List strings() { - java.util.List l = new java.util.ArrayList(); - while(true) - { - _token = _scanner.nextToken(); - if(_token.type != Token.TOK_STRING) - { - return l; - } - l.add(_token.value); - } + java.util.List l = new java.util.ArrayList(); + while(true) + { + _token = _scanner.nextToken(); + if(_token.type != Token.TOK_STRING) + { + return l; + } + l.add(_token.value); + } } static private class ParseError extends RuntimeException { - ParseError(String msg) - { - super(msg); - } + ParseError(String msg) + { + super(msg); + } } private Parser _parser; diff --git a/java/demo/Freeze/library/Library.ice b/java/demo/Freeze/library/Library.ice index 7111b0f1eac..87663189286 100644 --- a/java/demo/Freeze/library/Library.ice +++ b/java/demo/Freeze/library/Library.ice @@ -92,7 +92,7 @@ class Book * **/ ["freeze:write"] void destroy() - throws DatabaseException; + throws DatabaseException; /** * @@ -105,7 +105,7 @@ class Book * **/ ["freeze:write"] void rentBook(string name) - throws BookRentedException; + throws BookRentedException; /** * @@ -118,7 +118,7 @@ class Book * **/ ["cpp:const"] idempotent string getRenterName() - throws BookNotRentedException; + throws BookNotRentedException; /** * @@ -129,7 +129,7 @@ class Book * **/ ["freeze:write"] void returnBook() - throws BookNotRentedException; + throws BookNotRentedException; /** * @@ -177,7 +177,7 @@ interface Library * **/ Book* createBook(BookDescription description) - throws DatabaseException, BookExistsException; + throws DatabaseException, BookExistsException; /** * @@ -192,7 +192,7 @@ interface Library * **/ ["cpp:const"] idempotent Book* findByIsbn(string isbn) - throws DatabaseException; + throws DatabaseException; /** * @@ -207,7 +207,7 @@ interface Library * **/ ["cpp:const"] idempotent BookPrxSeq findByAuthors(string authors) - throws DatabaseException; + throws DatabaseException; /** * @@ -220,7 +220,7 @@ interface Library * **/ idempotent void setEvictorSize(int size) - throws DatabaseException; + throws DatabaseException; /** * diff --git a/java/demo/Freeze/library/LibraryI.java b/java/demo/Freeze/library/LibraryI.java index 47b6064b8d1..acf10ef3d26 100644 --- a/java/demo/Freeze/library/LibraryI.java +++ b/java/demo/Freeze/library/LibraryI.java @@ -13,68 +13,68 @@ class LibraryI extends _LibraryDisp { public synchronized BookPrx createBook(BookDescription description, Ice.Current current) - throws DatabaseException, BookExistsException + throws DatabaseException, BookExistsException { - BookPrx book = isbnToBook(description.isbn, current.adapter); - - try - { - book.ice_ping(); - - // - // The book already exists. - // - throw new BookExistsException(); - } - catch(Ice.ObjectNotExistException e) - { - // - // Book doesn't exist, ignore the exception. - // - } - - // - // Create a new book Servant. - // - BookI bookI = new BookI(this); - bookI.description = description; - - Ice.Identity ident = createBookIdentity(description.isbn); - - // - // Create a new Ice Object in the evictor, using the new - // identity and the new Servant. - // - // This can throw EvictorDeactivatedException (which indicates - // an internal error). The exception is currently ignored. - // - _evictor.add(bookI, ident); - - try - { - // - // Add the isbn number to the authors map. - // - String[] isbnSeq = (String[])_authors.get(description.authors); - int length = (isbnSeq == null) ? 0 : isbnSeq.length; - String[] newIsbnSeq = new String[length+1]; - - if(isbnSeq != null) - { - System.arraycopy(isbnSeq, 0, newIsbnSeq, 0, length); - } - newIsbnSeq[length] = description.isbn; - - _authors.fastPut(description.authors, newIsbnSeq); - - return book; - } - catch(Freeze.DatabaseException ex) - { - DatabaseException e = new DatabaseException(); - e.message = ex.message; - throw e; - } + BookPrx book = isbnToBook(description.isbn, current.adapter); + + try + { + book.ice_ping(); + + // + // The book already exists. + // + throw new BookExistsException(); + } + catch(Ice.ObjectNotExistException e) + { + // + // Book doesn't exist, ignore the exception. + // + } + + // + // Create a new book Servant. + // + BookI bookI = new BookI(this); + bookI.description = description; + + Ice.Identity ident = createBookIdentity(description.isbn); + + // + // Create a new Ice Object in the evictor, using the new + // identity and the new Servant. + // + // This can throw EvictorDeactivatedException (which indicates + // an internal error). The exception is currently ignored. + // + _evictor.add(bookI, ident); + + try + { + // + // Add the isbn number to the authors map. + // + String[] isbnSeq = (String[])_authors.get(description.authors); + int length = (isbnSeq == null) ? 0 : isbnSeq.length; + String[] newIsbnSeq = new String[length+1]; + + if(isbnSeq != null) + { + System.arraycopy(isbnSeq, 0, newIsbnSeq, 0, length); + } + newIsbnSeq[length] = description.isbn; + + _authors.fastPut(description.authors, newIsbnSeq); + + return book; + } + catch(Freeze.DatabaseException ex) + { + DatabaseException e = new DatabaseException(); + e.message = ex.message; + throw e; + } } // @@ -83,166 +83,166 @@ class LibraryI extends _LibraryDisp // public BookPrx findByIsbn(String isbn, Ice.Current current) - throws DatabaseException + throws DatabaseException { - try - { - BookPrx book = isbnToBook(isbn, current.adapter); - book.ice_ping(); - - return book; - } - catch(Ice.ObjectNotExistException ex) - { - // - // Book doesn't exist, return a null proxy. - // - return null; - } + try + { + BookPrx book = isbnToBook(isbn, current.adapter); + book.ice_ping(); + + return book; + } + catch(Ice.ObjectNotExistException ex) + { + // + // Book doesn't exist, return a null proxy. + // + return null; + } } public synchronized BookPrx[] findByAuthors(String authors, Ice.Current current) - throws DatabaseException + throws DatabaseException { - try - { - // - // Lookup all books that match the given authors, and - // return them to the caller. - // - String[] isbnSeq = (String[])_authors.get(authors); - - int length = (isbnSeq == null) ? 0 : isbnSeq.length; - BookPrx[] books = new BookPrx[length]; - - if(isbnSeq != null) - { - for(int i = 0; i < length; ++i) - { - books[i] = isbnToBook(isbnSeq[i], current.adapter); - } - } - - return books; - } - catch(Freeze.DatabaseException ex) - { - DatabaseException e = new DatabaseException(); - e.message = ex.message; - throw e; - } + try + { + // + // Lookup all books that match the given authors, and + // return them to the caller. + // + String[] isbnSeq = (String[])_authors.get(authors); + + int length = (isbnSeq == null) ? 0 : isbnSeq.length; + BookPrx[] books = new BookPrx[length]; + + if(isbnSeq != null) + { + for(int i = 0; i < length; ++i) + { + books[i] = isbnToBook(isbnSeq[i], current.adapter); + } + } + + return books; + } + catch(Freeze.DatabaseException ex) + { + DatabaseException e = new DatabaseException(); + e.message = ex.message; + throw e; + } } public void setEvictorSize(int size, Ice.Current current) - throws DatabaseException + throws DatabaseException { - // - // No synchronization necessary, _evictor is immutable. - // - _evictor.setSize(size); + // + // No synchronization necessary, _evictor is immutable. + // + _evictor.setSize(size); } public void shutdown(Ice.Current current) { - current.adapter.getCommunicator().shutdown(); + current.adapter.getCommunicator().shutdown(); } protected synchronized void remove(BookDescription description) - throws DatabaseException + throws DatabaseException { - try - { - String[] isbnSeq = (String[])_authors.get(description.authors); - - assert isbnSeq != null; - - - int i; - for(i = 0; i < isbnSeq.length; ++i) - { - if(isbnSeq[i].equals(description.isbn)) - { - break; - } - } - - assert i < isbnSeq.length; - - if(isbnSeq.length == 1) - { - // - // If there are no further associated isbn numbers then remove - // the record. - // - _authors.fastRemove(description.authors); - } - else - { - // - // Remove the isbn number from the sequence and write - // back the new record. - // - String[] newIsbnSeq = new String[isbnSeq.length-1]; - System.arraycopy(isbnSeq, 0, newIsbnSeq, 0, i); - if(i < isbnSeq.length - 1) - { - System.arraycopy(isbnSeq, i+1, newIsbnSeq, i, isbnSeq.length - i - 1); - } - - _authors.fastPut(description.authors, newIsbnSeq); - } - - // - // This can throw EvictorDeactivatedException (which - // indicates an internal error). The exception is - // currently ignored. - // - _evictor.remove(createBookIdentity(description.isbn)); - } - catch(Freeze.DatabaseException ex) - { - DatabaseException e = new DatabaseException(); - e.message = ex.message; - throw e; - } + try + { + String[] isbnSeq = (String[])_authors.get(description.authors); + + assert isbnSeq != null; + + + int i; + for(i = 0; i < isbnSeq.length; ++i) + { + if(isbnSeq[i].equals(description.isbn)) + { + break; + } + } + + assert i < isbnSeq.length; + + if(isbnSeq.length == 1) + { + // + // If there are no further associated isbn numbers then remove + // the record. + // + _authors.fastRemove(description.authors); + } + else + { + // + // Remove the isbn number from the sequence and write + // back the new record. + // + String[] newIsbnSeq = new String[isbnSeq.length-1]; + System.arraycopy(isbnSeq, 0, newIsbnSeq, 0, i); + if(i < isbnSeq.length - 1) + { + System.arraycopy(isbnSeq, i+1, newIsbnSeq, i, isbnSeq.length - i - 1); + } + + _authors.fastPut(description.authors, newIsbnSeq); + } + + // + // This can throw EvictorDeactivatedException (which + // indicates an internal error). The exception is + // currently ignored. + // + _evictor.remove(createBookIdentity(description.isbn)); + } + catch(Freeze.DatabaseException ex) + { + DatabaseException e = new DatabaseException(); + e.message = ex.message; + throw e; + } } LibraryI(Ice.Communicator communicator, String envName, String dbName, Freeze.Evictor evictor) { - _evictor = evictor; - _connection = Freeze.Util.createConnection(communicator, envName); - _authors = new StringIsbnSeqDict(_connection, dbName, true); + _evictor = evictor; + _connection = Freeze.Util.createConnection(communicator, envName); + _authors = new StringIsbnSeqDict(_connection, dbName, true); } void close() { - _authors.close(); - _connection.close(); + _authors.close(); + _connection.close(); } private Ice.Identity createBookIdentity(String isbn) { - // - // Note that the identity category is important since the - // locator was installed for the category 'book'. - // - Ice.Identity ident = new Ice.Identity(); - ident.category = "book"; - ident.name = isbn; - - return ident; + // + // Note that the identity category is important since the + // locator was installed for the category 'book'. + // + Ice.Identity ident = new Ice.Identity(); + ident.category = "book"; + ident.name = isbn; + + return ident; } private BookPrx isbnToBook(String isbn, Ice.ObjectAdapter adapter) { - return BookPrxHelper.uncheckedCast(adapter.createProxy(createBookIdentity(isbn))); + return BookPrxHelper.uncheckedCast(adapter.createProxy(createBookIdentity(isbn))); } private Freeze.Evictor _evictor; diff --git a/java/demo/Freeze/library/Parser.java b/java/demo/Freeze/library/Parser.java index dc0d641084a..b320cb1049e 100644 --- a/java/demo/Freeze/library/Parser.java +++ b/java/demo/Freeze/library/Parser.java @@ -13,366 +13,366 @@ class Parser { Parser(Ice.Communicator communicator, LibraryPrx library) { - _library = library; + _library = library; } void usage() { - System.err.print( - "help Print this message.\n" + - "exit, quit Exit this program.\n" + - "add isbn title authors Create new book.\n" + - "isbn NUMBER Find the book with given ISBN number.\n" + - "authors NAME Find all books by the given authors.\n" + - "next Set the current book to the next one that was found.\n" + - "current Display the current book.\n" + - "rent NAME Rent the current book for customer NAME.\n" + - "return Return the currently rented book.\n" + - "remove Permanently remove the current book from the library.\n" + - "size SIZE Set the evictor size for books to SIZE.\n" + - "shutdown Shut the library server down.\n"); + System.err.print( + "help Print this message.\n" + + "exit, quit Exit this program.\n" + + "add isbn title authors Create new book.\n" + + "isbn NUMBER Find the book with given ISBN number.\n" + + "authors NAME Find all books by the given authors.\n" + + "next Set the current book to the next one that was found.\n" + + "current Display the current book.\n" + + "rent NAME Rent the current book for customer NAME.\n" + + "return Return the currently rented book.\n" + + "remove Permanently remove the current book from the library.\n" + + "size SIZE Set the evictor size for books to SIZE.\n" + + "shutdown Shut the library server down.\n"); } void addBook(java.util.List args) { - if(args.size() != 3) - { - error("`add' requires at exactly three arguments (type `help' for more info)"); - return; - } - - try - { - BookDescription desc = new BookDescription(); - desc.isbn = (String)args.get(0); - desc.title = (String)args.get(1); - desc.authors = (String)args.get(2); - - BookPrx book = _library.createBook(desc); - System.out.println("added new book with isbn " + desc.isbn); - } - catch(DatabaseException ex) - { - error(ex.message); - } - catch(BookExistsException ex) - { - error("the book already exists."); - } - catch(Ice.LocalException ex) - { - error(ex.toString()); - } + if(args.size() != 3) + { + error("`add' requires at exactly three arguments (type `help' for more info)"); + return; + } + + try + { + BookDescription desc = new BookDescription(); + desc.isbn = (String)args.get(0); + desc.title = (String)args.get(1); + desc.authors = (String)args.get(2); + + BookPrx book = _library.createBook(desc); + System.out.println("added new book with isbn " + desc.isbn); + } + catch(DatabaseException ex) + { + error(ex.message); + } + catch(BookExistsException ex) + { + error("the book already exists."); + } + catch(Ice.LocalException ex) + { + error(ex.toString()); + } } void findIsbn(java.util.List args) { - if(args.size() != 1) - { - error("`isbn' requires exactly one argument (type `help' for more info)"); - return; - } - - try - { - _foundBooks = null; - _current = 0; + if(args.size() != 1) + { + error("`isbn' requires exactly one argument (type `help' for more info)"); + return; + } + + try + { + _foundBooks = null; + _current = 0; - BookPrx book = _library.findByIsbn((String)args.get(0)); - if(book == null) - { - System.out.println("no book with that ISBN number exists."); - } - else - { - _foundBooks = new BookPrx[1]; - _foundBooks[0] = book; - printCurrent(); - } - } - catch(DatabaseException ex) - { - error(ex.message); - } - catch(Ice.LocalException ex) - { - error(ex.toString()); - } + BookPrx book = _library.findByIsbn((String)args.get(0)); + if(book == null) + { + System.out.println("no book with that ISBN number exists."); + } + else + { + _foundBooks = new BookPrx[1]; + _foundBooks[0] = book; + printCurrent(); + } + } + catch(DatabaseException ex) + { + error(ex.message); + } + catch(Ice.LocalException ex) + { + error(ex.toString()); + } } void findAuthors(java.util.List args) { - if(args.size() != 1) - { - error("`authors' requires exactly one argument (type `help' for more info)"); - return; - } - - try - { - _foundBooks = _library.findByAuthors((String)args.get(0)); - _current = 0; - System.out.println("number of books found: " + _foundBooks.length); - printCurrent(); - } - catch(DatabaseException ex) - { - error(ex.message); - } - catch(Ice.LocalException ex) - { - error(ex.toString()); - } + if(args.size() != 1) + { + error("`authors' requires exactly one argument (type `help' for more info)"); + return; + } + + try + { + _foundBooks = _library.findByAuthors((String)args.get(0)); + _current = 0; + System.out.println("number of books found: " + _foundBooks.length); + printCurrent(); + } + catch(DatabaseException ex) + { + error(ex.message); + } + catch(Ice.LocalException ex) + { + error(ex.toString()); + } } void nextFoundBook() { - if(_foundBooks != null && _current != _foundBooks.length) - { - ++_current; - } - printCurrent(); + if(_foundBooks != null && _current != _foundBooks.length) + { + ++_current; + } + printCurrent(); } void printCurrent() { - try - { - if(_foundBooks != null && _current != _foundBooks.length) - { - BookDescription desc = _foundBooks[_current].getBookDescription(); - String renter = null; - try - { - renter = _foundBooks[_current].getRenterName(); - } - catch(BookNotRentedException ex) - { - } + try + { + if(_foundBooks != null && _current != _foundBooks.length) + { + BookDescription desc = _foundBooks[_current].getBookDescription(); + String renter = null; + try + { + renter = _foundBooks[_current].getRenterName(); + } + catch(BookNotRentedException ex) + { + } - System.out.println("current book is:" ); - System.out.println("isbn: " + desc.isbn); - System.out.println("title: " + desc.title); - System.out.println("authors: " + desc.authors); - if(renter != null) - { - System.out.println("rented: " + renter); - } - } - else - { - System.out.println("no current book"); - } - } - catch(Ice.ObjectNotExistException ex) - { + System.out.println("current book is:" ); + System.out.println("isbn: " + desc.isbn); + System.out.println("title: " + desc.title); + System.out.println("authors: " + desc.authors); + if(renter != null) + { + System.out.println("rented: " + renter); + } + } + else + { + System.out.println("no current book"); + } + } + catch(Ice.ObjectNotExistException ex) + { System.out.println("current book no longer exists"); - } - catch(Ice.LocalException ex) - { - error(ex.toString()); - } + } + catch(Ice.LocalException ex) + { + error(ex.toString()); + } } void rentCurrent(java.util.List args) { - if(args.size() != 1) - { - error("`rent' requires exactly one argument (type `help' for more info)"); - return; - } + if(args.size() != 1) + { + error("`rent' requires exactly one argument (type `help' for more info)"); + return; + } - try - { - if(_foundBooks != null && _current != _foundBooks.length) - { - _foundBooks[_current].rentBook((String)args.get(0)); - System.out.println("the book is now rented by `" + (String)args.get(0) + "'"); - } - else - { - System.out.println("no current book"); - } - } - catch(BookRentedException ex) - { - System.out.println("the book has already been rented."); - } - catch(Ice.ObjectNotExistException ex) - { + try + { + if(_foundBooks != null && _current != _foundBooks.length) + { + _foundBooks[_current].rentBook((String)args.get(0)); + System.out.println("the book is now rented by `" + (String)args.get(0) + "'"); + } + else + { + System.out.println("no current book"); + } + } + catch(BookRentedException ex) + { + System.out.println("the book has already been rented."); + } + catch(Ice.ObjectNotExistException ex) + { System.out.println("current book no longer exists"); - } - catch(Ice.LocalException ex) - { - error(ex.toString()); - } + } + catch(Ice.LocalException ex) + { + error(ex.toString()); + } } void returnCurrent() { - try - { - if(_foundBooks != null && _current != _foundBooks.length) - { - _foundBooks[_current].returnBook(); - System.out.println( "the book has been returned."); - } - else - { - System.out.println("no current book"); - } - } - catch(BookNotRentedException ex) - { - System.out.println("the book is not currently rented."); - } - catch(Ice.ObjectNotExistException ex) - { + try + { + if(_foundBooks != null && _current != _foundBooks.length) + { + _foundBooks[_current].returnBook(); + System.out.println( "the book has been returned."); + } + else + { + System.out.println("no current book"); + } + } + catch(BookNotRentedException ex) + { + System.out.println("the book is not currently rented."); + } + catch(Ice.ObjectNotExistException ex) + { System.out.println("current book no longer exists"); - } - catch(Ice.LocalException ex) - { - error(ex.toString()); - } + } + catch(Ice.LocalException ex) + { + error(ex.toString()); + } } void removeCurrent() { - try - { - if(_foundBooks != null && _current != _foundBooks.length) - { - _foundBooks[_current].destroy(); - System.out.println("removed current book" ); - } - else - { - System.out.println("no current book" ); - } - } - catch(DatabaseException ex) - { - error(ex.message); - } - catch(Ice.ObjectNotExistException ex) - { + try + { + if(_foundBooks != null && _current != _foundBooks.length) + { + _foundBooks[_current].destroy(); + System.out.println("removed current book" ); + } + else + { + System.out.println("no current book" ); + } + } + catch(DatabaseException ex) + { + error(ex.message); + } + catch(Ice.ObjectNotExistException ex) + { System.out.println("current book no longer exists"); - } - catch(Ice.LocalException ex) - { - error(ex.toString()); - } + } + catch(Ice.LocalException ex) + { + error(ex.toString()); + } } void setEvictorSize(java.util.List args) { - if(args.size() != 1) - { - error("`size' requires exactly one argument (type `help' for more info)"); - return; - } + if(args.size() != 1) + { + error("`size' requires exactly one argument (type `help' for more info)"); + return; + } - String s = (String)args.get(0); - try - { - _library.setEvictorSize(Integer.parseInt(s)); - } - catch(NumberFormatException ex) - { - error("not a number " + s); - } - catch(DatabaseException ex) - { - error(ex.message); - } - catch(Ice.LocalException ex) - { - error(ex.toString()); - } + String s = (String)args.get(0); + try + { + _library.setEvictorSize(Integer.parseInt(s)); + } + catch(NumberFormatException ex) + { + error("not a number " + s); + } + catch(DatabaseException ex) + { + error(ex.message); + } + catch(Ice.LocalException ex) + { + error(ex.toString()); + } } void shutdown() { - try - { - _library.shutdown(); - } - catch(Ice.LocalException ex) - { - error(ex.toString()); - } + try + { + _library.shutdown(); + } + catch(Ice.LocalException ex) + { + error(ex.toString()); + } } void error(String s) { - System.err.println("error: " + s); + System.err.println("error: " + s); } void warning(String s) { - System.err.println("warning: " + s); + System.err.println("warning: " + s); } String getInput() { - if(_interactive) - { - System.out.print(">>> "); - System.out.flush(); - } + if(_interactive) + { + System.out.print(">>> "); + System.out.flush(); + } - try - { - return _in.readLine(); - } - catch(java.io.IOException e) - { - return null; - } + try + { + return _in.readLine(); + } + catch(java.io.IOException e) + { + return null; + } } int parse() { - _foundBooks = new BookPrx[0]; - _current = 0; + _foundBooks = new BookPrx[0]; + _current = 0; - _in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); - _interactive = true; + _in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); + _interactive = true; - Grammar g = new Grammar(this); - g.parse(); + Grammar g = new Grammar(this); + g.parse(); - return 0; + return 0; } int parse(java.io.BufferedReader in) { - _foundBooks = new BookPrx[0]; - _current = 0; + _foundBooks = new BookPrx[0]; + _current = 0; - _in = in; - _interactive = false; + _in = in; + _interactive = false; - Grammar g = new Grammar(this); - g.parse(); + Grammar g = new Grammar(this); + g.parse(); - return 0; + return 0; } private BookPrx[] _foundBooks; diff --git a/java/demo/Freeze/library/RunParser.java b/java/demo/Freeze/library/RunParser.java index 426f1beefe7..1fc0e095c7d 100644 --- a/java/demo/Freeze/library/RunParser.java +++ b/java/demo/Freeze/library/RunParser.java @@ -14,26 +14,26 @@ class RunParser static void usage(String appName) { - System.err.println("Usage: " + appName + " [options] [file...]\n"); - System.err.print( - "Options:\n" + - "-h, --help Show this message.\n"); - //"-v, --version Display the Ice version.\n" + System.err.println("Usage: " + appName + " [options] [file...]\n"); + System.err.print( + "Options:\n" + + "-h, --help Show this message.\n"); + //"-v, --version Display the Ice version.\n" } static int runParser(String appName, String[] args, Ice.Communicator communicator) { - String file = null; - int idx = 0; + String file = null; + int idx = 0; - while(idx < args.length) - { - if(args[idx].equals("-h") | args[idx].equals("--help")) - { - usage(appName); - return 0; - } + while(idx < args.length) + { + if(args[idx].equals("-h") | args[idx].equals("--help")) + { + usage(appName); + return 0; + } /* else if(args[idx].equals("-v") || args[idx].equals("--version")) { @@ -41,56 +41,56 @@ class RunParser return 0; } */ - else if(args[idx].charAt(0) == '-') - { - System.err.println(appName + ": unknown option `" + args[idx] + "'"); - usage(appName); - return 1; - } - else - { - if(file == null) - { - file = args[idx]; - } - else - { - System.err.println(appName + ": only one file is supported."); - usage(appName); - return 1; - } - ++idx; - } - } + else if(args[idx].charAt(0) == '-') + { + System.err.println(appName + ": unknown option `" + args[idx] + "'"); + usage(appName); + return 1; + } + else + { + if(file == null) + { + file = args[idx]; + } + else + { + System.err.println(appName + ": only one file is supported."); + usage(appName); + return 1; + } + ++idx; + } + } - Ice.ObjectPrx base = communicator.propertyToProxy("Library.Proxy"); - LibraryPrx library = LibraryPrxHelper.checkedCast(base); - if(library == null) - { - System.err.println(appName + ": invalid object reference"); - return 1; - } + Ice.ObjectPrx base = communicator.propertyToProxy("Library.Proxy"); + LibraryPrx library = LibraryPrxHelper.checkedCast(base); + if(library == null) + { + System.err.println(appName + ": invalid object reference"); + return 1; + } - Parser parser = new Parser(communicator, library); - int status; + Parser parser = new Parser(communicator, library); + int status; - if(file == null) - { - status = parser.parse(); - } - else - { - try - { - status = parser.parse(new java.io.BufferedReader(new java.io.FileReader(file))); - } - catch(java.io.IOException ex) - { - status = 1; - ex.printStackTrace(); - } - } + if(file == null) + { + status = parser.parse(); + } + else + { + try + { + status = parser.parse(new java.io.BufferedReader(new java.io.FileReader(file))); + } + catch(java.io.IOException ex) + { + status = 1; + ex.printStackTrace(); + } + } - return status; + return status; } } diff --git a/java/demo/Freeze/library/Scanner.java b/java/demo/Freeze/library/Scanner.java index 27e42f2d83d..7bcf64d1862 100644 --- a/java/demo/Freeze/library/Scanner.java +++ b/java/demo/Freeze/library/Scanner.java @@ -11,74 +11,74 @@ class Scanner { Scanner(Parser p) { - _parser = p; + _parser = p; } Token nextToken() { - String s = next(); - if(s == null) - { - return null; - } + String s = next(); + if(s == null) + { + return null; + } - if(s.equals(";")) - { - return new Token(Token.TOK_SEMI); - } - else if(s.equals("help")) - { - return new Token(Token.TOK_HELP); - } - else if(s.equals("exit") || s.equals("quit")) - { - return new Token(Token.TOK_EXIT); - } - else if(s.equals("add")) - { - return new Token(Token.TOK_ADD_BOOK); - } - else if(s.equals("isbn")) - { - return new Token(Token.TOK_FIND_ISBN); - } - else if(s.equals("authors")) - { - return new Token(Token.TOK_FIND_AUTHORS); - } - else if(s.equals("next")) - { - return new Token(Token.TOK_NEXT_FOUND_BOOK); - } - else if(s.equals("current")) - { - return new Token(Token.TOK_PRINT_CURRENT); - } - else if(s.equals("rent")) - { - return new Token(Token.TOK_RENT_BOOK); - } - else if(s.equals("return")) - { - return new Token(Token.TOK_RETURN_BOOK); - } - else if(s.equals("remove")) - { - return new Token(Token.TOK_REMOVE_CURRENT); - } - else if(s.equals("size")) - { - return new Token(Token.TOK_SET_EVICTOR_SIZE); - } - else if(s.equals("shutdown")) - { - return new Token(Token.TOK_SHUTDOWN); - } - else - { - return new Token(Token.TOK_STRING, s); - } + if(s.equals(";")) + { + return new Token(Token.TOK_SEMI); + } + else if(s.equals("help")) + { + return new Token(Token.TOK_HELP); + } + else if(s.equals("exit") || s.equals("quit")) + { + return new Token(Token.TOK_EXIT); + } + else if(s.equals("add")) + { + return new Token(Token.TOK_ADD_BOOK); + } + else if(s.equals("isbn")) + { + return new Token(Token.TOK_FIND_ISBN); + } + else if(s.equals("authors")) + { + return new Token(Token.TOK_FIND_AUTHORS); + } + else if(s.equals("next")) + { + return new Token(Token.TOK_NEXT_FOUND_BOOK); + } + else if(s.equals("current")) + { + return new Token(Token.TOK_PRINT_CURRENT); + } + else if(s.equals("rent")) + { + return new Token(Token.TOK_RENT_BOOK); + } + else if(s.equals("return")) + { + return new Token(Token.TOK_RETURN_BOOK); + } + else if(s.equals("remove")) + { + return new Token(Token.TOK_REMOVE_CURRENT); + } + else if(s.equals("size")) + { + return new Token(Token.TOK_SET_EVICTOR_SIZE); + } + else if(s.equals("shutdown")) + { + return new Token(Token.TOK_SHUTDOWN); + } + else + { + return new Token(Token.TOK_STRING, s); + } } static private class EndOfInput extends Exception @@ -87,41 +87,41 @@ class Scanner private char get() - throws EndOfInput + throws EndOfInput { - // - // If there is an character in the unget buffer, return it. - // - if(_unget) - { - _unget = false; - return _ungetChar; - } + // + // If there is an character in the unget buffer, return it. + // + if(_unget) + { + _unget = false; + return _ungetChar; + } - // - // No current buffer? - // - if(_buf == null) - { - _buf = _parser.getInput(); - _pos = 0; - if(_buf == null) - { - throw new EndOfInput(); - } - } + // + // No current buffer? + // + if(_buf == null) + { + _buf = _parser.getInput(); + _pos = 0; + if(_buf == null) + { + throw new EndOfInput(); + } + } - // - // At the end-of-buffer? - // - while(_pos >= _buf.length()) - { - _buf = null; - _pos = 0; - return '\n'; - } + // + // At the end-of-buffer? + // + while(_pos >= _buf.length()) + { + _buf = null; + _pos = 0; + return '\n'; + } - return _buf.charAt(_pos++); + return _buf.charAt(_pos++); } // @@ -130,153 +130,153 @@ class Scanner private void unget(char c) { - assert(!_unget); - _unget = true; - _ungetChar = c; + assert(!_unget); + _unget = true; + _ungetChar = c; } private String next() { - // - // Eat any whitespace. - // - char c; - try - { - do - { - c = get(); - } - while(Character.isWhitespace(c) && c != '\n'); - } - catch(EndOfInput ignore) - { - return null; - } + // + // Eat any whitespace. + // + char c; + try + { + do + { + c = get(); + } + while(Character.isWhitespace(c) && c != '\n'); + } + catch(EndOfInput ignore) + { + return null; + } - StringBuffer buf = new StringBuffer(); + StringBuffer buf = new StringBuffer(); - if(c == ';' || c == '\n') - { - buf.append(';'); - } - else if(c == '\'') - { - try - { - while(true) - { - c = get(); - if(c == '\'') - { - break; - } - else - { - buf.append(c); - } - } - } - catch(EndOfInput e) - { - _parser.warning("EOF in string"); - } - } - else if(c == '\"') - { - try - { - while(true) - { - c = get(); - if(c == '\"') - { - break; - } - else if(c == '\\') - { - try - { - char next = get(); - switch(next) - { - case '\\': - case '"': - { - buf.append(next); - break; - } - - case 'n': - { - buf.append('\n'); - break; - } - - case 'r': - { - buf.append('\r'); - break; - } - - case 't': - { - buf.append('\t'); - break; - } - - case 'f': - { - buf.append('\f'); - break; - } - - default: - { - buf.append(c); - unget(next); - } - } - } - catch(EndOfInput e) - { - buf.append(c); - } - } - else - { - buf.append(c); - } - } - } - catch(EndOfInput e) - { - _parser.warning("EOF in string"); - } - } - else - { - // - // Otherwise it's a string. - // - try - { - do - { - buf.append(c); - c = get(); - } - while(!Character.isWhitespace(c) && c != ';' && c != '\n'); + if(c == ';' || c == '\n') + { + buf.append(';'); + } + else if(c == '\'') + { + try + { + while(true) + { + c = get(); + if(c == '\'') + { + break; + } + else + { + buf.append(c); + } + } + } + catch(EndOfInput e) + { + _parser.warning("EOF in string"); + } + } + else if(c == '\"') + { + try + { + while(true) + { + c = get(); + if(c == '\"') + { + break; + } + else if(c == '\\') + { + try + { + char next = get(); + switch(next) + { + case '\\': + case '"': + { + buf.append(next); + break; + } + + case 'n': + { + buf.append('\n'); + break; + } + + case 'r': + { + buf.append('\r'); + break; + } + + case 't': + { + buf.append('\t'); + break; + } + + case 'f': + { + buf.append('\f'); + break; + } + + default: + { + buf.append(c); + unget(next); + } + } + } + catch(EndOfInput e) + { + buf.append(c); + } + } + else + { + buf.append(c); + } + } + } + catch(EndOfInput e) + { + _parser.warning("EOF in string"); + } + } + else + { + // + // Otherwise it's a string. + // + try + { + do + { + buf.append(c); + c = get(); + } + while(!Character.isWhitespace(c) && c != ';' && c != '\n'); - unget(c); - } - catch(EndOfInput ignore) - { - } - } - - return buf.toString(); + unget(c); + } + catch(EndOfInput ignore) + { + } + } + + return buf.toString(); } private Parser _parser; diff --git a/java/demo/Freeze/library/Server.java b/java/demo/Freeze/library/Server.java index 2ce57e21a78..cc94c02d2f9 100644 --- a/java/demo/Freeze/library/Server.java +++ b/java/demo/Freeze/library/Server.java @@ -12,53 +12,53 @@ class LibraryServer extends Ice.Application public int run(String[] args) { - Ice.Properties properties = communicator().getProperties(); + Ice.Properties properties = communicator().getProperties(); - // - // Create an object adapter - // - Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Library"); + // + // Create an object adapter + // + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Library"); - // - // Create an evictor for books. - // - Freeze.Evictor evictor = Freeze.Util.createEvictor(adapter, _envName, "books", null, null, true); - int evictorSize = properties.getPropertyAsInt("Library.EvictorSize"); - if(evictorSize > 0) - { - evictor.setSize(evictorSize); - } + // + // Create an evictor for books. + // + Freeze.Evictor evictor = Freeze.Util.createEvictor(adapter, _envName, "books", null, null, true); + int evictorSize = properties.getPropertyAsInt("Library.EvictorSize"); + if(evictorSize > 0) + { + evictor.setSize(evictorSize); + } - adapter.addServantLocator(evictor, "book"); + adapter.addServantLocator(evictor, "book"); - // - // Create the library, and add it to the object adapter. - // - LibraryI library = new LibraryI(communicator(), _envName, "authors", evictor); - adapter.add(library, communicator().stringToIdentity("library")); + // + // Create the library, and add it to the object adapter. + // + LibraryI library = new LibraryI(communicator(), _envName, "authors", evictor); + adapter.add(library, communicator().stringToIdentity("library")); - // - // Create and install a factory for books. - // - Ice.ObjectFactory bookFactory = new BookFactory(library); - communicator().addObjectFactory(bookFactory, "::Demo::Book"); + // + // Create and install a factory for books. + // + Ice.ObjectFactory bookFactory = new BookFactory(library); + communicator().addObjectFactory(bookFactory, "::Demo::Book"); - // - // Everything ok, let's go. - // - adapter.activate(); + // + // Everything ok, let's go. + // + adapter.activate(); - shutdownOnInterrupt(); - communicator().waitForShutdown(); - defaultInterrupt(); + shutdownOnInterrupt(); + communicator().waitForShutdown(); + defaultInterrupt(); - library.close(); - return 0; + library.close(); + return 0; } LibraryServer(String envName) { - _envName = envName; + _envName = envName; } private String _envName; @@ -69,7 +69,7 @@ public class Server static public void main(String[] args) { - LibraryServer app = new LibraryServer("db"); - app.main("demo.Freeze.library.Server", args, "config.server"); + LibraryServer app = new LibraryServer("db"); + app.main("demo.Freeze.library.Server", args, "config.server"); } } diff --git a/java/demo/Freeze/library/Token.java b/java/demo/Freeze/library/Token.java index 0821f42f756..a34f83b7316 100644 --- a/java/demo/Freeze/library/Token.java +++ b/java/demo/Freeze/library/Token.java @@ -29,13 +29,13 @@ class Token Token(int t) { - type = t; - value = null; + type = t; + value = null; } Token(int t, String v) { - type = t; - value = v; + type = t; + value = v; } } diff --git a/java/demo/Freeze/phonebook/Client.java b/java/demo/Freeze/phonebook/Client.java index f2254da95b4..4b465773d99 100644 --- a/java/demo/Freeze/phonebook/Client.java +++ b/java/demo/Freeze/phonebook/Client.java @@ -11,37 +11,37 @@ public class Client extends Ice.Application { class ShutdownHook extends Thread { - public void - run() - { - try - { - communicator().destroy(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - } - } + public void + run() + { + try + { + communicator().destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + } } public int run(String[] args) { - // - // Since this is an interactive demo we want to clear the - // Application installed interrupt callback and install our - // own shutdown hook. - // - setInterruptHook(new ShutdownHook()); + // + // Since this is an interactive demo we want to clear the + // Application installed interrupt callback and install our + // own shutdown hook. + // + setInterruptHook(new ShutdownHook()); - return RunParser.runParser(appName(), args, communicator()); + return RunParser.runParser(appName(), args, communicator()); } static public void main(String[] args) { - Client app = new Client(); - app.main("demo.Freeze.phonebook.Client", args, "config.client"); + Client app = new Client(); + app.main("demo.Freeze.phonebook.Client", args, "config.client"); } } diff --git a/java/demo/Freeze/phonebook/Collocated.java b/java/demo/Freeze/phonebook/Collocated.java index 695f7a010e6..568beb53da2 100644 --- a/java/demo/Freeze/phonebook/Collocated.java +++ b/java/demo/Freeze/phonebook/Collocated.java @@ -11,95 +11,95 @@ class PhoneBookCollocated extends Ice.Application { class ShutdownHook extends Thread { - public void - run() - { - try - { - communicator().destroy(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - } - } + public void + run() + { + try + { + communicator().destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + } } public int run(String[] args) { - // - // Since this is an interactive demo we want to clear the - // Application installed interrupt callback and install our - // own shutdown hook. - // - setInterruptHook(new ShutdownHook()); + // + // Since this is an interactive demo we want to clear the + // Application installed interrupt callback and install our + // own shutdown hook. + // + setInterruptHook(new ShutdownHook()); - Ice.Properties properties = communicator().getProperties(); + Ice.Properties properties = communicator().getProperties(); - // - // Create and install a factory for contacts. - // - ContactFactory contactFactory = new ContactFactory(); - communicator().addObjectFactory(contactFactory, "::Demo::Contact"); + // + // Create and install a factory for contacts. + // + ContactFactory contactFactory = new ContactFactory(); + communicator().addObjectFactory(contactFactory, "::Demo::Contact"); - // - // Create an object adapter - // - Ice.ObjectAdapter adapter = communicator().createObjectAdapter("PhoneBook"); + // + // Create an object adapter + // + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("PhoneBook"); - // - // Create the Name index - // - NameIndex index = new NameIndex("name"); - Freeze.Index[] indices = new Freeze.Index[1]; - indices[0] = index; + // + // Create the Name index + // + NameIndex index = new NameIndex("name"); + Freeze.Index[] indices = new Freeze.Index[1]; + indices[0] = index; - // - // Create an evictor for contacts. - // When Freeze.Evictor.db.contacts.PopulateEmptyIndices is not 0 and the - // Name index is empty, Freeze will traverse the database to recreate - // the index during createEvictor(). Therefore the factories for the objects - // stored in evictor (contacts here) must be registered before the call - // to createEvictor(). - // - Freeze.Evictor evictor = Freeze.Util.createEvictor(adapter, _envName, "contacts", null, indices, true); - int evictorSize = properties.getPropertyAsInt("PhoneBook.EvictorSize"); - if(evictorSize > 0) - { - evictor.setSize(evictorSize); - } + // + // Create an evictor for contacts. + // When Freeze.Evictor.db.contacts.PopulateEmptyIndices is not 0 and the + // Name index is empty, Freeze will traverse the database to recreate + // the index during createEvictor(). Therefore the factories for the objects + // stored in evictor (contacts here) must be registered before the call + // to createEvictor(). + // + Freeze.Evictor evictor = Freeze.Util.createEvictor(adapter, _envName, "contacts", null, indices, true); + int evictorSize = properties.getPropertyAsInt("PhoneBook.EvictorSize"); + if(evictorSize > 0) + { + evictor.setSize(evictorSize); + } - // - // Completes the initialization of the contact factory. Note that ContactI/ - // ContactFactoryI uses this evictor only when a Contact is destroyed, - // which cannot happen during createEvictor(). - // - contactFactory.setEvictor(evictor); + // + // Completes the initialization of the contact factory. Note that ContactI/ + // ContactFactoryI uses this evictor only when a Contact is destroyed, + // which cannot happen during createEvictor(). + // + contactFactory.setEvictor(evictor); - // - // Register the evictor with the adapter - // - adapter.addServantLocator(evictor, "contact"); + // + // Register the evictor with the adapter + // + adapter.addServantLocator(evictor, "contact"); - // - // Create the phonebook, and add it to the Object Adapter. - // - PhoneBookI phoneBook = new PhoneBookI(evictor, contactFactory, index); - adapter.add(phoneBook, communicator().stringToIdentity("phonebook")); + // + // Create the phonebook, and add it to the Object Adapter. + // + PhoneBookI phoneBook = new PhoneBookI(evictor, contactFactory, index); + adapter.add(phoneBook, communicator().stringToIdentity("phonebook")); - // - // Everything ok, let's go. - // - int status = RunParser.runParser(appName(), args, communicator()); - adapter.destroy(); + // + // Everything ok, let's go. + // + int status = RunParser.runParser(appName(), args, communicator()); + adapter.destroy(); - return status; + return status; } PhoneBookCollocated(String envName) { - _envName = envName; + _envName = envName; } private String _envName; @@ -110,7 +110,7 @@ public class Collocated static public void main(String[] args) { - PhoneBookCollocated app = new PhoneBookCollocated("db"); - app.main("demo.Freeze.phonebook.Collocated", args, "config.collocated"); + PhoneBookCollocated app = new PhoneBookCollocated("db"); + app.main("demo.Freeze.phonebook.Collocated", args, "config.collocated"); } } diff --git a/java/demo/Freeze/phonebook/ContactFactory.java b/java/demo/Freeze/phonebook/ContactFactory.java index 8e037bc403e..180fc68cc5d 100644 --- a/java/demo/Freeze/phonebook/ContactFactory.java +++ b/java/demo/Freeze/phonebook/ContactFactory.java @@ -12,8 +12,8 @@ class ContactFactory extends Ice.LocalObjectImpl implements Ice.ObjectFactory public Ice.Object create(String type) { - assert(type.equals("::Demo::Contact")); - return new ContactI(this); + assert(type.equals("::Demo::Contact")); + return new ContactI(this); } public void @@ -28,13 +28,13 @@ class ContactFactory extends Ice.LocalObjectImpl implements Ice.ObjectFactory void setEvictor(Freeze.Evictor evictor) { - _evictor = evictor; + _evictor = evictor; } Freeze.Evictor getEvictor() { - return _evictor; + return _evictor; } private Freeze.Evictor _evictor; diff --git a/java/demo/Freeze/phonebook/ContactI.java b/java/demo/Freeze/phonebook/ContactI.java index 5547d3f2bb5..b8cc732feca 100644 --- a/java/demo/Freeze/phonebook/ContactI.java +++ b/java/demo/Freeze/phonebook/ContactI.java @@ -19,67 +19,67 @@ class ContactI extends Contact synchronized public String getName(Ice.Current current) { - return name; + return name; } synchronized public void setName(String name, Ice.Current current) - throws DatabaseException + throws DatabaseException { - this.name = name; + this.name = name; } synchronized public String getAddress(Ice.Current current) { - return address; + return address; } synchronized public void setAddress(String address, Ice.Current current) { - this.address = address; + this.address = address; } synchronized public String getPhone(Ice.Current current) { - return phone; + return phone; } synchronized public void setPhone(String phone, Ice.Current current) { - this.phone = phone; + this.phone = phone; } public void destroy(Ice.Current current) - throws DatabaseException + throws DatabaseException { - try - { - _factory.getEvictor().remove(current.id); - } - catch(Freeze.DatabaseException ex) - { - DatabaseException e = new DatabaseException(); - e.message = ex.message; - throw e; - } + try + { + _factory.getEvictor().remove(current.id); + } + catch(Freeze.DatabaseException ex) + { + DatabaseException e = new DatabaseException(); + e.message = ex.message; + throw e; + } } ContactI(ContactFactory factory) { - _factory = factory; - // - // It's possible to avoid this if there were two constructors - // - one for original creation of the Contact and one for - // loading of an existing Contact. - // - name = new String(); - address = new String(); - phone = new String(); + _factory = factory; + // + // It's possible to avoid this if there were two constructors + // - one for original creation of the Contact and one for + // loading of an existing Contact. + // + name = new String(); + address = new String(); + phone = new String(); } private ContactFactory _factory; diff --git a/java/demo/Freeze/phonebook/Grammar.java b/java/demo/Freeze/phonebook/Grammar.java index d71a6282506..5c0288a7ae8 100644 --- a/java/demo/Freeze/phonebook/Grammar.java +++ b/java/demo/Freeze/phonebook/Grammar.java @@ -11,173 +11,173 @@ class Grammar { Grammar(Parser p) { - _parser = p; - _scanner = new Scanner(_parser); + _parser = p; + _scanner = new Scanner(_parser); } void parse() { - while(true) - { - try - { - _token = _scanner.nextToken(); - if(_token == null) - { - return; - } - else if(_token.type == Token.TOK_SEMI) - { - // Continue - } - else if(_token.type == Token.TOK_HELP) - { - _token = _scanner.nextToken(); - if(_token.type != Token.TOK_SEMI) - { - throw new ParseError("Expected ';'"); - } + while(true) + { + try + { + _token = _scanner.nextToken(); + if(_token == null) + { + return; + } + else if(_token.type == Token.TOK_SEMI) + { + // Continue + } + else if(_token.type == Token.TOK_HELP) + { + _token = _scanner.nextToken(); + if(_token.type != Token.TOK_SEMI) + { + throw new ParseError("Expected ';'"); + } - _parser.usage(); - } - else if(_token.type == Token.TOK_EXIT) - { - _token = _scanner.nextToken(); - if(_token.type != Token.TOK_SEMI) - { - throw new ParseError("Expected ';'"); - } + _parser.usage(); + } + else if(_token.type == Token.TOK_EXIT) + { + _token = _scanner.nextToken(); + if(_token.type != Token.TOK_SEMI) + { + throw new ParseError("Expected ';'"); + } - return; - } - else if(_token.type == Token.TOK_ADD_CONTACTS) - { - java.util.List s = strings(); - if(_token.type != Token.TOK_SEMI) - { - throw new ParseError("Expected ';'"); - } - _parser.addContacts(s); - } - else if(_token.type == Token.TOK_FIND_CONTACTS) - { - java.util.List s = strings(); - if(_token.type != Token.TOK_SEMI) - { - throw new ParseError("Expected ';'"); - } - _parser.findContacts(s); - } - else if(_token.type == Token.TOK_NEXT_FOUND_CONTACT) - { - _token = _scanner.nextToken(); - if(_token.type != Token.TOK_SEMI) - { - throw new ParseError("Expected ';'"); - } + return; + } + else if(_token.type == Token.TOK_ADD_CONTACTS) + { + java.util.List s = strings(); + if(_token.type != Token.TOK_SEMI) + { + throw new ParseError("Expected ';'"); + } + _parser.addContacts(s); + } + else if(_token.type == Token.TOK_FIND_CONTACTS) + { + java.util.List s = strings(); + if(_token.type != Token.TOK_SEMI) + { + throw new ParseError("Expected ';'"); + } + _parser.findContacts(s); + } + else if(_token.type == Token.TOK_NEXT_FOUND_CONTACT) + { + _token = _scanner.nextToken(); + if(_token.type != Token.TOK_SEMI) + { + throw new ParseError("Expected ';'"); + } - _parser.nextFoundContact(); - } - else if(_token.type == Token.TOK_PRINT_CURRENT) - { - _token = _scanner.nextToken(); - if(_token.type != Token.TOK_SEMI) - { - throw new ParseError("Expected ';'"); - } + _parser.nextFoundContact(); + } + else if(_token.type == Token.TOK_PRINT_CURRENT) + { + _token = _scanner.nextToken(); + if(_token.type != Token.TOK_SEMI) + { + throw new ParseError("Expected ';'"); + } - _parser.printCurrent(); - } - else if(_token.type == Token.TOK_SET_CURRENT_NAME) - { - java.util.List s = strings(); - if(_token.type != Token.TOK_SEMI) - { - throw new ParseError("Expected ';'"); - } - _parser.setCurrentName(s); - } - else if(_token.type == Token.TOK_SET_CURRENT_ADDRESS) - { - java.util.List s = strings(); - if(_token.type != Token.TOK_SEMI) - { - throw new ParseError("Expected ';'"); - } - _parser.setCurrentAddress(s); - } - else if(_token.type == Token.TOK_SET_CURRENT_PHONE) - { - java.util.List s = strings(); - if(_token.type != Token.TOK_SEMI) - { - throw new ParseError("Expected ';'"); - } - _parser.setCurrentPhone(s); - } - else if(_token.type == Token.TOK_REMOVE_CURRENT) - { - _token = _scanner.nextToken(); - if(_token.type != Token.TOK_SEMI) - { - throw new ParseError("Expected ';'"); - } + _parser.printCurrent(); + } + else if(_token.type == Token.TOK_SET_CURRENT_NAME) + { + java.util.List s = strings(); + if(_token.type != Token.TOK_SEMI) + { + throw new ParseError("Expected ';'"); + } + _parser.setCurrentName(s); + } + else if(_token.type == Token.TOK_SET_CURRENT_ADDRESS) + { + java.util.List s = strings(); + if(_token.type != Token.TOK_SEMI) + { + throw new ParseError("Expected ';'"); + } + _parser.setCurrentAddress(s); + } + else if(_token.type == Token.TOK_SET_CURRENT_PHONE) + { + java.util.List s = strings(); + if(_token.type != Token.TOK_SEMI) + { + throw new ParseError("Expected ';'"); + } + _parser.setCurrentPhone(s); + } + else if(_token.type == Token.TOK_REMOVE_CURRENT) + { + _token = _scanner.nextToken(); + if(_token.type != Token.TOK_SEMI) + { + throw new ParseError("Expected ';'"); + } - _parser.removeCurrent(); - } - else if(_token.type == Token.TOK_SET_EVICTOR_SIZE) - { - java.util.List s = strings(); - if(_token.type != Token.TOK_SEMI) - { - throw new ParseError("Expected ';'"); - } - _parser.setEvictorSize(s); - } - else if(_token.type == Token.TOK_SHUTDOWN) - { - _token = _scanner.nextToken(); - if(_token.type != Token.TOK_SEMI) - { - throw new ParseError("Expected ';'"); - } + _parser.removeCurrent(); + } + else if(_token.type == Token.TOK_SET_EVICTOR_SIZE) + { + java.util.List s = strings(); + if(_token.type != Token.TOK_SEMI) + { + throw new ParseError("Expected ';'"); + } + _parser.setEvictorSize(s); + } + else if(_token.type == Token.TOK_SHUTDOWN) + { + _token = _scanner.nextToken(); + if(_token.type != Token.TOK_SEMI) + { + throw new ParseError("Expected ';'"); + } - _parser.shutdown(); - } - else - { - _parser.error("parse error"); - } - } - catch(ParseError e) - { - _parser.error("Parse error: " + e.getMessage()); - } - } + _parser.shutdown(); + } + else + { + _parser.error("parse error"); + } + } + catch(ParseError e) + { + _parser.error("Parse error: " + e.getMessage()); + } + } } private java.util.List strings() { - java.util.List l = new java.util.ArrayList(); - while(true) - { - _token = _scanner.nextToken(); - if(_token.type != Token.TOK_STRING) - { - return l; - } - l.add(_token.value); - } + java.util.List l = new java.util.ArrayList(); + while(true) + { + _token = _scanner.nextToken(); + if(_token.type != Token.TOK_STRING) + { + return l; + } + l.add(_token.value); + } } static private class ParseError extends RuntimeException { - ParseError(String msg) - { - super(msg); - } + ParseError(String msg) + { + super(msg); + } } private Parser _parser; diff --git a/java/demo/Freeze/phonebook/Parser.java b/java/demo/Freeze/phonebook/Parser.java index 089c54c9c29..f45b66ff009 100644 --- a/java/demo/Freeze/phonebook/Parser.java +++ b/java/demo/Freeze/phonebook/Parser.java @@ -13,353 +13,353 @@ class Parser { Parser(Ice.Communicator communicator, PhoneBookPrx phoneBook) { - _communicator = communicator; - _phoneBook = phoneBook; + _communicator = communicator; + _phoneBook = phoneBook; } void usage() { - System.err.print( - "help Print this message.\n" + - "exit, quit Exit this program.\n" + - "add NAMES... Create new contacts for NAMES in the phonebook.\n" + - "find NAME Find all contacts in the phonebook that match NAME.\n" + - " Set the current contact to the first one found.\n" + - "next Set the current contact to the next one that was found.\n" + - "current Display the current contact.\n" + - "name NAME Set the name for the current contact to NAME.\n" + - "address ADDRESS Set the address for the current contact to ADDRESS.\n" + - "phone PHONE Set the phone number for the current contact to PHONE.\n" + - "remove Permanently remove the current contact from the phonebook.\n" + - "size SIZE Set the evictor size for contacts to SIZE.\n" + - "shutdown Shut the phonebook server down.\n"); + System.err.print( + "help Print this message.\n" + + "exit, quit Exit this program.\n" + + "add NAMES... Create new contacts for NAMES in the phonebook.\n" + + "find NAME Find all contacts in the phonebook that match NAME.\n" + + " Set the current contact to the first one found.\n" + + "next Set the current contact to the next one that was found.\n" + + "current Display the current contact.\n" + + "name NAME Set the name for the current contact to NAME.\n" + + "address ADDRESS Set the address for the current contact to ADDRESS.\n" + + "phone PHONE Set the phone number for the current contact to PHONE.\n" + + "remove Permanently remove the current contact from the phonebook.\n" + + "size SIZE Set the evictor size for contacts to SIZE.\n" + + "shutdown Shut the phonebook server down.\n"); } void addContacts(java.util.List args) { - if(args.isEmpty()) - { - error("`add' requires at least one argument (type `help' for more info)"); - return; - } - - try - { - java.util.Iterator p = args.iterator(); - while(p.hasNext()) - { - ContactPrx contact = _phoneBook.createContact(); - String name = (String)p.next(); - contact.setName(name); - System.out.println("added new contact for `" + name + "'"); - } - } - catch(DatabaseException ex) - { - error(ex.message); - } - catch(Ice.LocalException ex) - { - error(ex.toString()); - } + if(args.isEmpty()) + { + error("`add' requires at least one argument (type `help' for more info)"); + return; + } + + try + { + java.util.Iterator p = args.iterator(); + while(p.hasNext()) + { + ContactPrx contact = _phoneBook.createContact(); + String name = (String)p.next(); + contact.setName(name); + System.out.println("added new contact for `" + name + "'"); + } + } + catch(DatabaseException ex) + { + error(ex.message); + } + catch(Ice.LocalException ex) + { + error(ex.toString()); + } } void findContacts(java.util.List args) { - if(args.size() != 1) - { - error("`find' requires exactly one argument (type `help' for more info)"); - return; - } - - try - { - String name = (String)args.get(0); - _foundContacts = _phoneBook.findContacts(name); - _current = 0; - System.out.println("number of contacts found: " + _foundContacts.length); - printCurrent(); - } - catch(DatabaseException ex) - { - error(ex.message); - } - catch(Ice.LocalException ex) - { - error(ex.toString()); - } + if(args.size() != 1) + { + error("`find' requires exactly one argument (type `help' for more info)"); + return; + } + + try + { + String name = (String)args.get(0); + _foundContacts = _phoneBook.findContacts(name); + _current = 0; + System.out.println("number of contacts found: " + _foundContacts.length); + printCurrent(); + } + catch(DatabaseException ex) + { + error(ex.message); + } + catch(Ice.LocalException ex) + { + error(ex.toString()); + } } void nextFoundContact() { - if(_current != _foundContacts.length) - { - ++_current; - } - printCurrent(); + if(_current != _foundContacts.length) + { + ++_current; + } + printCurrent(); } void printCurrent() { - try - { - if(_current != _foundContacts.length) - { - System.out.println("current contact is:" ); - System.out.println("name: " + _foundContacts[_current].getName()); - System.out.println("address: " + _foundContacts[_current].getAddress() ); - System.out.println("phone: " + _foundContacts[_current].getPhone()); - } - else - { - System.out.println("no current contact"); - } - } - catch(Ice.ObjectNotExistException ex) - { + try + { + if(_current != _foundContacts.length) + { + System.out.println("current contact is:" ); + System.out.println("name: " + _foundContacts[_current].getName()); + System.out.println("address: " + _foundContacts[_current].getAddress() ); + System.out.println("phone: " + _foundContacts[_current].getPhone()); + } + else + { + System.out.println("no current contact"); + } + } + catch(Ice.ObjectNotExistException ex) + { System.out.println("current contact no longer exists"); - } - catch(Ice.LocalException ex) - { - error(ex.toString()); - } + } + catch(Ice.LocalException ex) + { + error(ex.toString()); + } } void setCurrentName(java.util.List args) { - if(args.size() != 1) - { - error("`name' requires exactly one argument (type `help' for more info)"); - return; - } + if(args.size() != 1) + { + error("`name' requires exactly one argument (type `help' for more info)"); + return; + } - try - { - if(_current != _foundContacts.length) - { - String name = (String)args.get(0); - _foundContacts[_current].setName(name); - System.out.println("changed name to `" + name + "'"); - } - else - { - System.out.println("no current contact"); - } - } - catch(Ice.ObjectNotExistException ex) - { + try + { + if(_current != _foundContacts.length) + { + String name = (String)args.get(0); + _foundContacts[_current].setName(name); + System.out.println("changed name to `" + name + "'"); + } + else + { + System.out.println("no current contact"); + } + } + catch(Ice.ObjectNotExistException ex) + { System.out.println("current contact no longer exists"); - } - catch(DatabaseException ex) - { - error(ex.message); - } - catch(Ice.LocalException ex) - { - error(ex.toString()); - } + } + catch(DatabaseException ex) + { + error(ex.message); + } + catch(Ice.LocalException ex) + { + error(ex.toString()); + } } void setCurrentAddress(java.util.List args) { - if(args.size() != 1) - { - error("`address' requires exactly one argument (type `help' for more info)"); - return; - } + if(args.size() != 1) + { + error("`address' requires exactly one argument (type `help' for more info)"); + return; + } - try - { - if(_current != _foundContacts.length) - { - String addr = (String)args.get(0); - _foundContacts[_current].setAddress(addr); - System.out.println( "changed address to `" + addr + "'" ); - } - else - { - System.out.println( "no current contact" ); - } - } - catch(Ice.ObjectNotExistException ex) - { + try + { + if(_current != _foundContacts.length) + { + String addr = (String)args.get(0); + _foundContacts[_current].setAddress(addr); + System.out.println( "changed address to `" + addr + "'" ); + } + else + { + System.out.println( "no current contact" ); + } + } + catch(Ice.ObjectNotExistException ex) + { System.out.println("current contact no longer exists"); - } - catch(Ice.LocalException ex) - { - error(ex.toString()); - } + } + catch(Ice.LocalException ex) + { + error(ex.toString()); + } } void setCurrentPhone(java.util.List args) { - if(args.size() != 1) - { - error("`phone' requires exactly one argument (type `help' for more info)"); - return; - } + if(args.size() != 1) + { + error("`phone' requires exactly one argument (type `help' for more info)"); + return; + } - try - { - - if(_current != _foundContacts.length) - { - String number = (String)args.get(0); - _foundContacts[_current].setPhone(number); - System.out.println( "changed phone number to `" + number + "'" ); - } - else - { - System.out.println( "no current contact" ); - } - } - catch(Ice.ObjectNotExistException ex) - { + try + { + + if(_current != _foundContacts.length) + { + String number = (String)args.get(0); + _foundContacts[_current].setPhone(number); + System.out.println( "changed phone number to `" + number + "'" ); + } + else + { + System.out.println( "no current contact" ); + } + } + catch(Ice.ObjectNotExistException ex) + { System.out.println("current contact no longer exists"); - } - catch(Ice.LocalException ex) - { - error(ex.toString()); - } + } + catch(Ice.LocalException ex) + { + error(ex.toString()); + } } void removeCurrent() { - try - { - if(_current != _foundContacts.length) - { - _foundContacts[_current].destroy(); - System.out.println( "removed current contact" ); - } - else - { - System.out.println( "no current contact" ); - } - } - catch(Ice.ObjectNotExistException ex) - { + try + { + if(_current != _foundContacts.length) + { + _foundContacts[_current].destroy(); + System.out.println( "removed current contact" ); + } + else + { + System.out.println( "no current contact" ); + } + } + catch(Ice.ObjectNotExistException ex) + { System.out.println("current contact no longer exists"); - } - catch(DatabaseException ex) - { - error(ex.message); - } - catch(Ice.LocalException ex) - { - error(ex.toString()); - } + } + catch(DatabaseException ex) + { + error(ex.message); + } + catch(Ice.LocalException ex) + { + error(ex.toString()); + } } void setEvictorSize(java.util.List args) { - if(args.size() != 1) - { - error("`size' requires exactly one argument (type `help' for more info)"); - return; - } + if(args.size() != 1) + { + error("`size' requires exactly one argument (type `help' for more info)"); + return; + } - String s = (String)args.get(0); - try - { - _phoneBook.setEvictorSize(Integer.parseInt(s)); - } - catch(NumberFormatException ex) - { - error("not a number " + s); - } - catch(DatabaseException ex) - { - error(ex.message); - } - catch(Ice.LocalException ex) - { - error(ex.toString()); - } + String s = (String)args.get(0); + try + { + _phoneBook.setEvictorSize(Integer.parseInt(s)); + } + catch(NumberFormatException ex) + { + error("not a number " + s); + } + catch(DatabaseException ex) + { + error(ex.message); + } + catch(Ice.LocalException ex) + { + error(ex.toString()); + } } void shutdown() { - try - { - _phoneBook.shutdown(); - } - catch(Ice.LocalException ex) - { - error(ex.toString()); - } + try + { + _phoneBook.shutdown(); + } + catch(Ice.LocalException ex) + { + error(ex.toString()); + } } void error(String s) { - System.err.println("error: " + s); + System.err.println("error: " + s); } void warning(String s) { - System.err.println("warning: " + s); + System.err.println("warning: " + s); } String getInput() { - if(_interactive) - { - System.out.print(">>> "); - System.out.flush(); - } + if(_interactive) + { + System.out.print(">>> "); + System.out.flush(); + } - try - { - return _in.readLine(); - } - catch(java.io.IOException e) - { - return null; - } + try + { + return _in.readLine(); + } + catch(java.io.IOException e) + { + return null; + } } int parse() { - _foundContacts = new ContactPrx[0]; - _current = 0; + _foundContacts = new ContactPrx[0]; + _current = 0; - _in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); - _interactive = true; + _in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); + _interactive = true; - Grammar g = new Grammar(this); - g.parse(); + Grammar g = new Grammar(this); + g.parse(); - return 0; + return 0; } int parse(java.io.BufferedReader in) { - _foundContacts = new ContactPrx[0]; - _current = 0; + _foundContacts = new ContactPrx[0]; + _current = 0; - _in = in; - _interactive = false; + _in = in; + _interactive = false; - Grammar g = new Grammar(this); - g.parse(); + Grammar g = new Grammar(this); + g.parse(); - return 0; + return 0; } private ContactPrx[] _foundContacts; diff --git a/java/demo/Freeze/phonebook/PhoneBookI.java b/java/demo/Freeze/phonebook/PhoneBookI.java index a5e2205a4eb..ae91ab12882 100644 --- a/java/demo/Freeze/phonebook/PhoneBookI.java +++ b/java/demo/Freeze/phonebook/PhoneBookI.java @@ -13,75 +13,75 @@ class PhoneBookI extends _PhoneBookDisp { public ContactPrx createContact(Ice.Current current) - throws DatabaseException + throws DatabaseException { - // - // Generate a new unique identity. - // - Ice.Identity ident = new Ice.Identity(); - ident.name = Ice.Util.generateUUID(); - ident.category = "contact"; + // + // Generate a new unique identity. + // + Ice.Identity ident = new Ice.Identity(); + ident.name = Ice.Util.generateUUID(); + ident.category = "contact"; - // - // Create a new Contact Servant. - // - ContactI contact = new ContactI(_contactFactory); + // + // Create a new Contact Servant. + // + ContactI contact = new ContactI(_contactFactory); - // - // Create a new Ice Object in the evictor, using the new - // identity and the new Servant. - // - _evictor.add(contact, ident); + // + // Create a new Ice Object in the evictor, using the new + // identity and the new Servant. + // + _evictor.add(contact, ident); - return ContactPrxHelper.uncheckedCast(current.adapter.createProxy(ident)); + return ContactPrxHelper.uncheckedCast(current.adapter.createProxy(ident)); } public ContactPrx[] findContacts(String name, Ice.Current current) - throws DatabaseException + throws DatabaseException { - try - { - Ice.Identity[] identities = _index.find(name); + try + { + Ice.Identity[] identities = _index.find(name); - ContactPrx[] contacts = new ContactPrx[identities.length]; - for(int i = 0; i < identities.length; ++i) - { - contacts[i] = ContactPrxHelper.uncheckedCast - (current.adapter.createProxy(identities[i])); - } - return contacts; - } - catch(Freeze.DatabaseException ex) - { - DatabaseException e = new DatabaseException(); - e.message = ex.message; - throw e; - } + ContactPrx[] contacts = new ContactPrx[identities.length]; + for(int i = 0; i < identities.length; ++i) + { + contacts[i] = ContactPrxHelper.uncheckedCast + (current.adapter.createProxy(identities[i])); + } + return contacts; + } + catch(Freeze.DatabaseException ex) + { + DatabaseException e = new DatabaseException(); + e.message = ex.message; + throw e; + } } public void setEvictorSize(int size, Ice.Current current) - throws DatabaseException + throws DatabaseException { - // - // No synchronization necessary, _evictor is immutable. - // - _evictor.setSize(size); + // + // No synchronization necessary, _evictor is immutable. + // + _evictor.setSize(size); } public void shutdown(Ice.Current current) { - current.adapter.getCommunicator().shutdown(); + current.adapter.getCommunicator().shutdown(); } PhoneBookI(Freeze.Evictor evictor, ContactFactory contactFactory, - NameIndex index) + NameIndex index) { - _evictor = evictor; - _contactFactory = contactFactory; - _index = index; + _evictor = evictor; + _contactFactory = contactFactory; + _index = index; } private Freeze.Evictor _evictor; diff --git a/java/demo/Freeze/phonebook/RunParser.java b/java/demo/Freeze/phonebook/RunParser.java index 3c3bdd20ada..d26371a80c7 100644 --- a/java/demo/Freeze/phonebook/RunParser.java +++ b/java/demo/Freeze/phonebook/RunParser.java @@ -14,26 +14,26 @@ class RunParser static void usage(String appName) { - System.err.println("Usage: " + appName + " [options] [file...]\n"); - System.err.print( - "Options:\n" + - "-h, --help Show this message.\n"); - //"-v, --version Display the Ice version.\n" + System.err.println("Usage: " + appName + " [options] [file...]\n"); + System.err.print( + "Options:\n" + + "-h, --help Show this message.\n"); + //"-v, --version Display the Ice version.\n" } static int runParser(String appName, String[] args, Ice.Communicator communicator) { - String file = null; - int idx = 0; + String file = null; + int idx = 0; - while(idx < args.length) - { - if(args[idx].equals("-h") | args[idx].equals("--help")) - { - usage(appName); - return 0; - } + while(idx < args.length) + { + if(args[idx].equals("-h") | args[idx].equals("--help")) + { + usage(appName); + return 0; + } /* else if(args[idx].equals("-v") || args[idx].equals("--version")) { @@ -41,56 +41,56 @@ class RunParser return 0; } */ - else if(args[idx].charAt(0) == '-') - { - System.err.println(appName + ": unknown option `" + args[idx] + "'"); - usage(appName); - return 1; - } - else - { - if(file == null) - { - file = args[idx]; - } - else - { - System.err.println(appName + ": only one file is supported."); - usage(appName); - return 1; - } - ++idx; - } - } + else if(args[idx].charAt(0) == '-') + { + System.err.println(appName + ": unknown option `" + args[idx] + "'"); + usage(appName); + return 1; + } + else + { + if(file == null) + { + file = args[idx]; + } + else + { + System.err.println(appName + ": only one file is supported."); + usage(appName); + return 1; + } + ++idx; + } + } - Ice.ObjectPrx base = communicator.propertyToProxy("PhoneBook.Proxy"); - PhoneBookPrx phoneBook = PhoneBookPrxHelper.checkedCast(base); - if(phoneBook == null) - { - System.err.println(appName + ": invalid object reference"); - return 1; - } + Ice.ObjectPrx base = communicator.propertyToProxy("PhoneBook.Proxy"); + PhoneBookPrx phoneBook = PhoneBookPrxHelper.checkedCast(base); + if(phoneBook == null) + { + System.err.println(appName + ": invalid object reference"); + return 1; + } - Parser parser = new Parser(communicator, phoneBook); - int status; + Parser parser = new Parser(communicator, phoneBook); + int status; - if(file == null) - { - status = parser.parse(); - } - else - { - try - { - status = parser.parse(new java.io.BufferedReader(new java.io.FileReader(file))); - } - catch(java.io.IOException ex) - { - status = 1; - ex.printStackTrace(); - } - } + if(file == null) + { + status = parser.parse(); + } + else + { + try + { + status = parser.parse(new java.io.BufferedReader(new java.io.FileReader(file))); + } + catch(java.io.IOException ex) + { + status = 1; + ex.printStackTrace(); + } + } - return status; + return status; } } diff --git a/java/demo/Freeze/phonebook/Scanner.java b/java/demo/Freeze/phonebook/Scanner.java index e30cf50c485..0fa47a2e3af 100644 --- a/java/demo/Freeze/phonebook/Scanner.java +++ b/java/demo/Freeze/phonebook/Scanner.java @@ -11,74 +11,74 @@ class Scanner { Scanner(Parser p) { - _parser = p; + _parser = p; } Token nextToken() { - String s = next(); - if(s == null) - { - return null; - } + String s = next(); + if(s == null) + { + return null; + } - if(s.equals(";")) - { - return new Token(Token.TOK_SEMI); - } - else if(s.equals("help")) - { - return new Token(Token.TOK_HELP); - } - else if(s.equals("exit") || s.equals("quit")) - { - return new Token(Token.TOK_EXIT); - } - else if(s.equals("add")) - { - return new Token(Token.TOK_ADD_CONTACTS); - } - else if(s.equals("find")) - { - return new Token(Token.TOK_FIND_CONTACTS); - } - else if(s.equals("next")) - { - return new Token(Token.TOK_NEXT_FOUND_CONTACT); - } - else if(s.equals("current")) - { - return new Token(Token.TOK_PRINT_CURRENT); - } - else if(s.equals("name")) - { - return new Token(Token.TOK_SET_CURRENT_NAME); - } - else if(s.equals("address")) - { - return new Token(Token.TOK_SET_CURRENT_ADDRESS); - } - else if(s.equals("phone")) - { - return new Token(Token.TOK_SET_CURRENT_PHONE); - } - else if(s.equals("remove")) - { - return new Token(Token.TOK_REMOVE_CURRENT); - } - else if(s.equals("size")) - { - return new Token(Token.TOK_SET_EVICTOR_SIZE); - } - else if(s.equals("shutdown")) - { - return new Token(Token.TOK_SHUTDOWN); - } - else - { - return new Token(Token.TOK_STRING, s); - } + if(s.equals(";")) + { + return new Token(Token.TOK_SEMI); + } + else if(s.equals("help")) + { + return new Token(Token.TOK_HELP); + } + else if(s.equals("exit") || s.equals("quit")) + { + return new Token(Token.TOK_EXIT); + } + else if(s.equals("add")) + { + return new Token(Token.TOK_ADD_CONTACTS); + } + else if(s.equals("find")) + { + return new Token(Token.TOK_FIND_CONTACTS); + } + else if(s.equals("next")) + { + return new Token(Token.TOK_NEXT_FOUND_CONTACT); + } + else if(s.equals("current")) + { + return new Token(Token.TOK_PRINT_CURRENT); + } + else if(s.equals("name")) + { + return new Token(Token.TOK_SET_CURRENT_NAME); + } + else if(s.equals("address")) + { + return new Token(Token.TOK_SET_CURRENT_ADDRESS); + } + else if(s.equals("phone")) + { + return new Token(Token.TOK_SET_CURRENT_PHONE); + } + else if(s.equals("remove")) + { + return new Token(Token.TOK_REMOVE_CURRENT); + } + else if(s.equals("size")) + { + return new Token(Token.TOK_SET_EVICTOR_SIZE); + } + else if(s.equals("shutdown")) + { + return new Token(Token.TOK_SHUTDOWN); + } + else + { + return new Token(Token.TOK_STRING, s); + } } static private class EndOfInput extends Exception @@ -87,41 +87,41 @@ class Scanner private char get() - throws EndOfInput + throws EndOfInput { - // - // If there is an character in the unget buffer, return it. - // - if(_unget) - { - _unget = false; - return _ungetChar; - } + // + // If there is an character in the unget buffer, return it. + // + if(_unget) + { + _unget = false; + return _ungetChar; + } - // - // No current buffer? - // - if(_buf == null) - { - _buf = _parser.getInput(); - _pos = 0; - if(_buf == null) - { - throw new EndOfInput(); - } - } + // + // No current buffer? + // + if(_buf == null) + { + _buf = _parser.getInput(); + _pos = 0; + if(_buf == null) + { + throw new EndOfInput(); + } + } - // - // At the end-of-buffer? - // - while(_pos >= _buf.length()) - { - _buf = null; - _pos = 0; - return '\n'; - } + // + // At the end-of-buffer? + // + while(_pos >= _buf.length()) + { + _buf = null; + _pos = 0; + return '\n'; + } - return _buf.charAt(_pos++); + return _buf.charAt(_pos++); } // @@ -130,153 +130,153 @@ class Scanner private void unget(char c) { - assert(!_unget); - _unget = true; - _ungetChar = c; + assert(!_unget); + _unget = true; + _ungetChar = c; } private String next() { - // - // Eat any whitespace. - // - char c; - try - { - do - { - c = get(); - } - while(Character.isWhitespace(c) && c != '\n'); - } - catch(EndOfInput ignore) - { - return null; - } + // + // Eat any whitespace. + // + char c; + try + { + do + { + c = get(); + } + while(Character.isWhitespace(c) && c != '\n'); + } + catch(EndOfInput ignore) + { + return null; + } - StringBuffer buf = new StringBuffer(); + StringBuffer buf = new StringBuffer(); - if(c == ';' || c == '\n') - { - buf.append(';'); - } - else if(c == '\'') - { - try - { - while(true) - { - c = get(); - if(c == '\'') - { - break; - } - else - { - buf.append(c); - } - } - } - catch(EndOfInput e) - { - _parser.warning("EOF in string"); - } - } - else if(c == '\"') - { - try - { - while(true) - { - c = get(); - if(c == '\"') - { - break; - } - else if(c == '\\') - { - try - { - char next = get(); - switch(next) - { - case '\\': - case '"': - { - buf.append(next); - break; - } - - case 'n': - { - buf.append('\n'); - break; - } - - case 'r': - { - buf.append('\r'); - break; - } - - case 't': - { - buf.append('\t'); - break; - } - - case 'f': - { - buf.append('\f'); - break; - } - - default: - { - buf.append(c); - unget(next); - } - } - } - catch(EndOfInput e) - { - buf.append(c); - } - } - else - { - buf.append(c); - } - } - } - catch(EndOfInput e) - { - _parser.warning("EOF in string"); - } - } - else - { - // - // Otherwise it's a string. - // - try - { - do - { - buf.append(c); - c = get(); - } - while(!Character.isWhitespace(c) && c != ';' && c != '\n'); + if(c == ';' || c == '\n') + { + buf.append(';'); + } + else if(c == '\'') + { + try + { + while(true) + { + c = get(); + if(c == '\'') + { + break; + } + else + { + buf.append(c); + } + } + } + catch(EndOfInput e) + { + _parser.warning("EOF in string"); + } + } + else if(c == '\"') + { + try + { + while(true) + { + c = get(); + if(c == '\"') + { + break; + } + else if(c == '\\') + { + try + { + char next = get(); + switch(next) + { + case '\\': + case '"': + { + buf.append(next); + break; + } + + case 'n': + { + buf.append('\n'); + break; + } + + case 'r': + { + buf.append('\r'); + break; + } + + case 't': + { + buf.append('\t'); + break; + } + + case 'f': + { + buf.append('\f'); + break; + } + + default: + { + buf.append(c); + unget(next); + } + } + } + catch(EndOfInput e) + { + buf.append(c); + } + } + else + { + buf.append(c); + } + } + } + catch(EndOfInput e) + { + _parser.warning("EOF in string"); + } + } + else + { + // + // Otherwise it's a string. + // + try + { + do + { + buf.append(c); + c = get(); + } + while(!Character.isWhitespace(c) && c != ';' && c != '\n'); - unget(c); - } - catch(EndOfInput ignore) - { - } - } - - return buf.toString(); + unget(c); + } + catch(EndOfInput ignore) + { + } + } + + return buf.toString(); } private Parser _parser; diff --git a/java/demo/Freeze/phonebook/Server.java b/java/demo/Freeze/phonebook/Server.java index ac864e565f1..2556238ceae 100644 --- a/java/demo/Freeze/phonebook/Server.java +++ b/java/demo/Freeze/phonebook/Server.java @@ -12,73 +12,73 @@ class PhoneBookServer extends Ice.Application public int run(String[] args) { - Ice.Properties properties = communicator().getProperties(); + Ice.Properties properties = communicator().getProperties(); - // - // Create and install a factory for contacts. - // - ContactFactory contactFactory = new ContactFactory(); - communicator().addObjectFactory(contactFactory, "::Demo::Contact"); + // + // Create and install a factory for contacts. + // + ContactFactory contactFactory = new ContactFactory(); + communicator().addObjectFactory(contactFactory, "::Demo::Contact"); - // - // Create an object adapter - // - Ice.ObjectAdapter adapter = communicator().createObjectAdapter("PhoneBook"); + // + // Create an object adapter + // + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("PhoneBook"); - // - // Create the name index. - // - NameIndex index = new NameIndex("name"); - Freeze.Index[] indices = new Freeze.Index[1]; - indices[0] = index; + // + // Create the name index. + // + NameIndex index = new NameIndex("name"); + Freeze.Index[] indices = new Freeze.Index[1]; + indices[0] = index; - // - // Create an evictor for contacts. - // When Freeze.Evictor.db.contacts.PopulateEmptyIndices is not 0 and the - // Name index is empty, Freeze will traverse the database to recreate - // the index during createEvictor(). Therefore the factories for the objects - // stored in evictor (contacts here) must be registered before the call - // to createEvictor(). - // - Freeze.Evictor evictor = Freeze.Util.createEvictor(adapter, _envName, "contacts", null, indices, true); - int evictorSize = properties.getPropertyAsInt("PhoneBook.EvictorSize"); - if(evictorSize > 0) - { - evictor.setSize(evictorSize); - } + // + // Create an evictor for contacts. + // When Freeze.Evictor.db.contacts.PopulateEmptyIndices is not 0 and the + // Name index is empty, Freeze will traverse the database to recreate + // the index during createEvictor(). Therefore the factories for the objects + // stored in evictor (contacts here) must be registered before the call + // to createEvictor(). + // + Freeze.Evictor evictor = Freeze.Util.createEvictor(adapter, _envName, "contacts", null, indices, true); + int evictorSize = properties.getPropertyAsInt("PhoneBook.EvictorSize"); + if(evictorSize > 0) + { + evictor.setSize(evictorSize); + } - // - // Completes the initialization of the contact factory. Note that ContactI/ - // ContactFactoryI uses this evictor only when a Contact is destroyed, - // which cannot happen during createEvictor(). - // - contactFactory.setEvictor(evictor); + // + // Completes the initialization of the contact factory. Note that ContactI/ + // ContactFactoryI uses this evictor only when a Contact is destroyed, + // which cannot happen during createEvictor(). + // + contactFactory.setEvictor(evictor); - // - // Register the evictor with the adapter - // - adapter.addServantLocator(evictor, "contact"); + // + // Register the evictor with the adapter + // + adapter.addServantLocator(evictor, "contact"); - // - // Create the phonebook, and add it to the object adapter. - // - PhoneBookI phoneBook = new PhoneBookI(evictor, contactFactory, index); - adapter.add(phoneBook, communicator().stringToIdentity("phonebook")); + // + // Create the phonebook, and add it to the object adapter. + // + PhoneBookI phoneBook = new PhoneBookI(evictor, contactFactory, index); + adapter.add(phoneBook, communicator().stringToIdentity("phonebook")); - // - // Everything ok, let's go. - // - adapter.activate(); + // + // Everything ok, let's go. + // + adapter.activate(); - shutdownOnInterrupt(); - communicator().waitForShutdown(); - defaultInterrupt(); - return 0; + shutdownOnInterrupt(); + communicator().waitForShutdown(); + defaultInterrupt(); + return 0; } PhoneBookServer(String envName) { - _envName = envName; + _envName = envName; } private String _envName; @@ -89,7 +89,7 @@ public class Server static public void main(String[] args) { - PhoneBookServer app = new PhoneBookServer("db"); - app.main("demo.Freeze.phonebook.Server", args, "config.server"); + PhoneBookServer app = new PhoneBookServer("db"); + app.main("demo.Freeze.phonebook.Server", args, "config.server"); } } diff --git a/java/demo/Freeze/phonebook/Token.java b/java/demo/Freeze/phonebook/Token.java index 6b598e4a011..9e9ad211ba1 100644 --- a/java/demo/Freeze/phonebook/Token.java +++ b/java/demo/Freeze/phonebook/Token.java @@ -29,13 +29,13 @@ class Token Token(int t) { - type = t; - value = null; + type = t; + value = null; } Token(int t, String v) { - type = t; - value = v; + type = t; + value = v; } } |