當前位置: 首頁>>代碼示例>>Java>>正文


Java Message類代碼示例

本文整理匯總了Java中org.jivesoftware.smack.packet.Message的典型用法代碼示例。如果您正苦於以下問題:Java Message類的具體用法?Java Message怎麽用?Java Message使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Message類屬於org.jivesoftware.smack.packet包,在下文中一共展示了Message類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: perform

import org.jivesoftware.smack.packet.Message; //導入依賴的package包/類
@Override
public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception {
    // sending message
    String recipient = sampler.getPropertyAsString(RECIPIENT);
    String body = sampler.getPropertyAsString(BODY);
    boolean wait_response = sampler.getPropertyAsBoolean(WAIT_RESPONSE);
    if (wait_response) {
        body += "\r\n" + System.currentTimeMillis() + "@" + NEED_RESPONSE_MARKER;
    }

    Message msg = new Message(recipient);
    msg.setType(Message.Type.fromString(sampler.getPropertyAsString(TYPE, Message.Type.normal.toString())));
    msg.addBody("", body);
    res.setSamplerData(msg.toXML().toString());
    sampler.getXMPPConnection().sendPacket(msg);
    res.setSamplerData(msg.toXML().toString()); // second time to reflect the changes made to packet by conn

    if (wait_response) {
        return waitResponse(res, recipient);
    }
    return res;
}
 
開發者ID:Blazemeter,項目名稱:jmeter-bzm-plugins,代碼行數:23,代碼來源:SendMessage.java

示例2: waitResponse

import org.jivesoftware.smack.packet.Message; //導入依賴的package包/類
private SampleResult waitResponse(SampleResult res, String recipient) throws InterruptedException, SmackException {
    long time = 0;
    do {
        Iterator<Message> packets = responseMessages.iterator();
        Thread.sleep(conn.getPacketReplyTimeout() / 100); // optimistic
        while (packets.hasNext()) {
            Packet packet = packets.next();
            Message response = (Message) packet;
            if (XmppStringUtils.parseBareAddress(response.getFrom()).equals(recipient)) {
                packets.remove();
                res.setResponseData(response.toXML().toString().getBytes());
                if (response.getError() != null) {
                    res.setSuccessful(false);
                    res.setResponseCode("500");
                    res.setResponseMessage(response.getError().toString());
                }
                return res;
            }
        }
        time += conn.getPacketReplyTimeout() / 10;
        Thread.sleep(conn.getPacketReplyTimeout() / 10);
    } while (time < conn.getPacketReplyTimeout());
    throw new SmackException.NoResponseException();
}
 
開發者ID:Blazemeter,項目名稱:jmeter-bzm-plugins,代碼行數:25,代碼來源:SendMessage.java

示例3: addUI

import org.jivesoftware.smack.packet.Message; //導入依賴的package包/類
@Override
public void addUI(JComponent mainPanel, GridBagConstraints labelConstraints, GridBagConstraints editConstraints) {
    addToPanel(mainPanel, labelConstraints, 0, 0, new JLabel("Type: ", JLabel.RIGHT));
    addToPanel(mainPanel, editConstraints, 1, 0, msgType = new JComboBox<>());
    msgType.addItem(Message.Type.normal);
    msgType.addItem(Message.Type.chat);
    msgType.addItem(Message.Type.groupchat);
    msgType.addItem(Message.Type.headline);
    msgType.addItem(Message.Type.error);

    addToPanel(mainPanel, labelConstraints, 0, 1, new JLabel("Recipient: ", JLabel.RIGHT));
    addToPanel(mainPanel, editConstraints, 1, 1, msgRecipient = new JTextField(20));

    addToPanel(mainPanel, labelConstraints, 0, 2, new JLabel("Message Text: ", JLabel.RIGHT));
    addToPanel(mainPanel, editConstraints, 1, 2, msgBody = new JTextArea(5, 20));

    addToPanel(mainPanel, labelConstraints, 0, 3, new JLabel("Wait for Response: ", JLabel.RIGHT));
    addToPanel(mainPanel, editConstraints, 1, 3, waitResponse = new JCheckBox("(message that expects response should be auto-responded by another JMeter thread)"));
}
 
開發者ID:Blazemeter,項目名稱:jmeter-bzm-plugins,代碼行數:20,代碼來源:SendMessage.java

示例4: processPacket

import org.jivesoftware.smack.packet.Message; //導入依賴的package包/類
@Override
public void processPacket(Packet packet) throws SmackException.NotConnectedException {
    if (packet instanceof Message) {
        Message inMsg = (Message) packet;
        if (inMsg.getBody() != null) {
            if (inMsg.getBody().endsWith(NEED_RESPONSE_MARKER)) {
                if (inMsg.getExtension(NS_DELAYED) == null) {
                    log.debug("Will respond to message: " + inMsg.toXML());
                    sendResponseMessage(inMsg);
                } else {
                    log.debug("Will not consider history message: " + inMsg.toXML());
                }
            } else if (inMsg.getBody().endsWith(RESPONSE_MARKER)) {
                responseMessages.add(inMsg);
            }
        }
    }
}
 
開發者ID:Blazemeter,項目名稱:jmeter-bzm-plugins,代碼行數:19,代碼來源:SendMessage.java

示例5: perform

import org.jivesoftware.smack.packet.Message; //導入依賴的package包/類
@Test
public void perform() throws Exception {
    SendMessage action = new SendMessage();
    XMPPConnectionMock connection = new XMPPConnectionMock();
    action.connected(connection);
    Message resp = new Message();
    resp.setFrom("[email protected]");
    resp.setBody(SendMessage.RESPONSE_MARKER);
    action.processPacket(resp);
    JMeterXMPPSampler sampler = new JMeterXMPPSamplerMock();
    sampler.getXMPPConnection().setFromMode(XMPPConnection.FromMode.USER);
    sampler.setProperty(SendMessage.RECIPIENT, "[email protected]");
    sampler.setProperty(SendMessage.WAIT_RESPONSE, true);
    SampleResult res = new SampleResult();
    action.perform(sampler, res);
    Assert.assertTrue(res.getResponseDataAsString().contains(SendMessage.RESPONSE_MARKER));
    Assert.assertTrue(res.getSamplerData().contains("from"));
}
 
開發者ID:Blazemeter,項目名稱:jmeter-bzm-plugins,代碼行數:19,代碼來源:SendMessageTest.java

示例6: sendMessage

import org.jivesoftware.smack.packet.Message; //導入依賴的package包/類
public void sendMessage(String body, String chatJid, long timestamp) throws SmackException {
    Random random = new Random(timestamp + body.length() + chatJid.length());
    Log.d(TAG, "Sending message to : " + chatJid);
    MultiUserChat chat = MultiUserChatManager.getInstanceFor(groupChatConnection)
            .getMultiUserChat(chatJid);
    chat.addMessageListener(this);

    Message message = new Message();
    QuickbloxChatExtension extension = new QuickbloxChatExtension();
    extension.setProperty("date_sent", timestamp + "");
    message.setStanzaId(StanzaIdUtil.newStanzaId());
    message.setBody(body);
    message.addExtension(extension);
    message.setType(Message.Type.chat);

    chat.sendMessage(message);
}
 
開發者ID:ukevgen,項目名稱:BizareChat,代碼行數:18,代碼來源:QuickbloxGroupXmppConnection.java

示例7: sendDisplayedReceipt

import org.jivesoftware.smack.packet.Message; //導入依賴的package包/類
public void sendDisplayedReceipt(String receiverJid, String stanzaId, String dialog_id) {
    Chat chat;
    if ((chat = privateChats.get(receiverJid)) == null) {
        chat = ChatManager.getInstanceFor(privateChatConnection).createChat(receiverJid, this);
        privateChats.put(receiverJid, chat);
    }

    Message message = new Message(receiverJid);
    Displayed read = new Displayed(stanzaId);
    QuickbloxChatExtension extension = new QuickbloxChatExtension();
    extension.setProperty("dialog_id", dialog_id);

    message.setStanzaId(StanzaIdUtil.newStanzaId());
    message.setType(Message.Type.chat);
    message.addExtension(read);
    message.addExtension(extension);

    try {
        chat.sendMessage(message);
    } catch (SmackException.NotConnectedException ex) {
        Logger.logExceptionToFabric(ex);
        offlineMessages.add(message);
    }
}
 
開發者ID:ukevgen,項目名稱:BizareChat,代碼行數:25,代碼來源:QuickbloxPrivateXmppConnection.java

示例8: sendReceivedReceipt

import org.jivesoftware.smack.packet.Message; //導入依賴的package包/類
public void sendReceivedReceipt(String receiverJid, String stanzaId, String dialog_id) {
    Chat chat;
    if ((chat = privateChats.get(receiverJid)) == null) {
        chat = ChatManager.getInstanceFor(privateChatConnection).createChat(receiverJid, this);
        privateChats.put(receiverJid, chat);
    }

    Message message = new Message(receiverJid);
    Received delivered = new Received(stanzaId);
    QuickbloxChatExtension extension = new QuickbloxChatExtension();
    extension.setProperty("dialog_id", dialog_id);

    message.setStanzaId(StanzaIdUtil.newStanzaId());
    message.setType(Message.Type.chat);
    message.addExtension(delivered);
    message.addExtension(extension);

    try {
        chat.sendMessage(message);
    } catch (SmackException.NotConnectedException ex) {
        offlineMessages.add(message);
    }
}
 
開發者ID:ukevgen,項目名稱:BizareChat,代碼行數:24,代碼來源:QuickbloxPrivateXmppConnection.java

示例9: sendPrivateMessage

import org.jivesoftware.smack.packet.Message; //導入依賴的package包/類
public void sendPrivateMessage(String body, String receiverJid, long timestamp, String stanzaId) {
    Log.d(TAG, "Sending message to : " + receiverJid);

    Chat chat;
    if ((chat = privateChats.get(receiverJid)) == null) {
        chat = ChatManager.getInstanceFor(privateChatConnection).createChat(receiverJid, this);
        privateChats.put(receiverJid, chat);
    }

    QuickbloxChatExtension extension = new QuickbloxChatExtension();
    extension.setProperty("date_sent", timestamp + "");
    extension.setProperty("save_to_history", "1");

    Message message = new Message(receiverJid);
    message.setStanzaId(stanzaId);
    message.setBody(body);
    message.setType(Message.Type.chat);
    message.addExtension(new Markable());
    message.addExtension(extension);

    try {
        chat.sendMessage(message);
    } catch (SmackException.NotConnectedException ex) {
        offlineMessages.add(message);
    }
}
 
開發者ID:ukevgen,項目名稱:BizareChat,代碼行數:27,代碼來源:QuickbloxPrivateXmppConnection.java

示例10: sendPublicMessage

import org.jivesoftware.smack.packet.Message; //導入依賴的package包/類
public void sendPublicMessage(String body, String chatJid, long timestamp, String stanzaId) {
    Log.d(TAG, "Sending message to : " + chatJid);

    MultiUserChat mucChat = publicChats.get(chatJid);

    QuickbloxChatExtension extension = new QuickbloxChatExtension();
    extension.setProperty("date_sent", timestamp + "");
    extension.setProperty("save_to_history", "1");

    Message message = new Message(chatJid);
    message.setStanzaId(stanzaId);
    message.setBody(body);
    message.setType(Message.Type.groupchat);
    message.addExtension(extension);

    try {
        if (mucChat != null) {
            mucChat.sendMessage(message);
        }
    } catch (SmackException.NotConnectedException ex) {
        offlineMessages.add(message);
    }
}
 
開發者ID:ukevgen,項目名稱:BizareChat,代碼行數:24,代碼來源:QuickbloxPrivateXmppConnection.java

示例11: reconnectionSuccessful

import org.jivesoftware.smack.packet.Message; //導入依賴的package包/類
@Override
public void reconnectionSuccessful() {
    connected = true;
    if (!offlineMessages.isEmpty()) {
        JobExecutor.getInstance().execute(() -> {
            while (!offlineMessages.isEmpty()) {
                try {
                    if (!publicChatToLeave.isEmpty()) {
                        publicChats.get(publicChatToLeave).leave();
                        publicChatToLeave = "";
                    }
                    Message message = offlineMessages.peek();
                    privateChatConnection.sendStanza(message);
                } catch (SmackException ex) {
                    Logger.logExceptionToFabric(ex);
                    break;
                }
                offlineMessages.poll();
            }
        });
    }
    Log.d(TAG, "Reconnection successful");
}
 
