public static void sfSendEmail(String subject, String message) throws Exception { String SMTP_HOST_NAME = "smtp.gmail.com"; String SMTP_PORT = "465"; // message = "Test Email Notification From Monitor"; // subject = "Test Email Notification From Monitor"; String from = "*****@*****.**"; String[] recipients = { "*****@*****.**", "*****@*****.**", "*****@*****.**" }; String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory"; // String[] recipients = { "*****@*****.**"}; // String[] recipients = { "*****@*****.**", "*****@*****.**", // "*****@*****.**", "*****@*****.**", "*****@*****.**", // "*****@*****.**", "*****@*****.**"}; // String[] recipients = {"*****@*****.**"}; Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); boolean debug = true; Properties props = new Properties(); props.put("mail.smtp.host", SMTP_HOST_NAME); props.put("mail.smtp.auth", "true"); // props.put("mail.debug", "true"); props.put("mail.smtp.port", SMTP_PORT); props.put("mail.smtp.socketFactory.port", SMTP_PORT); props.put("mail.smtp.socketFactory.class", SSL_FACTORY); props.put("mail.smtp.socketFactory.fallback", "false"); Session session = Session.getDefaultInstance( props, new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication( "*****@*****.**", "els102sensorweb"); } }); // session.setDebug(debug); Message msg = new MimeMessage(session); InternetAddress addressFrom = new InternetAddress(from); msg.setFrom(addressFrom); InternetAddress[] addressTo = new InternetAddress[recipients.length]; for (int i = 0; i < recipients.length; i++) { addressTo[i] = new InternetAddress(recipients[i]); } msg.setRecipients(Message.RecipientType.TO, addressTo); // Setting the Subject and Content Type msg.setSubject(subject); msg.setContent(message, "text/plain"); Transport.send(msg); System.out.println("Sucessfully Sent mail to All Users"); }
/** When receive a message, analyze message content and then execute the command: Draw or Clear */ public void receive(Message msg) { byte[] buf = msg.getRawBuffer(); if (buf == null) { System.err.println( "[" + channel.getAddress() + "] received null buffer from " + msg.getSrc() + ", headers: " + msg.printHeaders()); return; } try { DrawCommand comm = (DrawCommand) Util.streamableFromByteBuffer( DrawCommand.class, buf, msg.getOffset(), msg.getLength()); switch (comm.mode) { case DrawCommand.DRAW: if (drawPanel != null) drawPanel.drawPoint(comm); break; case DrawCommand.CLEAR: clearPanel(); default: System.err.println("***** received invalid draw command " + comm.mode); break; } } catch (Exception e) { e.printStackTrace(); } }
// HDC WINAPI BeginPaint( HWND hwnd, PAINTSTRUCT *lps ) public static int BeginPaint(int hwnd, int lps) { WinWindow win = WinWindow.get(hwnd); if (lps == 0) return 0; Caret.HideCaret(hwnd); int rgn = WinRegion.CreateRectRgn(0, 0, win.rectWindow.width(), win.rectWindow.height()); Message.SendMessageA(hwnd, WM_NCPAINT, rgn, 0); GdiObj.DeleteObject(rgn); WinDC dc = win.getDC(); if (win.invalidationRect == null) { new WinRect(0, 0, win.rectClient.width(), win.rectClient.height()).write(lps + 8); } else { dc.clipX = win.invalidationRect.left; dc.clipY = win.invalidationRect.top; dc.clipCx = win.invalidationRect.width(); dc.clipCy = win.invalidationRect.height(); win.invalidationRect.write(lps + 8); } int hdc = dc.handle; writed(lps, hdc); writed(lps + 4, Message.SendMessageA(hwnd, WM_ERASEBKGND, hdc, 0)); return readd(lps); }
/** * Shows a warning message to the user when message delivery has failed. * * @param evt the event containing details on the message delivery failure */ public void messageDeliveryFailed(MessageDeliveryFailedEvent evt) { logger.error(evt.getReason()); String errorMsg = null; Message sourceMessage = (Message) evt.getSource(); Contact sourceContact = evt.getDestinationContact(); MetaContact metaContact = GuiActivator.getContactListService().findMetaContactByContact(sourceContact); if (evt.getErrorCode() == MessageDeliveryFailedEvent.OFFLINE_MESSAGES_NOT_SUPPORTED) { errorMsg = GuiActivator.getResources() .getI18NString( "service.gui.MSG_DELIVERY_NOT_SUPPORTED", new String[] {sourceContact.getDisplayName()}); } else if (evt.getErrorCode() == MessageDeliveryFailedEvent.NETWORK_FAILURE) { errorMsg = GuiActivator.getResources().getI18NString("service.gui.MSG_NOT_DELIVERED"); } else if (evt.getErrorCode() == MessageDeliveryFailedEvent.PROVIDER_NOT_REGISTERED) { errorMsg = GuiActivator.getResources().getI18NString("service.gui.MSG_SEND_CONNECTION_PROBLEM"); } else if (evt.getErrorCode() == MessageDeliveryFailedEvent.INTERNAL_ERROR) { errorMsg = GuiActivator.getResources().getI18NString("service.gui.MSG_DELIVERY_INTERNAL_ERROR"); } else { errorMsg = GuiActivator.getResources().getI18NString("service.gui.MSG_DELIVERY_ERROR"); } String reason = evt.getReason(); if (reason != null) errorMsg += " " + GuiActivator.getResources() .getI18NString("service.gui.ERROR_WAS", new String[] {reason}); ChatPanel chatPanel = chatWindowManager.getContactChat(metaContact, sourceContact); chatPanel.addMessage( sourceContact.getAddress(), metaContact.getDisplayName(), new Date(), Chat.OUTGOING_MESSAGE, sourceMessage.getContent(), sourceMessage.getContentType(), sourceMessage.getMessageUID(), evt.getCorrectedMessageUID()); chatPanel.addErrorMessage(metaContact.getDisplayName(), errorMsg); chatWindowManager.openChat(chatPanel, false); }
public void actionPerformed(ActionEvent event) { System.out.println("Sending mail"); /* Check that we have the local mailserver */ if ((serverField.getText()).equals("")) { System.out.println("Need name of local mailserver!"); return; } /* Check that we have the sender and recipient. */ if ((fromField.getText()).equals("")) { System.out.println("Need sender!"); return; } if ((toField.getText()).equals("")) { System.out.println("Need recipient!"); return; } /* Create the message */ Message mailMessage = new Message( fromField.getText(), toField.getText(), subjectField.getText(), messageText.getText()); /* Check that the message is valid, i.e., sender and recipient addresses look ok. */ if (!mailMessage.isValid()) { return; } /* Create the envelope, open the connection and try to send the message. */ Envelope envelope; try { envelope = new Envelope(mailMessage, serverField.getText()); } catch (UnknownHostException e) { /* If there is an error, do not go further */ return; } try { SMTPConnection connection = new SMTPConnection(envelope); connection.send(envelope); connection.close(); } catch (IOException error) { System.out.println("Sending failed: " + error); return; } System.out.println("Mail sent succesfully!"); }
private void register() { if (session != null && session.isConnected()) { onlineUsers.clear(); // get the current list Message msg = session.sendMessage("", "list", ""); System.out.println("LIST: " + msg.getBody()); StringTokenizer st = new StringTokenizer(msg.getBody(), "\n"); while (st.hasMoreTokens()) { onlineUsers.addElement(new HostItem(st.nextToken())); } session.postMessage("", "register", ""); } }
public String getLocal() { try { return m.usesLocalTable() ? "true" : "false"; } catch (Exception e) { return "exception"; } }
public String getComplete() { try { return m.isTablesComplete() ? "true" : "false"; } catch (IOException e) { return "exception"; } }
private static void updateWindow(WinWindow window) { Message.SendMessageA(window.handle, WM_PAINT, 0, 0); Iterator<WinWindow> children = window.getChildren(); while (children.hasNext()) { WinWindow child = children.next(); updateWindow(child); } }
public String getBitsOk() { try { if (!getComplete().equals("true")) return "incomplete"; return m.isBitCountOk() ? "true" : "false"; // LOOK using bit count 1 } catch (Exception e) { return "exception"; } }
// int GetUpdateRgn(HWND hWnd, HRGN hRgn, BOOL bErase) public static int GetUpdateRgn(int hWnd, int hRgn, int bErase) { WinWindow win = WinWindow.get(hWnd); WinRegion rgn = WinRegion.get(hRgn); if (win == null || rgn == null) return ERROR; if (win.needsPainting()) { if (bErase != 0) { rgn.rects.clear(); rgn.rects.add(new WinRect(0, 0, win.rectWindow.width(), win.rectWindow.height())); Message.SendMessageA(hWnd, WM_NCPAINT, hRgn, 0); int hdc = win.getDC().handle; Message.SendMessageA(hWnd, WM_ERASEBKGND, hdc, 0); ReleaseDC(hWnd, hdc); } rgn.rects.clear(); rgn.rects.add(new WinRect(0, 0, win.rectClient.width(), win.rectClient.height())); return SIMPLEREGION; } return NULLREGION; }
public void refresh() { Message message = new Message(); try { message = this.trainingTeaBLService.showFrameStrategy(); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (message.getMesType().equals(MessageType.traTea_showStrategy_fail)) { // JOptionPane.showMessageDialog(this, "整体框架策略尚未发布!"); jl1.setVisible(true); jb2.setEnabled(false); if (jsp1 != null) { jsp1.setVisible(false); } } else if (message.getMesType().equals(MessageType.traTea_showStrategy_success)) { jl1.setVisible(false); ArrayList<Dean> dean = message.getDeans(); ArrayList<String> attriOfDean = message.getAttriOfDean(); tm1 = new StrategyTableModel(dean, attriOfDean); if (jsp1 != null) { jt1.setModel(tm1); jsp1.setVisible(true); } else { jt1 = new JTable(); jt1.setModel(tm1); jsp1 = new JScrollPane(jt1); strategy.add(jsp1); } if (dean.size() >= 15) { jb1.setEnabled(false); } jb2.setEnabled(true); } else { JOptionPane.showMessageDialog(this, "你的网络貌似有点问题!"); } }
private void writeAll() { List<MessageBean> beans = messageTable.getBeans(); HashMap<Integer, Message> map = new HashMap<Integer, Message>(2 * beans.size()); for (MessageBean mb : beans) { map.put(mb.m.hashCode(), mb.m); } if (fileChooser == null) fileChooser = new FileManager(null, null, null, (PreferencesExt) prefs.node("FileManager")); String defloc = (raf.getLocation() == null) ? "." : raf.getLocation(); String dirName = fileChooser.chooseDirectory(defloc); if (dirName == null) return; try { int count = 0; for (Message m : map.values()) { String header = m.getHeader(); if (header != null) { header = header.split(" ")[0]; } else { header = Integer.toString(Math.abs(m.hashCode())); } File file = new File(dirName + "/" + header + ".bufr"); FileOutputStream fos = new FileOutputStream(file); WritableByteChannel wbc = fos.getChannel(); wbc.write(ByteBuffer.wrap(m.getHeader().getBytes())); byte[] raw = scan.getMessageBytes(m); wbc.write(ByteBuffer.wrap(raw)); wbc.close(); count++; } JOptionPane.showMessageDialog( BufrMessageViewer.this, count + " successfully written to " + dirName); } catch (IOException e1) { JOptionPane.showMessageDialog(BufrMessageViewer.this, e1.getMessage()); e1.printStackTrace(); } }
public void addTargetedMessage(Connection connection, Message message, MessageRow.Type type) { Entity target = message.getTarget(); if (target.equals(connection.getLocalUser())) { target = message.getSource(); } Tab tab = null; for (Tab _tab : getItems()) { if (_tab.getEntity().equals(target)) { tab = _tab; break; } } if (tab == null) { if (type == MessageRow.Type.PART && message.getSource().equals(connection.getLocalUser())) { return; } tab = create(connection, target); } tab.getContentPane().getMessagePane().addRow(new MessageRow(message, type)); }
/** * When a sent message is delivered shows it in the chat conversation panel. * * @param evt the event containing details on the message delivery */ public void messageDelivered(MessageDeliveredEvent evt) { Contact contact = evt.getDestinationContact(); MetaContact metaContact = GuiActivator.getContactListService().findMetaContactByContact(contact); if (logger.isTraceEnabled()) logger.trace("MESSAGE DELIVERED to contact: " + contact.getAddress()); ChatPanel chatPanel = chatWindowManager.getContactChat(metaContact, false); if (chatPanel != null) { Message msg = evt.getSourceMessage(); ProtocolProviderService protocolProvider = contact.getProtocolProvider(); if (logger.isTraceEnabled()) logger.trace( "MESSAGE DELIVERED: process message to chat for contact: " + contact.getAddress() + " MESSAGE: " + msg.getContent()); chatPanel.addMessage( this.mainFrame.getAccountAddress(protocolProvider), this.mainFrame.getAccountDisplayName(protocolProvider), evt.getTimestamp(), Chat.OUTGOING_MESSAGE, msg.getContent(), msg.getContentType(), msg.getMessageUID(), evt.getCorrectedMessageUID()); if (evt.isSmsMessage() && !ConfigurationUtils.isSmsNotifyTextDisabled()) { chatPanel.addMessage( contact.getDisplayName(), new Date(), Chat.ACTION_MESSAGE, GuiActivator.getResources().getI18NString("service.gui.SMS_SUCCESSFULLY_SENT"), "text"); } } }
/** * Handles a message received from the remote party. * * @param msg The Message object that was received. */ private void doMessageReceived(Message msg) { assert (SwingUtilities.isEventDispatchThread()) : "not in UI thread"; if (msg.getType() == Message.Type.ERROR) { JOptionPane.showMessageDialog( this, msg.getError().getMessage(), JavolinApp.getAppName() + ": Error", JOptionPane.ERROR_MESSAGE); } else if (msg.getType() == Message.Type.HEADLINE) { // Do nothing } else { String jid = msg.getFrom(); if (jid != null) setUserResource(jid); Date date = null; PacketExtension ext = msg.getExtension("x", "jabber:x:delay"); if (ext != null && ext instanceof DelayInformation) { date = ((DelayInformation) ext).getStamp(); } mLog.message(mRemoteIdFull, mRemoteNick, msg.getBody(), date); Audio.playMessage(); } }
private void dumpDDS() { List<MessageBean> beans = messageTable.getBeans(); HashMap<Integer, Message> map = new HashMap<Integer, Message>(2 * beans.size()); for (MessageBean mb : beans) { map.put(mb.m.hashCode(), mb.m); } if (fileChooser == null) fileChooser = new FileManager(null, null, null, (PreferencesExt) prefs.node("FileManager")); String defloc = (raf.getLocation() == null) ? "." : raf.getLocation(); int pos = defloc.lastIndexOf("."); if (pos > 0) defloc = defloc.substring(0, pos); String filename = fileChooser.chooseFilenameToSave(defloc + ".txt"); if (filename == null) return; try { File file = new File(filename); FileOutputStream fos = new FileOutputStream(file); int count = 0; for (Message m : map.values()) { Formatter f = new Formatter(fos); m.dump(f); f.flush(); count++; } fos.close(); JOptionPane.showMessageDialog( BufrMessageViewer.this, count + " successfully written to " + filename); } catch (IOException e1) { JOptionPane.showMessageDialog(BufrMessageViewer.this, e1.getMessage()); e1.printStackTrace(); } }
public void receiveMsg(Message msg) { // System.out.println(msg.getSubject() + " : " + msg.getBody()); String subject = msg.getSubject(); if (subject != null) { if (subject.equals("online")) { onlineUsers.addElement(new HostItem(msg.getBody())); displayMessage(msg.getBody() + " : Online", onlineClientAttrSet); } else if (subject.equals("offline")) { onlineUsers.removeElement(new HostItem(msg.getBody())); displayMessage(msg.getBody() + " : Offline", offlineClientAttrSet); } else if (subject.equals("eavesdrop enabled")) { Object[] values = jListOnlineUsers.getSelectedValues(); if (values == null) return; for (int i = 0; i < values.length; i++) { ((HostItem) values[i]).eavesDroppingEnabled = true; } jListOnlineUsers.updateUI(); } else if (subject.equals("eavesdrop disabled")) { Object[] values = jListOnlineUsers.getSelectedValues(); if (values == null) return; for (int i = 0; i < values.length; i++) { ((HostItem) values[i]).eavesDroppingEnabled = false; } jListOnlineUsers.updateUI(); } else if (subject.equals("globaleavesdrop enabled")) { displayMessage("Global Eavesdropping Enabled", onlineClientAttrSet); } else if (subject.equals("globaleavesdrop disabled")) { displayMessage("Global Eavesdropping Disabled", offlineClientAttrSet); } else { String to = msg.getTo(); String from = msg.getFrom() == null ? "server" : msg.getFrom(); String body = msg.getBody() != null ? msg.getBody() : ""; if (jTextFieldUser.getText().equals(to)) { // this message is sent to us displayMessage(subject, from, body, incomingMsgAttrSet); } else { // this is an eavesdrop message displayMessage(subject, to, from, body, eavesdropAttrSet); } } } else { subject = ""; String to = msg.getTo(); String from = msg.getFrom() == null ? "server" : msg.getFrom(); String body = msg.getBody() != null ? msg.getBody() : ""; if (jTextFieldUser.getText().equals(to)) { // this message is sent to us displayMessage(subject, from, body, incomingMsgAttrSet); } else { // this is an eavesdrop message displayMessage(subject, to, from, body, eavesdropAttrSet); } } }
public DialogPanel receiveIncomingMessage( Message message, BufferedImage myPhoto, BufferedImage friendPhoto, Mode mode) { if (mode == Mode.HOME_PANEL) { homeButton.setIcon(newDialogButIcon); PopUpMenu.displayMessage("You have new message from " + message.getNickname_From()); homeButton.addMouseListener( new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { homeButton.setIcon(newDialogButIconEntered); } @Override public void mouseExited(MouseEvent e) { homeButton.setIcon(newDialogButIcon); } }); } for (int i = 0; i < dialogTabArrayList.size(); i++) { if (message.getNickname_From().equals(dialogTabArrayList.get(i).getNickButton().getText())) { if (dialogTabArrayList.get(i).equals(currentDialogTab)) { dialogPanelArrayList.get(i).showIncomingMessage(message); } else { dialogPanelArrayList.get(i).showIncomingMessage(message); dialogTabArrayList.get(i).getNewMessageLabel().setVisible(true); } return null; } } final DialogTab dialogTab = new DialogTab(message.getNickname_From()); dialogTab.setBorder(new LineBorder(Color.WHITE)); dialogTabArrayList.add(dialogTab); dialogTab.getNewMessageLabel().setVisible(true); final DialogPanel dialogPanel = new DialogPanel(); try { dialogPanel.updateInfo(myPhoto, friendPhoto); } catch (IOException e) { e.printStackTrace(); } dialogPanelArrayList.add(dialogPanel); repaintDialogTabsPanel(); repaint(); revalidate(); dialogTab .getNickButton() .addActionListener( new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { for (int i = 0; i < dialogTabArrayList.size(); i++) { dialogTabArrayList.get(i).setBorder(new LineBorder(Color.WHITE)); } dialogTab.setBorder(new LineBorder(Color.RED)); dialogTab.getNewMessageLabel().setVisible(false); currentDialogTab = dialogTab; if (!(currentDialogPanel == null)) currentDialogPanel.setVisible(false); currentDialogPanel = dialogPanel; currentDialogPanel.setBounds(0, 84, 960, 1000); bigPanel.add(currentDialogPanel); currentDialogPanel.setVisible(true); repaintDialogTabsPanel(); repaint(); revalidate(); } }); dialogPanel.showIncomingMessage(message); noConversationsPanel.setVisible(false); return dialogPanel; }
public static void sendEmail(String subject, String message) throws Exception { /* String mailhost = "mail.vancouver.wsu.edu"; String cc = null; String bcc = null; boolean debug = false; String file = null; String mailer = "msgsend"; String sender = "mail.vancouver.wsu.edu"; Properties props = System.getProperties(); if (mailhost != null) props.put("mail.smtp.host", mailhost); // Get a Session object Session session = Session.getInstance(props, null); if (debug) session.setDebug(true); // construct the message Message msg = new MimeMessage(session); if (sender != null) msg.setFrom(new InternetAddress(sender)); else msg.setFrom(); msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(receivers[0], false)); if (cc != null) msg.setRecipients(Message.RecipientType.CC, InternetAddress.parse(cc, false)); if (bcc != null) msg.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(bcc, false)); msg.setSubject(subject); String text = content; if (file != null) { // Attach the specified file. // We need a multipart message to hold the attachment. MimeBodyPart mbp1 = new MimeBodyPart(); mbp1.setText(text); MimeBodyPart mbp2 = new MimeBodyPart(); mbp2.attachFile(file); MimeMultipart mp = new MimeMultipart(); mp.addBodyPart(mbp1); mp.addBodyPart(mbp2); msg.setContent(mp); } else { // If the desired charset is known, you can use // setText(text, charset) msg.setText(text); } msg.setHeader("X-Mailer", mailer); msg.setSentDate(new Date()); // send the thing off Transport.send(msg); System.out.println("\nMail was sent successfully."); */ // Xiaogang: checkbox // System.out.println("sendemail"+MainFrame.EMAIL_ENABLE); if (MainFrame.EMAIL_ENABLE == false) return; String SMTP_HOST_NAME = "smtp.gmail.com"; String SMTP_PORT = "465"; // message = "Test Email Notification From Monitor"; // subject = "Test Email Notification From Monitor"; String from = "*****@*****.**"; String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory"; String[] recipients = { "*****@*****.**", "*****@*****.**", "*****@*****.**" }; // String[] recipients = { "*****@*****.**"}; // String[] recipients = { , "*****@*****.**", "*****@*****.**", // "*****@*****.**", "*****@*****.**"}; // String[] recipients = {"*****@*****.**"}; Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); boolean debug = true; Properties props = new Properties(); props.put("mail.smtp.host", SMTP_HOST_NAME); props.put("mail.smtp.auth", "true"); // props.put("mail.debug", "true"); props.put("mail.smtp.port", SMTP_PORT); props.put("mail.smtp.socketFactory.port", SMTP_PORT); props.put("mail.smtp.socketFactory.class", SSL_FACTORY); props.put("mail.smtp.socketFactory.fallback", "false"); Session session = Session.getDefaultInstance( props, new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication( "*****@*****.**", "els102sensorweb"); } }); // session.setDebug(debug); Message msg = new MimeMessage(session); InternetAddress addressFrom = new InternetAddress(from); msg.setFrom(addressFrom); InternetAddress[] addressTo = new InternetAddress[recipients.length]; for (int i = 0; i < recipients.length; i++) { addressTo[i] = new InternetAddress(recipients[i]); } msg.setRecipients(Message.RecipientType.TO, addressTo); // Setting the Subject and Content Type msg.setSubject(subject); msg.setContent(message, "text/plain"); Transport.send(msg); System.out.println("Sucessfully Sent mail to All Users"); }
public String getDate() { return df.toDateTimeString(m.getReferenceTime()); }
public long getSize() { return m.getMessageSize(); }
public int getNobs() { return m.getNumberDatasets(); }
public String getHeader() { return m.getHeader(); }
public String getTable() { return m.getTableName(); }
public String getCenter() { return m.getCenterName(); }
public String getCategory() throws IOException { return m.getCategoryFullName(); }
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(); } }
public void run() { Object tmp; Message msg = null; int counter = 0; Vector v = new Vector(); while (running) { Util.sleep(10); try { tmp = channel.receive(0); if (tmp == null) continue; if (tmp instanceof View) { View vw = (View) tmp; control.viewNumber.setText(String.valueOf(vw.getVid().getId())); control.numMessagesInLastView.setText(String.valueOf(counter)); counter = 0; v.clear(); continue; } if (!(tmp instanceof Message)) continue; msg = (Message) tmp; measureThrougput(msg.size()); TotalPayload p = null; p = (TotalPayload) msg.getObject(); v.addElement(new Integer(p.getRandomSequence())); int size = v.size(); if (size % 50 == 0) { int value = 0; int i = 0; Iterator iter = v.iterator(); while (iter.hasNext()) { i++; int seq = ((Integer) iter.next()).intValue(); if (i % 2 == 0) { value *= seq; } else if (i % 3 == 0) { value -= seq; } else value += seq; } v.clear(); value = Math.abs(value); int r = value % 85; int g = value % 170; int b = value % 255; colorPanel.setSeq(r, g, b); } counter++; } catch (ChannelNotConnectedException e) { e.printStackTrace(); } catch (ChannelClosedException e) { e.printStackTrace(); } catch (TimeoutException e) { e.printStackTrace(); } } }
/** * When a message is received determines whether to open a new chat window or chat window tab, or * to indicate that a message is received from a contact which already has an open chat. When the * chat is found checks if in mode "Auto popup enabled" and if this is the case shows the message * in the appropriate chat panel. * * @param protocolContact the source contact of the event * @param contactResource the resource from which the contact is writing * @param metaContact the metacontact containing <tt>protocolContact</tt> * @param message the message to deliver * @param eventType the event type * @param timestamp the timestamp of the event * @param correctedMessageUID the identifier of the corrected message * @param isPrivateMessaging if <tt>true</tt> the message is received from private messaging * contact. * @param privateContactRoom the chat room associated with the private messaging contact. */ private void messageReceived( final Contact protocolContact, final ContactResource contactResource, final MetaContact metaContact, final Message message, final int eventType, final Date timestamp, final String correctedMessageUID, final boolean isPrivateMessaging, final ChatRoom privateContactRoom) { if (!SwingUtilities.isEventDispatchThread()) { SwingUtilities.invokeLater( new Runnable() { public void run() { messageReceived( protocolContact, contactResource, metaContact, message, eventType, timestamp, correctedMessageUID, isPrivateMessaging, privateContactRoom); } }); return; } // Obtain the corresponding chat panel. final ChatPanel chatPanel = chatWindowManager.getContactChat( metaContact, protocolContact, contactResource, message.getMessageUID()); // Show an envelope on the sender contact in the contact list and // in the systray. if (!chatPanel.isChatFocused()) contactList.setActiveContact(metaContact, true); // Distinguish the message type, depending on the type of event that // we have received. String messageType = null; if (eventType == MessageReceivedEvent.CONVERSATION_MESSAGE_RECEIVED) { messageType = Chat.INCOMING_MESSAGE; } else if (eventType == MessageReceivedEvent.SYSTEM_MESSAGE_RECEIVED) { messageType = Chat.SYSTEM_MESSAGE; } else if (eventType == MessageReceivedEvent.SMS_MESSAGE_RECEIVED) { messageType = Chat.SMS_MESSAGE; } String contactAddress = (contactResource != null) ? protocolContact.getAddress() + " (" + contactResource.getResourceName() + ")" : protocolContact.getAddress(); chatPanel.addMessage( contactAddress, protocolContact.getDisplayName(), timestamp, messageType, message.getContent(), message.getContentType(), message.getMessageUID(), correctedMessageUID); String resourceName = (contactResource != null) ? contactResource.getResourceName() : null; if (isPrivateMessaging) { chatWindowManager.openPrivateChatForChatRoomMember(privateContactRoom, protocolContact); } else { chatWindowManager.openChat(chatPanel, false); } ChatTransport chatTransport = chatPanel.getChatSession().findChatTransportForDescriptor(protocolContact, resourceName); chatPanel.setSelectedChatTransport(chatTransport, true); }