示例#1
0
 static {
   connectionCounter = new AtomicInteger(0);
   DEBUG_ENABLED = false;
   try {
     DEBUG_ENABLED = Boolean.getBoolean("smack.debugEnabled");
   } catch (Exception e) {
   }
   SmackConfiguration.getVersion();
 }
示例#2
0
  /**
   * Returns the private data specified by the given element name and namespace. Each chunk of
   * private data is uniquely identified by an element name and namespace pair.
   *
   * <p>If a PrivateDataProvider is registered for the specified element name/namespace pair then
   * that provider will determine the specific object type that is returned. If no provider is
   * registered, a {@link DefaultPrivateData} instance will be returned.
   *
   * @param elementName the element name.
   * @param namespace the namespace.
   * @return the private data.
   * @throws XMPPException if an error occurs getting the private data.
   */
  public PrivateData getPrivateData(final String elementName, final String namespace)
      throws XMPPException {
    // Create an IQ packet to get the private data.
    IQ privateDataGet =
        new IQ() {
          public String getChildElementXML() {
            StringBuilder buf = new StringBuilder();
            buf.append("<query xmlns=\"jabber:iq:private\">");
            buf.append("<")
                .append(elementName)
                .append(" xmlns=\"")
                .append(namespace)
                .append("\"/>");
            buf.append("</query>");
            return buf.toString();
          }
        };
    privateDataGet.setType(IQ.Type.GET);
    // Address the packet to the other account if user has been set.
    if (user != null) {
      privateDataGet.setTo(user);
    }

    // Setup a listener for the reply to the set operation.
    String packetID = privateDataGet.getPacketID();
    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(packetID));

    // Send the private data.
    connection.sendPacket(privateDataGet);

    // Wait up to five seconds for a response from the server.
    IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    collector.cancel();
    if (response == null) {
      throw new XMPPException("No response from the server.");
    }
    // If the server replied with an error, throw an exception.
    else if (response.getType() == IQ.Type.ERROR) {
      throw new XMPPException(response.getError());
    }
    return ((PrivateDataResult) response).getPrivateData();
  }
示例#3
0
 public boolean isReadAlive() {
   return System.currentTimeMillis() - this.readAlive
       < ((long) SmackConfiguration.getCheckAliveInterval());
 }