public NikeFS2Block allocateBlock ( ) throws IOException { // synchronized (this) { // // try to allocate from already created providers first // for (NikeFS2BlockProvider provider : blockProviders) { // if (provider.numberOfFreeBlocks() > 0) { // NikeFS2Block block = provider.allocateBlock(); // if (block != null) { // return block; // } // } // } // } // // force garbage collection and try again (stale files still around?) // // Running the finalization might cause the Finalizer thread to call the allocateBlock method again, // // hence the lock on "this" should be removed before calling System.runFinalization // System.gc(); // System.runFinalization(); // Thread.yield(); synchronized ( this ) { for ( NikeFS2BlockProvider provider : blockProviders ) { if ( provider . numberOfFreeBlocks ( ) > 0 ) { NikeFS2Block block = provider . allocateBlock ( ) ; if ( block != null ) { return block ; } } } // ok, we give up: // create new swap file and provider, and allocate from there XLogging . log ( "NikeFS2: Allocating new swap file. (#" + ( blockProviders . size ( ) + 1 ) + ": " + swapFileSize + " bytes)" , Importance . DEBUG ) ; File swapFile = NikeFS2SwapFileManager . createSwapFile ( ) ; NikeFS2BlockProvider addedProvider = new NikeFS2BlockProvider ( swapFile , swapFileSize , blockSize , true ) ; blockProviders . add ( addedProvider ) ; return addedProvider . allocateBlock ( ) ; } }
Allocates a new virtual storage block from this virtual file system instance . If no currently allocated swap file can provide any more storage blocks a new swap file will be allocated .