Package com.atomikos.persistence

Examples of com.atomikos.persistence.LogException


            }
            output_ = null;
            ooutput_ = null;
        } catch ( IOException e ) {
            errors = new Stack ();
            throw new LogException ( "Error closing previous output", errors );
        }
    }
View Full Code Here


  
    public synchronized Vector recover () throws LogException
    {
      
        if ( corrupt_ )
            throw new LogException ( "Instance might be corrupted" );

        Stack errors = new Stack ();
        Vector ret = new Vector ();
        InputStream in = null;

        try {
            FileInputStream f = file_.openLastValidVersionForReading();
     
            in = f;

            ObjectInputStream ins = new ObjectInputStream ( in );
            int count = 0;
            if ( console_ != null ) {
                console_.println ( "Starting read of logfile " + file_.getCurrentVersionFileName() );
            }
            while ( in.available () > 0 ) {
                // if crashed, then unproper closing might cause endless
                // blocking!
                // therefore, we check if avaible first.
                count++;
                Object nxt = ins.readObject ();

                ret.addElement ( nxt );
                if ( count % 10 == 0 ) {
                    if ( console_ != null )
                        console_.print ( "." );
                }

            }
            if ( console_ != null ) {
                console_.println ( "Done read of logfile" );
            }
        } catch ( java.io.EOFException unexpectedEOF ) {
            // ignore, since this happens if log was not closed properly
            // due to crash
          // merely return what was read so far...
        } catch ( StreamCorruptedException unexpectedEOF ) {
            // ignore, since this happens if log was not closed properly
            // due to crash
          // merely return what was read so far...
        } catch ( ObjectStreamException unexpectedEOF ) {
            // ignore, since this happens if log was not closed properly
            // due to crash
          // merely return what was read so far...
        } catch ( FileNotFoundException firstStart ) {
          // the file could not be opened for reading;
          // merely return the default empty vector
        } catch ( Exception e ) {
            System.err.println ( e.getMessage () );
            System.err.println ( e.getClass ().getName () );
            e.printStackTrace ();
            errors.push ( e );
            throw new LogException ( "Error in recover", errors );
        } finally {
            try {
                if ( in != null )
                    in.close ();

            } catch ( IOException io ) {
                errors.push ( io );
                throw new LogException ( "Error in recover", errors );
            }
        }

        return ret;
    }
View Full Code Here

            // Thus, we return the open stream to the client.
            // Any closing will be done later, during cleanup if necessary.

            if ( simulateCrash_ ) {
              corrupt_ = true;
              throw new LogException ( "Old file could not be deleted" );
            }
           
            try {
              file_.discardBackupVersion();
            } catch ( IOException errorOnDelete ) {
               corrupt_ = true;
                 // should restart
                 throw new LogException ( "Old file could not be deleted" );
            }
        } catch ( Exception e ) {
            errors.push ( e );
            throw new LogException ( "Error during checkpointing", errors );
        }
       
      

    }
View Full Code Here

    }

    public synchronized void flushObject ( Object o ) throws LogException
    {
        if ( ooutput_ == null )
            throw new LogException ( "Not Initialized or already closed" );
        try {
            ooutput_.writeObject ( o );
            output_.flush ();
            ooutput_.flush ();
            output_.getFD ().sync ();
        } catch ( IOException e ) {
            Stack errors = new Stack ();
            throw new LogException ( e.getMessage (), errors );
        }
    }
