1 package org.myoodb.simpleSslWeb; 25 26 import java.awt.*; 27 import java.awt.event.*; 28 29 31 public class Client extends java.applet.Applet implements Runnable , ActionListener 32 { 33 public static int PORT = 443; 35 public static String USERNAME = "admin"; 36 public static String PASSWORD = "admin"; 37 38 private Thread m_thread; 39 private Button m_addButton; 40 private TextArea m_textArea; 41 42 private synchronized void waitForAddPersonRequest() 43 { 44 try 45 { 46 wait(); 47 } 48 catch (InterruptedException e) 49 { 50 } 51 } 52 53 private synchronized void addPersonNotify() 54 { 55 notify(); 56 } 57 58 public void init() 59 { 60 m_textArea = new TextArea(60, 60); 61 m_textArea.setEditable(false); 62 63 m_addButton = new Button("Add Person"); 64 m_addButton.addActionListener(this); 65 66 setLayout(new BorderLayout()); 67 68 add("Center", m_textArea); 69 add("South", m_addButton); 70 } 71 72 public void run() 73 { 74 try 75 { 76 org.myoodb.MyOodbDatabase db = org.myoodb.MyOodbDatabase.open("myoowebs://" + getCodeBase().getHost() + ":" + PORT, USERNAME, PASSWORD); 78 79 org.myoodb.collectable.LinkedList root = (org.myoodb.collectable.LinkedList) db.getRoot("Persons"); 80 81 if (root == null) 82 { 83 root = (org.myoodb.collectable.LinkedList) db.createRoot(org.myoodb.collectable.LinkedListDbImpl.class, "Persons"); 84 } 86 87 while (m_thread != null) 88 { 89 waitForAddPersonRequest(); 90 91 org.myoodb.simple.Person person = (org.myoodb.simple.Person) db.createObject(org.myoodb.simple.PersonDbImpl.class); 92 person.setName("John Smith the " + root.size()); 94 95 root.add(person); 96 97 System.out.println("New persons in database: " + person); 98 m_textArea.append("New persons in database: " + person + "\n"); 99 100 java.util.Iterator iter = root.toArrayList().iterator(); 101 while (iter.hasNext()) 102 { 103 person = (org.myoodb.simple.Person) iter.next(); 104 105 long start = System.currentTimeMillis(); 106 String name = person.getName(); 107 long stop = System.currentTimeMillis(); 108 109 System.out.println(" - Existing persons in database: " + name + " / getTime:" + (stop-start)); 110 m_textArea.append(" - Existing persons in database: " + name + " / getTime: " + (stop-start) + "\n"); 111 } 112 } 113 } 114 catch (Exception e) 115 { 116 e.printStackTrace(); 117 } 118 } 119 120 public void start() 121 { 122 if (m_thread == null) 123 { 124 m_thread = new Thread (this); 125 m_thread.setDaemon(true); 126 m_thread.start(); 127 } 128 } 129 130 public void stop() 131 { 132 if (m_thread != null) 133 { 134 m_thread = null; 135 addPersonNotify(); 136 } 137 } 138 139 public void actionPerformed(ActionEvent evt) 140 { 141 addPersonNotify(); 142 } 143 } 144
| Popular Tags
|