⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 persistencecacheplugin.java

📁 java开源的企业总线.xmlBlaster
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
         log.severe("could not clear persistent storage. Cause: " + ex.getMessage());      }      /*      try {         // to be notified about reconnections / disconnections         this.glob.getJdbcQueueManager(this.storageId).unregisterListener(this);      }      catch (Exception ex) {         log.error(ME, "could not unregister listener. Cause: " + ex.getMessage());      }      */      //this.numOfBytes = 0L;      //this.numOfEntries = 0L;      this.storageSizeListenerHelper.invokeStorageSizeListener();      return ret;   }   /**    * Shutdown the implementation, sync with data store    */   public void shutdown() {      if (log.isLoggable(Level.FINER)) log.finer("shutdown()");      this.isDown = true;      this.glob.unregisterMBean(this.mbeanHandle);      long numTransients = getNumOfEntries() - getNumOfPersistentEntries();      if (numTransients > 0) {         log.warning("Shutting down persistence cache which contains " + numTransients + " transient messages");      }      this.transientStore.shutdown();      if (this.persistentStore != null && this.isConnected)         this.persistentStore.shutdown();      try {//         this.glob.getJdbcQueueManager(this.storageId).unregisterListener(this);         if (this.persistentStore != null)            this.persistentStore.unRegisterStorageProblemListener(this);      }      catch (Exception ex) {         log.severe("could not unregister listener. Cause: " + ex.toString());      }      this.storageSizeListenerHelper.invokeStorageSizeListener();      removeStorageSizeListener(null);      // glob.getQueuePluginManager().cleanup(this);      if (glob instanceof ServerScope) {         ((ServerScope)glob).getStoragePluginManager().cleanup(this);      }      else         log.warning("The global is not a ServerScope: we can not clean up this entry from the storage plugin manager");         }   public boolean isShutdown() {      return this.isDown;   }   /**    * JMX help    * @return a human readable usage help string    */   public java.lang.String usage() {      return "Manipulating the storage directly will most certainly destroy your data."      +ServerScope.getJmxUsageLinkInfo(this.getClass().getName(), null);   }   /**    * @return A link for JMX usage    */   public java.lang.String getUsageUrl() {      return ServerScope.getJavadocUrl(this.getClass().getName(), null);   }      /* dummy to have a copy/paste functionality in jconsole */   public void setUsageUrl(java.lang.String url) {}   /**    * @return Internal state as an XML ASCII string    */   public final String toXml(String extraOffset) {      StringBuffer sb = new StringBuffer(1000);      if (extraOffset == null) extraOffset = "";      String offset = Constants.OFFSET + extraOffset;      sb.append(offset).append("<PersistenceCachePlugin id='").append(getStorageId().getId());      sb.append("' type='").append(getType());      sb.append("' version='").append(getVersion());      sb.append("' maxEntriesCache='").append(this.transientStore.getMaxNumOfEntries());      sb.append("' maxBytesCache='").append(this.transientStore.getMaxNumOfBytes());      sb.append("' maxEntries='").append(getMaxNumOfEntries());      sb.append("' maxBytes='").append(getMaxNumOfBytes());      sb.append("' numOfEntries='").append(getNumOfEntries());      sb.append("' numOfBytes='").append(getNumOfBytes());      sb.append("'>");      sb.append(this.transientStore.toXml(extraOffset+Constants.INDENT));      if (this.persistentStore != null)         sb.append(this.persistentStore.toXml(extraOffset+Constants.INDENT));      sb.append(offset).append("</PersistenceCachePlugin>");      return sb.toString();   }   /**    * Enforced by I_Plugin    * @see org.xmlBlaster.util.plugin.I_Plugin#init(org.xmlBlaster.util.Global, PluginInfo)    */   public void init(org.xmlBlaster.util.Global glob, PluginInfo pluginInfo) {//      this.pluginProperties = pluginInfo.getParameters();      this.glob = (org.xmlBlaster.engine.ServerScope)glob;      this.pluginInfo = pluginInfo;   }   /**    * Enforced by I_Plugin    * @return "CACHE"    */   public String getType() { return "CACHE"; }   /**    * Enforced by I_Plugin    * @return "1.0"    */   public String getVersion() { return "1.0"; }   /**    * Enforced by I_StoragePlugin    * @return the pluginInfo object.    */   public PluginInfo getInfo() { return this.pluginInfo; }      public String checkConsistency(String fixIt, String reportFileName) {      boolean fix = Boolean.valueOf(fixIt).booleanValue();      return glob.getRequestBroker().checkConsistency(this, fix, reportFileName);   }   /**    * destroys all the resources associated to this queue. Even the persistent    * data is destroyed.    */   public void destroy() throws XmlBlasterException {      XmlBlasterException e = null;      this.isDown = true;      try {//         this.glob.getJdbcQueueManager(this.storageId).unregisterListener(this);         if (this.persistentStore != null)            this.persistentStore.unRegisterStorageProblemListener(this);      }      catch (Exception ex) {         log.severe("could not unregister listener. Cause: " + ex.toString());      }      try {         if (this.persistentStore != null && this.isConnected)            this.persistentStore.destroy();      }      catch (XmlBlasterException ex) {         e = ex;      }      this.transientStore.destroy();      if (e != null) throw e;   }   /**    * @see org.xmlBlaster.util.queue.I_StorageProblemNotifier#registerStorageProblemListener(I_StorageProblemListener)    */   public boolean registerStorageProblemListener(I_StorageProblemListener listener) {      if (this.persistentStore == null) return false;      return this.persistentStore.registerStorageProblemListener(listener);   }   /**    * @see org.xmlBlaster.util.queue.I_StorageProblemNotifier#unRegisterStorageProblemListener(I_StorageProblemListener)    */   public boolean unRegisterStorageProblemListener(I_StorageProblemListener listener) {      if (this.persistentStore == null || listener == null) return false;      return this.persistentStore.unRegisterStorageProblemListener(listener);   }   /**    * @see I_Map#change(I_MapEntry, I_ChangeCallback)    */   public I_MapEntry change(I_MapEntry entry, I_ChangeCallback callback) throws XmlBlasterException {      if (entry == null) return null;      synchronized(this) { // is this the correct synchronization ??         long oldSizeInBytes = entry.getSizeInBytes(); // must be here since newEntry could reference same obj.         I_MapEntry newEntry = entry;         boolean oldIsPersistent = entry.isPersistent();         if (callback != null) newEntry = callback.changeEntry(entry);         if (newEntry == null) {            return entry;         }         if (oldSizeInBytes != newEntry.getSizeInBytes()) {            throw new XmlBlasterException(this.glob, ErrorCode.INTERNAL_UNKNOWN, ME + ".change", "the size of the entry '" + entry.getUniqueId() + "' has changed from '" + oldSizeInBytes + "' to '" + newEntry.getSizeInBytes() +"'. This is not allowed");         }          I_MapEntry retEntry = this.transientStore.change(newEntry, null);                  if (oldIsPersistent != retEntry.isPersistent()) {            throw new XmlBlasterException(glob, ErrorCode.INTERNAL_NOTIMPLEMENTED, ME, "Changing of persistence flag of '" + entry.getLogId() + "' to persistent=" + retEntry.isPersistent() + " is not implemented");            // TODO: In case we changed the entry flag from persistent to transient it should be removed from the persistence.         }                  if (newEntry.isPersistent()) {            if (this.persistentStore != null && this.isConnected) {               retEntry = this.persistentStore.change(newEntry, null);            }            else {               if (log.isLoggable(Level.FINE)) log.fine("Can't update entry '" + entry.getLogId() + "' on persistence");               //throw new XmlBlasterException(glob, ErrorCode.RESOURCE_DB_UNAVAILABLE, ME, "Can't update entry '" + entry.getLogId() + "' on persistence");            }         }         return retEntry;      }   }   /**    * @see I_Map#change(long, I_ChangeCallback)    */   public I_MapEntry change(long uniqueId, I_ChangeCallback callback) throws XmlBlasterException {      synchronized (this) {         I_MapEntry oldEntry = get(uniqueId);         return change(oldEntry, callback);      }   }   /**    * @see I_Map#embeddedObjectsToXml(OutputStream, Properties)    */   public long embeddedObjectsToXml(OutputStream out, Properties props) throws Exception {      I_Map ps = this.persistentStore;      if (ps != null) {         return ps.embeddedObjectsToXml(out, props);      }      log.warning("Sorry, dumping transient entries to '" + out + "' is not implemented");      return 0;   }      /**    * @see I_AdminMap#dumpEmbeddedObjectsToFile(String)    */   public String dumpEmbeddedObjectsToFile(String fileName) throws Exception {      if (fileName == null || fileName.equalsIgnoreCase("String")) {         fileName = this.storageId.getStrippedId() + ".xml";      }      File to_file = new File(fileName);      if (to_file.getParent() != null) {         to_file.getParentFile().mkdirs();      }      FileOutputStream out = new FileOutputStream(to_file);      out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>".getBytes());      out.write(("\n<"+this.storageId.getPrefix()+" id='"+this.storageId.getStrippedId()+"'>").getBytes());      Properties props = new Properties();      props.put(Constants.TOXML_FORCEREADABLE, ""+true);  // to be human readable (minimize base64)      props.put(Constants.TOXML_ENCLOSINGTAG, "publish"); // to look similar to XmlScript      long count = embeddedObjectsToXml(out, props);      out.write(("\n</"+this.storageId.getPrefix()+">").getBytes());      out.close();      return "Dumped " + count + " entries to '" + to_file.getAbsolutePath() + "'";   }   /**    * @see I_Queue#addStorageSizeListener(I_StorageSizeListener)    */   public void addStorageSizeListener(I_StorageSizeListener listener) {      this.storageSizeListenerHelper.addStorageSizeListener(listener);   }      /**    * @see I_Queue#removeStorageSizeListener(I_StorageSizeListener)    */   public void removeStorageSizeListener(I_StorageSizeListener listener) {      this.storageSizeListenerHelper.removeStorageSizeListener(listener);   }      /**    * @see I_Queue#hasStorageSizeListener(I_StorageSizeListener)    */   public boolean hasStorageSizeListener(I_StorageSizeListener listener) {      return this.storageSizeListenerHelper.hasStorageSizeListener(listener);   }   /**    * @see I_Storage#getStorageSizeListeners()    */   public I_StorageSizeListener[] getStorageSizeListeners() {      return storageSizeListenerHelper.getStorageSizeListeners();   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -