1 package org.mr.kernel.dmf; 2 3 import java.util.HashMap ; 4 5 import org.apache.commons.logging.Log; 6 import org.apache.commons.logging.LogFactory; 7 import org.mr.MantaAgent; 8 import org.mr.MessageManipulator; 9 import org.mr.core.protocol.MantaBusMessage; 10 import org.mr.core.protocol.MantaBusMessageConsts; 11 import org.mr.core.util.exceptions.CreationException; 12 import org.mr.core.util.patterns.flow.FlowFramework; 13 import org.mr.kernel.Plugin; 14 15 60 61 69 public class DataManipulationFramework implements MessageManipulator, Plugin{ 70 71 private final static String PLUGIN_NAME = "MANTA-DMF"; 73 74 76 public final static String MANTA_MESSAGE_INCOMING_PARAM = "incoming"; 78 79 FlowFramework m_flowFramework = null; 81 82 private Log m_log = null; 84 85 89 public MantaBusMessage manipulate(MantaBusMessage orig, HashMap params, byte direction) { 90 try { 91 92 if(orig.getMessageType() != MantaBusMessageConsts.MESSAGE_TYPE_CLIENT) 93 return orig; 94 if(m_log.isDebugEnabled()) 95 m_log.debug("Enter DMF."); 96 DMFObject dmfObject = new DMFObject(orig); 98 dmfObject.putAll(params); 99 100 dmfObject.put(MANTA_MESSAGE_INCOMING_PARAM, direction==0?"true":"false" ); 103 105 if(m_log.isDebugEnabled()) 107 m_log.debug("Start DMF flow."); 108 dmfObject = (DMFObject)m_flowFramework.execute(dmfObject); 109 110 orig = dmfObject.getMantaBusMessage(); 111 dmfObject.clear(); 112 } catch (Exception e) { 113 if(m_log.isErrorEnabled()) 114 m_log.error("Unknown error occur.",e); 115 } 116 return orig; 117 } 118 119 123 128 public String getName() { 129 return PLUGIN_NAME; 130 } 131 132 137 public float getVersion() { 138 return 0.1f; 139 } 140 141 145 public void start() { 146 try { 147 m_log=LogFactory.getLog("DMF"); 148 StartupDMF startupDMF = new StartupDMF(); 149 m_flowFramework = startupDMF.getFlowFramework(); 150 MantaAgent.getInstance().getSingletonRepository().setMessageManipulator(this); 151 } catch (CreationException e) { 152 if(m_log.isErrorEnabled()) 153 m_log.error("DMF error initiating", e); 154 } 155 } 156 157 160 public void stop() { 161 m_flowFramework = null; 162 } 163 } 164 | Popular Tags |