Package freenet.client.async.PersistentJobRunner

Examples of freenet.client.async.PersistentJobRunner.CheckpointLock


            }
           
            @Override
            public boolean start(MemoryLimitedChunk chunk) {
                boolean shutdown = false;
                CheckpointLock lock = null;
                try {
                    lock = parent.jobRunner.lock();
                    innerDecode(chunk);
                } catch (IOException e) {
                    Logger.error(this, "Failed to decode "+this+" because of disk error: "+e, e);
                    parent.failOnDiskError(e);
                } catch (PersistenceDisabledException e) {
                    shutdown = true;
                } finally {
                    chunk.release();
                    try {
                        if(!shutdown) {
                            // We do want to call the callback even if we threw something, because we
                            // may be waiting to cancel. However we DON'T call it if we are shutting down.
                            synchronized(SplitFileFetcherCrossSegmentStorage.this) {
                                tryDecode = false;
                            }
                            parent.finishedEncoding(SplitFileFetcherCrossSegmentStorage.this);
                        }
                    } finally {
                        // Callback is part of the persistent job, unlock *after* calling it.
                        if(lock != null) lock.unlock(false, prio);
                    }
                }
                return true;
            }
           
View Full Code Here


          }
      }
    }

    private void migrate(ObjectContainer container) {
        CheckpointLock lock = null;
        boolean success;
        FCPPersistentRoot oldRoot;
        try {
            lock = clientLayerPersister.lock();
            oldRoot = FCPPersistentRoot.load(node.nodeDBHandle, container);
            success = migrateGlobalQueueFromOldDatabase(container, oldRoot);
            System.out.println(success ? "Successfully migrated global queue" : "Tried to migrate global queue, may have lost some requests");
        } catch (PersistenceDisabledException e) {
            Logger.error(this, "Cannot migrate as persistence disabled...");
            // Try again next time...
            return; // Don't GC persistent-temp.
        } catch (Throwable t) {
            // Paranoia. Have seen something like this... make it more obvious and make plugins still work...
            System.err.println("Unable to migrate from old database: "+t);
            t.printStackTrace();
            Logger.error(this, "Failed migrating from old database: "+t, t);
            return; // Something went seriously wrong, likely a bug. Don't delete.
        } finally {
            if(lock != null)
                lock.unlock(false, NativeThread.currentThread().getPriority());
        }
       
        // The global queue is the important bit. Write the progress so far.
        System.out.println("Writing migrated global queue");
        try {
            clientLayerPersister.waitAndCheckpoint();
        } catch (PersistenceDisabledException e1) {
            // Shutting down?
            return;
        }
       
        try {
            lock = clientLayerPersister.lock();
            success = migrateApplicationQueuesFromOldDatabase(container, oldRoot);
            if(success)
                System.out.println("Successfully loaded any old per-application queues");
            else
                System.out.println("Failed to load some per-application queues");
        } catch (PersistenceDisabledException e) {
            Logger.error(this, "Cannot migrate as persistence disabled...");
            // Try again next time...
            return; // Don't GC persistent-temp.
        } catch (Throwable t) {
            // Paranoia. Have seen something like this... make it more obvious and make plugins still work...
            System.err.println("Unable to migrate from old database: "+t);
            t.printStackTrace();
            Logger.error(this, "Failed migrating from old database: "+t, t);
            return; // Something went seriously wrong, likely a bug. Don't delete.
        } finally {
            if(lock != null)
                lock.unlock(false, NativeThread.currentThread().getPriority());
        }
       
        System.out.println("Writing migrated application queues");
        // Write now as well.
        try {
View Full Code Here

            }
           
            @Override
            public boolean start(MemoryLimitedChunk chunk) {
                boolean shutdown = false;
                CheckpointLock lock = null;
                try {
                    lock = parent.jobRunner.lock();
                    innerDecode(chunk);
                } catch (IOException e) {
                    Logger.error(this, "Failed to decode "+this+" because of disk error: "+e, e);
                    parent.failOnDiskError(e);
                } catch (PersistenceDisabledException e) {
                    // Shutting down.
                    // We don't call the callback here, so we don't care.
                    shutdown = true;
                } catch (Throwable e) {
                    Logger.error(this, "Failed to decode "+this+" because of internal error: "+e, e);
                    parent.fail(new FetchException(FetchExceptionMode.INTERNAL_ERROR, e));
                } finally {
                    chunk.release();
                    synchronized(SplitFileFetcherSegmentStorage.this) {
                        tryDecode = false;
                    }
                    try {
                        // We may not have completed, but we HAVE finished.
                        // Need to tell the parent, so it can do something about it.
                        // In particular, if we failed, we may need to complete cancellation, and we
                        // can't do that until both tryDecode=false and parent gets the callback.
                        if(!shutdown)
                            parent.finishedEncoding(SplitFileFetcherSegmentStorage.this);
                    } finally {
                        if(lock != null) lock.unlock(false, prio);
                    }
                }
                return true;
            }
           
View Full Code Here

            }
           
            @Override
            public boolean start(MemoryLimitedChunk chunk) {
                boolean shutdown = false;
                CheckpointLock lock = null;
                try {
                    lock = parent.jobRunner.lock();
                    innerEncode(chunk);
                } catch (PersistenceDisabledException e) {
                    // Will be retried on restarting.
                    shutdown = true;
                } finally {
                    chunk.release();
                    try {
                        if(!shutdown) {
                            // We do want to call the callback even if we threw something, because we
                            // may be waiting to cancel. However we DON'T call it if we are shutting down.
                            synchronized(SplitFileInserterSegmentStorage.this) {
                                encoding = false;
                            }
                            parent.onFinishedEncoding(SplitFileInserterSegmentStorage.this);
                        }
                    } finally {
                        // Callback is part of the persistent job, unlock *after* calling it.
                        if(lock != null) lock.unlock(false, prio);
                    }
                }
                return true;
            }
           
View Full Code Here

            }
           
            @Override
            public boolean start(MemoryLimitedChunk chunk) {
                boolean shutdown = false;
                CheckpointLock lock = null;
                try {
                    lock = parent.jobRunner.lock();
                    innerEncode(chunk);
                } catch (PersistenceDisabledException e) {
                    // Will be retried on restarting.
                    shutdown = true;
                } finally {
                    chunk.release();
                    try {
                        if(!shutdown) {
                            // We do want to call the callback even if we threw something, because we
                            // may be waiting to cancel. However we DON'T call it if we are shutting down.
                            synchronized(SplitFileInserterCrossSegmentStorage.this) {
                                encoding = false;
                            }
                            parent.onFinishedEncoding(SplitFileInserterCrossSegmentStorage.this);
                        }
                    } finally {
                        // Callback is part of the persistent job, unlock *after* calling it.
                        if(lock != null) lock.unlock(false, prio);
                    }
                }
                return true;
            }
           
View Full Code Here

TOP

Related Classes of freenet.client.async.PersistentJobRunner.CheckpointLock

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.