private void messageStresser() throws HeadlessException { String res = JOptionPane.showInputDialog(this, "Number of messages to send"); try { int count = Integer.parseInt(res); Thread t = new Thread(new Stresser(count)); t.start(); } catch (NumberFormatException nfe) { } }
public void run() { try { while (keepRunning) { if (Client.currentInstance.session != null && Client.currentInstance.session.isConnected()) { Client.currentInstance.session.postMessage("", cmd, ""); } try { Thread.currentThread().sleep(interval); } catch (InterruptedException ex) { } } } catch (Exception ex2) { } }
public void run() { while (true) { synchronized (semaphore) { try { semaphore.wait(); } catch (InterruptedException ex) { } } Color origColor = c.getBackground(); for (int i = 0; i < flashCount; i++) { c.setBackground(flashColor); try { Thread.currentThread().sleep(100); } catch (Exception ex) { } c.setBackground(origColor); } } }
public static void main(String[] args) { if (args.length > 0) { try { if (args[0].equals("-stress")) { String userName = args[1]; String server = args[2]; String targetUser = args[3]; int rate = Integer.parseInt(args[4]); Session session = new Session(); if (session.connect(server, userName)) { long msgCount = 0; while (true) { for (int i = 0; i < rate; i++) { msgCount++; session.postMessage( targetUser, ("subject " + String.valueOf(msgCount)), Util.randomString(1000)); } Thread.currentThread().sleep(2000); } } } else if (args[0].equals("-stress2")) { String userName = args[1]; String server = args[2]; String targetUser = args[3]; int rate = Integer.parseInt(args[4]); Session session = new Session(); long msgCount = 0; while (true) { if (session.connect(server, userName)) { for (int i = 0; i < rate; i++) { msgCount++; session.postMessage( targetUser, ("subject " + String.valueOf(msgCount)), Util.randomString(1000)); } session.disconnect(); } Thread.currentThread().sleep(2000); } } else if (args[0].equals("-stress3")) { String userName = args[1]; String server = args[2]; String targetUser = args[3]; int rate = Integer.parseInt(args[4]); Session session = new Session(); long msgCount = 0; while (true) { if (session.connect(server, userName)) { for (int i = 0; i < rate; i++) { msgCount++; session.postMessage( targetUser, ("subject " + String.valueOf(msgCount)), Util.randomString(1000)); } session.dropConnection(); } Thread.currentThread().sleep(2000); } } else if (args[0].equals("-stress4")) { String userName = args[1]; String server = args[2]; String targetUser = args[3]; int rate = Integer.parseInt(args[4]); Session session = new Session(); long msgCount = 0; while (true) { if (session.connect(server, userName)) { for (int i = 0; i < rate; i++) { msgCount++; session.postMessage( targetUser, ("subject " + String.valueOf(msgCount)), Util.fixedString(300000)); } session.dropConnection(); } Thread.currentThread().sleep(5000); } } else if (args[0].equals("-stress5")) { String userName = args[1]; String server = args[2]; String targetUser = args[3]; int rate = Integer.parseInt(args[4]); Session session = new Session(); if (session.connect(server, userName)) { long msgCount = 0; while (true) { for (int i = 0; i < rate; i++) { msgCount++; session.postMessage( targetUser, ("subject " + String.valueOf(msgCount)), Util.randomString(10)); } Thread.currentThread().sleep(2000); } } } else if (args[0].equals("-monitor")) { String userName = args[1]; String server = args[2]; long interval = Long.parseLong(args[3]); Session session = new Session(); long msgCount = 0; if (session.connect(server, userName)) { while (true) { Message msg = session.sendMessage("", "get send queue stats", ""); System.out.println("SEND QUEUE STATS"); System.out.println(msg.getBody()); Thread.currentThread().sleep(interval); } } } else if (args[0].equals("-responder")) { String userName = args[1]; String server = args[2]; long interval = Long.parseLong(args[3]); final Session session = new Session(); if (session.connect(server, userName)) { session.addListener( new AsyncMessageReceiverListener() { public void receiveMsg(Message msg) { session.postMessage( msg.getFrom(), "RE: " + msg.getFrom(), msg.getThread(), msg.getBody()); } public void messageReceiverClosed(MessageReceiver mr) {} }); while (true) { Thread.currentThread().sleep(interval); } } } else if (args[0].equals("-threaded-sender")) { String userName = args[1]; String server = args[2]; String targetUser = args[3]; int rate = Integer.parseInt(args[4]); Session session = new Session(); long msgCount = 0; if (session.connect(server, userName)) { while (true) { for (int i = 0; i < rate; i++) { msgCount++; Message reply = session.sendMessage( targetUser, ("subject " + String.valueOf(msgCount)), "body", 10000); if (reply == null) { System.out.println("reply not received"); } } Thread.currentThread().sleep(5000); } } } } catch (Exception e) { System.out.println( "Unable to start stress test. Format: -stress <user name> <server> <target user> <msg rate>"); } } else { Client client = new Client(); client.setSize(800, 420); center(client); client.show(); } }