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;
}
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;
}
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);
}
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;
}
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();
}
Aggregations