1 package dynaop.example; 2 3 import java.util.Date ; 4 5 import dynaop.ProxyFactory; 6 import dynaop.observer.Observer; 7 import dynaop.observer.Subject; 8 9 15 public class Main { 16 17 public static void main(String [] args) throws Exception { 18 Sequence.setFrame(new com.zanthan.sequence.SequenceFrame()); 20 21 Factory factory = Factory.getInstance(); 23 24 Date date = factory.createDate(); 26 System.out.println("=> Time: " + date.getTime()); 27 date.setTime(1000); 28 29 Book book = factory.createBook(); 31 Observer observer = BookTitleObserver.getInstance(); 32 ((Subject) book).addObserver(observer); 33 book.setTitle("Bitter EJB"); 34 book.setPublicationDate(date); 35 36 PersonProxy bob = (PersonProxy) factory.createPerson(); 39 bob.setId(100); 40 bob.getId(); 41 bob.getBooks().add(book); 42 bob.setEmail("crazybob@crazybob.org"); 43 44 PersonProxy krista = (PersonProxy) factory.createPerson(); 46 krista.setId(200); 47 System.out.println("=> Equals: " + bob.equals(krista)); 48 49 ((Identifiable) book).setId(10); 51 System.out.println("=> Equals: " + book.equals(krista)); 52 53 60 } 61 62 static void testPerformance() { 63 PersonProxy p = (PersonProxy) Factory.getInstance().createPerson(); 64 p.setId(50); 65 p.getId(); 66 p.getEmail(); 67 p.hashCode(); 68 69 long start = System.currentTimeMillis(); 70 for (int i = 0; i < 10000; i++) { 71 p.setId(50); 72 p.getId(); 73 p.getEmail(); 74 p.hashCode(); 75 } 76 System.out.println("*** Time: " + 77 (System.currentTimeMillis() - start) + "ms"); 78 } 79 80 static void testCglibPerformance() { 81 BookImpl b = (BookImpl) 82 ProxyFactory.getInstance().extend(BookImpl.class); 83 ((Identifiable) b).setId(50); 84 ((Identifiable) b).getId(); 85 b.hashCode(); 86 87 long start = System.currentTimeMillis(); 88 for (int i = 0; i < 10000; i++) { 89 ((Identifiable) b).setId(50); 90 ((Identifiable) b).getId(); 91 b.hashCode(); 92 } 93 System.out.println("*** Time: " + 94 (System.currentTimeMillis() - start) + "ms"); 95 } 96 } 97 | Popular Tags |