Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Base Plugin Class

By: selcux on Apr 16th, 2012  |  syntax: Java  |  size: 1.74 KB  |  views: 25  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public abstract class Plugin implements Runnable, IDataOperation.DataChangeListener {
  2.     protected PluginProperties properties = new PluginProperties(this);
  3.    
  4.     private boolean isRunning = false;
  5.     private long waitMillis = 0;
  6.     private Thread pluginThread = null;
  7.  
  8.     public PluginProperties getProperties() {
  9.         return properties;
  10.     }
  11.  
  12.     public boolean isRunning() {
  13.         return isRunning;
  14.     }
  15.  
  16.     public void setRunning(boolean isRunning) {
  17.         this.isRunning = isRunning;
  18.     }
  19.  
  20.     protected Plugin() {
  21.        
  22.         if (properties.getName() == null || properties.getName().isEmpty())
  23.         {
  24.             properties.setName(getClass().getName());
  25.         }
  26.        
  27.         onCreated();
  28.     }
  29.    
  30.     protected void onCreated()
  31.     {
  32.        
  33.     }
  34.  
  35.     public abstract void start();
  36.  
  37.     public abstract void end();
  38.    
  39.     public abstract void update();
  40.    
  41.  
  42.     @Override
  43.     public final void run() {
  44.         pluginThread = Thread.currentThread();
  45.             start();
  46.             while (isRunning) {
  47.                 synchronized (pluginThread)
  48.                 {
  49.                     try {
  50.                         update();
  51.                        
  52.                         pluginThread.wait(properties.getExecuteInterval().toStandardDuration().getMillis());
  53.                            
  54.                     } catch (InterruptedException ex) {
  55.                         Logger.getLogger(Plugin.class.getName()).log(Level.SEVERE, null, ex);
  56.                     }
  57.                    
  58.                 }
  59.             }
  60.             end();
  61.     }
  62.  
  63.     @Override
  64.     public void OnIntervalChange(long newIntervallMillis) {
  65.         waitMillis = newIntervallMillis;
  66.     }
  67.    
  68.    
  69. }