Search in sources :

Example 11 with PacketCollector

use of org.jivesoftware.smack.PacketCollector in project ecf by eclipse.

the class TranscriptManager method getTranscript.

/**
 * Returns the full conversation transcript of a given session.
 *
 * @param sessionID the id of the session to get the full transcript.
 * @param workgroupJID the JID of the workgroup that will process the request.
 * @return the full conversation transcript of a given session.
 * @throws XMPPException if an error occurs while getting the information.
 */
public Transcript getTranscript(String workgroupJID, String sessionID) throws XMPPException {
    Transcript request = new Transcript(sessionID);
    request.setTo(workgroupJID);
    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
    // Send the request
    connection.sendPacket(request);
    Transcript response = (Transcript) 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;
}
Also used : Transcript(org.jivesoftware.smackx.workgroup.packet.Transcript) PacketCollector(org.jivesoftware.smack.PacketCollector) XMPPException(org.jivesoftware.smack.XMPPException) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 12 with PacketCollector

use of org.jivesoftware.smack.PacketCollector in project ecf by eclipse.

the class TranscriptManager method getTranscripts.

/**
 * Returns the transcripts of a given user. The answer will contain the complete history of
 * conversations that a user had.
 *
 * @param userID the id of the user to get his conversations.
 * @param workgroupJID the JID of the workgroup that will process the request.
 * @return the transcripts of a given user.
 * @throws XMPPException if an error occurs while getting the information.
 */
public Transcripts getTranscripts(String workgroupJID, String userID) throws XMPPException {
    Transcripts request = new Transcripts(userID);
    request.setTo(workgroupJID);
    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
    // Send the request
    connection.sendPacket(request);
    Transcripts response = (Transcripts) 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;
}
Also used : PacketCollector(org.jivesoftware.smack.PacketCollector) XMPPException(org.jivesoftware.smack.XMPPException) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter) Transcripts(org.jivesoftware.smackx.workgroup.packet.Transcripts)

Example 13 with PacketCollector

use of org.jivesoftware.smack.PacketCollector in project ecf by eclipse.

the class TranscriptSearchManager method submitSearch.

/**
 * Submits the completed form and returns the result of the transcript search. The result
 * will include all the data returned from the server so be careful with the amount of
 * data that the search may return.
 *
 * @param serviceJID    the address of the workgroup service.
 * @param completedForm the filled out search form.
 * @return the result of the transcript search.
 * @throws XMPPException if an error occurs while submiting the search to the server.
 */
public ReportedData submitSearch(String serviceJID, Form completedForm) throws XMPPException {
    TranscriptSearch search = new TranscriptSearch();
    search.setType(IQ.Type.GET);
    search.setTo(serviceJID);
    search.addExtension(completedForm.getDataFormToSend());
    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(search.getPacketID()));
    connection.sendPacket(search);
    TranscriptSearch response = (TranscriptSearch) 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 ReportedData.getReportedDataFrom(response);
}
Also used : PacketCollector(org.jivesoftware.smack.PacketCollector) TranscriptSearch(org.jivesoftware.smackx.workgroup.packet.TranscriptSearch) XMPPException(org.jivesoftware.smack.XMPPException) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 14 with PacketCollector

use of org.jivesoftware.smack.PacketCollector in project ecf by eclipse.

the class FaultTolerantNegotiator method createIncomingStream.

public InputStream createIncomingStream(StreamInitiation initiation) throws XMPPException {
    PacketCollector collector = connection.createPacketCollector(getInitiationPacketFilter(initiation.getFrom(), initiation.getSessionID()));
    connection.sendPacket(super.createInitiationAccept(initiation, getNamespaces()));
    ExecutorService threadPoolExecutor = Executors.newFixedThreadPool(2);
    CompletionService<InputStream> service = new ExecutorCompletionService<InputStream>(threadPoolExecutor);
    List<Future<InputStream>> futures = new ArrayList<Future<InputStream>>();
    InputStream stream = null;
    XMPPException exception = null;
    try {
        futures.add(service.submit(new NegotiatorService(collector)));
        futures.add(service.submit(new NegotiatorService(collector)));
        int i = 0;
        while (stream == null && i < futures.size()) {
            Future<InputStream> future;
            try {
                i++;
                future = service.poll(10, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                continue;
            }
            if (future == null) {
                continue;
            }
            try {
                stream = future.get();
            } catch (InterruptedException e) {
            /* Do Nothing */
            } catch (ExecutionException e) {
                exception = new XMPPException(e.getCause());
            }
        }
    } finally {
        for (Future<InputStream> future : futures) {
            future.cancel(true);
        }
        collector.cancel();
        threadPoolExecutor.shutdownNow();
    }
    if (stream == null) {
        if (exception != null) {
            throw exception;
        } else {
            throw new XMPPException("File transfer negotiation failed.");
        }
    }
    return stream;
}
Also used : InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) PacketCollector(org.jivesoftware.smack.PacketCollector) XMPPException(org.jivesoftware.smack.XMPPException)

