All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sdmlib.replication.SeppelTaskHandler Maven / Gradle / Ivy

Go to download

SDMLib is a light weight modeling library. SDMLib intentionally comes without any tool or editor.

There is a newer version: 2.3.2341
Show newest version
package org.sdmlib.replication;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import de.uniks.networkparser.list.SimpleKeyValueList;

public class SeppelTaskHandler implements PropertyChangeListener
{

   private SeppelSpace seppelSpace;

   @Override
   public void propertyChange(PropertyChangeEvent evt)
   {
      if (evt.getNewValue() != null)
      {
         BoardTask task = (BoardTask) evt.getNewValue();
         
         SeppelBoardTaskAction runnable = handlerList.get(task.getName());
         
         boolean oldApplyingChangeMsg = seppelSpace.isApplyingChangeMsg();
         try
         {
            seppelSpace.setApplyingChangeMsg(false);
            
            runnable.run(task);
         }
         catch (Exception e)
         {
            // exception during exception handling? => abort
            // else call exception handling
            if ( ! Exception.class.getName().equals(task.getName()))
            {
               BoardTask exceptionTask = new BoardTask().withName(Exception.class.getName());
               exceptionTask.withTaskObject("failedTask", task).withTaskObject(Exception.class.getName(), e);
               PropertyChangeEvent newEvt = new PropertyChangeEvent(evt.getSource(), evt.getPropertyName(), evt.getOldValue(), exceptionTask);
               this.propertyChange(newEvt);
            }   
            else
            {
               e.printStackTrace(); 
            }
         }
         finally 
         {
            seppelSpace.setApplyingChangeMsg(oldApplyingChangeMsg);
         }
         
      }
      
   }

   public SeppelTaskHandler withSeppelSpace(SeppelSpace seppelSpace)
   {
      this.seppelSpace = seppelSpace;
      
      return this;
   }

   SimpleKeyValueList handlerList = new SimpleKeyValueList();
   
   public SeppelTaskHandler with(String string, SeppelBoardTaskAction runnable)
   {
      handlerList.put(string, runnable);
      
      return this;
   }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy