001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.geronimo.samples.daytrader.client.ws; 018 019 import java.awt.event.ActionEvent; 020 import java.awt.event.ActionListener; 021 import java.awt.BorderLayout; 022 import java.math.BigDecimal; 023 import java.util.TimerTask; 024 import java.net.URL; 025 026 import javax.swing.JFrame; 027 import javax.swing.JTextArea; 028 import javax.swing.ImageIcon; 029 import javax.swing.JLabel; 030 import javax.swing.JPanel; 031 import javax.swing.JScrollPane; 032 import javax.swing.JButton; 033 import javax.swing.JTextField; 034 import javax.swing.JPasswordField; 035 import javax.swing.JComboBox; 036 import javax.swing.JProgressBar; 037 import javax.swing.BorderFactory; 038 import javax.swing.SwingConstants; 039 import javax.swing.JMenuItem; 040 import javax.swing.border.EtchedBorder; 041 import javax.swing.border.BevelBorder; 042 043 public class ClientApp extends JFrame { 044 045 private JPanel jContentPane = null; 046 private JLabel jLabel = null; 047 private JPanel jPanel = null; 048 private JButton jButton = null; 049 private JTextField jTextField = null; 050 private JLabel jLabel1 = null; 051 private JScrollPane jScrollPane = null; 052 private JTextArea jTextArea = null; // 053 private JLabel jLabel2 = null; 054 private JPasswordField jPasswordField1 = null; 055 private JLabel jLabel3 = null; 056 private JPanel jPanel1 = null; 057 private JPanel jPanel2 = null; 058 private JPanel jPanel3 = null; 059 private JPanel jPanel4 = null; 060 private JPanel jPanel5 = null; 061 private JPanel jPanel6 = null; 062 private JButton jButton1 = null; 063 private JPanel jPanel7 = null; 064 private JPanel jPanel8 = null; 065 private JButton jButton2 = null; 066 private JButton jButton3 = null; 067 private JButton jButton4 = null; 068 private JButton jButton5 = null; 069 private JButton jButton6 = null; 070 private JButton jButton7 = null; 071 private JButton jButton8 = null; 072 private JLabel jLabel4 = null; 073 private JLabel jLabel5 = null; 074 private JLabel jLabel6 = null; 075 private JTextField jTextField2 = null; 076 private JTextField jTextField3 = null; 077 private JTextField jTextField4 = null; 078 private JLabel jLabel7 = null; 079 private JTextField jTextField5 = null; 080 private JPanel jPanel9 = null; 081 private JPanel jPanel10 = null; 082 private JLabel jLabel8 = null; 083 private JLabel jLabel9 = null; 084 private JComboBox jComboBox = null; 085 private JTextField jTextField1 = null; 086 private JTextField jTextField6 = null; 087 private JTextField jTextField7 = null; 088 private JButton jButton9 = null; 089 private JLabel jLabel10 = null; 090 private JLabel jLabel11 = null; 091 private JLabel jLabel12 = null; 092 private JLabel jLabel13 = null; 093 private JLabel jLabel14 = null; 094 private JLabel jLabel15 = null; 095 private JLabel jLabel16 = null; 096 private JLabel jLabel17 = null; 097 private JLabel jLabel18 = null; 098 private JLabel jLabel19 = null; 099 private JLabel jLabel20 = null; 100 private JLabel jLabel21 = null; 101 private JLabel jLabel22 = null; 102 private JLabel jLabel23 = null; 103 private JLabel jLabel24 = null; 104 private JLabel jLabel25 = null; 105 private JLabel jLabel26 = null; 106 private JProgressBar jProgressBar = null; 107 private JButton jButton10 = null; 108 private JPanel jPanel11 = null; 109 110 public static void main(String[] args) { 111 new ClientApp(); 112 } 113 114 public ClientApp() { 115 super(); 116 initialize(); 117 } 118 119 private void initialize() { 120 this.setContentPane(getJContentPane()); 121 this.setSize(673, 577); 122 this.setVisible(true); 123 this.setTitle("Web Services JAX RPC Client"); 124 this.setResizable(false); 125 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 126 127 } 128 /** 129 * This method initializes jContentPane 130 * 131 * @return JPanel 132 */ 133 private JPanel getJContentPane() { 134 if (jContentPane == null) { 135 jContentPane = new JPanel(); 136 jContentPane.setLayout(null); 137 jContentPane.add(getJLabel(), null); 138 jContentPane.add(getJPanel(), null); 139 jContentPane.add(getJScrollPane(), null); 140 jContentPane.add(getJLabel3(), null); 141 jContentPane.add(getJPanel1(), null); 142 jContentPane.add(getJPanel2(), null); 143 jContentPane.add(getJPanel3(), null); 144 jContentPane.add(getJPanel4(), null); 145 jContentPane.add(getJPanel5(), null); 146 jContentPane.add(getJPanel6(), null); 147 jContentPane.add(getJPanel7(), null); 148 jContentPane.add(getJPanel8(), null); 149 jContentPane.add(getJPanel11(), null); 150 jContentPane.setBackground(new java.awt.Color(244, 245, 245)); 151 } 152 return jContentPane; 153 } 154 /** 155 * This method initializes jLabel 156 * 157 * @return JLabel 158 */ 159 private JLabel getJLabel() { 160 if (jLabel == null) { 161 URL imageUrl = getClass().getResource("/images/dayTraderLogo.gif"); 162 if (imageUrl == null) { 163 throw new IllegalStateException("Cannont locate daytraderLogo.gif"); 164 } 165 ImageIcon imageIcon = new ImageIcon(imageUrl); 166 jLabel = new JLabel(imageIcon); 167 jLabel.setBounds(11, 7, 193, 71); 168 jLabel.setText(""); 169 } 170 return jLabel; 171 } 172 /** 173 * This method initializes jPanel 174 * 175 * @return JPanel 176 */ 177 private JPanel getJPanel() { 178 if (jPanel == null) { 179 jPanel = new JPanel(); 180 jPanel.setLayout(null); 181 jPanel.add(getJButton(), getJButton().getName()); 182 jPanel.add(getJTextField(), null); 183 jPanel.add(getJLabel1(), null); 184 jPanel.add(getJLabel2(), null); 185 jPanel.add(getJTextField1(), null); 186 jPanel.setBounds(11, 83, 287, 53); 187 jPanel.setBackground(new java.awt.Color(245, 245, 245)); 188 jPanel.setBorder( 189 BorderFactory.createEtchedBorder( 190 EtchedBorder.LOWERED)); 191 } 192 return jPanel; 193 } 194 195 /** 196 * This method initializes jButton 197 * 198 * @return JButton 199 */ 200 private JButton getJButton() { 201 if (jButton == null) { 202 jButton = new JButton(); 203 jButton.setBounds(9, 8, 68, 25); 204 jButton.setText("Login"); 205 jButton.setFont(new java.awt.Font("sansserif", 1, 10)); 206 jButton.setBorder( 207 BorderFactory.createBevelBorder( 208 BevelBorder.RAISED)); 209 jButton.setBackground(new java.awt.Color(220, 220, 220)); 210 jButton.addActionListener(new AppActionListener()); 211 } 212 return jButton; 213 } 214 /** 215 * This method initializes jTextField 216 * 217 * @return JTextField 218 */ 219 private JTextField getJTextField() { 220 if (jTextField == null) { 221 jTextField = new JTextField(); 222 jTextField.setBounds(182, 6, 93, 19); 223 jTextField.setToolTipText("UserName"); 224 jTextField.setText("uid:0"); 225 jTextField.setName("UserName"); 226 jTextField.setFont(new java.awt.Font("Arial", 0, 10)); 227 } 228 return jTextField; 229 } 230 /** 231 * This method initializes jLabel1 232 * 233 * @return JLabel 234 */ 235 private JLabel getJLabel1() { 236 if (jLabel1 == null) { 237 jLabel1 = new JLabel(); 238 jLabel1.setBounds(91, 7, 82, 15); 239 jLabel1.setText("Username"); 240 jLabel1.setFont(new java.awt.Font("Arial", 1, 10)); 241 jLabel1.setHorizontalAlignment(SwingConstants.RIGHT); 242 } 243 return jLabel1; 244 } 245 /** 246 * This method initializes jScrollPane 247 * 248 * @return JScrollPane 249 */ 250 private JScrollPane getJScrollPane() { 251 if (jScrollPane == null) { 252 jScrollPane = new JScrollPane(); 253 jScrollPane.setViewportView(getJTextArea()); 254 jScrollPane.setBounds(310, 8, 351, 255); 255 jScrollPane.setBorder( 256 BorderFactory.createTitledBorder( 257 null, 258 "Results", 259 0, 260 0)); 261 jScrollPane.setToolTipText("Result Output"); 262 jScrollPane.setName("ResultPane"); 263 } 264 return jScrollPane; 265 } 266 /** 267 * This method initializes jTextArea 268 * 269 * @return JTextArea 270 */ 271 private JTextArea getJTextArea() { 272 if (jTextArea == null) { 273 jTextArea = new JTextArea(); 274 jTextArea.setText(""); 275 jTextArea.setFont(new java.awt.Font("sansserif", 0, 10)); 276 //provide a generic output variable to allow the output source to be chagned easily 277 output = jTextArea; 278 } 279 return jTextArea; 280 } 281 /** 282 * This method initializes jLabel2 283 * 284 * @return JLabel 285 */ 286 private JLabel getJLabel2() { 287 if (jLabel2 == null) { 288 jLabel2 = new JLabel(); 289 jLabel2.setSize(82, 15); 290 jLabel2.setText("Password"); 291 jLabel2.setLocation(90, 27); 292 jLabel2.setFont(new java.awt.Font("Arial", 1, 10)); 293 jLabel2.setToolTipText("Trade User's password"); 294 jLabel2.setHorizontalAlignment(SwingConstants.RIGHT); 295 } 296 return jLabel2; 297 } 298 /** 299 * This method initializes jTextField1 300 * 301 * @return JTextField 302 */ 303 private JTextField getJTextField1() { 304 if (jPasswordField1 == null) { 305 jPasswordField1 = new JPasswordField(); 306 jPasswordField1.setSize(94, 19); 307 jPasswordField1.setLocation(181, 29); 308 jPasswordField1.setFont(new java.awt.Font("sansserif", 0, 10)); 309 jPasswordField1.setPreferredSize(new java.awt.Dimension(4, 15)); 310 jPasswordField1.setText("xxx"); 311 } 312 return jPasswordField1; 313 } 314 /** 315 * This method initializes jLabel3 316 * 317 * @return JLabel 318 */ 319 private JLabel getJLabel3() { 320 if (jLabel3 == null) { 321 jLabel3 = new JLabel(); 322 jLabel3.setBounds(212, 13, 87, 63); 323 jLabel3.setText( 324 "<html> Web Services Benchmark Scenario Application"); 325 jLabel3.setAutoscrolls(true); 326 jLabel3.setFont(new java.awt.Font("sansserif", 1, 12)); 327 jLabel3.setHorizontalAlignment(SwingConstants.CENTER); 328 } 329 return jLabel3; 330 } 331 /** 332 * This method initializes jPanel1 333 * 334 * @return JPanel 335 */ 336 private JPanel getJPanel1() { 337 if (jPanel1 == null) { 338 jPanel1 = new JPanel(); 339 jPanel1.setLayout(null); 340 jPanel1.add(getJButton1(), getJButton1().getName()); 341 jPanel1.setBounds(11, 142, 287, 38); 342 jPanel1.setBackground(new java.awt.Color(245, 245, 245)); 343 jPanel1.setBorder( 344 BorderFactory.createEtchedBorder( 345 EtchedBorder.LOWERED)); 346 } 347 return jPanel1; 348 } 349 /** 350 * This method initializes jPanel2 351 * 352 * @return JPanel 353 */ 354 private JPanel getJPanel2() { 355 if (jPanel2 == null) { 356 jPanel2 = new JPanel(); 357 jPanel2.setLayout(null); 358 jPanel2.add(getJButton2(), getJButton2().getName()); 359 jPanel2.add(getJLabel4(), null); 360 jPanel2.add(getJTextField2(), null); 361 jPanel2.setBounds(11, 185, 287, 38); 362 jPanel2.setBackground(new java.awt.Color(245, 245, 245)); 363 jPanel2.setBorder( 364 BorderFactory.createEtchedBorder( 365 EtchedBorder.LOWERED)); 366 367 } 368 return jPanel2; 369 } 370 /** 371 * This method initializes jPanel3 372 * 373 * @return JPanel 374 */ 375 private JPanel getJPanel3() { 376 if (jPanel3 == null) { 377 jPanel3 = new JPanel(); 378 jPanel3.setLayout(null); 379 jPanel3.add(getJButton3(), null); 380 jPanel3.setBounds(11, 228, 287, 38); 381 jPanel3.setBackground(new java.awt.Color(245, 245, 245)); 382 jPanel3.setBorder( 383 BorderFactory.createEtchedBorder( 384 EtchedBorder.LOWERED)); 385 } 386 return jPanel3; 387 } 388 /** 389 * This method initializes jPanel4 390 * 391 * @return JPanel 392 */ 393 private JPanel getJPanel4() { 394 if (jPanel4 == null) { 395 jPanel4 = new JPanel(); 396 jPanel4.setLayout(null); 397 jPanel4.add(getJButton4(), null); 398 jPanel4.add(getJLabel5(), null); 399 jPanel4.add(getJLabel6(), null); 400 jPanel4.add(getJTextField3(), null); 401 jPanel4.add(getJTextField4(), null); 402 jPanel4.setBounds(11, 271, 287, 53); 403 jPanel4.setBackground(new java.awt.Color(245, 245, 245)); 404 jPanel4.setBorder( 405 BorderFactory.createEtchedBorder( 406 EtchedBorder.LOWERED)); 407 } 408 return jPanel4; 409 } 410 /** 411 * This method initializes jPanel5 412 * 413 * @return JPanel 414 */ 415 private JPanel getJPanel5() { 416 if (jPanel5 == null) { 417 jPanel5 = new JPanel(); 418 jPanel5.setLayout(null); 419 jPanel5.add(getJButton5(), null); 420 jPanel5.add(getJLabel7(), null); 421 jPanel5.add(getJTextField5(), null); 422 jPanel5.setBounds(11, 329, 287, 38); 423 jPanel5.setBackground(new java.awt.Color(245, 245, 245)); 424 jPanel5.setBorder( 425 BorderFactory.createEtchedBorder( 426 EtchedBorder.LOWERED)); 427 } 428 return jPanel5; 429 } 430 /** 431 * This method initializes jPanel6 432 * 433 * @return JPanel 434 */ 435 private JPanel getJPanel6() { 436 if (jPanel6 == null) { 437 jPanel6 = new JPanel(); 438 jPanel6.setLayout(null); 439 jPanel6.add(getJButton6(), null); 440 jPanel6.setBounds(11, 373, 287, 38); 441 jPanel6.setBackground(new java.awt.Color(245, 245, 245)); 442 jPanel6.setBorder( 443 BorderFactory.createEtchedBorder( 444 EtchedBorder.LOWERED)); 445 } 446 return jPanel6; 447 } 448 /** 449 * This method initializes jButton1 450 * 451 * @return JButton 452 */ 453 private JButton getJButton1() { 454 if (jButton1 == null) { 455 jButton1 = new JButton(); 456 jButton1.setSize(141, 25); 457 jButton1.setLocation(14, 8); 458 jButton1.setText("Market Summary"); 459 jButton1.setFont(new java.awt.Font("sansserif", 1, 10)); 460 jButton1.setBorder( 461 BorderFactory.createBevelBorder( 462 BevelBorder.RAISED)); 463 jButton1.setBackground(new java.awt.Color(220, 220, 220)); 464 jButton1.setActionCommand("MarketSummary"); 465 jButton1.addActionListener(new AppActionListener()); 466 } 467 return jButton1; 468 } 469 /** 470 * This method initializes jPanel7 471 * 472 * @return JPanel 473 */ 474 private JPanel getJPanel7() { 475 if (jPanel7 == null) { 476 jPanel7 = new JPanel(); 477 jPanel7.setLayout(null); 478 jPanel7.add(getJButton7(), null); 479 jPanel7.setBounds(11, 417, 287, 38); 480 jPanel7.setBackground(new java.awt.Color(245, 245, 245)); 481 jPanel7.setBorder( 482 BorderFactory.createEtchedBorder( 483 EtchedBorder.LOWERED)); 484 } 485 return jPanel7; 486 } 487 /** 488 * This method initializes jPanel8 489 * 490 * @return JPanel 491 */ 492 private JPanel getJPanel8() { 493 if (jPanel8 == null) { 494 jPanel8 = new JPanel(); 495 jPanel8.setLayout(null); 496 jPanel8.add(getJButton8(), null); 497 jPanel8.setBounds(11, 462, 287, 38); 498 jPanel8.setBackground(new java.awt.Color(245, 245, 245)); 499 jPanel8.setBorder( 500 BorderFactory.createEtchedBorder( 501 EtchedBorder.LOWERED)); 502 } 503 504 return jPanel8; 505 } 506 /** 507 * This method initializes jButton2 508 * 509 * @return JButton 510 */ 511 private JButton getJButton2() { 512 if (jButton2 == null) { 513 jButton2 = new JButton(); 514 jButton2.setBounds(9, 8, 68, 25); 515 jButton2.setText("Quotes"); 516 jButton2.setFont(new java.awt.Font("sansserif", 1, 10)); 517 jButton2.setBorder( 518 BorderFactory.createBevelBorder( 519 BevelBorder.RAISED)); 520 jButton2.setBackground(new java.awt.Color(220, 220, 220)); 521 jButton2.addActionListener(new AppActionListener()); 522 } 523 return jButton2; 524 } 525 /** 526 * This method initializes jButton3 527 * 528 * @return JButton 529 */ 530 private JButton getJButton3() { 531 if (jButton3 == null) { 532 jButton3 = new JButton(); 533 jButton3.setSize(141, 25); 534 jButton3.setLocation(14, 8); 535 jButton3.setText("Account Info"); 536 jButton3.setFont(new java.awt.Font("sansserif", 1, 10)); 537 jButton3.setBorder( 538 BorderFactory.createBevelBorder( 539 BevelBorder.RAISED)); 540 jButton3.setBackground(new java.awt.Color(220, 220, 220)); 541 jButton3.setActionCommand("Account"); 542 jButton3.addActionListener(new AppActionListener()); 543 } 544 return jButton3; 545 } 546 /** 547 * This method initializes jButton4 548 * 549 * @return JButton 550 */ 551 private JButton getJButton4() { 552 if (jButton4 == null) { 553 jButton4 = new JButton(); 554 jButton4.setBounds(9, 8, 68, 25); 555 jButton4.setText("Buy"); 556 jButton4.setFont(new java.awt.Font("sansserif", 1, 10)); 557 jButton4.setBorder( 558 BorderFactory.createBevelBorder( 559 BevelBorder.RAISED)); 560 jButton4.setBackground(new java.awt.Color(220, 220, 220)); 561 jButton4.addActionListener(new AppActionListener()); 562 } 563 return jButton4; 564 } 565 /** 566 * This method initializes jButton5 567 * 568 * @return JButton 569 */ 570 private JButton getJButton5() { 571 if (jButton5 == null) { 572 jButton5 = new JButton(); 573 jButton5.setBounds(9, 8, 68, 25); 574 jButton5.setText("Sell"); 575 jButton5.setFont(new java.awt.Font("sansserif", 1, 10)); 576 jButton5.setBorder( 577 BorderFactory.createBevelBorder( 578 BevelBorder.RAISED)); 579 jButton5.setBackground(new java.awt.Color(220, 220, 220)); 580 jButton5.addActionListener(new AppActionListener()); 581 } 582 return jButton5; 583 } 584 /** 585 * This method initializes jButton6 586 * 587 * @return JButton 588 */ 589 private JButton getJButton6() { 590 if (jButton6 == null) { 591 jButton6 = new JButton(); 592 jButton6.setSize(141, 25); 593 jButton6.setLocation(14, 8); 594 jButton6.setText("View Orders"); 595 jButton6.setFont(new java.awt.Font("sansserif", 1, 10)); 596 jButton6.setBorder( 597 BorderFactory.createBevelBorder( 598 BevelBorder.RAISED)); 599 jButton6.setBackground(new java.awt.Color(220, 220, 220)); 600 jButton6.setActionCommand("Orders"); 601 jButton6.addActionListener(new AppActionListener()); 602 } 603 return jButton6; 604 } 605 /** 606 * This method initializes jButton7 607 * 608 * @return JButton 609 */ 610 private JButton getJButton7() { 611 if (jButton7 == null) { 612 jButton7 = new JButton(); 613 jButton7.setSize(141, 25); 614 jButton7.setLocation(14, 8); 615 jButton7.setText("View Holdings"); 616 jButton7.setFont(new java.awt.Font("sansserif", 1, 10)); 617 jButton7.setBorder( 618 BorderFactory.createBevelBorder( 619 BevelBorder.RAISED)); 620 jButton7.setBackground(new java.awt.Color(220, 220, 220)); 621 jButton7.setActionCommand("Holdings"); 622 jButton7.addActionListener(new AppActionListener()); 623 } 624 return jButton7; 625 } 626 /** 627 * This method initializes jButton8 628 * 629 * @return JButton 630 */ 631 private JButton getJButton8() { 632 if (jButton8 == null) { 633 jButton8 = new JButton(); 634 jButton8.setSize(141, 25); 635 jButton8.setLocation(14, 8); 636 jButton8.setText("Logout"); 637 jButton8.setFont(new java.awt.Font("sansserif", 1, 10)); 638 jButton8.setBorder( 639 BorderFactory.createBevelBorder( 640 BevelBorder.RAISED)); 641 jButton8.setBackground(new java.awt.Color(220, 220, 220)); 642 jButton8.addActionListener(new AppActionListener()); 643 } 644 return jButton8; 645 } 646 /** 647 * This method initializes jLabel4 648 * 649 * @return JLabel 650 */ 651 private JLabel getJLabel4() { 652 if (jLabel4 == null) { 653 jLabel4 = new JLabel(); 654 jLabel4.setBounds(91, 7, 82, 15); 655 jLabel4.setText("Symbols"); 656 jLabel4.setFont(new java.awt.Font("Arial", 1, 10)); 657 jLabel4.setHorizontalAlignment(SwingConstants.RIGHT); 658 } 659 return jLabel4; 660 } 661 /** 662 * This method initializes jLabel5 663 * 664 * @return JLabel 665 */ 666 private JLabel getJLabel5() { 667 if (jLabel5 == null) { 668 jLabel5 = new JLabel(); 669 jLabel5.setBounds(91, 7, 82, 15); 670 jLabel5.setText("Symbol"); 671 jLabel5.setFont(new java.awt.Font("Arial", 1, 10)); 672 jLabel5.setHorizontalAlignment(SwingConstants.RIGHT); 673 } 674 return jLabel5; 675 } 676 /** 677 * This method initializes jLabel6 678 * 679 * @return JLabel 680 */ 681 private JLabel getJLabel6() { 682 if (jLabel6 == null) { 683 jLabel6 = new JLabel(); 684 jLabel6.setSize(82, 15); 685 jLabel6.setText("Quantity"); 686 jLabel6.setLocation(90, 27); 687 jLabel6.setFont(new java.awt.Font("Arial", 1, 10)); 688 jLabel6.setHorizontalAlignment(SwingConstants.RIGHT); 689 } 690 return jLabel6; 691 } 692 /** 693 * This method initializes jTextField2 694 * 695 * @return JTextField 696 */ 697 private JTextField getJTextField2() { 698 if (jTextField2 == null) { 699 jTextField2 = new JTextField(); 700 jTextField2.setBounds(182, 6, 93, 19); 701 jTextField2.setToolTipText("Stock symbols"); 702 jTextField2.setText("s:1"); 703 jTextField2.setName("Symbols"); 704 jTextField2.setFont(new java.awt.Font("Arial", 0, 10)); 705 } 706 return jTextField2; 707 } 708 /** 709 * This method initializes jTextField3 710 * 711 * @return JTextField 712 */ 713 private JTextField getJTextField3() { 714 if (jTextField3 == null) { 715 jTextField3 = new JTextField(); 716 jTextField3.setBounds(182, 6, 93, 19); 717 jTextField3.setToolTipText("Stock symbols"); 718 jTextField3.setText("s:1"); 719 jTextField3.setName("symbol"); 720 jTextField3.setFont(new java.awt.Font("Arial", 0, 10)); 721 } 722 return jTextField3; 723 } 724 /** 725 * This method initializes jTextField4 726 * 727 * @return JTextField 728 */ 729 private JTextField getJTextField4() { 730 if (jTextField4 == null) { 731 jTextField4 = new JTextField(); 732 jTextField4.setBounds(182, 27, 93, 19); 733 jTextField4.setToolTipText("Quantity of shares to purchase"); 734 jTextField4.setText("100"); 735 jTextField4.setName("quantity"); 736 jTextField4.setFont(new java.awt.Font("Arial", 0, 10)); 737 } 738 return jTextField4; 739 } 740 /** 741 * This method initializes jLabel7 742 * 743 * @return JLabel 744 */ 745 private JLabel getJLabel7() { 746 if (jLabel7 == null) { 747 jLabel7 = new JLabel(); 748 jLabel7.setBounds(91, 7, 82, 15); 749 jLabel7.setText("Holding ID"); 750 jLabel7.setFont(new java.awt.Font("Arial", 1, 10)); 751 jLabel7.setHorizontalAlignment(SwingConstants.RIGHT); 752 } 753 return jLabel7; 754 } 755 /** 756 * This method initializes jTextField5 757 * 758 * @return JTextField 759 */ 760 private JTextField getJTextField5() { 761 if (jTextField5 == null) { 762 jTextField5 = new JTextField(); 763 jTextField5.setBounds(182, 6, 93, 19); 764 jTextField5.setToolTipText("Holding ID of stock to sell"); 765 jTextField5.setText("0"); 766 jTextField5.setName("holdingID"); 767 jTextField5.setFont(new java.awt.Font("Arial", 0, 10)); 768 } 769 return jTextField5; 770 } 771 /** 772 * This method initializes jPanel9 773 * 774 * @return JPanel 775 */ 776 private JPanel getJPanel9() { 777 if (jPanel9 == null) { 778 jPanel9 = new JPanel(); 779 jPanel9.setLayout(null); 780 jPanel9.add(getJLabel8(), null); 781 jPanel9.add(getJLabel9(), null); 782 jPanel9.add(getJComboBox(), null); 783 jPanel9.add(getJTextField7(), null); 784 jPanel9.add(getJTextField6(), null); 785 jPanel9.add(getJButton9(), null); 786 jPanel9.add(getJLabel27(), null); 787 jPanel9.add(getJTextField12(), null); 788 jPanel9.setBounds(11, 15, 347, 89); 789 jPanel9.setBackground(new java.awt.Color(245, 245, 245)); 790 jPanel9.setBorder( 791 BorderFactory.createTitledBorder( 792 null, 793 "Scenario Setup", 794 0, 795 0)); 796 jPanel9.setName("jPanel9"); 797 } 798 return jPanel9; 799 } 800 /** 801 * This method initializes jPanel10 802 * 803 * @return JPanel 804 */ 805 private JPanel getJPanel10() { 806 if (jPanel10 == null) { 807 jPanel10 = new JPanel(); 808 jPanel10.setLayout(null); 809 jPanel10.add(getJLabel10(), null); 810 jPanel10.add(getJLabel11(), null); 811 jPanel10.add(getJLabel12(), null); 812 jPanel10.add(getJLabel13(), null); 813 jPanel10.add(getJLabel14(), null); 814 jPanel10.add(getJLabel15(), null); 815 jPanel10.add(getJLabel16(), null); 816 jPanel10.add(getJLabel17(), null); 817 jPanel10.add(getJLabel18(), null); 818 jPanel10.add(getJLabel19(), null); 819 jPanel10.add(getJLabel20(), null); 820 jPanel10.add(getJLabel21(), null); 821 jPanel10.add(getJLabel22(), null); 822 jPanel10.add(getJLabel23(), null); 823 jPanel10.add(getJLabel24(), null); 824 jPanel10.add(getJLabel25(), null); 825 jPanel10.add(getJLabel26(), null); 826 jPanel10.add(getJProgressBar(), null); 827 jPanel10.add(getJButton10(), null); 828 jPanel10.setBounds(9, 106, 347, 153); 829 jPanel10.setBackground(new java.awt.Color(245, 245, 245)); 830 jPanel10.setBorder( 831 BorderFactory.createTitledBorder( 832 null, 833 "Scenario Statistics", 834 0, 835 0)); 836 jPanel10.setFont(new java.awt.Font("sansserif", 0, 10)); 837 } 838 return jPanel10; 839 } 840 /** 841 * This method initializes jLabel8 842 * 843 * @return JLabel 844 */ 845 private JLabel getJLabel8() { 846 if (jLabel8 == null) { 847 jLabel8 = new JLabel(); 848 jLabel8.setBounds(11, 43, 59, 13); 849 jLabel8.setText("#Threads"); 850 jLabel8.setFont(new java.awt.Font("Arial", 1, 10)); 851 jLabel8.setHorizontalAlignment(SwingConstants.RIGHT); 852 } 853 return jLabel8; 854 } 855 /** 856 * This method initializes jLabel9 857 * 858 * @return JLabel 859 */ 860 private JLabel getJLabel9() { 861 if (jLabel9 == null) { 862 jLabel9 = new JLabel(); 863 jLabel9.setBounds(11, 65, 59, 13); 864 jLabel9.setText("Iterations"); 865 jLabel9.setFont(new java.awt.Font("Arial", 1, 10)); 866 jLabel9.setHorizontalAlignment(SwingConstants.RIGHT); 867 } 868 return jLabel9; 869 } 870 // @jve:visual-info decl-index=0 visual-constraint="0,0" 871 /** 872 * This method initializes jComboBox 873 * 874 * @return JComboBox 875 */ 876 private JComboBox getJComboBox() { 877 if (jComboBox == null) { 878 jComboBox = new JComboBox(); 879 jComboBox.setBounds(166, 41, 161, 16); 880 jComboBox.setBackground(new java.awt.Color(220, 220, 220)); 881 jComboBox.setFont(new java.awt.Font("Arial", 1, 10)); 882 jComboBox.addItem("Get Quote"); 883 jComboBox.addItem("Get Quote - NULL"); 884 // TODO more scenarios here 885 // jComboBox.addItem("Holdings Only"); 886 } 887 return jComboBox; 888 } 889 /** 890 * This method initializes jTextField1 891 * 892 * @return JTextField 893 */ 894 private JTextField getJTextField7() { 895 if (jTextField7 == null) { 896 jTextField7 = new JTextField(); 897 jTextField7.setBounds(76, 43, 77, 13); 898 jTextField7.setText("10"); 899 jTextField7.setFont(new java.awt.Font("Arial", 1, 10)); 900 jTextField7.setHorizontalAlignment( 901 SwingConstants.RIGHT); 902 } 903 return jTextField7; 904 } 905 /** 906 * This method initializes jTextField6 907 * 908 * @return JTextField 909 */ 910 private JTextField getJTextField6() { 911 if (jTextField6 == null) { 912 jTextField6 = new JTextField(); 913 jTextField6.setBounds(79, 66, 77, 13); 914 jTextField6.setText("10000"); 915 jTextField6.setFont(new java.awt.Font("Arial", 1, 10)); 916 jTextField6.setHorizontalAlignment( 917 SwingConstants.RIGHT); 918 } 919 return jTextField6; 920 } 921 /** 922 * This method initializes jButton9 923 * 924 * @return JButton 925 */ 926 private JButton getJButton9() { 927 if (jButton9 == null) { 928 jButton9 = new JButton(); 929 jButton9.setBounds(169, 66, 149, 15); 930 jButton9.setBackground(new java.awt.Color(220, 220, 220)); 931 jButton9.setFont(new java.awt.Font("Arial", 1, 10)); 932 jButton9.setText("Start Scenario!"); 933 jButton9.setActionCommand("start"); 934 jButton9.addActionListener(new ActionListener() { 935 public void actionPerformed(ActionEvent e) { 936 String command = e.getActionCommand(); 937 if (command.equalsIgnoreCase("start")) { 938 int numThreads = Integer.parseInt(jTextField7.getText()); 939 int reqPerThread = 940 Integer.parseInt(jTextField6.getText()) 941 / numThreads; 942 startScenario(numThreads, reqPerThread); 943 jButton9.setText("Stop"); 944 jButton9.setActionCommand("stop"); 945 } else if (command.equalsIgnoreCase("stop")) { 946 stopScenario(); 947 jButton9.setText("Start Scenario!"); 948 jButton9.setActionCommand("start"); 949 950 } 951 } 952 }); 953 954 } 955 return jButton9; 956 } 957 958 /** 959 * This method initializes jLabel10 960 * 961 * @return JLabel 962 */ 963 private JLabel getJLabel10() { 964 if (jLabel10 == null) { 965 jLabel10 = new JLabel(); 966 jLabel10.setBounds(11, 25, 106, 13); 967 jLabel10.setText("Avg. Req/Sec"); 968 jLabel10.setFont(new java.awt.Font("Arial", 1, 10)); 969 jLabel10.setHorizontalAlignment(SwingConstants.RIGHT); 970 jLabel10.setToolTipText("The average requests per second"); 971 } 972 return jLabel10; 973 } 974 /** 975 * This method initializes jLabel11 976 * 977 * @return JLabel 978 */ 979 private JLabel getJLabel11() { 980 if (jLabel11 == null) { 981 jLabel11 = new JLabel(); 982 jLabel11.setBounds(11, 50, 106, 13); 983 jLabel11.setText("Current Req/Sec"); 984 jLabel11.setFont(new java.awt.Font("Arial", 1, 10)); 985 jLabel11.setHorizontalAlignment(SwingConstants.RIGHT); 986 jLabel11.setToolTipText( 987 "The average request per second in the last 5 second interval"); 988 } 989 return jLabel11; 990 } 991 /** 992 * This method initializes jLabel12 993 * 994 * @return JLabel 995 */ 996 private JLabel getJLabel12() { 997 if (jLabel12 == null) { 998 jLabel12 = new JLabel(); 999 jLabel12.setBounds(11, 75, 106, 13); 1000 jLabel12.setText("Total Requests"); 1001 jLabel12.setFont(new java.awt.Font("Arial", 1, 10)); 1002 jLabel12.setHorizontalAlignment(SwingConstants.RIGHT); 1003 jLabel12.setToolTipText( 1004 "The total number of requests since the beginning of the scenario"); 1005 } 1006 return jLabel12; 1007 } 1008 /** 1009 * This method initializes jLabel13 1010 * 1011 * @return JLabel 1012 */ 1013 private JLabel getJLabel13() { 1014 if (jLabel13 == null) { 1015 jLabel13 = new JLabel(); 1016 jLabel13.setBounds(11, 95, 106, 13); 1017 jLabel13.setText("Total Errors"); 1018 jLabel13.setFont(new java.awt.Font("Arial", 1, 10)); 1019 jLabel13.setHorizontalAlignment(SwingConstants.RIGHT); 1020 jLabel13.setToolTipText( 1021 "The total number of errors since the beginning of the scenario"); 1022 } 1023 return jLabel13; 1024 } 1025 /** 1026 * This method initializes jLabel14 1027 * 1028 * @return JLabel 1029 */ 1030 private JLabel getJLabel14() { 1031 if (jLabel14 == null) { 1032 jLabel14 = new JLabel(); 1033 jLabel14.setBounds(125, 25, 57, 15); 1034 jLabel14.setText("0.0"); 1035 jLabel14.setBackground(java.awt.Color.white); 1036 jLabel14.setForeground(java.awt.Color.black); 1037 jLabel14.setFont(new java.awt.Font("sansserif", 0, 10)); 1038 } 1039 return jLabel14; 1040 } 1041 /** 1042 * This method initializes jLabel15 1043 * 1044 * @return JLabel 1045 */ 1046 private JLabel getJLabel15() { 1047 if (jLabel15 == null) { 1048 jLabel15 = new JLabel(); 1049 jLabel15.setBounds(125, 50, 57, 15); 1050 jLabel15.setText("0.0"); 1051 jLabel15.setBackground(java.awt.Color.white); 1052 jLabel15.setForeground(java.awt.Color.black); 1053 jLabel15.setFont(new java.awt.Font("sansserif", 0, 10)); 1054 } 1055 return jLabel15; 1056 } 1057 /** 1058 * This method initializes jLabel16 1059 * 1060 * @return JLabel 1061 */ 1062 private JLabel getJLabel16() { 1063 if (jLabel16 == null) { 1064 jLabel16 = new JLabel(); 1065 jLabel16.setBounds(125, 75, 57, 15); 1066 jLabel16.setText("0"); 1067 jLabel16.setBackground(java.awt.Color.white); 1068 jLabel16.setForeground(java.awt.Color.black); 1069 jLabel16.setFont(new java.awt.Font("sansserif", 0, 10)); 1070 } 1071 return jLabel16; 1072 } 1073 /** 1074 * This method initializes jLabel17 1075 * 1076 * @return JLabel 1077 */ 1078 private JLabel getJLabel17() { 1079 if (jLabel17 == null) { 1080 jLabel17 = new JLabel(); 1081 jLabel17.setBounds(125, 95, 57, 15); 1082 jLabel17.setText("0"); 1083 jLabel17.setBackground(java.awt.Color.white); 1084 jLabel17.setForeground(java.awt.Color.black); 1085 jLabel17.setFont(new java.awt.Font("sansserif", 0, 10)); 1086 } 1087 return jLabel17; 1088 } 1089 /** 1090 * This method initializes jLabel18 1091 * 1092 * @return JLabel 1093 */ 1094 private JLabel getJLabel18() { 1095 if (jLabel18 == null) { 1096 jLabel18 = new JLabel(); 1097 jLabel18.setBounds(189, 25, 100, 13); 1098 jLabel18.setText("Avg. Resp. Time(ms)"); 1099 jLabel18.setFont(new java.awt.Font("Arial", 1, 10)); 1100 jLabel18.setHorizontalAlignment(SwingConstants.RIGHT); 1101 jLabel18.setToolTipText("The average response time for requests"); 1102 } 1103 return jLabel18; 1104 } 1105 /** 1106 * This method initializes jLabel19 1107 * 1108 * @return JLabel 1109 */ 1110 private JLabel getJLabel19() { 1111 if (jLabel19 == null) { 1112 jLabel19 = new JLabel(); 1113 jLabel19.setBounds(189, 50, 100, 13); 1114 jLabel19.setText("Min. Resp. Time(ms)"); 1115 jLabel19.setFont(new java.awt.Font("Arial", 1, 10)); 1116 jLabel19.setHorizontalAlignment(SwingConstants.RIGHT); 1117 jLabel19.setToolTipText( 1118 "The minimum response time for all requests"); 1119 } 1120 return jLabel19; 1121 } 1122 /** 1123 * This method initializes jLabel20 1124 * 1125 * @return JLabel 1126 */ 1127 private JLabel getJLabel20() { 1128 if (jLabel20 == null) { 1129 jLabel20 = new JLabel(); 1130 jLabel20.setBounds(189, 75, 100, 13); 1131 jLabel20.setText("Max. Resp. Time(ms)"); 1132 jLabel20.setFont(new java.awt.Font("Arial", 1, 10)); 1133 jLabel20.setHorizontalAlignment(SwingConstants.RIGHT); 1134 jLabel20.setToolTipText( 1135 "The maximum response time for all requests"); 1136 } 1137 return jLabel20; 1138 } 1139 /** 1140 * This method initializes jLabel21 1141 * 1142 * @return JLabel 1143 */ 1144 private JLabel getJLabel21() { 1145 if (jLabel21 == null) { 1146 jLabel21 = new JLabel(); 1147 jLabel21.setBounds(189, 95, 95, 13); 1148 jLabel21.setText("Total Time (secs)"); 1149 jLabel21.setFont(new java.awt.Font("Arial", 1, 10)); 1150 jLabel21.setHorizontalAlignment(SwingConstants.RIGHT); 1151 jLabel21.setToolTipText( 1152 "The time in seconds since the beginning of the run"); 1153 } 1154 return jLabel21; 1155 } 1156 /** 1157 * This method initializes jLabel22 1158 * 1159 * @return JLabel 1160 */ 1161 private JLabel getJLabel22() { 1162 if (jLabel22 == null) { 1163 jLabel22 = new JLabel(); 1164 jLabel22.setBounds(293, 25, 50, 15); 1165 jLabel22.setText("0.00"); 1166 jLabel22.setBackground(java.awt.Color.white); 1167 jLabel22.setForeground(java.awt.Color.black); 1168 jLabel22.setFont(new java.awt.Font("sansserif", 0, 10)); 1169 } 1170 return jLabel22; 1171 } 1172 /** 1173 * This method initializes jLabel23 1174 * 1175 * @return JLabel 1176 */ 1177 private JLabel getJLabel23() { 1178 if (jLabel23 == null) { 1179 jLabel23 = new JLabel(); 1180 jLabel23.setBounds(293, 50, 50, 15); 1181 jLabel23.setText("0.00"); 1182 jLabel23.setBackground(java.awt.Color.white); 1183 jLabel23.setForeground(java.awt.Color.black); 1184 jLabel23.setFont(new java.awt.Font("sansserif", 0, 10)); 1185 } 1186 return jLabel23; 1187 } 1188 /** 1189 * This method initializes jLabel24 1190 * 1191 * @return JLabel 1192 */ 1193 private JLabel getJLabel24() { 1194 if (jLabel24 == null) { 1195 jLabel24 = new JLabel(); 1196 jLabel24.setBounds(293, 75, 50, 15); 1197 jLabel24.setText("0.00"); 1198 jLabel24.setBackground(java.awt.Color.white); 1199 jLabel24.setForeground(java.awt.Color.black); 1200 jLabel24.setFont(new java.awt.Font("sansserif", 0, 10)); 1201 } 1202 return jLabel24; 1203 } 1204 /** 1205 * This method initializes jLabel25 1206 * 1207 * @return JLabel 1208 */ 1209 private JLabel getJLabel25() { 1210 if (jLabel25 == null) { 1211 jLabel25 = new JLabel(); 1212 jLabel25.setBounds(293, 95, 50, 15); 1213 jLabel25.setText("0"); 1214 jLabel25.setBackground(java.awt.Color.white); 1215 jLabel25.setForeground(java.awt.Color.black); 1216 jLabel25.setFont(new java.awt.Font("sansserif", 0, 10)); 1217 } 1218 return jLabel25; 1219 } 1220 /** 1221 * This method initializes jLabel26 1222 * 1223 * @return JLabel 1224 */ 1225 private JLabel getJLabel26() { 1226 if (jLabel26 == null) { 1227 jLabel26 = new JLabel(); 1228 jLabel26.setBounds(12, 127, 98, 13); 1229 jLabel26.setText("Scenario Progress"); 1230 jLabel26.setFont(new java.awt.Font("Arial", 1, 10)); 1231 jLabel26.setHorizontalAlignment(SwingConstants.RIGHT); 1232 jLabel26.setToolTipText( 1233 "The total number of errors since the beginning of the scenario"); 1234 } 1235 return jLabel26; 1236 } 1237 /** 1238 * This method initializes jProgressBar 1239 * 1240 * @return JProgressBar 1241 */ 1242 private JProgressBar getJProgressBar() { 1243 if (jProgressBar == null) { 1244 jProgressBar = new JProgressBar(); 1245 jProgressBar.setBounds(117, 126, 145, 15); 1246 jProgressBar.setValue(0); 1247 jProgressBar.setBackground(new java.awt.Color(220, 220, 220)); 1248 } 1249 return jProgressBar; 1250 } 1251 /** 1252 * This method initializes jButton10 1253 * 1254 * @return JButton 1255 */ 1256 private JButton getJButton10() { 1257 if (jButton10 == null) { 1258 jButton10 = new JButton(); 1259 jButton10.setBounds(272, 125, 66, 16); 1260 jButton10.setBackground(new java.awt.Color(220, 220, 220)); 1261 jButton10.setFont(new java.awt.Font("Arial", 1, 10)); 1262 jButton10.setText("Clear"); 1263 jButton10.addActionListener(new ActionListener() { 1264 public void actionPerformed(ActionEvent e) { 1265 clearScenarioStats(); 1266 output.append("\n\tScenario: Cleared statistics"); 1267 } 1268 }); 1269 } 1270 return jButton10; 1271 } 1272 // @jve:visual-info decl-index=0 visual-constraint="0,0" 1273 /** 1274 * This method initializes jPanel11 1275 * 1276 * @return JPanel 1277 */ 1278 private JPanel getJPanel11() { 1279 if (jPanel11 == null) { 1280 jPanel11 = new JPanel(); 1281 jPanel11.setLayout(null); 1282 jPanel11.add(getJPanel9(), getJPanel9().getName()); 1283 jPanel11.add(getJPanel9(), null); 1284 jPanel11.add(getJPanel10(), null); 1285 jPanel11.setBounds(302, 262, 361, 262); 1286 jPanel11.setBackground(new java.awt.Color(208, 208, 205)); 1287 jPanel11.setBorder( 1288 BorderFactory.createTitledBorder( 1289 null, 1290 "Benchmark Scenario", 1291 3, 1292 0)); 1293 } 1294 return jPanel11; 1295 } 1296 String currentUser = null; 1297 class AppActionListener implements ActionListener { 1298 public void actionPerformed(java.awt.event.ActionEvent event) { 1299 String action = event.getActionCommand(); 1300 try { 1301 String parm1, parm2, result = null; 1302 if (action.equalsIgnoreCase("Login")) { 1303 parm1 = jTextField.getText(); // userID 1304 parm2 = new String(jPasswordField1.getPassword()); // password 1305 AccountDataBean accountData = 1306 getTrade().login(parm1, parm2); 1307 result = accountData.toString(); 1308 currentUser = accountData.getProfileID(); 1309 } else if (action.equalsIgnoreCase("MarketSummary")) { 1310 MarketSummaryDataBeanWS marketSummary = 1311 getTrade().getMarketSummary(); 1312 result = marketSummary.toString(); 1313 } else if (action.equalsIgnoreCase("Quotes")) { 1314 parm1 = jTextField2.getText(); // symbol 1315 QuoteDataBean quoteData = getTrade().getQuote(parm1); 1316 result = quoteData.toString(); 1317 1318 } 1319 1320 else if (currentUser==null) 1321 { 1322 result = "Error: User login is required for this operation"; 1323 } 1324 else if (action.equalsIgnoreCase("Account")) { 1325 AccountDataBean accountData = 1326 getTrade().getAccountData(currentUser); 1327 AccountProfileDataBean accountProfileData = 1328 getTrade().getAccountProfileData(currentUser); 1329 result = 1330 accountData.toString() + accountProfileData.toString(); 1331 } else if (action.equalsIgnoreCase("Buy")) { 1332 parm1 = jTextField3.getText(); // symbol 1333 parm2 = jTextField4.getText(); // quantity 1334 OrderDataBean orderData = 1335 getTrade().buy( 1336 currentUser, 1337 parm1, 1338 Double.parseDouble(parm2), 1339 0); 1340 result = orderData.toString(); 1341 } else if (action.equalsIgnoreCase("Sell")) { 1342 parm1 = jTextField5.getText(); // holding ID 1343 OrderDataBean orderData = 1344 getTrade().sell( 1345 currentUser, 1346 Integer.valueOf(parm1), 1347 0); 1348 result = orderData.toString(); 1349 } else if (action.equalsIgnoreCase("Orders")) { 1350 Object[] orders = getTrade().getOrders(currentUser); 1351 if (orders.length == 0) { 1352 result = "No orders"; 1353 } 1354 else { 1355 result = ""; 1356 for (int i = 0; i < orders.length; i++) 1357 result += new StringBuffer().append("\n").append(orders[i].toString()).toString(); 1358 } 1359 1360 } else if (action.equalsIgnoreCase("Holdings")) { 1361 Object[] holdings = getTrade().getHoldings(currentUser); 1362 if (holdings.length == 0) { 1363 result = "No holdings"; 1364 } 1365 else { 1366 result = ""; 1367 for (int i = 0; i < holdings.length; i++) 1368 result += "\n" 1369 + holdings[i].toString(); 1370 } 1371 1372 } else if (action.equalsIgnoreCase("Logout")) { 1373 getTrade().logout(currentUser); 1374 result = "\n\n\tUser: " + currentUser + " logged out"; 1375 currentUser = null; 1376 } 1377 jTextArea.setText(result); 1378 } catch (Exception e1) { 1379 System.out.println("ClientApp error;\n" + e1.toString()); 1380 e1.printStackTrace(); 1381 } 1382 } 1383 } 1384 1385 private void startScenario(int numThreads, int reqPerThread) { 1386 output.setText( 1387 "Scenario: Starting " 1388 + numThreads 1389 + " threads running " 1390 + reqPerThread 1391 + " requests each"); 1392 1393 //TODO - code generic scenario 1394 threads = new Thread[numThreads]; 1395 for (int i = 0; i < numThreads; i++) { 1396 threads[i] = new ClientScenario(reqPerThread); 1397 threads[i].setName("ScenarioThreads " + i); 1398 } 1399 ClientScenario.setNumThreads(numThreads); 1400 ClientScenario.setStartTime(0); 1401 ClientScenario.setServicePort(getJTextField12().getText()); 1402 //TODO this is a cheap scenario implementation -- needs to be generic 1403 String scenario = (String) jComboBox.getSelectedItem(); 1404 if ( scenario.equalsIgnoreCase("Get Quote - NULL") ) 1405 { 1406 ClientScenario.symbol = null; 1407 } 1408 else 1409 { 1410 ClientScenario.symbol = null; 1411 } 1412 System.out.println("Running Scenario: " + scenario + " symbol = " + ClientScenario.symbol); 1413 //Start a timer daemon to gather statistics 1414 stats = new java.util.Timer(true); 1415 stats.scheduleAtFixedRate(new StatsTimerTask(), 1000, 5000); 1416 for (int i = 0; i < numThreads; i++) 1417 threads[i].start(); 1418 } 1419 1420 private void stopScenario() { 1421 1422 // Signal all scenario threads to stop 1423 output.setText("Stopping all scenario threads"); 1424 long numThreads = ClientScenario.getNumThreads(); 1425 for (int i = 0; i < numThreads; i++) { 1426 ClientScenario client = (ClientScenario) threads[i]; 1427 client.setStop(true); 1428 } 1429 1430 stats.cancel(); 1431 output.append( 1432 "\nstopScenario: All scenario threads and statkeeper stopped"); 1433 } 1434 1435 private void clearScenarioStats() { 1436 1437 //TODO min Resp is not working after clear - know why avg = 0.0 after clear 1438 int currTotReq = 0; 1439 long numThreads = ClientScenario.getNumThreads(); 1440 for (int i = 0; i < numThreads; i++) { 1441 ClientScenario client = (ClientScenario) threads[i]; 1442 currTotReq += client.clearStats(); 1443 } 1444 ClientScenario.setTotReqsAtLastInterval(currTotReq); 1445 ClientScenario.setStatStartTime(System.currentTimeMillis()); 1446 jLabel14.setText("0"); 1447 jLabel15.setText("0"); 1448 1449 jLabel22.setText("0.0"); 1450 jLabel23.setText("0.0"); 1451 jLabel24.setText("0.0"); 1452 } 1453 1454 Thread[] threads; 1455 java.util.Timer stats; 1456 JTextArea output; 1457 1458 class StatsTimerTask extends TimerTask { 1459 public void run() { 1460 long totReqs = 0, totErrs = 0, statReqs = 0, totResp = 0; 1461 long totTime = 0, currTime; 1462 1463 // Scenario just started? 1464 if (ClientScenario.getStartTime() == 0) { 1465 //Clear stats 1466 clearScenarioStats(); 1467 ClientScenario.setStartTime(System.currentTimeMillis()); 1468 return; 1469 } 1470 1471 // First get the rawdata from each thread 1472 for (int i = 0; i < threads.length; i++) { 1473 ClientScenario thread = ((ClientScenario) threads[i]); 1474 totReqs += thread.getNumReqs(); 1475 totErrs += thread.getNumErrs(); 1476 totResp += thread.getTotResp(); 1477 statReqs += thread.getNumStatReqs(); 1478 } 1479 float avgResp = (float)totResp / (float)statReqs; 1480 long maxResp = ClientScenario.getMaxResp(); 1481 long minResp = ClientScenario.getMinResp(); 1482 1483 currTime = System.currentTimeMillis(); 1484 long totalTime = currTime - ClientScenario.getStartTime(); 1485 long intervalTime = currTime - ClientScenario.getIntervalStartTime(); 1486 long statTime = currTime - ClientScenario.getStatStartTime(); 1487 ClientScenario.setIntervalStartTime(currTime); 1488 1489 // Scenario Finished? 1490 if ((totReqs + totErrs) >= ClientScenario.getTotalNumRequests()) { 1491 output.setText( 1492 "Scenario: Run completed:" 1493 + totReqs 1494 + " requests in" 1495 + totTime / 1000 1496 + " seconds"); 1497 this.cancel(); 1498 jLabel16.setText("" + totReqs); 1499 jLabel17.setText("" + totErrs); 1500 jLabel25.setText("" + totTime / 1000); 1501 jButton9.setText("Start Scenario!"); 1502 jButton9.setActionCommand("start"); 1503 jProgressBar.setValue(100); 1504 return; 1505 } 1506 BigDecimal reqPerSec = 1507 new BigDecimal( 1508 (double) statReqs / (double)statTime * 1000.0).setScale( 1509 2, 1510 ROUND); 1511 BigDecimal lastReqPerSec = 1512 new BigDecimal( 1513 (double) (totReqs - ClientScenario.getTotReqsAtLastInterval()) 1514 / (double) intervalTime 1515 * 1000).setScale( 1516 2, 1517 ROUND); 1518 BigDecimal avgRespTime = 1519 new BigDecimal(avgResp).setScale(2, ROUND); 1520 BigDecimal maxRespBD = new BigDecimal(maxResp).setScale(2, ROUND); 1521 BigDecimal minRespBD = new BigDecimal(minResp).setScale(2, ROUND); 1522 int percentComplete = 1523 (int) (100.0 1524 * totReqs 1525 / (double) (ClientScenario.getTotalNumRequests())); 1526 1527 jLabel14.setText(reqPerSec.toString()); 1528 jLabel15.setText(lastReqPerSec.toString()); 1529 jLabel16.setText("" + totReqs); 1530 jLabel17.setText("" + totErrs); 1531 1532 jLabel22.setText(avgRespTime.toString()); 1533 jLabel23.setText(minRespBD.toString()); 1534 jLabel24.setText(maxRespBD.toString()); 1535 jLabel25.setText("" + totTime / 1000); 1536 1537 jProgressBar.setValue(percentComplete); 1538 ClientScenario.setTotReqsAtLastInterval(totReqs); 1539 } 1540 } 1541 1542 private static TradeWSServices trade = null; 1543 TradeWSServices getTrade() throws Exception { 1544 ClientScenario.setServicePort(getJTextField12().getText()); 1545 return ClientScenario.getTradeSingleton(); 1546 } 1547 1548 private static ClientScenario client = null; 1549 ClientScenario getClientScenario() { 1550 if (client == null) 1551 client = new ClientScenario(); 1552 return client; 1553 } 1554 //miscellaneous 1555 private int ROUND = BigDecimal.ROUND_HALF_UP; 1556 private static final BigDecimal ZERO = new BigDecimal(0.0); 1557 1558 1559 private JMenuItem jMenuItem2 = null; 1560 private JLabel jLabel27 = null; 1561 private JTextField jTextField12 = null; 1562 /** 1563 * This method initializes jMenuItem2 1564 * 1565 * @return JMenuItem 1566 */ 1567 private JMenuItem getJMenuItem2() { 1568 if(jMenuItem2 == null) { 1569 jMenuItem2 = new JMenuItem(); 1570 jMenuItem2.setText("Service Port URL"); 1571 jMenuItem2.addActionListener(new ActionListener() { 1572 public void actionPerformed(ActionEvent e) { 1573 String command = e.getActionCommand(); 1574 if (command.equalsIgnoreCase("start")) { 1575 int numThreads = Integer.parseInt(jTextField7.getText()); 1576 int reqPerThread = 1577 Integer.parseInt(jTextField6.getText()) 1578 / numThreads; 1579 startScenario(numThreads, reqPerThread); 1580 jButton9.setText("Stop"); 1581 jButton9.setActionCommand("stop"); 1582 } else if (command.equalsIgnoreCase("stop")) { 1583 stopScenario(); 1584 jButton9.setText("Start Scenario!"); 1585 jButton9.setActionCommand("start"); 1586 1587 } 1588 } 1589 } 1590 ); 1591 } 1592 return jMenuItem2; 1593 } 1594 /** 1595 * This method initializes jLabel27 1596 * 1597 * @return JLabel 1598 */ 1599 private JLabel getJLabel27() { 1600 if(jLabel27 == null) { 1601 jLabel27 = new JLabel(); 1602 jLabel27.setBounds(9, 17, 122, 14); 1603 jLabel27.setText("Service Port URL"); 1604 jLabel27.setToolTipText("URL pointing to the concrete WSDL for the service"); 1605 jLabel27.setFont(new java.awt.Font("sansserif", 1, 10)); 1606 } 1607 return jLabel27; 1608 } 1609 /** 1610 * This method initializes jTextField12 1611 * 1612 * @return JTextField 1613 */ 1614 private JTextField getJTextField12() { 1615 if(jTextField12 == null) { 1616 jTextField12 = new JTextField(); 1617 jTextField12.setBounds(138, 16, 202, 16); 1618 jTextField12.setFont(new java.awt.Font("sansserif", 1, 10)); 1619 jTextField12.setText(ClientScenario.getServicePort()); 1620 } 1621 return jTextField12; 1622 } 1623 } // @jve:visual-info decl-index=0 visual-constraint="0,0"