public boolean restoreState(InputObjectState os) {
      InputObjectState copy = new InputObjectState(os);
      try {
        heuristic = copy.unpackInt();
      } catch (IOException e) {
      }

      return super.restoreState(os);
    }
示例#2
0
  private boolean unpackPrimitive(final Field afield, InputObjectState os) {
    try {
      // TODO arrays

      if (afield.getType().equals(Boolean.TYPE)) afield.setBoolean(_theObject, os.unpackBoolean());
      else if (afield.getType().equals(Byte.TYPE)) afield.setByte(_theObject, os.unpackByte());
      else if (afield.getType().equals(Short.TYPE)) afield.setShort(_theObject, os.unpackShort());
      else if (afield.getType().equals(Integer.TYPE)) afield.setInt(_theObject, os.unpackInt());
      else if (afield.getType().equals(Long.TYPE)) afield.setLong(_theObject, os.unpackLong());
      else if (afield.getType().equals(Float.TYPE)) afield.setFloat(_theObject, os.unpackFloat());
      else if (afield.getType().equals(Double.TYPE))
        afield.setDouble(_theObject, os.unpackDouble());
      else if (afield.getType().equals(Character.TYPE)) afield.setChar(_theObject, os.unpackChar());
      else return false;
    } catch (final IOException ex) {
      ex.printStackTrace();

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

      return false;
    }

    return true;
  }