Example 15 with PacketCollector

use of org.jivesoftware.smack.PacketCollector in project ecf by eclipse.

the class OfflineMessageManager method getMessages.

/**
 * Returns an Iterator with all the offline <tt>Messages</tt> of the user. The returned offline
 * messages will not be deleted from the server. Use {@link #deleteMessages(java.util.List)}
 * to delete the messages.
 *
 * @return an Iterator with all the offline <tt>Messages</tt> of the user.
 * @throws XMPPException If the user is not allowed to make this request or the server does
 *                       not support offline message retrieval.
 */
public Iterator<Message> getMessages() throws XMPPException {
    List<Message> messages = new ArrayList<Message>();
    OfflineMessageRequest request = new OfflineMessageRequest();
    request.setFetch(true);
    // Filter packets looking for an answer from the server.
    PacketFilter responseFilter = new PacketIDFilter(request.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    // Filter offline messages that were requested by this request
    PacketCollector messageCollector = connection.createPacketCollector(packetFilter);
    // Send the retrieval request to the server.
    connection.sendPacket(request);
    // Wait up to a certain number of seconds for a reply.
    IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    response.cancel();
    if (answer == null) {
        throw new XMPPException("No response from server.");
    } else if (answer.getError() != null) {
        throw new XMPPException(answer.getError());
    }
    // Collect the received offline messages
    Message message = (Message) messageCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    while (message != null) {
        messages.add(message);
        message = (Message) messageCollector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    }
    // Stop queuing offline messages
    messageCollector.cancel();
    return messages.iterator();
}
Also used : Message(org.jivesoftware.smack.packet.Message) ArrayList(java.util.ArrayList) OfflineMessageRequest(org.jivesoftware.smackx.packet.OfflineMessageRequest) PacketCollector(org.jivesoftware.smack.PacketCollector) IQ(org.jivesoftware.smack.packet.IQ) XMPPException(org.jivesoftware.smack.XMPPException)

Aggregations

PacketCollector (org.jivesoftware.smack.PacketCollector)46 XMPPException (org.jivesoftware.smack.XMPPException)44 PacketIDFilter (org.jivesoftware.smack.filter.PacketIDFilter)36 IQ (org.jivesoftware.smack.packet.IQ)24 PacketFilter (org.jivesoftware.smack.filter.PacketFilter)21 Packet (org.jivesoftware.smack.packet.Packet)10 ArrayList (java.util.ArrayList)6 AndFilter (org.jivesoftware.smack.filter.AndFilter)6 PacketTypeFilter (org.jivesoftware.smack.filter.PacketTypeFilter)6 MUCAdmin (org.jivesoftware.smackx.packet.MUCAdmin)6 MUCOwner (org.jivesoftware.smackx.packet.MUCOwner)6 FromMatchesFilter (org.jivesoftware.smack.filter.FromMatchesFilter)4 Message (org.jivesoftware.smack.packet.Message)4 OfflineMessageRequest (org.jivesoftware.smackx.packet.OfflineMessageRequest)4 PacketInterceptor (org.jivesoftware.smack.PacketInterceptor)3 Presence (org.jivesoftware.smack.packet.Presence)3 MUCInitialPresence (org.jivesoftware.smackx.packet.MUCInitialPresence)3 Registration (org.jivesoftware.smack.packet.Registration)2 StreamInitiation (org.jivesoftware.smackx.packet.StreamInitiation)2 AgentInfo (org.jivesoftware.smackx.workgroup.packet.AgentInfo)2