Exemplo n.º 1
0
 @SuppressWarnings("unchecked")
 private XMPPBean sendAndWaitForResult(B bean) {
   if (bean != null) {
     this.connection.sendPacket(new BeanIQAdapter(bean));
   }
   while (true) {
     BeanIQAdapter adapter = (BeanIQAdapter) (beanCollector.nextResult(timeout));
     XMPPBean resultBean = null;
     if (adapter != null) {
       if (adapter.getBean().getNamespace().equals(resultBeanPrototype.getNamespace())) {
         resultBean = (ResultBeanType) (adapter.getBean());
       } else {
         resultBean = (B) (adapter.getBean());
       }
     }
     if (adapter == null || resultBean == null) {
       if (retryCount >= maxRetries) {
         return null;
       } else {
         retryCount++;
         sendAndWaitForResult(bean);
       }
     } else if (resultBean.getId().equals(beanOut.getId())) {
       return resultBean;
     }
   }
 }
Exemplo n.º 2
0
        @SuppressWarnings({"rawtypes", "unchecked"})
        @Override
        public void processIQ(XMPPIQ iq) throws RemoteException {

          if (!(iq.from.equals(mGameServiceJid) || iq.from.equals(mServerCoordinatorJid))) {
            String msg =
                "Discarded IQ from unknown JID "
                    + iq.from
                    + " to prevent GameService zombies from interfering"
                    + " - see IQProxy.AbstractCallback.processIQ()";
            Log.w(TAG, msg);
            return;
          }

          Log.v(
              TAG,
              "AbstractCallback: ID: "
                  + iq.packetID
                  + " type: "
                  + iq.type
                  + " ns: "
                  + iq.namespace
                  + " payload: "
                  + iq.payload);

          XMPPBean inBean = convertXMPPIQToBean(iq);

          Log.v(TAG, "Converted Abstract Bean: " + beanToString(inBean));

          if (_waitingCallbacks.containsKey(inBean.getId())) {
            IXMPPCallback callback = _waitingCallbacks.get(inBean.getId());

            if (null != callback) {
              try {
                callback.invoke(inBean);
              } catch (ClassCastException e) {
                e.printStackTrace();
              }
            }
          } else {
            // refer XMPPIQ as XMPPBean to the current active Activities GameState
            // (hold in XHuntService)
            mXhuntService.getGameState().processPacket(inBean);
          }
        }
Exemplo n.º 3
0
  /**
   * Formats a Bean to a string.
   *
   * @param bean the bean
   * @return the formatted string of the Bean
   */
  public String beanToString(XMPPBean bean) {
    String str =
        "XMPPBean: [NS="
            + bean.getNamespace()
            + " id="
            + bean.getId()
            + " from="
            + bean.getFrom()
            + " to="
            + bean.getTo()
            + " type="
            + bean.getType()
            + " payload="
            + bean.payloadToXML();

    if (bean.errorCondition != null) str += " errorCondition=" + bean.errorCondition;
    if (bean.errorText != null) str += " errorText=" + bean.errorText;
    if (bean.errorType != null) str += " errorType=" + bean.errorType;

    str += "]";

    return str;
  }
Exemplo n.º 4
0
  /**
   * Convert an XMPPBean to an XMPPIQ to send it via the MXAProxy/MXA.
   *
   * @param bean the bean to convert
   * @param mergePayload true if the playload should be merged
   * @return the XMPPIQ
   */
  public XMPPIQ beanToIQ(XMPPBean bean, boolean mergePayload) {
    // default XMPP IQ type
    int type = XMPPIQ.TYPE_GET;

    switch (bean.getType()) {
      case XMPPBean.TYPE_GET:
        type = XMPPIQ.TYPE_GET;
        break;
      case XMPPBean.TYPE_SET:
        type = XMPPIQ.TYPE_SET;
        break;
      case XMPPBean.TYPE_RESULT:
        type = XMPPIQ.TYPE_RESULT;
        break;
      case XMPPBean.TYPE_ERROR:
        type = XMPPIQ.TYPE_ERROR;
        break;
    }

    XMPPIQ iq;

    if (mergePayload) iq = new XMPPIQ(bean.getFrom(), bean.getTo(), type, null, null, bean.toXML());
    else
      iq =
          new XMPPIQ(
              bean.getFrom(),
              bean.getTo(),
              type,
              bean.getChildElement(),
              bean.getNamespace(),
              bean.payloadToXML());

    iq.packetID = bean.getId();

    return iq;
  }
Exemplo n.º 5
0
 @Override
 public void sendXMPPBean(XMPPBean out, IXMPPCallback<? extends XMPPBean> callback) {
   _waitingCallbacks.put(out.getId(), callback);
   mMXAProxy.sendIQ(beanToIQ(out, true));
 }