示例#1
0
  private boolean unpackObjectType(final Field afield, InputObjectState os) {
    try {
      // TODO arrays

      if (afield.getType().equals(Boolean.class))
        afield.set(_theObject, new Boolean(os.unpackBoolean()));
      else if (afield.getType().equals(Byte.class))
        afield.set(_theObject, new Byte(os.unpackByte()));
      else if (afield.getType().equals(Short.class))
        afield.set(_theObject, new Short(os.unpackShort()));
      else if (afield.getType().equals(Integer.class))
        afield.set(_theObject, new Integer(os.unpackInt()));
      else if (afield.getType().equals(Long.class))
        afield.set(_theObject, new Long(os.unpackLong()));
      else if (afield.getType().equals(Float.class))
        afield.set(_theObject, new Float(os.unpackFloat()));
      else if (afield.getType().equals(Double.class))
        afield.set(_theObject, new Double(os.unpackDouble()));
      else if (afield.getType().equals(Character.class))
        afield.set(_theObject, new Character(os.unpackChar()));
      else if (afield.getType().equals(String.class)) afield.set(_theObject, os.unpackString());
      else if (afield.getType().isAnnotationPresent(Transactional.class))
        return unpackTransactionalInstance(afield, os);
      else return false;
    } catch (final IOException ex) {
      ex.printStackTrace();

      return false;
    } catch (final Exception ex) {
      ex.printStackTrace();

      return false;
    }

    return true;
  }
 /** restore the endpoint reference to the coordinator for this participant */
 protected void restoreEndpointReference(InputObjectState ios) throws IOException {
   String endpointString = ios.unpackString();
   Source source = new StreamSource(new StringReader(endpointString));
   endpoint = new W3CEndpointReference(source);
 }
示例#3
0
  private boolean unpackObjectArray(final Field afield, InputObjectState os) {
    boolean success = true;

    try {
      Class<?> c = afield.getType();
      final int size = Array.getLength(afield.get(_theObject));

      if (c.equals(Integer[].class)) {
        final Integer[] objs = (Integer[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) {
          boolean ref = os.unpackBoolean();

          if (ref) objs[i] = os.unpackInt();
          else objs[i] = null;
        }
      } else if (c.equals(Boolean[].class)) {
        final Boolean[] objs = (Boolean[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) {
          boolean ref = os.unpackBoolean();

          if (ref) objs[i] = os.unpackBoolean();
          else objs[i] = null;
        }
      } else if (c.equals(Byte[].class)) {
        final Byte[] objs = (Byte[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) {
          boolean ref = os.unpackBoolean();

          if (ref) objs[i] = os.unpackByte();
          else objs[i] = null;
        }
      } else if (c.equals(Short[].class)) {
        final Short[] objs = (Short[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) {
          boolean ref = os.unpackBoolean();

          if (ref) objs[i] = os.unpackShort();
          else objs[i] = null;
        }
      } else if (c.equals(Long[].class)) {
        final Long[] objs = (Long[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) {
          boolean ref = os.unpackBoolean();

          if (ref) objs[i] = os.unpackLong();
          else objs[i] = null;
        }
      } else if (c.equals(Float[].class)) {
        final Float[] objs = (Float[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) {
          boolean ref = os.unpackBoolean();

          if (ref) objs[i] = os.unpackFloat();
          else objs[i] = null;
        }
      } else if (c.equals(Double[].class)) {
        final Double[] objs = (Double[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) {
          boolean ref = os.unpackBoolean();

          if (ref) objs[i] = os.unpackDouble();
          else objs[i] = null;
        }
      } else if (c.equals(Character[].class)) {
        final Character[] objs = (Character[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) {
          boolean ref = os.unpackBoolean();

          if (ref) objs[i] = os.unpackChar();
          else objs[i] = null;
        }
      } else if (c.equals(String[].class)) {
        final String[] objs = (String[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) {
          boolean ref = os.unpackBoolean();

          if (ref) objs[i] = os.unpackString();
          else objs[i] = null;
        }
      } else {
        System.err.println("Array type " + c + " not supported!");

        success = false;
      }
    } catch (final Throwable ex) {
      ex.printStackTrace();

      success = false;
    }

    return success;
  }
示例#4
0
  public boolean restore_state(InputObjectState os, int t) {
    boolean res = false;

    try {
      _heuristic = os.unpackInt();
      _committed = os.unpackBoolean();

      _tranID = XidImple.unpack(os);

      _theXAResource = null;
      _recoveryObject = null;

      if (os.unpackInt() == RecoverableXAConnection.OBJECT_RECOVERY) {
        _productName = os.unpackString();
        _productVersion = os.unpackString();
        _jndiName = os.unpackString();

        boolean haveXAResource = os.unpackBoolean();

        if (haveXAResource) {
          try {
            // Read the classname of the serialized XAResource
            String className = os.unpackString();

            byte[] b = os.unpackBytes();

            ByteArrayInputStream s = new ByteArrayInputStream(b);
            ObjectInputStream o = new ObjectInputStream(s);

            // Give the list of deserializers a chance to deserialize the record
            boolean deserialized = false;
            Iterator<SerializableXAResourceDeserializer> iterator =
                getXAResourceDeserializers().iterator();
            while (iterator.hasNext()) {
              SerializableXAResourceDeserializer proxyXAResourceDeserializer = iterator.next();
              if (proxyXAResourceDeserializer.canDeserialze(className)) {
                _theXAResource = proxyXAResourceDeserializer.deserialze(o);
                deserialized = true;
                break;
              }
            }

            // Give it a go ourselves
            if (!deserialized) {
              _theXAResource = (XAResource) o.readObject();
            }
            o.close();

            if (jtaLogger.logger.isTraceEnabled()) {
              jtaLogger.logger.trace("XAResourceRecord.restore_state - XAResource de-serialized");
            }
          } catch (Exception ex) {
            // not serializable in the first place!

            jtaLogger.i18NLogger.warn_resources_arjunacore_restorestate(ex);

            return false;
          }
        } else {
          /*
           * Lookup new XAResource via XARecoveryModule if possible.
           */

          _theXAResource = getNewXAResource();

          if (_theXAResource == null) {
            jtaLogger.i18NLogger.warn_resources_arjunacore_norecoveryxa(toString());

            /*
             * Don't prevent tx from activating because there may be
             * other participants that can still recover. Plus, we will
             * try to get a new XAResource later for this instance.
             */

            res = true;
          }
        }
      } else {
        String creatorName = os.unpackString();

        _recoveryObject =
            ClassloadingUtility.loadAndInstantiateClass(
                RecoverableXAConnection.class, creatorName, null);
        if (_recoveryObject == null) {
          throw new ClassNotFoundException();
        }

        _recoveryObject.unpackFrom(os);
        _theXAResource = _recoveryObject.getResource();

        if (jtaLogger.logger.isTraceEnabled()) {
          jtaLogger.logger.trace(
              "XAResourceRecord.restore_state - XAResource got from " + creatorName);
        }
      }

      res = true;
    } catch (Exception e) {
      jtaLogger.i18NLogger.warn_resources_arjunacore_restorestateerror(
          _theXAResource.toString(), XAHelper.xidToString(_tranID), e);

      res = false;
    }

    if (res) res = super.restore_state(os, t);

    return res;
  }