📄 storagecorecontroller.java
字号:
}finally{ try{ this.closeCondition.signalAll(); }catch (Throwable e) {/**/} this.storageControllerLock.unlock(); } } /** * Creates a new StorageBuffer * * @return the new StorageBuffer */ protected StorageBuffer releaseNewStorageBuffer() { if(this.isClosed.get()) throw new IllegalStateException("StorageController is already closed -- server is shutting down"); this.storageControllerLock.lock(); try{ if(this.isClosed.get()) throw new IllegalStateException("StorageController is already closed -- server is shutting down"); return this.currentBuffer; }finally{ try{ this.closeCondition.signalAll(); }catch (Throwable e) {/**/} this.storageControllerLock.unlock(); } } /** * Creates a new IndexModifier on the storage index * * @return - a new modifier * @throws IOException - * if an IO exception occurs */ protected IndexModifier createIndexModifier() throws IOException { if(this.isClosed.get()) throw new IllegalStateException("StorageController is already closed -- server is shutting down"); this.storageControllerLock.lock(); try{ if(this.isClosed.get()) throw new IllegalStateException("StorageController is already closed -- server is shutting down"); if (LOG.isInfoEnabled()) LOG.info("new IndexModifier created - release to StorageModifier"); return new IndexModifier(this.storageDir, new StandardAnalyzer(), false); }finally{ try{ this.closeCondition.signalAll(); }catch (Throwable e) {/**/} this.storageControllerLock.unlock(); } } private void close() throws IOException { if(this.isClosed.get()) throw new IllegalStateException("StorageController is already closed -- server is shutting down"); this.storageControllerLock.lock(); try{ if(this.isClosed.get()) throw new IllegalStateException("StorageController is already closed -- server is shutting down"); this.isClosed.set(true); while(this.storageControllerLock.getQueueLength()>0) try{ this.closeCondition.await(); }catch (Exception e) { // } if (LOG.isInfoEnabled()) LOG.info("StorageController has been closed -- server is shutting down -- release all resources"); if (this.storageQuery != null) this.storageQuery.decrementRef(); if(this.recoverController != null) this.recoverController.destroy(); this.storageLock.close(); this.modifier.close(); this.idGenerator.stopIDGenerator(); }finally{ this.storageControllerLock.unlock(); } } /** * Forces the StorageModifier to write all buffered changes. * * @throws IOException - * if an IO exception occurs * */ public void forceWrite() throws IOException { if(this.isClosed.get()) throw new IllegalStateException("StorageController is already closed -- server is shutting down"); this.modifier.forceWrite(); } private boolean createLuceneStorageLog(File directory) throws IOException { if (directory.isDirectory() && !directory.exists()) { if(!directory.createNewFile()) throw new StorageException("Can not create directory -- "+directory); } File file = new File(directory.getAbsolutePath() + System.getProperty("file.separator") + STORAGELOG); return file.createNewFile(); } /** * Creates a unique ID to store as an id for * {@link org.apache.lucene.gdata.data.ServerBaseEntry} instances * * @return - a unique id * @throws StorageException - * if no id can be released */ public synchronized String releaseId() { try { return this.idGenerator.getUID(); } catch (InterruptedException e) { throw new StorageException("Can't release new ID", e); } } /** * @see org.apache.lucene.gdata.storage.StorageController#destroy() */ public void destroy() { try { close(); } catch (Exception e) { LOG.error("Closing StorageCoreController failed -- " + e.getMessage(), e); } } /** * * @return - the lucene directory used as a storage */ protected Directory getDirectory() { return this.storageDir; } /** * @see org.apache.lucene.gdata.storage.StorageController#getStorage() */ public Storage getStorage() throws StorageException { try { return new StorageImplementation(); } catch (StorageException e) { StorageException ex = new StorageException( "Can't create Storage instance -- " + e.getMessage(), e); ex.setStackTrace(e.getStackTrace()); throw ex; } } private void createAdminAccount() throws StorageException{ GDataAccount adminAccount = GDataAccount.createAdminAccount(); StorageAccountWrapper wrapper = new StorageAccountWrapper(adminAccount); this.getStorageModifier().createAccount(wrapper); } protected ConcurrentStorageLock getLock(){ return this.storageLock; } /** * The size of the <tt>StorageBuffer</tt>. * * @return - storage buffer size */ public int getBufferSize() { return this.storageBufferSize; } /** * The size of the <tt>StorageBuffer</tt>. This size should be at least * as big as the persist factor to prevent the <tt>StorageBuffer</tt> from * resizing * * @param storageBufferSize */ @Requiered public void setBufferSize(int storageBufferSize) { this.storageBufferSize = storageBufferSize; } /** * An integer value after how many changes to the StorageModifier the * buffered changes will be persisted / written to the index * * @return - the persist factor */ public int getPersistFactor() { return this.storagePersistFactor; } /** * @param storagePersistFactor */ @Requiered public void setPersistFactor(int storagePersistFactor) { this.storagePersistFactor = storagePersistFactor; } /** * @return Returns the indexOptimizeInterval. */ public int getIndexOptimizeInterval() { return this.indexOptimizeInterval; } /** * @param indexOptimizeInterval The indexOptimizeInterval to set. */ @Requiered public void setOptimizeInterval(int indexOptimizeInterval) { this.indexOptimizeInterval = indexOptimizeInterval; } /** * @return Returns the keepRecoveredFiles. */ public boolean isKeepRecoveredFiles() { return this.keepRecoveredFiles; } /** * @param keepRecoveredFiles The keepRecoveredFiles to set. */ @Requiered public void setKeepRecoveredFiles(boolean keepRecoveredFiles) { this.keepRecoveredFiles = keepRecoveredFiles; } /** * @return Returns the recover. */ public boolean isRecover() { return this.recover; } /** * @param recover The recover to set. */ @Requiered public void setRecover(boolean recover) { this.recover = recover; } /** * @param storageDir The storageDir to set. */ public void setStorageDir(Directory storageDir) { this.storageDir = storageDir; } /** * @param storageDirectory The storageDirectory to set. */ @Requiered public void setDirectory(String storageDirectory) { this.storageDirectory = storageDirectory; } protected void writeRecoverEntry(StorageEntryWrapper wrapper) throws RecoverException{ if(this.recoverController!= null &&!this.recoverController.isRecovering() ) this.recoverController.storageModified(wrapper); } protected void registerNewRecoverWriter() throws IOException { if(this.recoverController == null || this.recoverController.isRecovering()) return; this.recoverController.destroy(); this.recoverController = createRecoverController(false,false); this.recoverController.initialize(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -