当前位置: 首页>>代码示例>>Java>>正文


Java Connection.createPacketCollector方法代码示例

本文整理汇总了Java中org.jivesoftware.smack.Connection.createPacketCollector方法的典型用法代码示例。如果您正苦于以下问题:Java Connection.createPacketCollector方法的具体用法?Java Connection.createPacketCollector怎么用?Java Connection.createPacketCollector使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jivesoftware.smack.Connection的用法示例。


在下文中一共展示了Connection.createPacketCollector方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSharedGroups

import org.jivesoftware.smack.Connection; //导入方法依赖的package包/类
/**
 * Returns the collection that will contain the name of the shared groups where the user
 * logged in with the specified session belongs.
 *
 * @param connection connection to use to get the user's shared groups.
 * @return collection with the shared groups' name of the logged user.
 */
public static List getSharedGroups(Connection connection) throws XMPPException {
    // Discover the shared groups of the logged user
    SharedGroupsInfo info = new SharedGroupsInfo();
    info.setType(IQ.Type.GET);

    // Create a packet collector to listen for a response.
    PacketCollector collector =
        connection.createPacketCollector(new PacketIDFilter(info.getPacketID()));

    connection.sendPacket(info);

    // Wait up to 5 seconds for a result.
    IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from the server.");
    }
    if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }
    return ((SharedGroupsInfo) result).getGroups();
}
 
开发者ID:ice-coffee,项目名称:EIM,代码行数:31,代码来源:SharedGroupManager.java

示例2: getReply

import org.jivesoftware.smack.Connection; //导入方法依赖的package包/类
static public Packet getReply(Connection connection, Packet packet, long timeout)
	throws XMPPException
{
       PacketFilter responseFilter = new PacketIDFilter(packet.getPacketID());
       PacketCollector response = connection.createPacketCollector(responseFilter);
       
       connection.sendPacket(packet);

       // Wait up to a certain number of seconds for a reply.
       Packet result = response.nextResult(timeout);

       // Stop queuing results
       response.cancel();

       if (result == null) {
           throw new XMPPException("No response from server.");
       }
       else if (result.getError() != null) {
           throw new XMPPException(result.getError());
       }
       return result;
}
 
开发者ID:ice-coffee,项目名称:EIM,代码行数:23,代码来源:SyncPacketSend.java

示例3: getWorkgroups

import org.jivesoftware.smack.Connection; //导入方法依赖的package包/类
public static Collection<String> getWorkgroups(String serviceJID, String agentJID, Connection connection) throws XMPPException {
    AgentWorkgroups request = new AgentWorkgroups(agentJID);
    request.setTo(serviceJID);
    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
    // Send the request
    connection.sendPacket(request);

    AgentWorkgroups response = (AgentWorkgroups)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

    // Cancel the collector.
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from server on status set.");
    }
    if (response.getError() != null) {
        throw new XMPPException(response.getError());
    }
    return response.getWorkgroups();
}
 
开发者ID:ice-coffee,项目名称:EIM,代码行数:20,代码来源:Agent.java

示例4: getSearchForm

import org.jivesoftware.smack.Connection; //导入方法依赖的package包/类
/**
 * Returns the form for all search fields supported by the search service.
 *
 * @param con           the current Connection.
 * @param searchService the search service to use. (ex. search.jivesoftware.com)
 * @return the search form received by the server.
 * @throws org.jivesoftware.smack.XMPPException
 *          thrown if a server error has occurred.
 */
public Form getSearchForm(Connection con, String searchService) throws XMPPException {
    UserSearch search = new UserSearch();
    search.setType(IQ.Type.GET);
    search.setTo(searchService);

    PacketCollector collector = con.createPacketCollector(new PacketIDFilter(search.getPacketID()));
    con.sendPacket(search);

    IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

    // Cancel the collector.
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from server on status set.");
    }
    if (response.getError() != null) {
        throw new XMPPException(response.getError());
    }
    return Form.getFormFrom(response);
}
 
开发者ID:ice-coffee,项目名称:EIM,代码行数:30,代码来源:UserSearch.java

示例5: sendSearchForm

import org.jivesoftware.smack.Connection; //导入方法依赖的package包/类
/**
 * Sends the filled out answer form to be sent and queried by the search service.
 *
 * @param con           the current Connection.
 * @param searchForm    the <code>Form</code> to send for querying.
 * @param searchService the search service to use. (ex. search.jivesoftware.com)
 * @return ReportedData the data found from the query.
 * @throws org.jivesoftware.smack.XMPPException
 *          thrown if a server error has occurred.
 */
public ReportedData sendSearchForm(Connection con, Form searchForm, String searchService) throws XMPPException {
    UserSearch search = new UserSearch();
    search.setType(IQ.Type.SET);
    search.setTo(searchService);
    search.addExtension(searchForm.getDataFormToSend());

    PacketCollector collector = con.createPacketCollector(new PacketIDFilter(search.getPacketID()));

    con.sendPacket(search);

    IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

    // Cancel the collector.
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from server on status set.");
    }
    if (response.getError() != null) {
        return sendSimpleSearchForm(con, searchForm, searchService);
    }


    return ReportedData.getReportedDataFrom(response);
}
 
开发者ID:ice-coffee,项目名称:EIM,代码行数:35,代码来源:UserSearch.java

示例6: save

import org.jivesoftware.smack.Connection; //导入方法依赖的package包/类
/**
 * Save this vCard for the user connected by 'connection'. Connection should be authenticated
 * and not anonymous.<p>
 * <p/>
 * NOTE: the method is asynchronous and does not wait for the returned value.
 *
 * @param connection the Connection to use.
 * @throws XMPPException thrown if there was an issue setting the VCard in the server.
 */
public void save(Connection connection) throws XMPPException {
    checkAuthenticated(connection, true);

    setType(IQ.Type.SET);
    setFrom(connection.getUser());
    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(getPacketID()));
    connection.sendPacket(this);

    Packet response = collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

    // Cancel the collector.
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from server on status set.");
    }
    if (response.getError() != null) {
        throw new XMPPException(response.getError());
    }
}
 
开发者ID:ice-coffee,项目名称:EIM,代码行数:29,代码来源:VCard.java

示例7: doLoad

import org.jivesoftware.smack.Connection; //导入方法依赖的package包/类
private void doLoad(Connection connection, String user) throws XMPPException {
    setType(Type.GET);
    PacketCollector collector = connection.createPacketCollector(
            new PacketIDFilter(getPacketID()));
    connection.sendPacket(this);

    VCard result = null;
    try {
        result = (VCard) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

        if (result == null) {
            String errorMessage = "Timeout getting VCard information";
            throw new XMPPException(errorMessage, new XMPPError(
                    XMPPError.Condition.request_timeout, errorMessage));
        }
        if (result.getError() != null) {
            throw new XMPPException(result.getError());
        }
    }
    catch (ClassCastException e) {
        System.out.println("No VCard for " + user);
    }

    copyFieldsFrom(result);
}
 
开发者ID:ice-coffee,项目名称:EIM,代码行数:26,代码来源:VCard.java

示例8: getLastActivity

import org.jivesoftware.smack.Connection; //导入方法依赖的package包/类
/**
 * Retrieve the last activity of a particular jid.
 * @param con the current Connection.
 * @param jid the JID of the user.
 * @return the LastActivity packet of the jid.
 * @throws XMPPException thrown if a server error has occured.
 * @deprecated This method only retreives the lapsed time since the last logout of a particular jid. 
 * Replaced by {@link  org.jivesoftware.smackx.LastActivityManager#getLastActivity(Connection, String)  getLastActivity}
 */
public static LastActivity getLastActivity(Connection con, String jid) throws XMPPException {
    LastActivity activity = new LastActivity();
    jid = StringUtils.parseBareAddress(jid);
    activity.setTo(jid);

    PacketCollector collector = con.createPacketCollector(new PacketIDFilter(activity.getPacketID()));
    con.sendPacket(activity);

    LastActivity response = (LastActivity) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

    // Cancel the collector.
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from server on status set.");
    }
    if (response.getError() != null) {
        throw new XMPPException(response.getError());
    }
    return response;
}
 
开发者ID:CJC-ivotten,项目名称:androidPN-client.,代码行数:30,代码来源:LastActivity.java

示例9: getSharedGroups

