Changeset 7324


Ignore:
Timestamp:
Apr 6, 2017, 10:47:40 AM (6 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #2074: Support for plug-ins to save custom information in the static cache

The functionality could be implemented by subclassing the ObjectInputStream and implementing the resolveClass() method.

Location:
trunk/src/core/net/sf/basedb
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/Job.java

    r7323 r7324  
    14261426    @since 3.11
    14271427  */
    1428   Serializable loadState()
     1428  Serializable loadState(ClassLoader loader)
    14291429  {
    14301430    Serializable state = null;
     
    14331433      String key = "/job-state/" + getId();
    14341434      StaticCache cache = Application.getStaticCache();
    1435       state = (Serializable)cache.load(key, 2000);
     1435      state = (Serializable)cache.load(key, loader, 2000);
    14361436      if (state != null) cache.delete(key, 2000);
    14371437    }
  • trunk/src/core/net/sf/basedb/core/PluginRequest.java

    r7322 r7324  
    8383    this.plugin = plugin;
    8484    this.command = command;
    85     this.state = job.loadState();
     85    this.state = job.loadState(plugin.getClass().getClassLoader());
    8686    this.pluginConfiguration = pluginConfiguration;
    8787    this.pluginDefinition = pluginDefinition;
  • trunk/src/core/net/sf/basedb/util/StaticCache.java

    r7141 r7324  
    3333import java.io.ObjectInputStream;
    3434import java.io.ObjectOutputStream;
     35import java.io.ObjectStreamClass;
    3536import java.io.OutputStream;
    3637import java.io.Serializable;
     
    408409  public Object load(String key, int timeout)
    409410  {
     411    return load(key, null, timeout);
     412  }
     413 
     414  public Object load(String key, ClassLoader loader, int timeout)
     415  {
    410416    if (disabled) return null;
    411417    Serializable object = null;
     
    416422      if (in != null)
    417423      {
    418         ObjectInputStream oin = new ObjectInputStream(in);
     424        // Create stream and override resolveClass so we
     425        // can load classes from the given class loader
     426        ObjectInputStream oin = new ObjectInputStream(in)
     427        {
     428          @Override
     429          protected Class<?> resolveClass(ObjectStreamClass streamClass)
     430              throws IOException, ClassNotFoundException
     431          {
     432            Class<?> c = null;
     433            try
     434            {
     435              c = super.resolveClass(streamClass);
     436            }
     437            catch (ClassNotFoundException ex)
     438            {
     439              if (loader == null) throw ex;
     440              c = Class.forName(streamClass.getName(), false, loader);
     441            }
     442            return c;
     443          }
     444        };
    419445        try
    420446        {
     
    444470    }
    445471    return object;   
     472   
    446473  }
    447474 
Note: See TracChangeset for help on using the changeset viewer.