示例#3
0
  protected static OSRecordHolder readObjectStoreRecord(String type) {
    try {
      RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
      InputObjectState states = new InputObjectState();

      if (recoveryStore.allObjUids(type, states) && states.notempty()) {

        Uid uid = UidHelper.unpackFrom(states);

        if (uid.notEquals(Uid.nullUid())) {
          InputObjectState ios = recoveryStore.read_committed(uid, type);

          return new OSRecordHolder(uid, type, ios);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return null;
  }
示例#4
0
  private static void clearObjectStore(String type) {
    try {
      RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
      InputObjectState states = new InputObjectState();

      if (recoveryStore.allObjUids(type, states) && states.notempty()) {
        boolean finished = false;

        do {
          Uid uid = UidHelper.unpackFrom(states);

          if (uid.notEquals(Uid.nullUid())) {
            recoveryStore.remove_committed(uid, type);
          } else {
            finished = true;
          }
        } while (!finished);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
示例#5
0
  private boolean unpackPrimitiveArray(final Field afield, InputObjectState os) {
    boolean success = true;

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

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

        for (int i = 0; (i < size) && success; i++) objs[i] = os.unpackInt();
      } else if (c.equals(boolean[].class)) {
        final boolean[] objs = (boolean[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) objs[i] = os.unpackBoolean();
      } else if (c.equals(byte[].class)) {
        final byte[] objs = (byte[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) objs[i] = os.unpackByte();
      } else if (c.equals(short[].class)) {
        final short[] objs = (short[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) objs[i] = os.unpackShort();
      } else if (c.equals(long[].class)) {
        final long[] objs = (long[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) objs[i] = os.unpackLong();
      } else if (c.equals(float[].class)) {
        final float[] objs = (float[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) objs[i] = os.unpackFloat();
      } else if (c.equals(double[].class)) {
        final double[] objs = (double[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) objs[i] = os.unpackDouble();
      } else if (c.equals(char[].class)) {
        final char[] objs = (char[]) afield.get(_theObject);

        for (int i = 0; (i < size) && success; i++) objs[i] = os.unpackChar();
      } else success = false;
    } catch (final Throwable ex) {
      ex.printStackTrace();

      success = false;
    }

    return success;
  }
示例#6
0
  public boolean restore_state(InputObjectState objectState, int objectType) {
    super.restore_state(objectState, objectType);
    try {
      for (int x = 0; x < _width; x++) {
        for (int y = 0; y < _height; y++) {
          _values[x][y] = objectState.unpackInt();
        }
      }

      return true;
    } catch (Exception exception) {
      System.err.println("AITMatrixImpl01.restore_state: " + exception);
      return false;
    }
  }
示例#7
0
  private boolean unpackTransactionalInstance(final Field afield, InputObjectState os) {
    try {
      boolean ptr = os.unpackBoolean();

      if (!ptr) afield.set(_theObject, null);
      else {
        Uid u = UidHelper.unpackFrom(os);

        afield.set(_theObject, _container.getHandle(u));
      }
    } catch (final Exception ex) {
      ex.printStackTrace();

      return false;
    }

    return true;
  }
示例#8
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;
  }
示例#9
0
  private final ArrayList<InputObjectState> scanLog(final Uid logName, final String typeName)
      throws ObjectStoreException {
    /*
     * Make sure no new entries can be created while we scan.
     */

    synchronized (_lock) {
      try {
        String fname = genPathName(logName, typeName, StateStatus.OS_COMMITTED);
        File fd = openAndLock(fname, FileLock.F_WRLCK, true);
        RandomAccessFile iFile = new RandomAccessFile(fd, FILE_MODE);
        // iFile.getChannel().lock();

        try {
          /*
           * Create a list of ObjectState entries.
           */

          ArrayList<InputObjectState> objectStates = new ArrayList<InputObjectState>();

          iFile.seek(0); // make sure we're at the start

          while (iFile.getFilePointer() < iFile.length()) {
            byte[] buff = new byte[_redzone.length];

            iFile.read(buff);

            if (!redzoneProtected(buff)) {
              // end

              break;

              /*
               * TODO add an end-of-log entry and check for that. Currently just assume
               * that no RZ means end, rather than corruption.
               */
            } else {
              int uidSize = iFile.readInt();
              byte[] uidString = new byte[uidSize];

              iFile.read(uidString);

              Uid txId = new Uid(new String(uidString));
              int imageSize = iFile.readInt();
              byte[] imageState = new byte[imageSize];

              iFile.read(imageState);

              try {
                InputObjectState state = new InputObjectState(txId, "", imageState);

                objectStates.add(state);
              } catch (final Exception ex) {
                ex.printStackTrace();

                throw new ObjectStoreException(ex.toString(), ex);
              }
            }
          }

          unlockAndClose(fd, iFile);
          iFile = null;

          /*
           * At this stage we now have a list of ObjectState entries.
           * Now we need to go through and prune the list. This is
           * complicated by the fact that there can be 1.. entries for
           * a specific transaction since we continually update the
           * log as we drive recovery. If an entry hasn't been deleted
           * then we will keep the latest one we find.
           */

          /*
           * First search for those entries that have been deleted.
           */

          ArrayList<InputObjectState> deletedLogs = new ArrayList<InputObjectState>();

          for (int i = 0; i < objectStates.size(); i++) {
            InputObjectState curr = objectStates.get(i);

            try {
              if (Arrays.equals(curr.unpackBytes(), _removedState)) {
                deletedLogs.add(curr);
              } else curr.reread(); // don't forget to reset the read pointer!
            } catch (final Exception ex) {
              // if not a delete record then the first entry won't
              // be an the defined byte array.
              curr.reread(); // don't forget to reset the read pointer!
            }
          }

          if (deletedLogs.size() > 0) {
            /*
             * make sure we remove them from the first list to save time.
             */

            objectStates.removeAll(deletedLogs);

            deleteEntries(objectStates, deletedLogs);

            /*
             * At this stage we should only have entries that refer
             * to in-flight transactions. Go through the list and
             * remove N-1 references for each transaction id.
             */

            pruneEntries(objectStates);

            /*
             * Now return the list of committed entries.
             */

            return objectStates;
          } else return objectStates;
        } finally {
          if (iFile != null) unlockAndClose(fd, iFile);
        }
      } catch (final ObjectStoreException ex) {
        ex.printStackTrace();

        throw ex;
      } catch (final Exception ex) {
        ex.printStackTrace();

        throw new ObjectStoreException(ex.toString(), ex);
      }
    }
  }
示例#10
0
  /**
   * This is a recovery-only method and should not be called during normal execution. As such we
   * need to load in all of the logs we can find that aren't already loaded (or activated).
   */
  public boolean allObjUids(String tName, InputObjectState state, int match)
      throws ObjectStoreException {
    /*
     * match will always be OS_COMMITTED since that's all we ever write for
     * the logs.
     */

    // in case of asynchronous removals trigger the purger now.

    _purger.trigger();

    /*
     * Get a list of logs. Load them in to memory if we aren't already
     * working on them/it. But we can prune the entry once we're
     * finished or the memory footprint will grow. We should do this
     * for all frozen entries eventually too.
     */

    InputObjectState logs = new InputObjectState();
    OutputObjectState objUids = new OutputObjectState();

    /*
     * We never call this method except during recovery. As such we shouldn't
     * need to worry about optimizations such as checking whether or not the
     * log is in current working memory.
     */

    if (!super.allObjUids(tName, logs, match)) return false;
    else {
      /*
       * Now we have all of the log names let's attach to each one
       * and locate the committed instances (not deleted.)
       */

      Uid logName = new Uid(Uid.nullUid());

      try {
        do {
          logName = UidHelper.unpackFrom(logs);

          if (logName.notEquals(Uid.nullUid())) {
            /*
             * Could check to see if log is in current working memory.
             */

            /*
             * TODO
             *
             * First purge the log if we can, but we need to know that
             * we're not playing with an instance that is being manipulated
             * from another VM instance.
             */

            ArrayList<InputObjectState> txs = scanLog(logName, tName);

            if (txs.size() > 0) {
              for (int i = 0; i < txs.size(); i++) {
                UidHelper.packInto(txs.get(i).stateUid(), objUids);
              }
            }
          }
        } while (logName.notEquals(Uid.nullUid()));

        // remember null terminator

        UidHelper.packInto(Uid.nullUid(), objUids);

        state.setBuffer(objUids.buffer());
      } catch (final IOException 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);
 }
示例#12
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;
  }
示例#13
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;
  }