View Full Code Here

            throw le;
        } catch ( Exception e ) {

            // bad exit condition
            errors.push ( e );
            throw new LogException ( e.getMessage (), errors );

        }// catch

        finally {
            initialized_ = true;
View Full Code Here

    {
        Stack errors = new Stack ();
        Vector hist = new Vector ();

        if ( !initialized_ )
            throw new LogException ( "Not initialized" );
        Enumeration enumm = logTable_.elements ();

        while ( enumm.hasMoreElements () ) {
            SystemLogImage next = (SystemLogImage) enumm.nextElement ();
View Full Code Here

        if ( img == null )
            return;

        // test if last checkpoint was written ok.
        if ( panic_ )
            throw new LogException ( "StreamObjectLog: PANIC" );

        try {

            try {
                logstream_.flushObject ( img );
                writeCheckpoint ();
                // fout_.flush();
            } catch ( LogException ioerr ) {
                ioerr.printStackTrace ();
                errors.push ( ioerr );
                // System.err.println ( ioerr.getMessage() );
                // ioerr.printStackTrace();
                // make sure that logfile remains in consistent state by
                // checkpointing
                try {
                    logstream_.writeCheckpoint ( logTable_.elements () );
                } catch ( Exception e ) {
                    errors.push ( e );
                }
                throw new LogException ( ioerr.getMessage (), errors );
            }

            // replace/add local tid status in logTable_.
            // for Checkpointing!

            if ( img.isForgettable () ) {
                if ( logTable_.containsKey ( img.getId () ) ) {
                    // to avoid that logTable_ keeps growing!
                    logTable_.remove ( img.getId () );
                    size_--;
                    // System.err.println ( "Log size - 1 " );
                }

            } else {
                if ( !logTable_.containsKey ( img.getId () ) ) {
                    size_++;
                    // System.err.println ( "Log size + 1 " );
                }
                logTable_.put ( img.getId (), img );

            }

        }// try
        catch ( LogException le ) {
            System.err.println ( "Error in StreamObjectLog.flush() "
                    + le.getMessage () );
            throw le;
        } catch ( Exception e ) {

            System.err.println ( "Error in StreamObjectLog.flush() "
                    + e.getMessage () );

            errors.push ( e );
            throw new LogException ( e.getMessage (), errors );
        }// catch
    }
View Full Code Here

        } catch ( LogException le ) {
            throw le;
        } catch ( Exception e ) {
          e.printStackTrace();
            errors.push ( e );
            throw new LogException ( e.getMessage (), errors );
        }
    }
View Full Code Here

      }
      output_ = null;
      // ooutput_ = null;
    } catch (IOException e) {
 
      throw new LogException("Error closing previous output", e);
    }
  }
View Full Code Here

  }

  public synchronized Vector<Recoverable> recover() throws LogException {

    if (corrupt_)
      throw new LogException("Instance might be corrupted");

    Vector<Recoverable> ret = new Vector<Recoverable>();
    InputStream in = null;

    try {
      FileInputStream f = file_.openLastValidVersionForReading();

      in = f;

      ObjectInputStream ins = new ObjectInputStream(in);
      int count = 0;
      if (LOGGER.isInfoEnabled()) {
        LOGGER.logInfo("Starting read of logfile " + file_.getCurrentVersionFileName());
      }

      while (in.available() > 0) {
        // if crashed, then unproper closing might cause endless blocking!
        // therefore, we check if avaible first.
        count++;
        Recoverable nxt = (Recoverable) ins.readObject();

        ret.addElement(nxt);
        if (count % 10 == 0) {
          LOGGER.logInfo(".");
        }

      }
      LOGGER.logInfo("Done read of logfile");

    } catch (java.io.EOFException unexpectedEOF) {
      LOGGER.logDebug("Unexpected EOF - logfile not closed properly last time?", unexpectedEOF);
      // merely return what was read so far...
    } catch (StreamCorruptedException unexpectedEOF) {
      LOGGER.logDebug("Unexpected EOF - logfile not closed properly last time?", unexpectedEOF);
      // merely return what was read so far...
    } catch (ObjectStreamException unexpectedEOF) {
      LOGGER.logDebug("Unexpected EOF - logfile not closed properly last time?", unexpectedEOF);
      // merely return what was read so far...
    } catch (FileNotFoundException firstStart) {
      // the file could not be opened for reading;
      // merely return the default empty vector
    } catch (Exception e) {
      String msg = "Error in recover";
      LOGGER.logWarning(msg, e);
      throw new LogException(msg, e);
    } finally {
      try {
        if (in != null)
          in.close();

      } catch (IOException io) {
        throw new LogException("Error in recover", io);
      }
    }

    return ret;
  }
View Full Code Here

TOP

Related Classes of com.atomikos.persistence.LogException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.