import org.jivesoftware.smack.Connection; //导入方法依赖的package包/类
/**
 * Returns the collection that will contain the name of the shared groups where the user
 * logged in with the specified session belongs.
 *
 * @param connection connection to use to get the user's shared groups.
 * @return collection with the shared groups' name of the logged user.
 */
public static List<String> getSharedGroups(Connection connection) throws XMPPException {
    // Discover the shared groups of the logged user
    SharedGroupsInfo info = new SharedGroupsInfo();
    info.setType(IQ.Type.GET);

    // Create a packet collector to listen for a response.
    PacketCollector collector =
        connection.createPacketCollector(new PacketIDFilter(info.getPacketID()));

    connection.sendPacket(info);

    // Wait up to 5 seconds for a result.
    IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from the server.");
    }
    if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }
    return ((SharedGroupsInfo) result).getGroups();
}
 
开发者ID:CJC-ivotten,项目名称:androidPN-client.,代码行数:31,代码来源:SharedGroupManager.java

示例10: initiateIncomingStream

import org.jivesoftware.smack.Connection; //导入方法依赖的package包/类
Packet initiateIncomingStream(Connection connection, StreamInitiation initiation) throws XMPPException {
    StreamInitiation response = createInitiationAccept(initiation,
            getNamespaces());

    // establish collector to await response
    PacketCollector collector = connection
            .createPacketCollector(getInitiationPacketFilter(initiation.getFrom(), initiation.getSessionID()));
    connection.sendPacket(response);

    Packet streamMethodInitiation = collector
            .nextResult(SmackConfiguration.getPacketReplyTimeout());
    collector.cancel();
    if (streamMethodInitiation == null) {
        throw new XMPPException("No response from file transfer initiator");
    }

    return streamMethodInitiation;
}
 
开发者ID:CJC-ivotten,项目名称:androidPN-client.,代码行数:19,代码来源:StreamNegotiator.java

示例11: sendSimpleSearchForm

import org.jivesoftware.smack.Connection; //导入方法依赖的package包/类
/**
 * Sends the filled out answer form to be sent and queried by the search service.
 *
 * @param con           the current Connection.
 * @param searchForm    the <code>Form</code> to send for querying.
 * @param searchService the search service to use. (ex. search.jivesoftware.com)
 * @return ReportedData the data found from the query.
 * @throws org.jivesoftware.smack.XMPPException
 *          thrown if a server error has occurred.
 */
public ReportedData sendSimpleSearchForm(Connection con, Form searchForm, String searchService) throws XMPPException {
    SimpleUserSearch search = new SimpleUserSearch();
    search.setForm(searchForm);
    search.setType(IQ.Type.SET);
    search.setTo(searchService);

    PacketCollector collector = con.createPacketCollector(new PacketIDFilter(search.getPacketID()));

    con.sendPacket(search);

    IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

    // Cancel the collector.
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from server on status set.");
    }
    if (response.getError() != null) {
        throw new XMPPException(response.getError());
    }

    if (response instanceof SimpleUserSearch) {
        return ((SimpleUserSearch) response).getReportedData();
    }
    return null;
}
 
开发者ID:ice-coffee,项目名称:EIM,代码行数:37,代码来源:UserSearch.java

示例12: doLoad

import org.jivesoftware.smack.Connection; //导入方法依赖的package包/类
private void doLoad(Connection connection, String user) throws XMPPException {
    setType(Type.GET);
    PacketCollector collector = connection.createPacketCollector(
            new PacketIDFilter(getPacketID()));
    connection.sendPacket(this);

    VCard result = null;
    Packet packet = collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

    if (packet == null) {
        String errorMessage = "Timeout getting VCard information";
        throw new XMPPException(errorMessage, new XMPPError(XMPPError.Condition.request_timeout, errorMessage));
    }
    if (packet.getError() != null) {
        throw new XMPPException(packet.getError());
    }

    try {
       result = (VCard) packet;
    }
    catch (ClassCastException e) {
        System.out.println("No VCard for " + user);
        return;
    }

    copyFieldsFrom(result);
}
 
开发者ID:CJC-ivotten,项目名称:androidPN-client.,代码行数:28,代码来源:VCard.java


注:本文中的org.jivesoftware.smack.Connection.createPacketCollector方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。