/** 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(); } }
/** * 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); }
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 getComplete() { try { return m.isTablesComplete() ? "true" : "false"; } catch (IOException e) { return "exception"; } }
public String getLocal() { try { return m.usesLocalTable() ? "true" : "false"; } catch (Exception e) { return "exception"; } }
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"; } }
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 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, "你的网络貌似有点问题!"); } }
/** * 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(); } }
/** * Logs in user, eventually * * @param username * @param password */ public static Boolean login(String username, String password) { Boolean status; if (username.equals("sigve") && password.equals("1337")) { setUser(User.getUser(1)); // get user 1 for now GregorianCalendar now = new GregorianCalendar(2012, 3, 23); // arbitrary date for now System.out.println("User logged in"); pushView(new CalendarView()); Client.setNotifications(Message.getMessages(Client.user)); Client.setActiveWeek( now.get(GregorianCalendar.YEAR), now.get(GregorianCalendar.MONTH), now.get(GregorianCalendar.DATE)); status = true; } else { System.out.println("Wrong username and/or password"); status = false; } return status; }
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 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 getCategory() throws IOException { return m.getCategoryFullName(); }
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(); } } }
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 String getCenter() { return m.getCenterName(); }
/** * 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); }
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; }