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 | |
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')
79 files changed, 4709 insertions, 4709 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; } } diff --git a/java/demo/Glacier2/callback/CallbackI.java b/java/demo/Glacier2/callback/CallbackI.java index ad15e477242..5165a6e7431 100644 --- a/java/demo/Glacier2/callback/CallbackI.java +++ b/java/demo/Glacier2/callback/CallbackI.java @@ -15,27 +15,27 @@ public final class CallbackI extends _CallbackDisp initiateCallback(CallbackReceiverPrx proxy, Ice.Current current) { System.out.println("initiating callback"); - try - { - proxy.callback(current.ctx); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - } + try + { + proxy.callback(current.ctx); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } } public void shutdown(Ice.Current current) { System.out.println("Shutting down..."); - try - { - current.adapter.getCommunicator().shutdown(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - } + try + { + current.adapter.getCommunicator().shutdown(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } } } diff --git a/java/demo/Glacier2/callback/Client.java b/java/demo/Glacier2/callback/Client.java index 8f76465789a..2d70db5fa7c 100644 --- a/java/demo/Glacier2/callback/Client.java +++ b/java/demo/Glacier2/callback/Client.java @@ -13,18 +13,18 @@ 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(); + } + } } private static void @@ -36,8 +36,8 @@ public class Client extends Ice.Application "o: send callback as oneway\n" + "O: send callback as batch oneway\n" + "f: flush all batch requests\n" + - "v: set/reset override context field\n" + - "F: set/reset fake category\n" + + "v: set/reset override context field\n" + + "F: set/reset fake category\n" + "s: shutdown server\n" + "x: exit\n" + "?: help\n"); @@ -46,71 +46,71 @@ public class Client extends Ice.Application 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.RouterPrx defaultRouter = communicator().getDefaultRouter(); - if(defaultRouter == null) - { - System.err.println("no default router set"); - return 1; - } - - Glacier2.RouterPrx router = Glacier2.RouterPrxHelper.checkedCast(defaultRouter); - if(router == null) - { - System.err.println("configured router is not a Glacier2 router"); - return 1; - } + Ice.RouterPrx defaultRouter = communicator().getDefaultRouter(); + if(defaultRouter == null) + { + System.err.println("no default router set"); + return 1; + } + + Glacier2.RouterPrx router = Glacier2.RouterPrxHelper.checkedCast(defaultRouter); + if(router == null) + { + System.err.println("configured router is not a Glacier2 router"); + return 1; + } java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); - while(true) - { - System.out.println("This demo accepts any user-id / password combination."); + while(true) + { + System.out.println("This demo accepts any user-id / password combination."); - try - { - String id; - System.out.print("user id: "); - System.out.flush(); - id = in.readLine(); - - String pw; - System.out.print("password: "); - System.out.flush(); - pw = in.readLine(); - - try - { - router.createSession(id, pw); - break; - } - catch(Glacier2.PermissionDeniedException ex) - { - System.out.println("permission denied:\n" + ex.reason); - } - catch(Glacier2.CannotCreateSessionException ex) - { - System.out.println("cannot create session:\n" + ex.reason); - } - } + try + { + String id; + System.out.print("user id: "); + System.out.flush(); + id = in.readLine(); + + String pw; + System.out.print("password: "); + System.out.flush(); + pw = in.readLine(); + + try + { + router.createSession(id, pw); + break; + } + catch(Glacier2.PermissionDeniedException ex) + { + System.out.println("permission denied:\n" + ex.reason); + } + catch(Glacier2.CannotCreateSessionException ex) + { + System.out.println("cannot create session:\n" + ex.reason); + } + } catch(java.io.IOException ex) { ex.printStackTrace(); } - } + } - String category = router.getCategoryForClient(); - Ice.Identity callbackReceiverIdent = new Ice.Identity(); - callbackReceiverIdent.name = "callbackReceiver"; - callbackReceiverIdent.category = category; - Ice.Identity callbackReceiverFakeIdent = new Ice.Identity(); - callbackReceiverFakeIdent.name = "callbackReceiver"; - callbackReceiverFakeIdent.category = "fake"; + String category = router.getCategoryForClient(); + Ice.Identity callbackReceiverIdent = new Ice.Identity(); + callbackReceiverIdent.name = "callbackReceiver"; + callbackReceiverIdent.category = category; + Ice.Identity callbackReceiverFakeIdent = new Ice.Identity(); + callbackReceiverFakeIdent.name = "callbackReceiver"; + callbackReceiverFakeIdent.category = "fake"; Ice.ObjectPrx base = communicator().propertyToProxy("Callback.Proxy"); CallbackPrx twoway = CallbackPrxHelper.checkedCast(base); @@ -123,14 +123,14 @@ public class Client extends Ice.Application adapter.activate(); CallbackReceiverPrx twowayR = CallbackReceiverPrxHelper.uncheckedCast( - adapter.createProxy(callbackReceiverIdent)); + adapter.createProxy(callbackReceiverIdent)); CallbackReceiverPrx onewayR = CallbackReceiverPrxHelper.uncheckedCast(twowayR.ice_oneway()); menu(); String line = null; - String override = null; - boolean fake = false; + String override = null; + boolean fake = false; do { try @@ -144,73 +144,73 @@ public class Client extends Ice.Application } if(line.equals("t")) { - java.util.Map context = new java.util.HashMap(); - context.put("_fwd", "t"); - if(override != null) - { - context.put("_ovrd", override); - } + java.util.Map context = new java.util.HashMap(); + context.put("_fwd", "t"); + if(override != null) + { + context.put("_ovrd", override); + } twoway.initiateCallback(twowayR, context); } else if(line.equals("o")) { - java.util.Map context = new java.util.HashMap(); - context.put("_fwd", "o"); - if(override != null) - { - context.put("_ovrd", override); - } + java.util.Map context = new java.util.HashMap(); + context.put("_fwd", "o"); + if(override != null) + { + context.put("_ovrd", override); + } oneway.initiateCallback(onewayR, context); } else if(line.equals("O")) { - java.util.Map context = new java.util.HashMap(); - context.put("_fwd", "O"); - if(override != null) - { - context.put("_ovrd", override); - } - batchOneway.initiateCallback(onewayR, context); + java.util.Map context = new java.util.HashMap(); + context.put("_fwd", "O"); + if(override != null) + { + context.put("_ovrd", override); + } + batchOneway.initiateCallback(onewayR, context); } else if(line.equals("f")) { - communicator().flushBatchRequests(); + communicator().flushBatchRequests(); + } + else if(line.equals("v")) + { + if(override == null) + { + override = "some_value"; + System.out.println("override context field is now `" + override + "'"); + } + else + { + override = null; + System.out.println("override context field is empty"); + } + } + else if(line.equals("F")) + { + fake = !fake; + + if(fake) + { + twowayR = CallbackReceiverPrxHelper.uncheckedCast( + twowayR.ice_identity(callbackReceiverFakeIdent)); + onewayR = CallbackReceiverPrxHelper.uncheckedCast( + onewayR.ice_identity(callbackReceiverFakeIdent)); + } + else + { + twowayR = CallbackReceiverPrxHelper.uncheckedCast( + twowayR.ice_identity(callbackReceiverIdent)); + onewayR = CallbackReceiverPrxHelper.uncheckedCast( + onewayR.ice_identity(callbackReceiverIdent)); + } + + System.out.println("callback receiver identity: " + + communicator().identityToString(twowayR.ice_getIdentity())); } - else if(line.equals("v")) - { - if(override == null) - { - override = "some_value"; - System.out.println("override context field is now `" + override + "'"); - } - else - { - override = null; - System.out.println("override context field is empty"); - } - } - else if(line.equals("F")) - { - fake = !fake; - - if(fake) - { - twowayR = CallbackReceiverPrxHelper.uncheckedCast( - twowayR.ice_identity(callbackReceiverFakeIdent)); - onewayR = CallbackReceiverPrxHelper.uncheckedCast( - onewayR.ice_identity(callbackReceiverFakeIdent)); - } - else - { - twowayR = CallbackReceiverPrxHelper.uncheckedCast( - twowayR.ice_identity(callbackReceiverIdent)); - onewayR = CallbackReceiverPrxHelper.uncheckedCast( - onewayR.ice_identity(callbackReceiverIdent)); - } - - System.out.println("callback receiver identity: " + - communicator().identityToString(twowayR.ice_getIdentity())); - } else if(line.equals("s")) { twoway.shutdown(); diff --git a/java/demo/Glacier2/callback/Server.java b/java/demo/Glacier2/callback/Server.java index c71dce1b4ca..6c994eec66a 100644 --- a/java/demo/Glacier2/callback/Server.java +++ b/java/demo/Glacier2/callback/Server.java @@ -17,7 +17,7 @@ public class Server extends Ice.Application Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Callback.Server"); adapter.add(new CallbackI(), communicator().stringToIdentity("callback")); adapter.activate(); - communicator().waitForShutdown(); + communicator().waitForShutdown(); return 0; } diff --git a/java/demo/Glacier2/callback/SessionI.java b/java/demo/Glacier2/callback/SessionI.java index e5225f17eec..bff3178ffd8 100644 --- a/java/demo/Glacier2/callback/SessionI.java +++ b/java/demo/Glacier2/callback/SessionI.java @@ -11,14 +11,14 @@ public final class SessionI extends Glacier2._SessionDisp { SessionI(String userId) { - _userId = userId; + _userId = userId; } public void destroy(Ice.Current current) { - System.out.println("destroying session for user `" + _userId + "'"); - current.adapter.remove(current.id); + System.out.println("destroying session for user `" + _userId + "'"); + current.adapter.remove(current.id); } final private String _userId; diff --git a/java/demo/Glacier2/callback/SessionManagerI.java b/java/demo/Glacier2/callback/SessionManagerI.java index 5063db2b209..2dffa9206a1 100644 --- a/java/demo/Glacier2/callback/SessionManagerI.java +++ b/java/demo/Glacier2/callback/SessionManagerI.java @@ -12,8 +12,8 @@ public final class SessionManagerI extends Glacier2._SessionManagerDisp public Glacier2.SessionPrx create(String userId, Glacier2.SessionControlPrx control, Ice.Current current) { - System.out.println("creating session for user `" + userId + "'"); - Glacier2.Session session = new SessionI(userId); - return Glacier2.SessionPrxHelper.uncheckedCast(current.adapter.addWithUUID(session)); + System.out.println("creating session for user `" + userId + "'"); + Glacier2.Session session = new SessionI(userId); + return Glacier2.SessionPrxHelper.uncheckedCast(current.adapter.addWithUUID(session)); } } diff --git a/java/demo/Glacier2/callback/SessionServer.java b/java/demo/Glacier2/callback/SessionServer.java index 82aee95c839..5f3bf6d1464 100644 --- a/java/demo/Glacier2/callback/SessionServer.java +++ b/java/demo/Glacier2/callback/SessionServer.java @@ -11,32 +11,32 @@ public class SessionServer { static final class DummyPermissionVerifierI extends Glacier2._PermissionsVerifierDisp { - public boolean - checkPermissions(String userId, String password, Ice.StringHolder reason, Ice.Current current) - { - System.out.println("verified user `" + userId + "' with password `" + password + "'"); - return true; - } + public boolean + checkPermissions(String userId, String password, Ice.StringHolder reason, Ice.Current current) + { + System.out.println("verified user `" + userId + "' with password `" + password + "'"); + return true; + } }; static class Application extends Ice.Application { - public int - run(String[] args) - { - Ice.ObjectAdapter adapter = communicator().createObjectAdapter("SessionServer"); - adapter.add(new DummyPermissionVerifierI(), communicator().stringToIdentity("verifier")); - adapter.add(new SessionManagerI(), communicator().stringToIdentity("sessionmanager")); - adapter.activate(); - communicator().waitForShutdown(); - return 0; - } + public int + run(String[] args) + { + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("SessionServer"); + adapter.add(new DummyPermissionVerifierI(), communicator().stringToIdentity("verifier")); + adapter.add(new SessionManagerI(), communicator().stringToIdentity("sessionmanager")); + adapter.activate(); + communicator().waitForShutdown(); + return 0; + } }; public static void main(String[] args) { - Application app = new Application(); + Application app = new Application(); int status = app.main("Server", args, "config.sessionserver"); System.exit(status); } diff --git a/java/demo/Ice/async/Client.java b/java/demo/Ice/async/Client.java index 3a89d037dd2..d87aee7e8a1 100644 --- a/java/demo/Ice/async/Client.java +++ b/java/demo/Ice/async/Client.java @@ -30,25 +30,25 @@ public class Client extends Ice.Application public class AMI_Hello_sayHelloI extends AMI_Hello_sayHello { public void ice_response() - { - } + { + } - public void ice_exception(Ice.LocalException ex) - { - ex.printStackTrace(); - } + public void ice_exception(Ice.LocalException ex) + { + ex.printStackTrace(); + } - public void ice_exception(Ice.UserException ex) - { - if(ex instanceof Demo.RequestCanceledException) - { - System.out.println("Request canceled"); - } - else - { - ex.printStackTrace(); - } - } + public void ice_exception(Ice.UserException ex) + { + if(ex instanceof Demo.RequestCanceledException) + { + System.out.println("Request canceled"); + } + else + { + ex.printStackTrace(); + } + } } private static void @@ -71,7 +71,7 @@ public class Client extends Ice.Application // Application installed interrupt callback and install our // own shutdown hook. // - setInterruptHook(new ShutdownHook()); + setInterruptHook(new ShutdownHook()); HelloPrx hello = HelloPrxHelper.checkedCast(communicator().propertyToProxy("Hello.Proxy")); if(hello == null) @@ -98,16 +98,16 @@ public class Client extends Ice.Application } if(line.equals("i")) { - hello.sayHello(0); + hello.sayHello(0); } else if(line.equals("d")) { hello.sayHello_async(new AMI_Hello_sayHelloI(), 5000); - } + } else if(line.equals("s")) { - hello.shutdown(); - } + hello.shutdown(); + } else if(line.equals("x")) { // Nothing to do diff --git a/java/demo/Ice/async/HelloI.java b/java/demo/Ice/async/HelloI.java index ce555b3e9dd..9df4d2c71cc 100644 --- a/java/demo/Ice/async/HelloI.java +++ b/java/demo/Ice/async/HelloI.java @@ -21,14 +21,14 @@ public class HelloI extends _HelloDisp sayHello_async(AMD_Hello_sayHello cb, int delay, Ice.Current current) { if(delay == 0) - { - System.out.println("Hello World!"); - cb.ice_response(); - } - else - { - _workQueue.add(cb, delay); - } + { + System.out.println("Hello World!"); + cb.ice_response(); + } + else + { + _workQueue.add(cb, delay); + } } public void @@ -36,16 +36,16 @@ public class HelloI extends _HelloDisp { System.out.println("Shutting down..."); - _workQueue.destroy(); - try - { - _workQueue.join(); - } - catch(java.lang.InterruptedException ex) - { - } + _workQueue.destroy(); + try + { + _workQueue.join(); + } + catch(java.lang.InterruptedException ex) + { + } - current.adapter.getCommunicator().shutdown(); + current.adapter.getCommunicator().shutdown(); } private WorkQueue _workQueue; diff --git a/java/demo/Ice/async/Server.java b/java/demo/Ice/async/Server.java index 6077a8b9a34..25ba4e2baac 100644 --- a/java/demo/Ice/async/Server.java +++ b/java/demo/Ice/async/Server.java @@ -16,14 +16,14 @@ public class Server extends Ice.Application public void run() { - _workQueue.destroy(); - try - { - _workQueue.join(); - } - catch(java.lang.InterruptedException ex) - { - } + _workQueue.destroy(); + try + { + _workQueue.join(); + } + catch(java.lang.InterruptedException ex) + { + } try { @@ -39,13 +39,13 @@ public class Server extends Ice.Application public int run(String[] args) { - setInterruptHook(new ShutdownHook()); + setInterruptHook(new ShutdownHook()); Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Hello"); - _workQueue = new WorkQueue(); + _workQueue = new WorkQueue(); adapter.add(new HelloI(_workQueue), communicator().stringToIdentity("hello")); - _workQueue.start(); + _workQueue.start(); adapter.activate(); communicator().waitForShutdown(); diff --git a/java/demo/Ice/async/WorkQueue.java b/java/demo/Ice/async/WorkQueue.java index 036a1978b49..bc18061058a 100644 --- a/java/demo/Ice/async/WorkQueue.java +++ b/java/demo/Ice/async/WorkQueue.java @@ -14,100 +14,100 @@ public class WorkQueue extends Thread class CallbackEntry { AMD_Hello_sayHello cb; - int delay; + int delay; } public synchronized void run() { while(!_done) - { - if(_callbacks.size() == 0) - { - try - { - wait(); - } - catch(java.lang.InterruptedException ex) - { - } - } + { + if(_callbacks.size() == 0) + { + try + { + wait(); + } + catch(java.lang.InterruptedException ex) + { + } + } - if(_callbacks.size() != 0) - { - // - // Get next work item. - // - CallbackEntry entry = (CallbackEntry)_callbacks.getFirst(); + if(_callbacks.size() != 0) + { + // + // Get next work item. + // + CallbackEntry entry = (CallbackEntry)_callbacks.getFirst(); - // - // Wait for the amount of time indicated in delay to - // emulate a process that takes a significant period of - // time to complete. - // - try - { - wait(entry.delay); - } - catch(java.lang.InterruptedException ex) - { - } + // + // Wait for the amount of time indicated in delay to + // emulate a process that takes a significant period of + // time to complete. + // + try + { + wait(entry.delay); + } + catch(java.lang.InterruptedException ex) + { + } - if(!_done) - { - // - // Print greeting and send response. - // - _callbacks.removeFirst(); - System.err.println("Belated Hello World!"); - entry.cb.ice_response(); - } - } - } + if(!_done) + { + // + // Print greeting and send response. + // + _callbacks.removeFirst(); + System.err.println("Belated Hello World!"); + entry.cb.ice_response(); + } + } + } - // - // Throw exception for any outstanding requests. - // - java.util.Iterator p = _callbacks.iterator(); - while(p.hasNext()) - { - CallbackEntry entry = (CallbackEntry)p.next(); - entry.cb.ice_exception(new RequestCanceledException()); - } + // + // Throw exception for any outstanding requests. + // + java.util.Iterator p = _callbacks.iterator(); + while(p.hasNext()) + { + CallbackEntry entry = (CallbackEntry)p.next(); + entry.cb.ice_exception(new RequestCanceledException()); + } } public synchronized void add(AMD_Hello_sayHello cb, int delay) { if(!_done) - { - // - // Add the work item. - // - CallbackEntry entry = new CallbackEntry(); - entry.cb = cb; - entry.delay = delay; + { + // + // Add the work item. + // + CallbackEntry entry = new CallbackEntry(); + entry.cb = cb; + entry.delay = delay; - if(_callbacks.size() == 0) - { - notify(); - } - _callbacks.add(entry); - } - else - { - // - // Destroyed, throw exception. - // - cb.ice_exception(new RequestCanceledException()); - } + if(_callbacks.size() == 0) + { + notify(); + } + _callbacks.add(entry); + } + else + { + // + // Destroyed, throw exception. + // + cb.ice_exception(new RequestCanceledException()); + } } public synchronized void destroy() { _done = true; - notify(); + notify(); } private java.util.LinkedList _callbacks = new java.util.LinkedList(); diff --git a/java/demo/Ice/bidir/CallbackSenderI.java b/java/demo/Ice/bidir/CallbackSenderI.java index 71a8745f900..05805692ca7 100755 --- a/java/demo/Ice/bidir/CallbackSenderI.java +++ b/java/demo/Ice/bidir/CallbackSenderI.java @@ -19,56 +19,56 @@ class CallbackSenderI extends _CallbackSenderDisp implements java.lang.Runnable synchronized public void destroy() { - System.out.println("destroying callback sender"); - _destroy = true; + System.out.println("destroying callback sender"); + _destroy = true; - this.notify(); + this.notify(); } synchronized public void addClient(Ice.Identity ident, Ice.Current current) { - System.out.println("adding client `" + _communicator.identityToString(ident) + "'"); + System.out.println("adding client `" + _communicator.identityToString(ident) + "'"); - Ice.ObjectPrx base = current.con.createProxy(ident); - CallbackReceiverPrx client = CallbackReceiverPrxHelper.uncheckedCast(base); - _clients.addElement(client); + Ice.ObjectPrx base = current.con.createProxy(ident); + CallbackReceiverPrx client = CallbackReceiverPrxHelper.uncheckedCast(base); + _clients.addElement(client); } synchronized public void run() { - while(!_destroy) - { - try - { - this.wait(2000); - } - catch(java.lang.InterruptedException ex) - { - } + while(!_destroy) + { + try + { + this.wait(2000); + } + catch(java.lang.InterruptedException ex) + { + } - if(!_destroy && !_clients.isEmpty()) - { - ++_num; + if(!_destroy && !_clients.isEmpty()) + { + ++_num; - java.util.Iterator p = _clients.iterator(); - while(p.hasNext()) - { - CallbackReceiverPrx r = (CallbackReceiverPrx)p.next(); - try - { - r.callback(_num); - } - catch(Exception ex) - { - System.out.println("removing client `" + _communicator.identityToString(r.ice_getIdentity()) + "':"); - ex.printStackTrace(); - p.remove(); - } - } - } - } + java.util.Iterator p = _clients.iterator(); + while(p.hasNext()) + { + CallbackReceiverPrx r = (CallbackReceiverPrx)p.next(); + try + { + r.callback(_num); + } + catch(Exception ex) + { + System.out.println("removing client `" + _communicator.identityToString(r.ice_getIdentity()) + "':"); + ex.printStackTrace(); + p.remove(); + } + } + } + } } private Ice.Communicator _communicator; diff --git a/java/demo/Ice/bidir/Client.java b/java/demo/Ice/bidir/Client.java index b7c3136f220..84c4989a6e5 100755 --- a/java/demo/Ice/bidir/Client.java +++ b/java/demo/Ice/bidir/Client.java @@ -15,7 +15,7 @@ public class Client extends Ice.Application run(String[] args) { CallbackSenderPrx server = - CallbackSenderPrxHelper.checkedCast(communicator().propertyToProxy("Callback.Client.CallbackServer")); + CallbackSenderPrxHelper.checkedCast(communicator().propertyToProxy("Callback.Client.CallbackServer")); if(server == null) { System.err.println("invalid proxy"); @@ -23,14 +23,14 @@ public class Client extends Ice.Application } Ice.ObjectAdapter adapter = communicator().createObjectAdapter(""); - Ice.Identity ident = new Ice.Identity(); - ident.name = Ice.Util.generateUUID(); - ident.category = ""; + Ice.Identity ident = new Ice.Identity(); + ident.name = Ice.Util.generateUUID(); + ident.category = ""; adapter.add(new CallbackReceiverI(), ident); adapter.activate(); - server.ice_getConnection().setAdapter(adapter); - server.addClient(ident); - communicator().waitForShutdown(); + server.ice_getConnection().setAdapter(adapter); + server.addClient(ident); + communicator().waitForShutdown(); return 0; } diff --git a/java/demo/Ice/bidir/Server.java b/java/demo/Ice/bidir/Server.java index 2a97cc22795..47106babf54 100755 --- a/java/demo/Ice/bidir/Server.java +++ b/java/demo/Ice/bidir/Server.java @@ -19,24 +19,24 @@ public class Server extends Ice.Application adapter.add(sender, communicator().stringToIdentity("sender")); adapter.activate(); - Thread t = new Thread(sender); - t.start(); + Thread t = new Thread(sender); + t.start(); - try - { - communicator().waitForShutdown(); - } - finally - { - sender.destroy(); - try - { - t.join(); - } - catch(java.lang.InterruptedException ex) - { - } - } + try + { + communicator().waitForShutdown(); + } + finally + { + sender.destroy(); + try + { + t.join(); + } + catch(java.lang.InterruptedException ex) + { + } + } return 0; } diff --git a/java/demo/Ice/callback/CallbackSenderI.java b/java/demo/Ice/callback/CallbackSenderI.java index 617c7f1af42..dacda16de3f 100644 --- a/java/demo/Ice/callback/CallbackSenderI.java +++ b/java/demo/Ice/callback/CallbackSenderI.java @@ -15,27 +15,27 @@ public final class CallbackSenderI extends _CallbackSenderDisp initiateCallback(CallbackReceiverPrx proxy, Ice.Current current) { System.out.println("initiating callback"); - try - { - proxy.callback(current.ctx); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - } + try + { + proxy.callback(current.ctx); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } } public void shutdown(Ice.Current current) { System.out.println("Shutting down..."); - try - { - current.adapter.getCommunicator().shutdown(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - } + try + { + current.adapter.getCommunicator().shutdown(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } } } diff --git a/java/demo/Ice/callback/Client.java b/java/demo/Ice/callback/Client.java index cd8ae849b14..63495d8233c 100644 --- a/java/demo/Ice/callback/Client.java +++ b/java/demo/Ice/callback/Client.java @@ -13,18 +13,18 @@ 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(); + } + } } private static void @@ -38,7 +38,7 @@ public class Client extends Ice.Application "d: send callback as datagram\n" + "D: send callback as batch datagram\n" + "f: flush all batch requests\n" + - "S: switch secure mode on/off\n" + + "S: switch secure mode on/off\n" + "s: shutdown server\n" + "x: exit\n" + "?: help\n"); @@ -47,16 +47,16 @@ public class Client extends Ice.Application 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()); CallbackSenderPrx twoway = CallbackSenderPrxHelper.checkedCast( - communicator().propertyToProxy("Callback.Client.CallbackServer"). - ice_twoway().ice_timeout(-1).ice_secure(false)); + communicator().propertyToProxy("Callback.Client.CallbackServer"). + ice_twoway().ice_timeout(-1).ice_secure(false)); if(twoway == null) { System.err.println("invalid proxy"); @@ -72,13 +72,13 @@ public class Client extends Ice.Application adapter.activate(); CallbackReceiverPrx twowayR = - CallbackReceiverPrxHelper.uncheckedCast(adapter.createProxy( + CallbackReceiverPrxHelper.uncheckedCast(adapter.createProxy( communicator().stringToIdentity("callbackReceiver"))); CallbackReceiverPrx onewayR = CallbackReceiverPrxHelper.uncheckedCast(twowayR.ice_oneway()); CallbackReceiverPrx datagramR = CallbackReceiverPrxHelper.uncheckedCast(twowayR.ice_datagram()); - boolean secure = false; - String secureStr = ""; + boolean secure = false; + String secureStr = ""; menu(); @@ -110,53 +110,53 @@ public class Client extends Ice.Application } else if(line.equals("d")) { - if(secure) - { - System.out.println("secure datagrams are not supported"); - } - else - { - datagram.initiateCallback(datagramR); - } + if(secure) + { + System.out.println("secure datagrams are not supported"); + } + else + { + datagram.initiateCallback(datagramR); + } } else if(line.equals("D")) { - if(secure) - { - System.out.println("secure datagrams are not supported"); - } - else - { - batchDatagram.initiateCallback(datagramR); - } + if(secure) + { + System.out.println("secure datagrams are not supported"); + } + else + { + batchDatagram.initiateCallback(datagramR); + } + } + else if(line.equals("S")) + { + secure = !secure; + secureStr = secure ? "s" : ""; + + twoway = CallbackSenderPrxHelper.uncheckedCast(twoway.ice_secure(secure)); + oneway = CallbackSenderPrxHelper.uncheckedCast(oneway.ice_secure(secure)); + batchOneway = CallbackSenderPrxHelper.uncheckedCast(batchOneway.ice_secure(secure)); + datagram = CallbackSenderPrxHelper.uncheckedCast(datagram.ice_secure(secure)); + batchDatagram = CallbackSenderPrxHelper.uncheckedCast(batchDatagram.ice_secure(secure)); + + twowayR = CallbackReceiverPrxHelper.uncheckedCast(twowayR.ice_secure(secure)); + onewayR = CallbackReceiverPrxHelper.uncheckedCast(onewayR.ice_secure(secure)); + datagramR = CallbackReceiverPrxHelper.uncheckedCast(datagramR.ice_secure(secure)); + + if(secure) + { + System.out.println("secure mode is now on"); + } + else + { + System.out.println("secure mode is now off"); + } } - else if(line.equals("S")) - { - secure = !secure; - secureStr = secure ? "s" : ""; - - twoway = CallbackSenderPrxHelper.uncheckedCast(twoway.ice_secure(secure)); - oneway = CallbackSenderPrxHelper.uncheckedCast(oneway.ice_secure(secure)); - batchOneway = CallbackSenderPrxHelper.uncheckedCast(batchOneway.ice_secure(secure)); - datagram = CallbackSenderPrxHelper.uncheckedCast(datagram.ice_secure(secure)); - batchDatagram = CallbackSenderPrxHelper.uncheckedCast(batchDatagram.ice_secure(secure)); - - twowayR = CallbackReceiverPrxHelper.uncheckedCast(twowayR.ice_secure(secure)); - onewayR = CallbackReceiverPrxHelper.uncheckedCast(onewayR.ice_secure(secure)); - datagramR = CallbackReceiverPrxHelper.uncheckedCast(datagramR.ice_secure(secure)); - - if(secure) - { - System.out.println("secure mode is now on"); - } - else - { - System.out.println("secure mode is now off"); - } - } else if(line.equals("f")) { - communicator().flushBatchRequests(); + communicator().flushBatchRequests(); } else if(line.equals("s")) { diff --git a/java/demo/Ice/hello/Client.java b/java/demo/Ice/hello/Client.java index 532da40bd98..9b05b8f22ef 100644 --- a/java/demo/Ice/hello/Client.java +++ b/java/demo/Ice/hello/Client.java @@ -13,18 +13,18 @@ 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(); + } + } } private static void @@ -49,15 +49,15 @@ public class Client extends Ice.Application 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()); HelloPrx twoway = HelloPrxHelper.checkedCast( - communicator().propertyToProxy("Hello.Proxy").ice_twoway().ice_timeout(-1).ice_secure(false)); + communicator().propertyToProxy("Hello.Proxy").ice_twoway().ice_timeout(-1).ice_secure(false)); if(twoway == null) { System.err.println("invalid proxy"); @@ -68,9 +68,9 @@ public class Client extends Ice.Application HelloPrx datagram = HelloPrxHelper.uncheckedCast(twoway.ice_datagram()); HelloPrx batchDatagram = HelloPrxHelper.uncheckedCast(twoway.ice_batchDatagram()); - boolean secure = false; + boolean secure = false; int timeout = -1; - int delay = 0; + int delay = 0; menu(); @@ -102,29 +102,29 @@ public class Client extends Ice.Application } else if(line.equals("d")) { - if(secure) - { - System.out.println("secure datagrams are not supported"); - } - else - { - datagram.sayHello(delay); - } + if(secure) + { + System.out.println("secure datagrams are not supported"); + } + else + { + datagram.sayHello(delay); + } } else if(line.equals("D")) { - if(secure) - { - System.out.println("secure datagrams are not supported"); - } - else - { - batchDatagram.sayHello(delay); - } + if(secure) + { + System.out.println("secure datagrams are not supported"); + } + else + { + batchDatagram.sayHello(delay); + } } else if(line.equals("f")) { - communicator().flushBatchRequests(); + communicator().flushBatchRequests(); } else if(line.equals("T")) { @@ -172,13 +172,13 @@ public class Client extends Ice.Application } else if(line.equals("S")) { - secure = !secure; + secure = !secure; - twoway = HelloPrxHelper.uncheckedCast(twoway.ice_secure(secure)); - oneway = HelloPrxHelper.uncheckedCast(oneway.ice_secure(secure)); - batchOneway = HelloPrxHelper.uncheckedCast(batchOneway.ice_secure(secure)); - datagram = HelloPrxHelper.uncheckedCast(datagram.ice_secure(secure)); - batchDatagram = HelloPrxHelper.uncheckedCast(batchDatagram.ice_secure(secure)); + twoway = HelloPrxHelper.uncheckedCast(twoway.ice_secure(secure)); + oneway = HelloPrxHelper.uncheckedCast(oneway.ice_secure(secure)); + batchOneway = HelloPrxHelper.uncheckedCast(batchOneway.ice_secure(secure)); + datagram = HelloPrxHelper.uncheckedCast(datagram.ice_secure(secure)); + batchDatagram = HelloPrxHelper.uncheckedCast(batchDatagram.ice_secure(secure)); if(secure) { diff --git a/java/demo/Ice/hello/HelloI.java b/java/demo/Ice/hello/HelloI.java index 9c9dfffdf8f..1514caf31ae 100644 --- a/java/demo/Ice/hello/HelloI.java +++ b/java/demo/Ice/hello/HelloI.java @@ -15,7 +15,7 @@ public class HelloI extends _HelloDisp sayHello(int delay, Ice.Current current) { if(delay > 0) - { + { try { Thread.currentThread().sleep(delay); @@ -23,7 +23,7 @@ public class HelloI extends _HelloDisp catch(InterruptedException ex1) { } - } + } System.out.println("Hello World!"); } @@ -31,6 +31,6 @@ public class HelloI extends _HelloDisp shutdown(Ice.Current current) { System.out.println("Shutting down..."); - current.adapter.getCommunicator().shutdown(); + current.adapter.getCommunicator().shutdown(); } } diff --git a/java/demo/Ice/invoke/Client.java b/java/demo/Ice/invoke/Client.java index 362c1401f28..1d6cb450fab 100644 --- a/java/demo/Ice/invoke/Client.java +++ b/java/demo/Ice/invoke/Client.java @@ -32,29 +32,29 @@ 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()); Ice.ObjectPrx obj = communicator().propertyToProxy("Printer.Proxy"); diff --git a/java/demo/Ice/latency/Client.java b/java/demo/Ice/latency/Client.java index dba60c230b2..f82adedd9df 100644 --- a/java/demo/Ice/latency/Client.java +++ b/java/demo/Ice/latency/Client.java @@ -21,21 +21,21 @@ class Client extends Ice.Application return 1; } - // - // A method needs to be invoked thousands of times before the JIT compiler - // will convert it to native code. To ensure an accurate latency measurement, - // we need to "warm up" the JIT compiler. - // - { - final int repetitions = 20000; - System.out.print("warming up the JIT compiler..."); - System.out.flush(); - for(int i = 0; i < repetitions; i++) - { - ping.ice_ping(); - } - System.out.println(" ok"); - } + // + // A method needs to be invoked thousands of times before the JIT compiler + // will convert it to native code. To ensure an accurate latency measurement, + // we need to "warm up" the JIT compiler. + // + { + final int repetitions = 20000; + System.out.print("warming up the JIT compiler..."); + System.out.flush(); + for(int i = 0; i < repetitions; i++) + { + ping.ice_ping(); + } + System.out.println(" ok"); + } long tv1 = System.currentTimeMillis(); final int repetitions = 100000; diff --git a/java/demo/Ice/minimal/Client.java b/java/demo/Ice/minimal/Client.java index 6d215ce60fa..6ed109b7254 100755 --- a/java/demo/Ice/minimal/Client.java +++ b/java/demo/Ice/minimal/Client.java @@ -21,7 +21,7 @@ public class Client return 1; } - hello.sayHello(); + hello.sayHello(); return 0; } @@ -54,8 +54,8 @@ public class Client ex.printStackTrace(); status = 1; } - } - - System.exit(status); + } + + System.exit(status); } } diff --git a/java/demo/Ice/minimal/Server.java b/java/demo/Ice/minimal/Server.java index 9667d1786d8..78fd87663c6 100755 --- a/java/demo/Ice/minimal/Server.java +++ b/java/demo/Ice/minimal/Server.java @@ -49,8 +49,8 @@ public class Server ex.printStackTrace(); status = 1; } - } - - System.exit(status); + } + + System.exit(status); } } diff --git a/java/demo/Ice/nested/Client.java b/java/demo/Ice/nested/Client.java index c5f4cf25d8a..aec6d8d2baf 100644 --- a/java/demo/Ice/nested/Client.java +++ b/java/demo/Ice/nested/Client.java @@ -13,38 +13,38 @@ public class Client extends Ice.Application { class ShutdownHook extends Thread { - public void - run() - { - /* - * For this demo we won't destroy the communicator since it has to - * wait for any outstanding invocations to complete which may take - * some time if the nesting level is exceeded. - * - try - { - communicator().destroy(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - } - */ - } + public void + run() + { + /* + * For this demo we won't destroy the communicator since it has to + * wait for any outstanding invocations to complete which may take + * some time if the nesting level is exceeded. + * + 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()); NestedPrx nested = NestedPrxHelper.checkedCast( - communicator().propertyToProxy("Nested.Client.NestedServer")); + communicator().propertyToProxy("Nested.Client.NestedServer")); if(nested == null) { System.err.println("invalid proxy"); @@ -53,7 +53,7 @@ public class Client extends Ice.Application Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Nested.Client"); NestedPrx self = - NestedPrxHelper.uncheckedCast(adapter.createProxy(communicator().stringToIdentity("nestedClient"))); + NestedPrxHelper.uncheckedCast(adapter.createProxy(communicator().stringToIdentity("nestedClient"))); adapter.add(new NestedI(self), communicator().stringToIdentity("nestedClient")); adapter.activate(); diff --git a/java/demo/Ice/session/Client.java b/java/demo/Ice/session/Client.java index 43ff57b1783..9ef0679bada 100644 --- a/java/demo/Ice/session/Client.java +++ b/java/demo/Ice/session/Client.java @@ -13,111 +13,111 @@ public class Client extends Ice.Application { class ShutdownHook extends Thread { - public void - run() - { - System.out.println("Hi"); - cleanup(true); - try - { - communicator().destroy(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - } - } + public void + run() + { + System.out.println("Hi"); + cleanup(true); + try + { + communicator().destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + } } static private class SessionRefreshThread extends Thread { - SessionRefreshThread(Ice.Logger logger, long timeout, SessionPrx session) - { - _logger = logger; - _session = session; - _timeout = timeout; - } + SessionRefreshThread(Ice.Logger logger, long timeout, SessionPrx session) + { + _logger = logger; + _session = session; + _timeout = timeout; + } - synchronized public void - run() - { - while(!_terminated) - { - try - { - wait(_timeout); - } - catch(InterruptedException e) - { - } - if(!_terminated) - { - try - { - _session.refresh(); - } - catch(Ice.LocalException ex) - { - _logger.warning("SessionRefreshThread: " + ex); - _terminated = true; - } - } - } - } + synchronized public void + run() + { + while(!_terminated) + { + try + { + wait(_timeout); + } + catch(InterruptedException e) + { + } + if(!_terminated) + { + try + { + _session.refresh(); + } + catch(Ice.LocalException ex) + { + _logger.warning("SessionRefreshThread: " + ex); + _terminated = true; + } + } + } + } - synchronized private void - terminate() - { - _terminated = true; - notify(); - } + synchronized private void + terminate() + { + _terminated = true; + notify(); + } - final private Ice.Logger _logger; - final private SessionPrx _session; - final private long _timeout; - private boolean _terminated = false; + final private Ice.Logger _logger; + final private SessionPrx _session; + final private long _timeout; + private boolean _terminated = false; } private static void menu() { System.out.println( - "usage:\n" + - "c: create a new per-client hello object\n" + - "0-9: send a greeting to a hello object\n" + - "s: shutdown the server and exit\n" + - "x: exit\n" + - "t: exit without destroying the session\n" + - "?: help\n"); + "usage:\n" + + "c: create a new per-client hello object\n" + + "0-9: send a greeting to a hello object\n" + + "s: shutdown the server and exit\n" + + "x: exit\n" + + "t: exit without destroying the session\n" + + "?: help\n"); } 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()); java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); - String name; - try - { - do - { - System.out.print("Please enter your name ==> "); - System.out.flush(); - name = in.readLine().trim(); - } - while(name.length() == 0); - } - catch(java.io.IOException ex) - { - ex.printStackTrace(); - return 0; - } + String name; + try + { + do + { + System.out.print("Please enter your name ==> "); + System.out.flush(); + name = in.readLine().trim(); + } + while(name.length() == 0); + } + catch(java.io.IOException ex) + { + ex.printStackTrace(); + return 0; + } Ice.ObjectPrx base = communicator().propertyToProxy("SessionFactory.Proxy"); SessionFactoryPrx factory = SessionFactoryPrxHelper.checkedCast(base); @@ -127,72 +127,72 @@ public class Client extends Ice.Application return 1; } - synchronized(this) - { - _session = factory.create(name); - _refresh = new SessionRefreshThread(communicator().getLogger(), 5000, _session); - _refresh.start(); - } - - java.util.ArrayList hellos = new java.util.ArrayList(); + synchronized(this) + { + _session = factory.create(name); + _refresh = new SessionRefreshThread(communicator().getLogger(), 5000, _session); + _refresh.start(); + } + + java.util.ArrayList hellos = new java.util.ArrayList(); menu(); - try - { - boolean destroy = true; - boolean shutdown = false; - while(true) - { + try + { + boolean destroy = true; + boolean shutdown = false; + while(true) + { System.out.print("==> "); System.out.flush(); - String line = in.readLine(); + String line = in.readLine(); if(line == null) { break; } - if(line.length() > 0 && Character.isDigit(line.charAt(0))) - { - int index; - try - { - index = Integer.parseInt(line); - } - catch(NumberFormatException e) - { - menu(); - continue; - } - if(index < hellos.size()) - { - HelloPrx hello = (HelloPrx)hellos.get(index); - hello.sayHello(); - } - else - { - System.out.println("index is too high. " + hellos.size() + " exist so far. " + - "Use 'c' to create a new hello object."); - } - } + if(line.length() > 0 && Character.isDigit(line.charAt(0))) + { + int index; + try + { + index = Integer.parseInt(line); + } + catch(NumberFormatException e) + { + menu(); + continue; + } + if(index < hellos.size()) + { + HelloPrx hello = (HelloPrx)hellos.get(index); + hello.sayHello(); + } + else + { + System.out.println("index is too high. " + hellos.size() + " exist so far. " + + "Use 'c' to create a new hello object."); + } + } else if(line.equals("c")) { hellos.add(_session.createHello()); - System.out.println("created hello object " + (hellos.size()-1)); + System.out.println("created hello object " + (hellos.size()-1)); } else if(line.equals("s")) { - destroy = false; - shutdown = true; - break; + destroy = false; + shutdown = true; + break; } else if(line.equals("x")) { - break; + break; } else if(line.equals("t")) { - destroy = false; - break; + destroy = false; + break; } else if(line.equals("?")) { @@ -205,24 +205,24 @@ public class Client extends Ice.Application } } - cleanup(destroy); - if(shutdown) - { - factory.shutdown(); - } - } - catch(java.io.IOException ex) - { - ex.printStackTrace(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - } - finally - { - cleanup(true); - } + cleanup(destroy); + if(shutdown) + { + factory.shutdown(); + } + } + catch(java.io.IOException ex) + { + ex.printStackTrace(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + finally + { + cleanup(true); + } return 0; } @@ -230,28 +230,28 @@ public class Client extends Ice.Application synchronized private void cleanup(boolean destroy) { - // - // The refresher thread must be terminated before destroy is - // called, otherwise it might get ObjectNotExistException. - // - if(_refresh != null) - { - _refresh.terminate(); - try - { - _refresh.join(); - } - catch(InterruptedException e) - { - } - _refresh = null; - } - - if(destroy && _session != null) - { - _session.destroy(); - _session = null; - } + // + // The refresher thread must be terminated before destroy is + // called, otherwise it might get ObjectNotExistException. + // + if(_refresh != null) + { + _refresh.terminate(); + try + { + _refresh.join(); + } + catch(InterruptedException e) + { + } + _refresh = null; + } + + if(destroy && _session != null) + { + _session.destroy(); + _session = null; + } } public static void diff --git a/java/demo/Ice/session/HelloI.java b/java/demo/Ice/session/HelloI.java index e8002b61947..a5c9eca446c 100644 --- a/java/demo/Ice/session/HelloI.java +++ b/java/demo/Ice/session/HelloI.java @@ -14,8 +14,8 @@ public class HelloI extends _HelloDisp public HelloI(String name, int id) { - _name = name; - _id = id; + _name = name; + _id = id; } public void diff --git a/java/demo/Ice/session/ReapThread.java b/java/demo/Ice/session/ReapThread.java index 73af959b456..a0ebc1fdebf 100644 --- a/java/demo/Ice/session/ReapThread.java +++ b/java/demo/Ice/session/ReapThread.java @@ -13,72 +13,72 @@ class ReapThread extends Thread { static class SessionProxyPair { - SessionProxyPair(Demo.SessionPrx p, SessionI s) - { - proxy = p; - session = s; - } + SessionProxyPair(Demo.SessionPrx p, SessionI s) + { + proxy = p; + session = s; + } - Demo.SessionPrx proxy; - SessionI session; + Demo.SessionPrx proxy; + SessionI session; }; synchronized public void run() { - while(!_terminated) - { - try - { - wait(_timeout); - } - catch(InterruptedException e) - { - } - - if(!_terminated) - { - java.util.Iterator p = _sessions.iterator(); - while(p.hasNext()) - { - SessionProxyPair s = (SessionProxyPair)p.next(); - try - { - // - // Session destruction may take time in a - // real-world example. Therefore the current time - // is computed for each iteration. - // - if((System.currentTimeMillis() - s.session.timestamp()) > _timeout) - { - String name = s.proxy.getName(); - s.proxy.destroy(); - System.out.println("The session " + name + " has timed out."); - p.remove(); - } - } - catch(Ice.ObjectNotExistException e) - { - p.remove(); - } - } - } - } + while(!_terminated) + { + try + { + wait(_timeout); + } + catch(InterruptedException e) + { + } + + if(!_terminated) + { + java.util.Iterator p = _sessions.iterator(); + while(p.hasNext()) + { + SessionProxyPair s = (SessionProxyPair)p.next(); + try + { + // + // Session destruction may take time in a + // real-world example. Therefore the current time + // is computed for each iteration. + // + if((System.currentTimeMillis() - s.session.timestamp()) > _timeout) + { + String name = s.proxy.getName(); + s.proxy.destroy(); + System.out.println("The session " + name + " has timed out."); + p.remove(); + } + } + catch(Ice.ObjectNotExistException e) + { + p.remove(); + } + } + } + } } synchronized public void terminate() { - _terminated = true; - notify(); - - _sessions.clear(); + _terminated = true; + notify(); + + _sessions.clear(); } synchronized public void add(SessionPrx proxy, SessionI session) { - _sessions.add(new SessionProxyPair(proxy, session)); + _sessions.add(new SessionProxyPair(proxy, session)); } private final long _timeout = 10 * 1000; // 10 seconds. diff --git a/java/demo/Ice/session/Server.java b/java/demo/Ice/session/Server.java index 8ac9b9eeeab..59bd60dc08f 100644 --- a/java/demo/Ice/session/Server.java +++ b/java/demo/Ice/session/Server.java @@ -15,21 +15,21 @@ public class Server extends Ice.Application run(String[] args) { Ice.ObjectAdapter adapter = communicator().createObjectAdapter("SessionFactory"); - ReapThread reaper = new ReapThread(); - reaper.start(); + ReapThread reaper = new ReapThread(); + reaper.start(); adapter.add(new SessionFactoryI(reaper), communicator().stringToIdentity("SessionFactory")); adapter.activate(); communicator().waitForShutdown(); - reaper.terminate(); - try - { - reaper.join(); - } - catch(InterruptedException e) - { - } + reaper.terminate(); + try + { + reaper.join(); + } + catch(InterruptedException e) + { + } return 0; } diff --git a/java/demo/Ice/session/SessionFactoryI.java b/java/demo/Ice/session/SessionFactoryI.java index b1a7a70d9f2..cd7cdfd3dd0 100644 --- a/java/demo/Ice/session/SessionFactoryI.java +++ b/java/demo/Ice/session/SessionFactoryI.java @@ -13,23 +13,23 @@ class SessionFactoryI extends _SessionFactoryDisp { SessionFactoryI(ReapThread reaper) { - _reaper = reaper; + _reaper = reaper; } public synchronized SessionPrx create(String name, Ice.Current c) { - SessionI session = new SessionI(name); - SessionPrx proxy = SessionPrxHelper.uncheckedCast(c.adapter.addWithUUID(session)); - _reaper.add(proxy, session); - return proxy; + SessionI session = new SessionI(name); + SessionPrx proxy = SessionPrxHelper.uncheckedCast(c.adapter.addWithUUID(session)); + _reaper.add(proxy, session); + return proxy; } public void shutdown(Ice.Current c) { - System.out.println("Shutting down..."); - c.adapter.getCommunicator().shutdown(); + System.out.println("Shutting down..."); + c.adapter.getCommunicator().shutdown(); } private ReapThread _reaper; diff --git a/java/demo/Ice/session/SessionI.java b/java/demo/Ice/session/SessionI.java index bca977d64ee..8ef6ed3534a 100644 --- a/java/demo/Ice/session/SessionI.java +++ b/java/demo/Ice/session/SessionI.java @@ -14,78 +14,78 @@ class SessionI extends _SessionDisp public SessionI(String name) { - _name = name; - _timestamp = System.currentTimeMillis(); - System.out.println("The session " + _name + " is now created."); + _name = name; + _timestamp = System.currentTimeMillis(); + System.out.println("The session " + _name + " is now created."); } synchronized public HelloPrx createHello(Ice.Current c) { - if(_destroy) - { - throw new Ice.ObjectNotExistException(); - } - HelloPrx hello = HelloPrxHelper.uncheckedCast(c.adapter.addWithUUID(new HelloI(_name, _nextId++))); - _objs.add(hello); - return hello; + if(_destroy) + { + throw new Ice.ObjectNotExistException(); + } + HelloPrx hello = HelloPrxHelper.uncheckedCast(c.adapter.addWithUUID(new HelloI(_name, _nextId++))); + _objs.add(hello); + return hello; } synchronized public void refresh(Ice.Current c) { - if(_destroy) - { - throw new Ice.ObjectNotExistException(); - } - _timestamp = System.currentTimeMillis(); + if(_destroy) + { + throw new Ice.ObjectNotExistException(); + } + _timestamp = System.currentTimeMillis(); } synchronized public String getName(Ice.Current c) { - if(_destroy) - { - throw new Ice.ObjectNotExistException(); - } - return _name; + if(_destroy) + { + throw new Ice.ObjectNotExistException(); + } + return _name; } synchronized public void destroy(Ice.Current c) { - if(_destroy) - { - throw new Ice.ObjectNotExistException(); - } + if(_destroy) + { + throw new Ice.ObjectNotExistException(); + } - _destroy = true; - System.out.println("The session " + _name + " is now destroyed."); - try - { - c.adapter.remove(c.id); - java.util.Iterator p = _objs.iterator(); - while(p.hasNext()) - { - c.adapter.remove(((HelloPrx)p.next()).ice_getIdentity()); - } - } - catch(Ice.ObjectAdapterDeactivatedException e) - { - // This method is called on shutdown of the server, in - // which case this exception is expected. - } - _objs.clear(); + _destroy = true; + System.out.println("The session " + _name + " is now destroyed."); + try + { + c.adapter.remove(c.id); + java.util.Iterator p = _objs.iterator(); + while(p.hasNext()) + { + c.adapter.remove(((HelloPrx)p.next()).ice_getIdentity()); + } + } + catch(Ice.ObjectAdapterDeactivatedException e) + { + // This method is called on shutdown of the server, in + // which case this exception is expected. + } + _objs.clear(); } synchronized public long timestamp() { - if(_destroy) - { - throw new Ice.ObjectNotExistException(); - } - return _timestamp; + if(_destroy) + { + throw new Ice.ObjectNotExistException(); + } + return _timestamp; } private String _name; diff --git a/java/demo/Ice/throughput/Client.java b/java/demo/Ice/throughput/Client.java index 95139d85bb3..f413bc855b7 100644 --- a/java/demo/Ice/throughput/Client.java +++ b/java/demo/Ice/throughput/Client.java @@ -13,18 +13,18 @@ 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(); + } + } } private static void @@ -54,12 +54,12 @@ public class Client extends Ice.Application 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.ObjectPrx base = communicator().propertyToProxy("Throughput.Throughput"); ThroughputPrx throughput = ThroughputPrxHelper.checkedCast(base); @@ -68,32 +68,32 @@ public class Client extends Ice.Application System.err.println("invalid proxy"); return 1; } - ThroughputPrx throughputOneway = ThroughputPrxHelper.uncheckedCast(throughput.ice_oneway()); + ThroughputPrx throughputOneway = ThroughputPrxHelper.uncheckedCast(throughput.ice_oneway()); byte[] byteSeq = new byte[ByteSeqSize.value]; - String[] stringSeq = new String[StringSeqSize.value]; - for(int i = 0; i < StringSeqSize.value; ++i) - { - stringSeq[i] = "hello"; - } - - StringDouble[] structSeq = new StringDouble[StringDoubleSeqSize.value]; - for(int i = 0; i < StringDoubleSeqSize.value; ++i) - { - structSeq[i] = new StringDouble(); - structSeq[i].s = "hello"; - structSeq[i].d = 3.14; - } - - Fixed[] fixedSeq = new Fixed[FixedSeqSize.value]; - for(int i = 0; i < FixedSeqSize.value; ++i) - { - fixedSeq[i] = new Fixed(); - fixedSeq[i].i = 0; - fixedSeq[i].j = 0; - fixedSeq[i].d = 0; - } + String[] stringSeq = new String[StringSeqSize.value]; + for(int i = 0; i < StringSeqSize.value; ++i) + { + stringSeq[i] = "hello"; + } + + StringDouble[] structSeq = new StringDouble[StringDoubleSeqSize.value]; + for(int i = 0; i < StringDoubleSeqSize.value; ++i) + { + structSeq[i] = new StringDouble(); + structSeq[i].s = "hello"; + structSeq[i].d = 3.14; + } + + Fixed[] fixedSeq = new Fixed[FixedSeqSize.value]; + for(int i = 0; i < FixedSeqSize.value; ++i) + { + fixedSeq[i] = new Fixed(); + fixedSeq[i].i = 0; + fixedSeq[i].j = 0; + fixedSeq[i].d = 0; + } // // A method needs to be invoked thousands of times before the JIT compiler @@ -102,49 +102,49 @@ public class Client extends Ice.Application // { byte[] emptyBytes= new byte[1]; - String[] emptyStrings = new String[1]; - StringDouble[] emptyStructs = new StringDouble[1]; - emptyStructs[0] = new StringDouble(); - Fixed[] emptyFixed = new Fixed[1]; - emptyFixed[0] = new Fixed(); + String[] emptyStrings = new String[1]; + StringDouble[] emptyStructs = new StringDouble[1]; + emptyStructs[0] = new StringDouble(); + Fixed[] emptyFixed = new Fixed[1]; + emptyFixed[0] = new Fixed(); final int repetitions = 10000; System.out.print("warming up the JIT compiler..."); System.out.flush(); for(int i = 0; i < repetitions; i++) { - throughput.sendByteSeq(emptyBytes); - throughput.sendStringSeq(emptyStrings); - throughput.sendStructSeq(emptyStructs); - throughput.sendFixedSeq(emptyFixed); - - throughput.recvByteSeq(); - throughput.recvStringSeq(); - throughput.recvStructSeq(); - throughput.recvFixedSeq(); - - throughput.echoByteSeq(emptyBytes); - throughput.echoStringSeq(emptyStrings); - throughput.echoStructSeq(emptyStructs); - throughput.echoFixedSeq(emptyFixed); + throughput.sendByteSeq(emptyBytes); + throughput.sendStringSeq(emptyStrings); + throughput.sendStructSeq(emptyStructs); + throughput.sendFixedSeq(emptyFixed); + + throughput.recvByteSeq(); + throughput.recvStringSeq(); + throughput.recvStructSeq(); + throughput.recvFixedSeq(); + + throughput.echoByteSeq(emptyBytes); + throughput.echoStringSeq(emptyStrings); + throughput.echoStructSeq(emptyStructs); + throughput.echoFixedSeq(emptyFixed); } - throughput.endWarmup(); - + throughput.endWarmup(); + System.out.println(" ok"); } - menu(); + menu(); java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); - char currentType = '1'; - int seqSize = ByteSeqSize.value; + char currentType = '1'; + int seqSize = ByteSeqSize.value; - // Initial ping to setup the connection. - throughput.ice_ping(); - + // Initial ping to setup the connection. + throughput.ice_ping(); + String line = null; do { @@ -158,280 +158,280 @@ public class Client extends Ice.Application break; } - long tmsec = System.currentTimeMillis(); - final int repetitions = 100; - - if(line.equals("1") || line.equals("2") || line.equals("3") || line.equals("4")) - { - currentType = line.charAt(0); - - switch(currentType) - { - case '1': - { - System.out.println("using byte sequences"); - seqSize = ByteSeqSize.value; - break; - } - - case '2': - { - System.out.println("using string sequences"); - seqSize = StringSeqSize.value; - break; - } - - case '3': - { - System.out.println("using variable-length struct sequences"); - seqSize = StringDoubleSeqSize.value; - break; - } - - case '4': - { - System.out.println("using fixed-length struct sequences"); - seqSize = FixedSeqSize.value; - break; - } - } - } + long tmsec = System.currentTimeMillis(); + final int repetitions = 100; + + if(line.equals("1") || line.equals("2") || line.equals("3") || line.equals("4")) + { + currentType = line.charAt(0); + + switch(currentType) + { + case '1': + { + System.out.println("using byte sequences"); + seqSize = ByteSeqSize.value; + break; + } + + case '2': + { + System.out.println("using string sequences"); + seqSize = StringSeqSize.value; + break; + } + + case '3': + { + System.out.println("using variable-length struct sequences"); + seqSize = StringDoubleSeqSize.value; + break; + } + + case '4': + { + System.out.println("using fixed-length struct sequences"); + seqSize = FixedSeqSize.value; + break; + } + } + } else if(line.equals("t") || line.equals("o") || line.equals("r") || line.equals("e")) { - char c = line.charAt(0); - - switch(c) - { - case 't': - case 'o': - { - System.out.print("sending"); - break; - } - - case 'r': - { - System.out.print("receiving"); - break; - } - - case 'e': - { - System.out.print("sending and receiving"); - break; - } - } - - System.out.print(" " + repetitions); - switch(currentType) - { - case '1': - { - System.out.print(" byte"); - break; - } - - case '2': - { - System.out.print(" string"); - break; - } - - case '3': - { - System.out.print(" variable-length struct"); - break; - } - - case '4': - { - System.out.print(" fixed-length struct"); - break; - } - } - - System.out.print(" sequences of size " + seqSize); - - if(c == 'o') - { - System.out.print(" as oneway"); - } - - System.out.println("..."); - - for(int i = 0; i < repetitions; ++i) - { - switch(currentType) - { - case '1': - { - switch(c) - { - case 't': - { - throughput.sendByteSeq(byteSeq); - break; - } - - case 'o': - { - throughputOneway.sendByteSeq(byteSeq); - break; - } - - case 'r': - { - throughput.recvByteSeq(); - break; - } - - case 'e': - { - throughput.echoByteSeq(byteSeq); - break; - } - } - break; - } - - case '2': - { - switch(c) - { - case 't': - { - throughput.sendStringSeq(stringSeq); - break; - } - - case 'o': - { - throughputOneway.sendStringSeq(stringSeq); - break; - } - - case 'r': - { - throughput.recvStringSeq(); - break; - } - - case 'e': - { - throughput.echoStringSeq(stringSeq); - break; - } - } - break; - } - - case '3': - { - switch(c) - { - case 't': - { - throughput.sendStructSeq(structSeq); - break; - } - - case 'o': - { - throughputOneway.sendStructSeq(structSeq); - break; - } - - case 'r': - { - throughput.recvStructSeq(); - break; - } - - case 'e': - { - throughput.echoStructSeq(structSeq); - break; - } - } - break; - } - - case '4': - { - switch(c) - { - case 't': - { - throughput.sendFixedSeq(fixedSeq); - break; - } - - case 'o': - { - throughputOneway.sendFixedSeq(fixedSeq); - break; - } - - case 'r': - { - throughput.recvFixedSeq(); - break; - } - - case 'e': - { - throughput.echoFixedSeq(fixedSeq); - break; - } - } - break; - } - } - } - - double dmsec = System.currentTimeMillis() - tmsec; - System.out.println("time for " + repetitions + " sequences: " + dmsec + "ms"); - System.out.println("time per sequence: " + dmsec / repetitions + "ms"); - int wireSize = 0; - switch(currentType) - { - case '1': - { - wireSize = 1; - break; - } - - case '2': - { - wireSize = stringSeq[0].length(); - break; - } - - case '3': - { - wireSize = structSeq[0].s.length(); - wireSize += 8; // Size of double on the wire. - break; - } - - case '4': - { - wireSize = 16; // Size of two ints and a double on the wire. - break; - } - } - double mbit = repetitions * seqSize * wireSize * 8.0 / dmsec / 1000.0; - if(c == 'e') - { - mbit *= 2; - } - System.out.println("throughput: " + new java.text.DecimalFormat("#.##").format(mbit) + "Mbps"); - } - else if(line.equals("s")) - { - throughput.shutdown(); - } - else if(line.equals("x")) + char c = line.charAt(0); + + switch(c) + { + case 't': + case 'o': + { + System.out.print("sending"); + break; + } + + case 'r': + { + System.out.print("receiving"); + break; + } + + case 'e': + { + System.out.print("sending and receiving"); + break; + } + } + + System.out.print(" " + repetitions); + switch(currentType) + { + case '1': + { + System.out.print(" byte"); + break; + } + + case '2': + { + System.out.print(" string"); + break; + } + + case '3': + { + System.out.print(" variable-length struct"); + break; + } + + case '4': + { + System.out.print(" fixed-length struct"); + break; + } + } + + System.out.print(" sequences of size " + seqSize); + + if(c == 'o') + { + System.out.print(" as oneway"); + } + + System.out.println("..."); + + for(int i = 0; i < repetitions; ++i) + { + switch(currentType) + { + case '1': + { + switch(c) + { + case 't': + { + throughput.sendByteSeq(byteSeq); + break; + } + + case 'o': + { + throughputOneway.sendByteSeq(byteSeq); + break; + } + + case 'r': + { + throughput.recvByteSeq(); + break; + } + + case 'e': + { + throughput.echoByteSeq(byteSeq); + break; + } + } + break; + } + + case '2': + { + switch(c) + { + case 't': + { + throughput.sendStringSeq(stringSeq); + break; + } + + case 'o': + { + throughputOneway.sendStringSeq(stringSeq); + break; + } + + case 'r': + { + throughput.recvStringSeq(); + break; + } + + case 'e': + { + throughput.echoStringSeq(stringSeq); + break; + } + } + break; + } + + case '3': + { + switch(c) + { + case 't': + { + throughput.sendStructSeq(structSeq); + break; + } + + case 'o': + { + throughputOneway.sendStructSeq(structSeq); + break; + } + + case 'r': + { + throughput.recvStructSeq(); + break; + } + + case 'e': + { + throughput.echoStructSeq(structSeq); + break; + } + } + break; + } + + case '4': + { + switch(c) + { + case 't': + { + throughput.sendFixedSeq(fixedSeq); + break; + } + + case 'o': + { + throughputOneway.sendFixedSeq(fixedSeq); + break; + } + + case 'r': + { + throughput.recvFixedSeq(); + break; + } + + case 'e': + { + throughput.echoFixedSeq(fixedSeq); + break; + } + } + break; + } + } + } + + double dmsec = System.currentTimeMillis() - tmsec; + System.out.println("time for " + repetitions + " sequences: " + dmsec + "ms"); + System.out.println("time per sequence: " + dmsec / repetitions + "ms"); + int wireSize = 0; + switch(currentType) + { + case '1': + { + wireSize = 1; + break; + } + + case '2': + { + wireSize = stringSeq[0].length(); + break; + } + + case '3': + { + wireSize = structSeq[0].s.length(); + wireSize += 8; // Size of double on the wire. + break; + } + + case '4': + { + wireSize = 16; // Size of two ints and a double on the wire. + break; + } + } + double mbit = repetitions * seqSize * wireSize * 8.0 / dmsec / 1000.0; + if(c == 'e') + { + mbit *= 2; + } + System.out.println("throughput: " + new java.text.DecimalFormat("#.##").format(mbit) + "Mbps"); + } + else if(line.equals("s")) + { + throughput.shutdown(); + } + else if(line.equals("x")) { // Nothing to do } diff --git a/java/demo/Ice/throughput/ThroughputI.java b/java/demo/Ice/throughput/ThroughputI.java index fca0554d5e2..5508620ee41 100644 --- a/java/demo/Ice/throughput/ThroughputI.java +++ b/java/demo/Ice/throughput/ThroughputI.java @@ -18,28 +18,28 @@ public final class ThroughputI extends _ThroughputDisp _byteSeq = new byte[ByteSeqSize.value]; - _stringSeq = new String[StringSeqSize.value]; - for(int i = 0; i < StringSeqSize.value; ++i) - { - _stringSeq[i] = "hello"; - } - - _structSeq = new StringDouble[StringDoubleSeqSize.value]; - for(int i = 0; i < StringDoubleSeqSize.value; ++i) - { - _structSeq[i] = new StringDouble(); - _structSeq[i].s = "hello"; - _structSeq[i].d = 3.14; - } - - _fixedSeq = new Fixed[FixedSeqSize.value]; - for(int i = 0; i < FixedSeqSize.value; ++i) - { - _fixedSeq[i] = new Fixed(); - _fixedSeq[i].i = 0; - _fixedSeq[i].j = 0; - _fixedSeq[i].d = 0; - } + _stringSeq = new String[StringSeqSize.value]; + for(int i = 0; i < StringSeqSize.value; ++i) + { + _stringSeq[i] = "hello"; + } + + _structSeq = new StringDouble[StringDoubleSeqSize.value]; + for(int i = 0; i < StringDoubleSeqSize.value; ++i) + { + _structSeq[i] = new StringDouble(); + _structSeq[i].s = "hello"; + _structSeq[i].d = 3.14; + } + + _fixedSeq = new Fixed[FixedSeqSize.value]; + for(int i = 0; i < FixedSeqSize.value; ++i) + { + _fixedSeq[i] = new Fixed(); + _fixedSeq[i].i = 0; + _fixedSeq[i].j = 0; + _fixedSeq[i].d = 0; + } } public void @@ -57,13 +57,13 @@ public final class ThroughputI extends _ThroughputDisp recvByteSeq(Ice.Current current) { if(_warmup) - { + { return _emptyByteSeq; - } - else - { + } + else + { return _byteSeq; - } + } } public byte[] @@ -81,13 +81,13 @@ public final class ThroughputI extends _ThroughputDisp recvStringSeq(Ice.Current current) { if(_warmup) - { + { return _emptyStringSeq; - } - else - { + } + else + { return _stringSeq; - } + } } public String[] @@ -105,13 +105,13 @@ public final class ThroughputI extends _ThroughputDisp recvStructSeq(Ice.Current current) { if(_warmup) - { + { return _emptyStructSeq; - } - else - { + } + else + { return _structSeq; - } + } } public StringDouble[] @@ -129,13 +129,13 @@ public final class ThroughputI extends _ThroughputDisp recvFixedSeq(Ice.Current current) { if(_warmup) - { + { return _emptyFixedSeq; - } - else - { + } + else + { return _fixedSeq; - } + } } public Fixed[] diff --git a/java/demo/Ice/value/Client.java b/java/demo/Ice/value/Client.java index 9f32eefa169..831e424ebfa 100644 --- a/java/demo/Ice/value/Client.java +++ b/java/demo/Ice/value/Client.java @@ -13,18 +13,18 @@ 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(); + } + } } private static void @@ -43,12 +43,12 @@ public class Client extends Ice.Application 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.ObjectPrx base = communicator().propertyToProxy("Value.Initial"); InitialPrx initial = InitialPrxHelper.checkedCast(base); @@ -79,12 +79,12 @@ public class Client extends Ice.Application PrinterHolder printer = new PrinterHolder(); PrinterPrxHolder printerProxy = new PrinterPrxHolder(); - boolean gotException = false; + boolean gotException = false; try { initial.getPrinter(printer, printerProxy); - System.err.println("Did not get the expected NoObjectFactoryException!"); - System.exit(1); + System.err.println("Did not get the expected NoObjectFactoryException!"); + System.exit(1); } catch(Ice.NoObjectFactoryException ex) { @@ -130,13 +130,13 @@ public class Client extends Ice.Application readline(in); Printer derivedAsBase = initial.getDerivedPrinter(); - System.out.println("The type ID of the received object is \"" + derivedAsBase.ice_id() + "\""); - assert(derivedAsBase.ice_id().equals("::Demo::Printer")); + System.out.println("The type ID of the received object is \"" + derivedAsBase.ice_id() + "\""); + assert(derivedAsBase.ice_id().equals("::Demo::Printer")); System.out.println(); System.out.println("Now we install a factory for the derived class, and try again."); System.out.println("Because we receive the derived object as a base object,"); - System.out.println("we need to do a class cast to get from the base to the derived object."); + System.out.println("we need to do a class cast to get from the base to the derived object."); System.out.println("[press enter]"); readline(in); @@ -146,7 +146,7 @@ public class Client extends Ice.Application DerivedPrinter derived = (Demo.DerivedPrinter)derivedAsBase; System.out.println("==> class cast to derived object succeded"); - System.out.println("The type ID of the received object is \"" + derived.ice_id() + "\""); + System.out.println("The type ID of the received object is \"" + derived.ice_id() + "\""); System.out.println(); System.out.println("Let's print the message contained in the derived object, and"); @@ -183,7 +183,7 @@ public class Client extends Ice.Application System.out.println(); System.out.println("That's it for this demo. Have fun with Ice!"); - initial.shutdown(); + initial.shutdown(); return 0; } diff --git a/java/demo/Ice/value/InitialI.java b/java/demo/Ice/value/InitialI.java index c0afc64a5a8..6fd9e098378 100644 --- a/java/demo/Ice/value/InitialI.java +++ b/java/demo/Ice/value/InitialI.java @@ -54,7 +54,7 @@ class InitialI extends Initial public void shutdown(Ice.Current current) { - current.adapter.getCommunicator().shutdown(); + current.adapter.getCommunicator().shutdown(); } private Simple _simple = new Simple(); diff --git a/java/demo/IceBox/hello/Client.java b/java/demo/IceBox/hello/Client.java index 022a8ea2834..57db06b79ca 100644 --- a/java/demo/IceBox/hello/Client.java +++ b/java/demo/IceBox/hello/Client.java @@ -13,18 +13,18 @@ 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(); + } + } } private void @@ -45,15 +45,15 @@ public class Client extends Ice.Application 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()); HelloPrx twoway = HelloPrxHelper.checkedCast( - communicator().propertyToProxy("Hello.Proxy").ice_twoway().ice_timeout(-1).ice_secure(false)); + communicator().propertyToProxy("Hello.Proxy").ice_twoway().ice_timeout(-1).ice_secure(false)); if(twoway == null) { System.err.println("invalid object reference"); @@ -102,7 +102,7 @@ public class Client extends Ice.Application } else if(line.equals("f")) { - communicator().flushBatchRequests(); + communicator().flushBatchRequests(); } else if(line.equals("x")) { @@ -135,8 +135,8 @@ public class Client extends Ice.Application public static void main(String[] args) { - Client app = new Client(); - int status = app.main("Client", args, "config.client"); - System.exit(status); + Client app = new Client(); + int status = app.main("Client", args, "config.client"); + System.exit(status); } } diff --git a/java/demo/IceGrid/allocate/Client.java b/java/demo/IceGrid/allocate/Client.java index 23f4ed77418..806f95b6f73 100644 --- a/java/demo/IceGrid/allocate/Client.java +++ b/java/demo/IceGrid/allocate/Client.java @@ -13,257 +13,257 @@ public class Client extends Ice.Application { class ShutdownHook extends Thread { - public void - run() - { - cleanup(); - try - { - communicator().destroy(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - } - } + public void + run() + { + cleanup(); + try + { + communicator().destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + } } static private class SessionKeepAliveThread extends Thread { SessionKeepAliveThread(IceGrid.SessionPrx session, long timeout) - { - _session = session; - _timeout = timeout; - _terminated = false; - } + { + _session = session; + _timeout = timeout; + _terminated = false; + } - synchronized public void - run() - { - while(!_terminated) - { - try - { - wait(_timeout); - } - catch(InterruptedException e) - { - } - if(_terminated) - { - break; - } - try - { - _session.keepAlive(); - } - catch(Ice.LocalException ex) - { - break; - } - } - } + synchronized public void + run() + { + while(!_terminated) + { + try + { + wait(_timeout); + } + catch(InterruptedException e) + { + } + if(_terminated) + { + break; + } + try + { + _session.keepAlive(); + } + catch(Ice.LocalException ex) + { + break; + } + } + } - synchronized private void - terminate() - { - _terminated = true; - notify(); - } + synchronized private void + terminate() + { + _terminated = true; + notify(); + } - final private IceGrid.SessionPrx _session; - final private long _timeout; - private boolean _terminated; + final private IceGrid.SessionPrx _session; + final private long _timeout; + private boolean _terminated; } private void menu() { - System.out.println( - "usage:\n" + - "t: send greeting\n" + - "s: shutdown server\n" + - "x: exit\n" + - "?: help\n"); + System.out.println( + "usage:\n" + + "t: send greeting\n" + + "s: shutdown server\n" + + "x: exit\n" + + "?: help\n"); } 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()); - int status = 0; - IceGrid.RegistryPrx registry = - IceGrid.RegistryPrxHelper.checkedCast(communicator().stringToProxy("DemoIceGrid/Registry")); - if(registry == null) - { - System.err.println("could not contact registry"); - return 1; - } + int status = 0; + IceGrid.RegistryPrx registry = + IceGrid.RegistryPrxHelper.checkedCast(communicator().stringToProxy("DemoIceGrid/Registry")); + if(registry == null) + { + System.err.println("could not contact registry"); + return 1; + } - java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); - while(true) - { - System.out.println("This demo accepts any user-id / password combination."); + java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); + while(true) + { + System.out.println("This demo accepts any user-id / password combination."); - try - { - String id; - System.out.print("user id: "); - System.out.flush(); - id = in.readLine(); - - String pw; - System.out.print("password: "); - System.out.flush(); - pw = in.readLine(); - - try - { - synchronized(this) - { - _session = registry.createSession(id, pw); - } - break; - } - catch(IceGrid.PermissionDeniedException ex) - { - System.out.println("permission denied:\n" + ex.reason); - } - } - catch(java.io.IOException ex) - { - ex.printStackTrace(); - } - } + try + { + String id; + System.out.print("user id: "); + System.out.flush(); + id = in.readLine(); + + String pw; + System.out.print("password: "); + System.out.flush(); + pw = in.readLine(); + + try + { + synchronized(this) + { + _session = registry.createSession(id, pw); + } + break; + } + catch(IceGrid.PermissionDeniedException ex) + { + System.out.println("permission denied:\n" + ex.reason); + } + } + catch(java.io.IOException ex) + { + ex.printStackTrace(); + } + } - synchronized(this) - { - _keepAlive = new SessionKeepAliveThread(_session, registry.getSessionTimeout() / 2); - _keepAlive.start(); - } + synchronized(this) + { + _keepAlive = new SessionKeepAliveThread(_session, registry.getSessionTimeout() / 2); + _keepAlive.start(); + } - try - { - // - // First try to retrieve object by identity, which will - // work if the application-single.xml descriptor is - // used. Otherwise we retrieve object by type, which will - // succeed if the application-multiple.xml descriptor is - // used. - // - HelloPrx hello; - try - { - hello = HelloPrxHelper.checkedCast( - _session.allocateObjectById(communicator().stringToIdentity("hello"))); - } - catch(IceGrid.ObjectNotRegisteredException ex) - { - hello = HelloPrxHelper.checkedCast(_session.allocateObjectByType("::Demo::Hello")); - } + try + { + // + // First try to retrieve object by identity, which will + // work if the application-single.xml descriptor is + // used. Otherwise we retrieve object by type, which will + // succeed if the application-multiple.xml descriptor is + // used. + // + HelloPrx hello; + try + { + hello = HelloPrxHelper.checkedCast( + _session.allocateObjectById(communicator().stringToIdentity("hello"))); + } + catch(IceGrid.ObjectNotRegisteredException ex) + { + hello = HelloPrxHelper.checkedCast(_session.allocateObjectByType("::Demo::Hello")); + } - menu(); - - String line = null; - do - { - try - { - System.out.print("==> "); - System.out.flush(); - line = in.readLine(); - if(line == null) - { - break; - } - if(line.equals("t")) - { - hello.sayHello(); - } - else if(line.equals("s")) - { - hello.shutdown(); - } - else if(line.equals("x")) - { - // Nothing to do - } - else if(line.equals("?")) - { - menu(); - } - else - { - System.out.println("unknown command `" + line + "'"); - menu(); - } - } - catch(java.io.IOException ex) - { - ex.printStackTrace(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - } - } - while(!line.equals("x")); - } - catch(IceGrid.AllocationException ex) - { - System.err.println("could not allocate object: " + ex.reason); - status = 1; - } - catch(Exception ex) - { - System.err.println("expected exception: " + ex); - status = 1; - } + menu(); + + String line = null; + do + { + try + { + System.out.print("==> "); + System.out.flush(); + line = in.readLine(); + if(line == null) + { + break; + } + if(line.equals("t")) + { + hello.sayHello(); + } + else if(line.equals("s")) + { + hello.shutdown(); + } + else if(line.equals("x")) + { + // Nothing to do + } + else if(line.equals("?")) + { + menu(); + } + else + { + System.out.println("unknown command `" + line + "'"); + menu(); + } + } + catch(java.io.IOException ex) + { + ex.printStackTrace(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + } + while(!line.equals("x")); + } + catch(IceGrid.AllocationException ex) + { + System.err.println("could not allocate object: " + ex.reason); + status = 1; + } + catch(Exception ex) + { + System.err.println("expected exception: " + ex); + status = 1; + } - cleanup(); + cleanup(); - return status; + return status; } synchronized void cleanup() { - // - // Destroy the keepAlive thread and the sesion object otherwise - // the session will be kept allocated until the timeout occurs. - // Destroying the session will release all allocated objects. - // - if(_keepAlive != null) - { - _keepAlive.terminate(); - try - { - _keepAlive.join(); - } - catch(InterruptedException e) - { - } - _keepAlive = null; - } - if(_session != null) - { - _session.destroy(); - _session = null; - } + // + // Destroy the keepAlive thread and the sesion object otherwise + // the session will be kept allocated until the timeout occurs. + // Destroying the session will release all allocated objects. + // + if(_keepAlive != null) + { + _keepAlive.terminate(); + try + { + _keepAlive.join(); + } + catch(InterruptedException e) + { + } + _keepAlive = null; + } + if(_session != null) + { + _session.destroy(); + _session = null; + } } public static void main(String[] args) { - Client app = new Client(); - int status = app.main("Client", args, "config.client"); - System.exit(status); + Client app = new Client(); + int status = app.main("Client", args, "config.client"); + System.exit(status); } SessionKeepAliveThread _keepAlive; diff --git a/java/demo/IceGrid/allocate/HelloI.java b/java/demo/IceGrid/allocate/HelloI.java index cece7b2bc8b..39bfae4682d 100644 --- a/java/demo/IceGrid/allocate/HelloI.java +++ b/java/demo/IceGrid/allocate/HelloI.java @@ -13,7 +13,7 @@ public class HelloI extends _HelloDisp { public HelloI(String name) { - _name = name; + _name = name; } public void diff --git a/java/demo/IceGrid/allocate/Server.java b/java/demo/IceGrid/allocate/Server.java index b622578f9f4..1c7722e7a71 100644 --- a/java/demo/IceGrid/allocate/Server.java +++ b/java/demo/IceGrid/allocate/Server.java @@ -13,8 +13,8 @@ public class Server extends Ice.Application run(String[] args) { Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Hello"); - Ice.Properties properties = communicator().getProperties(); - Ice.Identity id = communicator().stringToIdentity(properties.getProperty("Identity")); + Ice.Properties properties = communicator().getProperties(); + Ice.Identity id = communicator().stringToIdentity(properties.getProperty("Identity")); adapter.add(new HelloI(properties.getProperty("Ice.ServerId")), id); adapter.activate(); communicator().waitForShutdown(); @@ -24,8 +24,8 @@ public class Server extends Ice.Application static public void main(String[] args) { - Server app = new Server(); - int status = app.main("Server", args); - System.exit(status); + Server app = new Server(); + int status = app.main("Server", args); + System.exit(status); } } diff --git a/java/demo/IceGrid/sessionActivation/Client.java b/java/demo/IceGrid/sessionActivation/Client.java index b77fbd9fa13..f16c19c13a0 100644 --- a/java/demo/IceGrid/sessionActivation/Client.java +++ b/java/demo/IceGrid/sessionActivation/Client.java @@ -13,33 +13,33 @@ public class Client extends Ice.Application { class ShutdownHook extends Thread { - public void - run() - { - cleanup(); - try - { - communicator().destroy(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - } - } + public void + run() + { + cleanup(); + try + { + communicator().destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + } } static private class SessionKeepAliveThread extends Thread { SessionKeepAliveThread(IceGrid.SessionPrx session, long timeout) - { - _session = session; - _timeout = timeout; - _terminated = false; - } + { + _session = session; + _timeout = timeout; + _terminated = false; + } - synchronized public void - run() - { + synchronized public void + run() + { while(!_terminated) { try @@ -51,29 +51,29 @@ public class Client extends Ice.Application } if(_terminated) { - break; - } + break; + } try { _session.keepAlive(); } catch(Ice.LocalException ex) { - break; + break; } } - } + } - synchronized private void - terminate() - { - _terminated = true; - notify(); - } + synchronized private void + terminate() + { + _terminated = true; + notify(); + } - final private IceGrid.SessionPrx _session; - final private long _timeout; - private boolean _terminated; + final private IceGrid.SessionPrx _session; + final private long _timeout; + private boolean _terminated; } private void @@ -89,129 +89,129 @@ public class Client extends Ice.Application 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()); - int status = 0; + int status = 0; IceGrid.RegistryPrx registry = - IceGrid.RegistryPrxHelper.checkedCast(communicator().stringToProxy("DemoIceGrid/Registry")); - if(registry == null) - { + IceGrid.RegistryPrxHelper.checkedCast(communicator().stringToProxy("DemoIceGrid/Registry")); + if(registry == null) + { System.err.println("could not contact registry"); - return 1; - } + return 1; + } java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); - while(true) - { - System.out.println("This demo accepts any user-id / password combination."); + while(true) + { + System.out.println("This demo accepts any user-id / password combination."); - try - { - String id; - System.out.print("user id: "); - System.out.flush(); - id = in.readLine(); - - String pw; - System.out.print("password: "); - System.out.flush(); - pw = in.readLine(); - - try - { - synchronized(this) - { - _session = registry.createSession(id, pw); - } - break; - } - catch(IceGrid.PermissionDeniedException ex) - { - System.out.println("permission denied:\n" + ex.reason); - } - } + try + { + String id; + System.out.print("user id: "); + System.out.flush(); + id = in.readLine(); + + String pw; + System.out.print("password: "); + System.out.flush(); + pw = in.readLine(); + + try + { + synchronized(this) + { + _session = registry.createSession(id, pw); + } + break; + } + catch(IceGrid.PermissionDeniedException ex) + { + System.out.println("permission denied:\n" + ex.reason); + } + } catch(java.io.IOException ex) { ex.printStackTrace(); } - } + } - synchronized(this) - { - _keepAlive = new SessionKeepAliveThread(_session, registry.getSessionTimeout() / 2); - _keepAlive.start(); - } + synchronized(this) + { + _keepAlive = new SessionKeepAliveThread(_session, registry.getSessionTimeout() / 2); + _keepAlive.start(); + } - try - { - HelloPrx hello = HelloPrxHelper.checkedCast( - _session.allocateObjectById(communicator().stringToIdentity("hello"))); + try + { + HelloPrx hello = HelloPrxHelper.checkedCast( + _session.allocateObjectById(communicator().stringToIdentity("hello"))); - menu(); - - String line = null; - do - { - try - { - System.out.print("==> "); - System.out.flush(); - line = in.readLine(); - if(line == null) - { - break; - } - if(line.equals("t")) - { - hello.sayHello(); - } - else if(line.equals("x")) - { - // Nothing to do - } - else if(line.equals("?")) - { - menu(); - } - else - { - System.out.println("unknown command `" + line + "'"); - menu(); - } - } - catch(java.io.IOException ex) - { - ex.printStackTrace(); - } - catch(Ice.LocalException ex) - { - ex.printStackTrace(); - } - } - while(!line.equals("x")); - } - catch(IceGrid.AllocationException ex) - { - System.err.println("could not allocate object: " + ex.reason); - status = 1; - } - catch(IceGrid.ObjectNotRegisteredException ex) - { - System.err.println("object not registered with registry"); - status = 1; - } - catch(Exception ex) - { - System.err.println("expected exception: " + ex); - status = 1; - } + menu(); + + String line = null; + do + { + try + { + System.out.print("==> "); + System.out.flush(); + line = in.readLine(); + if(line == null) + { + break; + } + if(line.equals("t")) + { + hello.sayHello(); + } + else if(line.equals("x")) + { + // Nothing to do + } + else if(line.equals("?")) + { + menu(); + } + else + { + System.out.println("unknown command `" + line + "'"); + menu(); + } + } + catch(java.io.IOException ex) + { + ex.printStackTrace(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + } + while(!line.equals("x")); + } + catch(IceGrid.AllocationException ex) + { + System.err.println("could not allocate object: " + ex.reason); + status = 1; + } + catch(IceGrid.ObjectNotRegisteredException ex) + { + System.err.println("object not registered with registry"); + status = 1; + } + catch(Exception ex) + { + System.err.println("expected exception: " + ex); + status = 1; + } - cleanup(); + cleanup(); return status; } @@ -219,36 +219,36 @@ public class Client extends Ice.Application synchronized void cleanup() { - // - // Destroy the keepAlive thread and the sesion object otherwise - // the session will be kept allocated until the timeout occurs. - // Destroying the session will release all allocated objects. - // - if(_keepAlive != null) - { - _keepAlive.terminate(); - try - { - _keepAlive.join(); - } - catch(InterruptedException e) - { - } - _keepAlive = null; - } - if(_session != null) - { - _session.destroy(); - _session = null; - } + // + // Destroy the keepAlive thread and the sesion object otherwise + // the session will be kept allocated until the timeout occurs. + // Destroying the session will release all allocated objects. + // + if(_keepAlive != null) + { + _keepAlive.terminate(); + try + { + _keepAlive.join(); + } + catch(InterruptedException e) + { + } + _keepAlive = null; + } + if(_session != null) + { + _session.destroy(); + _session = null; + } } public static void main(String[] args) { - Client app = new Client(); - int status = app.main("Client", args, "config.client"); - System.exit(status); + Client app = new Client(); + int status = app.main("Client", args, "config.client"); + System.exit(status); } SessionKeepAliveThread _keepAlive; diff --git a/java/demo/IceGrid/sessionActivation/HelloI.java b/java/demo/IceGrid/sessionActivation/HelloI.java index a7906b1237c..9d24965de41 100644 --- a/java/demo/IceGrid/sessionActivation/HelloI.java +++ b/java/demo/IceGrid/sessionActivation/HelloI.java @@ -13,7 +13,7 @@ public class HelloI extends _HelloDisp { public HelloI(String name) { - _name = name; + _name = name; } public void diff --git a/java/demo/IceGrid/sessionActivation/Server.java b/java/demo/IceGrid/sessionActivation/Server.java index b622578f9f4..1c7722e7a71 100644 --- a/java/demo/IceGrid/sessionActivation/Server.java +++ b/java/demo/IceGrid/sessionActivation/Server.java @@ -13,8 +13,8 @@ public class Server extends Ice.Application run(String[] args) { Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Hello"); - Ice.Properties properties = communicator().getProperties(); - Ice.Identity id = communicator().stringToIdentity(properties.getProperty("Identity")); + Ice.Properties properties = communicator().getProperties(); + Ice.Identity id = communicator().stringToIdentity(properties.getProperty("Identity")); adapter.add(new HelloI(properties.getProperty("Ice.ServerId")), id); adapter.activate(); communicator().waitForShutdown(); @@ -24,8 +24,8 @@ public class Server extends Ice.Application static public void main(String[] args) { - Server app = new Server(); - int status = app.main("Server", args); - System.exit(status); + Server app = new Server(); + int status = app.main("Server", args); + System.exit(status); } } diff --git a/java/demo/IceGrid/simple/Client.java b/java/demo/IceGrid/simple/Client.java index d877a201051..58ed8b8a64d 100644 --- a/java/demo/IceGrid/simple/Client.java +++ b/java/demo/IceGrid/simple/Client.java @@ -13,18 +13,18 @@ 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(); + } + } } private void @@ -41,34 +41,34 @@ public class Client extends Ice.Application 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()); - // - // First we try to connect to the object with the `hello' - // identity. If it's not registered with the registry, we - // search for an object with the ::Demo::Hello type. - // - HelloPrx hello = null; - try - { - hello = HelloPrxHelper.checkedCast(communicator().stringToProxy("hello")); - } - catch(Ice.NotRegisteredException ex) - { - IceGrid.QueryPrx query = - IceGrid.QueryPrxHelper.checkedCast(communicator().stringToProxy("DemoIceGrid/Query")); - hello = HelloPrxHelper.checkedCast(query.findObjectByType("::Demo::Hello")); - } - if(hello == null) - { + // + // First we try to connect to the object with the `hello' + // identity. If it's not registered with the registry, we + // search for an object with the ::Demo::Hello type. + // + HelloPrx hello = null; + try + { + hello = HelloPrxHelper.checkedCast(communicator().stringToProxy("hello")); + } + catch(Ice.NotRegisteredException ex) + { + IceGrid.QueryPrx query = + IceGrid.QueryPrxHelper.checkedCast(communicator().stringToProxy("DemoIceGrid/Query")); + hello = HelloPrxHelper.checkedCast(query.findObjectByType("::Demo::Hello")); + } + if(hello == null) + { System.err.println("couldn't find a `::Demo::Hello' object"); - return 1; - } + return 1; + } menu(); @@ -125,8 +125,8 @@ public class Client extends Ice.Application public static void main(String[] args) { - Client app = new Client(); - int status = app.main("Client", args, "config.client"); - System.exit(status); + Client app = new Client(); + int status = app.main("Client", args, "config.client"); + System.exit(status); } } diff --git a/java/demo/IceGrid/simple/HelloI.java b/java/demo/IceGrid/simple/HelloI.java index cece7b2bc8b..39bfae4682d 100644 --- a/java/demo/IceGrid/simple/HelloI.java +++ b/java/demo/IceGrid/simple/HelloI.java @@ -13,7 +13,7 @@ public class HelloI extends _HelloDisp { public HelloI(String name) { - _name = name; + _name = name; } public void diff --git a/java/demo/IceGrid/simple/Server.java b/java/demo/IceGrid/simple/Server.java index b622578f9f4..1c7722e7a71 100644 --- a/java/demo/IceGrid/simple/Server.java +++ b/java/demo/IceGrid/simple/Server.java @@ -13,8 +13,8 @@ public class Server extends Ice.Application run(String[] args) { Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Hello"); - Ice.Properties properties = communicator().getProperties(); - Ice.Identity id = communicator().stringToIdentity(properties.getProperty("Identity")); + Ice.Properties properties = communicator().getProperties(); + Ice.Identity id = communicator().stringToIdentity(properties.getProperty("Identity")); adapter.add(new HelloI(properties.getProperty("Ice.ServerId")), id); adapter.activate(); communicator().waitForShutdown(); @@ -24,8 +24,8 @@ public class Server extends Ice.Application static public void main(String[] args) { - Server app = new Server(); - int status = app.main("Server", args); - System.exit(status); + Server app = new Server(); + int status = app.main("Server", args); + System.exit(status); } } diff --git a/java/demo/IceStorm/clock/Publisher.java b/java/demo/IceStorm/clock/Publisher.java index 8e4a85e2666..780d89101ad 100644 --- a/java/demo/IceStorm/clock/Publisher.java +++ b/java/demo/IceStorm/clock/Publisher.java @@ -14,14 +14,14 @@ public class Publisher extends Ice.Application public void usage() { - System.out.println("Usage: " + appName() + " [--datagram|--twoway|--oneway] [topic]"); + System.out.println("Usage: " + appName() + " [--datagram|--twoway|--oneway] [topic]"); } public int run(String[] args) { IceStorm.TopicManagerPrx manager = IceStorm.TopicManagerPrxHelper.checkedCast( - communicator().propertyToProxy("IceStorm.TopicManager.Proxy")); + communicator().propertyToProxy("IceStorm.TopicManager.Proxy")); if(manager == null) { System.err.println("invalid proxy"); @@ -29,107 +29,107 @@ public class Publisher extends Ice.Application } String topicName = "time"; - boolean datagram = false; - boolean twoway = false; - boolean oneway = false; - int optsSet = 0; - for(int i = 0; i < args.length; ++i) - { - if(args[i].equals("--datagram")) - { - datagram = true; - ++optsSet; - } - else if(args[i].equals("--twoway")) - { - twoway = true; - ++optsSet; - } - else if(args[i].equals("--oneway")) - { - oneway = true; - ++optsSet; - } - else if(args[i].startsWith("--")) - { - usage(); - return 1; - } - else - { - topicName = args[i]; - break; - } - } + boolean datagram = false; + boolean twoway = false; + boolean oneway = false; + int optsSet = 0; + for(int i = 0; i < args.length; ++i) + { + if(args[i].equals("--datagram")) + { + datagram = true; + ++optsSet; + } + else if(args[i].equals("--twoway")) + { + twoway = true; + ++optsSet; + } + else if(args[i].equals("--oneway")) + { + oneway = true; + ++optsSet; + } + else if(args[i].startsWith("--")) + { + usage(); + return 1; + } + else + { + topicName = args[i]; + break; + } + } - if(optsSet > 1) - { - usage(); - return 1; - } + if(optsSet > 1) + { + usage(); + return 1; + } - // - // Retrieve the topic. - // - IceStorm.TopicPrx topic; - try - { - topic = manager.retrieve(topicName); - } - catch(IceStorm.NoSuchTopic e) - { - try - { - topic = manager.create(topicName); - } - catch(IceStorm.TopicExists ex) - { - System.err.println(appName() + ": temporary failure, try again."); - return 1; - } - } + // + // Retrieve the topic. + // + IceStorm.TopicPrx topic; + try + { + topic = manager.retrieve(topicName); + } + catch(IceStorm.NoSuchTopic e) + { + try + { + topic = manager.create(topicName); + } + catch(IceStorm.TopicExists ex) + { + System.err.println(appName() + ": temporary failure, try again."); + return 1; + } + } - // - // Get the topic's publisher object, and create a Clock proxy with - // the mode specified as an argument of this application. - // - Ice.ObjectPrx publisher = topic.getPublisher(); - if(datagram) - { - publisher = publisher.ice_datagram(); - } - else if(twoway) - { - // Do nothing. - } - else // if(oneway) - { - publisher = publisher.ice_oneway(); - } - ClockPrx clock = ClockPrxHelper.uncheckedCast(publisher); + // + // Get the topic's publisher object, and create a Clock proxy with + // the mode specified as an argument of this application. + // + Ice.ObjectPrx publisher = topic.getPublisher(); + if(datagram) + { + publisher = publisher.ice_datagram(); + } + else if(twoway) + { + // Do nothing. + } + else // if(oneway) + { + publisher = publisher.ice_oneway(); + } + ClockPrx clock = ClockPrxHelper.uncheckedCast(publisher); System.out.println("publishing tick events. Press ^C to terminate the application."); - try - { - java.text.SimpleDateFormat date = new java.text.SimpleDateFormat("MM/dd/yy HH:mm:ss:SSS"); - while(true) - { - + try + { + java.text.SimpleDateFormat date = new java.text.SimpleDateFormat("MM/dd/yy HH:mm:ss:SSS"); + while(true) + { + clock.tick(date.format(new java.util.Date())); - try - { - Thread.currentThread().sleep(1000); - } - catch(java.lang.InterruptedException e) - { - } - } - } - catch(Ice.CommunicatorDestroyedException ex) - { - // Ignore - } + try + { + Thread.currentThread().sleep(1000); + } + catch(java.lang.InterruptedException e) + { + } + } + } + catch(Ice.CommunicatorDestroyedException ex) + { + // Ignore + } return 0; } diff --git a/java/demo/IceStorm/clock/Subscriber.java b/java/demo/IceStorm/clock/Subscriber.java index ebc5833170b..ec5f9502bbd 100644 --- a/java/demo/IceStorm/clock/Subscriber.java +++ b/java/demo/IceStorm/clock/Subscriber.java @@ -14,88 +14,88 @@ public class Subscriber extends Ice.Application public class ClockI extends _ClockDisp { public void - tick(String date, Ice.Current current) - { - System.out.println(date); - } + tick(String date, Ice.Current current) + { + System.out.println(date); + } } public void usage() { - System.out.println("Usage: " + appName() + " [--batch] [--datagram|--twoway|--ordered|--oneway] [topic]"); + System.out.println("Usage: " + appName() + " [--batch] [--datagram|--twoway|--ordered|--oneway] [topic]"); } public int run(String[] args) { IceStorm.TopicManagerPrx manager = IceStorm.TopicManagerPrxHelper.checkedCast( - communicator().propertyToProxy("IceStorm.TopicManager.Proxy")); + communicator().propertyToProxy("IceStorm.TopicManager.Proxy")); if(manager == null) { - System.err.println("invalid proxy"); + System.err.println("invalid proxy"); return 1; } String topicName = "time"; - boolean datagram = false; - boolean twoway = false; - boolean ordered = false; - boolean oneway = false; - boolean batch = false; - int optsSet = 0; - for(int i = 0; i < args.length; ++i) - { - if(args[i].equals("--datagram")) - { - datagram = true; - ++optsSet; - } - else if(args[i].equals("--twoway")) - { - twoway = true; - ++optsSet; - } - else if(args[i].equals("--ordered")) - { - ordered = true; - ++optsSet; - } - else if(args[i].equals("--oneway")) - { - oneway = true; - ++optsSet; - } - else if(args[i].equals("--batch")) - { - batch = true; - } - else if(args[i].startsWith("--")) - { - usage(); - return 1; - } - else - { - topicName = args[i]; - break; - } - } + boolean datagram = false; + boolean twoway = false; + boolean ordered = false; + boolean oneway = false; + boolean batch = false; + int optsSet = 0; + for(int i = 0; i < args.length; ++i) + { + if(args[i].equals("--datagram")) + { + datagram = true; + ++optsSet; + } + else if(args[i].equals("--twoway")) + { + twoway = true; + ++optsSet; + } + else if(args[i].equals("--ordered")) + { + ordered = true; + ++optsSet; + } + else if(args[i].equals("--oneway")) + { + oneway = true; + ++optsSet; + } + else if(args[i].equals("--batch")) + { + batch = true; + } + else if(args[i].startsWith("--")) + { + usage(); + return 1; + } + else + { + topicName = args[i]; + break; + } + } - if(batch) - { - if(twoway || ordered) - { - System.err.println(appName() + ": batch can only be set with oneway or datagram"); - return 1; - } - } + if(batch) + { + if(twoway || ordered) + { + System.err.println(appName() + ": batch can only be set with oneway or datagram"); + return 1; + } + } - if(optsSet > 1) - { - usage(); - return 1; - } + if(optsSet > 1) + { + usage(); + return 1; + } IceStorm.TopicPrx topic; try @@ -120,54 +120,54 @@ public class Subscriber extends Ice.Application // // Add a Servant for the Ice Object. // - java.util.Map qos = new java.util.HashMap(); - Ice.ObjectPrx subscriber = adapter.addWithUUID(new ClockI()); - // - // Set up the proxy. - // - if(datagram) - { - subscriber = subscriber.ice_datagram(); - } - else if(twoway) - { - // Do nothing to the subscriber proxy. Its already twoway. - } - else if(ordered) - { - // Do nothing to the subscriber proxy. Its already twoway. - qos.put("reliability", "ordered"); - } - else // if(oneway) - { - subscriber = subscriber.ice_oneway(); - } - if(batch) - { - if(datagram) - { - subscriber = subscriber.ice_batchDatagram(); - } - else - { - subscriber = subscriber.ice_batchOneway(); - } - } - - try - { - topic.subscribeAndGetPublisher(qos, subscriber); - } - catch(IceStorm.AlreadySubscribed e) - { - e.printStackTrace(); - return 1; - } - catch(IceStorm.BadQoS e) - { - e.printStackTrace(); - return 1; - } + java.util.Map qos = new java.util.HashMap(); + Ice.ObjectPrx subscriber = adapter.addWithUUID(new ClockI()); + // + // Set up the proxy. + // + if(datagram) + { + subscriber = subscriber.ice_datagram(); + } + else if(twoway) + { + // Do nothing to the subscriber proxy. Its already twoway. + } + else if(ordered) + { + // Do nothing to the subscriber proxy. Its already twoway. + qos.put("reliability", "ordered"); + } + else // if(oneway) + { + subscriber = subscriber.ice_oneway(); + } + if(batch) + { + if(datagram) + { + subscriber = subscriber.ice_batchDatagram(); + } + else + { + subscriber = subscriber.ice_batchOneway(); + } + } + + try + { + topic.subscribeAndGetPublisher(qos, subscriber); + } + catch(IceStorm.AlreadySubscribed e) + { + e.printStackTrace(); + return 1; + } + catch(IceStorm.BadQoS e) + { + e.printStackTrace(); + return 1; + } adapter.activate(); shutdownOnInterrupt(); diff --git a/java/demo/book/evictor/EvictorBase.java b/java/demo/book/evictor/EvictorBase.java index 1fd3c59c660..fce84685d83 100644 --- a/java/demo/book/evictor/EvictorBase.java +++ b/java/demo/book/evictor/EvictorBase.java @@ -15,13 +15,13 @@ public abstract class EvictorBase extends Ice.LocalObjectImpl implements Ice.Ser public EvictorBase() { - _size = 1000; + _size = 1000; } public EvictorBase(int size) { - _size = size < 0 ? 1000 : size; + _size = size < 0 ? 1000 : size; } public abstract Ice.Object @@ -33,107 +33,107 @@ public abstract class EvictorBase extends Ice.LocalObjectImpl implements Ice.Ser synchronized public final Ice.Object locate(Ice.Current c, Ice.LocalObjectHolder cookie) { - // - // Create a cookie. - // - EvictorCookie ec = new EvictorCookie(); - cookie.value = ec; - - // - // Check if we a servant in the map already. - // - ec.entry = (EvictorEntry)_map.get(c.id); - boolean newEntry = ec.entry == null; - if(!newEntry) - { - // - // Got an entry already, dequeue the entry from - // its current position. - // - ec.entry.pos.remove(); - } - else - { - // - // We do not have entry. Ask the derived class to - // instantiate a servant and add a new entry to the map. - // - ec.entry = new EvictorEntry(); - Ice.LocalObjectHolder cookieHolder = new Ice.LocalObjectHolder(); - ec.entry.servant = add(c, cookieHolder); // Down-call - if(ec.entry.servant == null) - { - return null; - } - ec.entry.userCookie = cookieHolder.value; - ec.entry.useCount = 0; - _map.put(c.id, ec.entry); - } - - // - // Increment the use count of the servant and enqueue - // the entry at the front, so we get LRU order. - // - ++(ec.entry.useCount); - _queue.addFirst(c.id); - ec.entry.pos = _queue.iterator(); - ec.entry.pos.next(); // Position the iterator on the element. - - return ec.entry.servant; + // + // Create a cookie. + // + EvictorCookie ec = new EvictorCookie(); + cookie.value = ec; + + // + // Check if we a servant in the map already. + // + ec.entry = (EvictorEntry)_map.get(c.id); + boolean newEntry = ec.entry == null; + if(!newEntry) + { + // + // Got an entry already, dequeue the entry from + // its current position. + // + ec.entry.pos.remove(); + } + else + { + // + // We do not have entry. Ask the derived class to + // instantiate a servant and add a new entry to the map. + // + ec.entry = new EvictorEntry(); + Ice.LocalObjectHolder cookieHolder = new Ice.LocalObjectHolder(); + ec.entry.servant = add(c, cookieHolder); // Down-call + if(ec.entry.servant == null) + { + return null; + } + ec.entry.userCookie = cookieHolder.value; + ec.entry.useCount = 0; + _map.put(c.id, ec.entry); + } + + // + // Increment the use count of the servant and enqueue + // the entry at the front, so we get LRU order. + // + ++(ec.entry.useCount); + _queue.addFirst(c.id); + ec.entry.pos = _queue.iterator(); + ec.entry.pos.next(); // Position the iterator on the element. + + return ec.entry.servant; } synchronized public final void finished(Ice.Current c, Ice.Object o, Ice.LocalObject cookie) { - EvictorCookie ec = (EvictorCookie)cookie; - - // - // Decrement use count and check if - // there is something to evict. - // - --(ec.entry.useCount); - evictServants(); + EvictorCookie ec = (EvictorCookie)cookie; + + // + // Decrement use count and check if + // there is something to evict. + // + --(ec.entry.useCount); + evictServants(); } synchronized public final void deactivate(String category) { - _size = 0; - evictServants(); + _size = 0; + evictServants(); } private class EvictorEntry { - Ice.Object servant; - Ice.LocalObject userCookie; - java.util.Iterator pos; + Ice.Object servant; + Ice.LocalObject userCookie; + java.util.Iterator pos; int useCount; } private class EvictorCookie extends Ice.LocalObjectImpl { - public EvictorEntry entry; + public EvictorEntry entry; } private void evictServants() { - // - // If the evictor queue has grown larger than the limit, - // look at the excess elements to see whether any of them - // can be evicted. - // - for(int i = _map.size() - _size; i > 0; --i) - { - java.util.Iterator p = _queue.riterator(); - Ice.Identity id = (Ice.Identity)p.next(); - EvictorEntry e = (EvictorEntry)_map.get(id); - if(e.useCount == 0) - { - evict(e.servant, e.userCookie); // Down-call - p.remove(); - _map.remove(id); - } - } + // + // If the evictor queue has grown larger than the limit, + // look at the excess elements to see whether any of them + // can be evicted. + // + for(int i = _map.size() - _size; i > 0; --i) + { + java.util.Iterator p = _queue.riterator(); + Ice.Identity id = (Ice.Identity)p.next(); + EvictorEntry e = (EvictorEntry)_map.get(id); + if(e.useCount == 0) + { + evict(e.servant, e.userCookie); // Down-call + p.remove(); + _map.remove(id); + } + } } private java.util.Map _map = new java.util.HashMap(); diff --git a/java/demo/book/evictor/LinkedList.java b/java/demo/book/evictor/LinkedList.java index 753aaeb59f2..1c1e61a74d9 100644 --- a/java/demo/book/evictor/LinkedList.java +++ b/java/demo/book/evictor/LinkedList.java @@ -31,193 +31,193 @@ public class LinkedList public java.lang.Object getFirst() { - if(_size == 0) - { - throw new java.util.NoSuchElementException(); - } + if(_size == 0) + { + throw new java.util.NoSuchElementException(); + } - return _header.next.element; + return _header.next.element; } public void addFirst(java.lang.Object o) { - addBefore(o, _header.next); + addBefore(o, _header.next); } public boolean isEmpty() { - return _size == 0; + return _size == 0; } public int size() { - return _size; + return _size; } public java.util.Iterator iterator() { - return new ForwardIterator(); + return new ForwardIterator(); } public java.util.Iterator riterator() { - return new ReverseIterator(); + return new ReverseIterator(); } private class ForwardIterator implements java.util.Iterator { - public boolean - hasNext() - { - return _next != null; - } - - public java.lang.Object - next() - { + public boolean + hasNext() + { + return _next != null; + } + + public java.lang.Object + next() + { if(_next == null) - { + { throw new java.util.NoSuchElementException(); - } - - _current = _next; - - if(_next.next != _header) - { - _next = _next.next; - } - else - { - _next = null; - } - return _current.element; - } - - public void - remove() - { - if(_current == null) - { + } + + _current = _next; + + if(_next.next != _header) + { + _next = _next.next; + } + else + { + _next = null; + } + return _current.element; + } + + public void + remove() + { + if(_current == null) + { throw new IllegalStateException(); - } - LinkedList.this.remove(_current); - _current = null; - } - - ForwardIterator() - { - if(_header.next == _header) - { - _next = null; - } - else - { - _next = _header.next; - } - _current = null; - } - - private Entry _current; - private Entry _next; + } + LinkedList.this.remove(_current); + _current = null; + } + + ForwardIterator() + { + if(_header.next == _header) + { + _next = null; + } + else + { + _next = _header.next; + } + _current = null; + } + + private Entry _current; + private Entry _next; } private class ReverseIterator implements java.util.Iterator { - public boolean - hasNext() - { - return _next != null; - } - - public java.lang.Object - next() - { + public boolean + hasNext() + { + return _next != null; + } + + public java.lang.Object + next() + { if(_next == null) - { + { throw new java.util.NoSuchElementException(); - } - - _current = _next; - - if(_next.previous != _header) - { - _next = _next.previous; - } - else - { - _next = null; - } - return _current.element; - } - - public void - remove() - { - if(_current == null) - { + } + + _current = _next; + + if(_next.previous != _header) + { + _next = _next.previous; + } + else + { + _next = null; + } + return _current.element; + } + + public void + remove() + { + if(_current == null) + { throw new IllegalStateException(); - } - LinkedList.this.remove(_current); - _current = null; - } - - ReverseIterator() - { - if(_header.next == _header) - { - _next = null; - } - else - { - _next = _header.previous; - } - _current = null; - } - - private Entry _current; - private Entry _next; + } + LinkedList.this.remove(_current); + _current = null; + } + + ReverseIterator() + { + if(_header.next == _header) + { + _next = null; + } + else + { + _next = _header.previous; + } + _current = null; + } + + private Entry _current; + private Entry _next; } private static class Entry { - java.lang.Object element; - Entry next; - Entry previous; - - Entry(java.lang.Object element, Entry next, Entry previous) - { - this.element = element; - this.next = next; - this.previous = previous; - } + java.lang.Object element; + Entry next; + Entry previous; + + Entry(java.lang.Object element, Entry next, Entry previous) + { + this.element = element; + this.next = next; + this.previous = previous; + } } private Entry addBefore(java.lang.Object o, Entry e) { - Entry newEntry = new Entry(o, e, e.previous); - newEntry.previous.next = newEntry; - newEntry.next.previous = newEntry; - _size++; - return newEntry; + Entry newEntry = new Entry(o, e, e.previous); + newEntry.previous.next = newEntry; + newEntry.next.previous = newEntry; + _size++; + return newEntry; } private void remove(Entry e) { - if(e == _header) - { - throw new java.util.NoSuchElementException(); - } - - e.previous.next = e.next; - e.next.previous = e.previous; - _size--; + if(e == _header) + { + throw new java.util.NoSuchElementException(); + } + + e.previous.next = e.next; + e.next.previous = e.previous; + _size--; } private Entry _header = new Entry(null, null, null); diff --git a/java/demo/book/printer/Client.java b/java/demo/book/printer/Client.java index 20a98aa6536..9f373631dbb 100755 --- a/java/demo/book/printer/Client.java +++ b/java/demo/book/printer/Client.java @@ -14,31 +14,31 @@ public class Client { int status = 0; Ice.Communicator ic = null; try { - ic = Ice.Util.initialize(args); - Ice.ObjectPrx base = ic.stringToProxy( - "SimplePrinter:default -p 10000"); - Demo.PrinterPrx printer = Demo.PrinterPrxHelper.checkedCast(base); - if (printer == null) - throw new Error("Invalid proxy"); + ic = Ice.Util.initialize(args); + Ice.ObjectPrx base = ic.stringToProxy( + "SimplePrinter:default -p 10000"); + Demo.PrinterPrx printer = Demo.PrinterPrxHelper.checkedCast(base); + if (printer == null) + throw new Error("Invalid proxy"); - printer.printString("Hello World!"); + printer.printString("Hello World!"); } catch (Ice.LocalException e) { e.printStackTrace(); - status = 1; + status = 1; } catch (Exception e) { - System.err.println(e.getMessage()); - status = 1; - } - if (ic != null) { - // Clean up - // - try { - ic.destroy(); - } catch (Exception e) { - System.err.println(e.getMessage()); - status = 1; - } - } + System.err.println(e.getMessage()); + status = 1; + } + if (ic != null) { + // Clean up + // + try { + ic.destroy(); + } catch (Exception e) { + System.err.println(e.getMessage()); + status = 1; + } + } System.exit(status); } } diff --git a/java/demo/book/printer/Printer.ice b/java/demo/book/printer/Printer.ice index 20e46cdf549..01a4d213aa0 100755 --- a/java/demo/book/printer/Printer.ice +++ b/java/demo/book/printer/Printer.ice @@ -15,7 +15,7 @@ module Demo interface Printer { - void printString(string s); + void printString(string s); }; }; diff --git a/java/demo/book/printer/Server.java b/java/demo/book/printer/Server.java index 603aac1995a..af0d145175e 100755 --- a/java/demo/book/printer/Server.java +++ b/java/demo/book/printer/Server.java @@ -11,33 +11,33 @@ public class Server { public static void main(String[] args) { - int status = 0; - Ice.Communicator ic = null; + int status = 0; + Ice.Communicator ic = null; try { - ic = Ice.Util.initialize(args); - Ice.ObjectAdapter adapter - = ic.createObjectAdapterWithEndpoints( - "SimplePrinterAdapter", "default -p 10000"); - Ice.Object object = new PrinterI(); - adapter.add( - object, - ic.stringToIdentity("SimplePrinter")); - adapter.activate(); - ic.waitForShutdown(); + ic = Ice.Util.initialize(args); + Ice.ObjectAdapter adapter + = ic.createObjectAdapterWithEndpoints( + "SimplePrinterAdapter", "default -p 10000"); + Ice.Object object = new PrinterI(); + adapter.add( + object, + ic.stringToIdentity("SimplePrinter")); + adapter.activate(); + ic.waitForShutdown(); } catch (Exception e) { - e.printStackTrace(); - status = 1; - } - if (ic != null) { - // Clean up - // - try { - ic.destroy(); - } catch (Exception e) { - System.err.println(e.getMessage()); - status = 1; - } - } + e.printStackTrace(); + status = 1; + } + if (ic != null) { + // Clean up + // + try { + ic.destroy(); + } catch (Exception e) { + System.err.println(e.getMessage()); + status = 1; + } + } System.exit(status); } } diff --git a/java/demo/book/simple_filesystem/Client.java b/java/demo/book/simple_filesystem/Client.java index 0e681a82ef3..158e8ba3e93 100755 --- a/java/demo/book/simple_filesystem/Client.java +++ b/java/demo/book/simple_filesystem/Client.java @@ -18,67 +18,67 @@ public class Client { static void listRecursive(DirectoryPrx dir, int depth) { - char[] indentCh = new char[++depth]; - java.util.Arrays.fill(indentCh, '\t'); - String indent = new String(indentCh); + char[] indentCh = new char[++depth]; + java.util.Arrays.fill(indentCh, '\t'); + String indent = new String(indentCh); - NodePrx[] contents = dir.list(); + NodePrx[] contents = dir.list(); - for (int i = 0; i < contents.length; ++i) { - DirectoryPrx subdir = DirectoryPrxHelper.checkedCast(contents[i]); - FilePrx file = FilePrxHelper.uncheckedCast(contents[i]); - System.out.println(indent + contents[i].name() + (subdir != null ? " (directory):" : " (file):")); - if (subdir != null) { - listRecursive(subdir, depth); - } else { - String[] text = file.read(); - for (int j = 0; j < text.length; ++j) - System.out.println(indent + "\t" + text[j]); - } - } + for (int i = 0; i < contents.length; ++i) { + DirectoryPrx subdir = DirectoryPrxHelper.checkedCast(contents[i]); + FilePrx file = FilePrxHelper.uncheckedCast(contents[i]); + System.out.println(indent + contents[i].name() + (subdir != null ? " (directory):" : " (file):")); + if (subdir != null) { + listRecursive(subdir, depth); + } else { + String[] text = file.read(); + for (int j = 0; j < text.length; ++j) + System.out.println(indent + "\t" + text[j]); + } + } } public static void main(String[] args) { - int status = 0; - Ice.Communicator ic = null; + int status = 0; + Ice.Communicator ic = null; try { - // Create a communicator - // - ic = Ice.Util.initialize(args); + // Create a communicator + // + ic = Ice.Util.initialize(args); - // Create a proxy for the root directory - // - Ice.ObjectPrx base = ic.stringToProxy("RootDir:default -p 10000"); + // Create a proxy for the root directory + // + Ice.ObjectPrx base = ic.stringToProxy("RootDir:default -p 10000"); - // Down-cast the proxy to a Directory proxy - // - DirectoryPrx rootDir = DirectoryPrxHelper.checkedCast(base); - if (rootDir == null) - throw new RuntimeException("Invalid proxy"); + // Down-cast the proxy to a Directory proxy + // + DirectoryPrx rootDir = DirectoryPrxHelper.checkedCast(base); + if (rootDir == null) + throw new RuntimeException("Invalid proxy"); - // Recursively list the contents of the root directory - // - System.out.println("Contents of root directory:"); - listRecursive(rootDir, 0); + // Recursively list the contents of the root directory + // + System.out.println("Contents of root directory:"); + listRecursive(rootDir, 0); } catch (Ice.LocalException e) { e.printStackTrace(); - status = 1; + status = 1; } catch (Exception e) { - System.err.println(e.getMessage()); - status = 1; - } - if (ic != null) { - // Clean up - // - try { - ic.destroy(); - } catch (Exception e) { - System.err.println(e.getMessage()); - status = 1; - } - } + System.err.println(e.getMessage()); + status = 1; + } + if (ic != null) { + // Clean up + // + try { + ic.destroy(); + } catch (Exception e) { + System.err.println(e.getMessage()); + status = 1; + } + } System.exit(status); } } diff --git a/java/demo/book/simple_filesystem/Filesystem.ice b/java/demo/book/simple_filesystem/Filesystem.ice index 1fab7e0a7c2..c2458a5e8a8 100755 --- a/java/demo/book/simple_filesystem/Filesystem.ice +++ b/java/demo/book/simple_filesystem/Filesystem.ice @@ -9,23 +9,23 @@ module Filesystem { exception GenericError { - string reason; + string reason; }; interface Node { - idempotent string name(); + idempotent string name(); }; sequence<string> Lines; interface File extends Node { - idempotent Lines read(); - idempotent void write(Lines text) throws GenericError; + idempotent Lines read(); + idempotent void write(Lines text) throws GenericError; }; sequence<Node*> NodeSeq; interface Directory extends Node { - idempotent NodeSeq list(); + idempotent NodeSeq list(); }; }; diff --git a/java/demo/book/simple_filesystem/Filesystem/DirectoryI.java b/java/demo/book/simple_filesystem/Filesystem/DirectoryI.java index a79bf2ee4db..4eb05f98356 100755 --- a/java/demo/book/simple_filesystem/Filesystem/DirectoryI.java +++ b/java/demo/book/simple_filesystem/Filesystem/DirectoryI.java @@ -16,23 +16,23 @@ public final class DirectoryI extends _DirectoryDisp public DirectoryI(String name, DirectoryI parent) { - _name = name; - _parent = parent; + _name = name; + _parent = parent; - // Create an identity. The parent has the fixed identity "/" - // - Ice.Identity myID = - _adapter.getCommunicator().stringToIdentity(_parent != null ? Ice.Util.generateUUID() : "RootDir"); + // Create an identity. The parent has the fixed identity "/" + // + Ice.Identity myID = + _adapter.getCommunicator().stringToIdentity(_parent != null ? Ice.Util.generateUUID() : "RootDir"); - // Add the identity to the object adapter - // - _adapter.add(this, myID); + // Add the identity to the object adapter + // + _adapter.add(this, myID); - // Create a proxy for the new node and add it as a child to the parent - // - NodePrx thisNode = NodePrxHelper.uncheckedCast(_adapter.createProxy(myID)); - if (_parent != null) - _parent.addChild(thisNode); + // Create a proxy for the new node and add it as a child to the parent + // + NodePrx thisNode = NodePrxHelper.uncheckedCast(_adapter.createProxy(myID)); + if (_parent != null) + _parent.addChild(thisNode); } // Slice Node::name() operation @@ -40,7 +40,7 @@ public final class DirectoryI extends _DirectoryDisp public String name(Ice.Current current) { - return _name; + return _name; } // Slice Directory::list() operation @@ -48,9 +48,9 @@ public final class DirectoryI extends _DirectoryDisp public NodePrx[] list(Ice.Current current) { - NodePrx[] result = new NodePrx[_contents.size()]; - _contents.toArray(result); - return result; + NodePrx[] result = new NodePrx[_contents.size()]; + _contents.toArray(result); + return result; } // addChild is called by the child in order to add @@ -59,7 +59,7 @@ public final class DirectoryI extends _DirectoryDisp void addChild(NodePrx child) { - _contents.add(child); + _contents.add(child); } public static Ice.ObjectAdapter _adapter; diff --git a/java/demo/book/simple_filesystem/Filesystem/FileI.java b/java/demo/book/simple_filesystem/Filesystem/FileI.java index 3aadc6f24f6..1bbd9d03e4a 100755 --- a/java/demo/book/simple_filesystem/Filesystem/FileI.java +++ b/java/demo/book/simple_filesystem/Filesystem/FileI.java @@ -16,23 +16,23 @@ public class FileI extends _FileDisp public FileI(String name, DirectoryI parent) { - _name = name; - _parent = parent; + _name = name; + _parent = parent; - assert(_parent != null); + assert(_parent != null); - // Create an identity - // - Ice.Identity myID = _adapter.getCommunicator().stringToIdentity(Ice.Util.generateUUID()); + // Create an identity + // + Ice.Identity myID = _adapter.getCommunicator().stringToIdentity(Ice.Util.generateUUID()); - // Add the identity to the object adapter - // - _adapter.add(this, myID); + // Add the identity to the object adapter + // + _adapter.add(this, myID); - // Create a proxy for the new node and add it as a child to the parent - // - NodePrx thisNode = NodePrxHelper.uncheckedCast(_adapter.createProxy(myID)); - _parent.addChild(thisNode); + // Create a proxy for the new node and add it as a child to the parent + // + NodePrx thisNode = NodePrxHelper.uncheckedCast(_adapter.createProxy(myID)); + _parent.addChild(thisNode); } // Slice Node::name() operation @@ -40,7 +40,7 @@ public class FileI extends _FileDisp public String name(Ice.Current current) { - return _name; + return _name; } // Slice File::read() operation @@ -48,16 +48,16 @@ public class FileI extends _FileDisp public String[] read(Ice.Current current) { - return _lines; + return _lines; } // Slice File::write() operation public void write(String[] text, Ice.Current current) - throws GenericError + throws GenericError { - _lines = text; + _lines = text; } public static Ice.ObjectAdapter _adapter; diff --git a/java/demo/book/simple_filesystem/Server.java b/java/demo/book/simple_filesystem/Server.java index ae847feec1e..bb94f350b31 100755 --- a/java/demo/book/simple_filesystem/Server.java +++ b/java/demo/book/simple_filesystem/Server.java @@ -14,68 +14,68 @@ public class Server extends Ice.Application { run(String[] args) { // Terminate cleanly on receipt of a signal - // - shutdownOnInterrupt(); + // + shutdownOnInterrupt(); - // Create an object adapter (stored in the _adapter - // static members) - // - Ice.ObjectAdapter adapter = communicator().createObjectAdapterWithEndpoints( - "SimpleFilesystem", "default -p 10000"); - DirectoryI._adapter = adapter; - FileI._adapter = adapter; + // Create an object adapter (stored in the _adapter + // static members) + // + Ice.ObjectAdapter adapter = communicator().createObjectAdapterWithEndpoints( + "SimpleFilesystem", "default -p 10000"); + DirectoryI._adapter = adapter; + FileI._adapter = adapter; - // Create the root directory (with name "/" and no parent) - // - DirectoryI root = new DirectoryI("/", null); + // Create the root directory (with name "/" and no parent) + // + DirectoryI root = new DirectoryI("/", null); - // Create a file called "README" in the root directory - // - File file = new FileI("README", root); - String[] text; - text = new String[]{ "This file system contains a collection of poetry." }; - try { - file.write(text, null); - } catch (GenericError e) { - System.err.println(e.reason); - } + // Create a file called "README" in the root directory + // + File file = new FileI("README", root); + String[] text; + text = new String[]{ "This file system contains a collection of poetry." }; + try { + file.write(text, null); + } catch (GenericError e) { + System.err.println(e.reason); + } - // Create a directory called "Coleridge" in the root directory - // - DirectoryI coleridge = new DirectoryI("Coleridge", root); + // Create a directory called "Coleridge" in the root directory + // + DirectoryI coleridge = new DirectoryI("Coleridge", root); - // Create a file called "Kubla_Khan" in the Coleridge directory - // - file = new FileI("Kubla_Khan", coleridge); - text = new String[]{ "In Xanadu did Kubla Khan", - "A stately pleasure-dome decree:", - "Where Alph, the sacred river, ran", - "Through caverns measureless to man", - "Down to a sunless sea." }; - try { - file.write(text, null); - } catch (GenericError e) { - System.err.println(e.reason); - } + // Create a file called "Kubla_Khan" in the Coleridge directory + // + file = new FileI("Kubla_Khan", coleridge); + text = new String[]{ "In Xanadu did Kubla Khan", + "A stately pleasure-dome decree:", + "Where Alph, the sacred river, ran", + "Through caverns measureless to man", + "Down to a sunless sea." }; + try { + file.write(text, null); + } catch (GenericError e) { + System.err.println(e.reason); + } - // All objects are created, allow client requests now - // - adapter.activate(); + // All objects are created, allow client requests now + // + adapter.activate(); - // Wait until we are done - // - communicator().waitForShutdown(); + // Wait until we are done + // + communicator().waitForShutdown(); - if (interrupted()) - System.err.println(appName() + ": terminating"); + if (interrupted()) + System.err.println(appName() + ": terminating"); - return 0; + return 0; } public static void main(String[] args) { Server app = new Server(); - System.exit(app.main("Server", args)); + System.exit(app.main("Server", args)); } } |