開發者ID:ukevgen,項目名稱:BizareChat,代碼行數:24,代碼來源:QuickbloxPrivateXmppConnection.java

示例12: processPublicMessage

import org.jivesoftware.smack.packet.Message; //導入依賴的package包/類
void processPublicMessage(Message message) {
    JobExecutor.getInstance().execute(() -> {
        MessageModel messageModel = getMessageModel(message);
        MessageModel messageModelFromDb = daoSession.getMessageModelDao()
                .queryBuilder()
                .where(MessageModelDao.Properties.MessageId.eq(message.getStanzaId()))
                .unique();
        if (messageModelFromDb != null) {
            messageModelFromDb.setMessageId(messageModel.getMessageId());
            messageModelFromDb.setRead(MessageState.DELIVERED);
            daoSession.getMessageModelDao().deleteByKeyInTx(message.getStanzaId());
        } else {
            messageModelFromDb = messageModel;
        }

        savePublicMessageToDb(messageModelFromDb);

        if (messageModelFromDb.getSenderId().longValue() != CurrentUser.getInstance().getCurrentUserId()) {
            EventBus.getDefault().post(new PublicMessageEvent(messageModel));
        }
    });
}
 
開發者ID:ukevgen,項目名稱:BizareChat,代碼行數:23,代碼來源:BizareChatMessageService.java

示例13: testInvitation

import org.jivesoftware.smack.packet.Message; //導入依賴的package包/類
public void testInvitation() {
    try {
        GroupChatInvitation invitation = new GroupChatInvitation("[email protected]" + getChatDomain());
        Message message = new Message(getBareJID(1));
        message.setBody("Group chat invitation!");
        message.addExtension(invitation);
        getConnection(0).sendStanza(message);

        Thread.sleep(250);

        Message result = (Message)collector.pollResult();
        assertNotNull("Message not delivered correctly.", result);

        GroupChatInvitation resultInvite = (GroupChatInvitation)result.getExtension("x",
                "jabber:x:conference");

        assertEquals("Invitation not to correct room", "[email protected]" + getChatDomain(),
                resultInvite.getRoomAddress());
    }
    catch (Exception e) {
        fail(e.getMessage());
    }
}
 
開發者ID:TTalkIM,項目名稱:Smack,代碼行數:24,代碼來源:GroupChatInvitationTest.java

示例14: updateTypingStatus

import org.jivesoftware.smack.packet.Message; //導入依賴的package包/類
public void updateTypingStatus(final ChatState chatState, final String jid, final int chatType) {
    if (!Preferences.isTesting()) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Message message = new Message(JidCreate.from(jid));
                    message.addExtension(new ChatStateExtension(chatState));

                    if (chatType == Chat.TYPE_1_T0_1) {
                        message.setType(Message.Type.chat);
                    } else {
                        message.setType(Message.Type.groupchat);
                    }

                    sendMessageDependingOnType(message, jid, chatType);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}
 
開發者ID:esl,項目名稱:mangosta-android,代碼行數:24,代碼來源:RoomManager.java

示例15: saveMessage

import org.jivesoftware.smack.packet.Message; //導入依賴的package包/類
private void saveMessage(Message message) {
    String messageId = assignMessageId(message);

    if (RealmManager.getInstance().chatMessageExists(messageId)) { // message sent confirmation
        manageMessageAlreadyExists(message, null, messageId);

    } else if (isMessageCorrection(message)) { // message correction
        manageMessageCorrection(message, null);

    } else { // normal message received
        manageMessageReceived(message, null, messageId, false);

        if (canBeTextMessageOrSticker(message)) {
            MessageNotifications.chatMessageNotification(messageId);
        }
    }
}
 
開發者ID:esl,項目名稱:mangosta-android,代碼行數:18,代碼來源:XMPPSession.java


注:本文中的org.jivesoftware.smack.packet.Message類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。