1 24 25 package org.objectweb.dream.router; 26 27 import java.util.HashMap ; 28 import java.util.Map ; 29 30 import org.objectweb.dream.AbstractComponent; 31 import org.objectweb.dream.Push; 32 import org.objectweb.dream.PushException; 33 import org.objectweb.dream.message.Message; 34 import org.objectweb.dream.message.manager.MessageManager; 35 import org.objectweb.fractal.api.NoSuchInterfaceException; 36 import org.objectweb.fractal.api.control.IllegalBindingException; 37 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 38 import org.objectweb.util.monolog.api.BasicLevel; 39 40 52 public abstract class AbstractRouterImpl extends AbstractComponent 53 implements 54 Push 55 { 56 57 58 protected Map outPushMap; 59 60 61 public static final String DEFAULT_OUT_PUSH_ITF_NAME = "defaultOutPush"; 62 63 67 protected Push defaultOutPushItf = null; 68 69 70 protected MessageManager messageManagerItf; 71 72 73 protected boolean initialized; 74 75 76 public AbstractRouterImpl() 77 { 78 outPushMap = new HashMap (); 79 initialized = false; 80 } 81 82 protected abstract Push getOutput(Message message, Map context) 83 throws PushException; 84 85 96 public void push(Message message, Map context) throws PushException 97 { 98 Push outPush = getOutput(message, context); 99 if (outPush == null) 100 { 101 if (defaultOutPushItf == null) 102 { 103 logger.log(BasicLevel.ERROR, "No route for message " + message 104 + ". The message will be dropped"); 105 messageManagerItf.deleteMessage(message); 106 return; 107 } 108 defaultOutPushItf.push(message, context); 109 } 110 else 111 { 112 outPush.push(message, context); 113 } 114 } 115 116 120 123 public String [] listFc() 124 { 125 String [] tab = new String [outPushMap.size() + 1]; 126 outPushMap.keySet().toArray(tab); 127 tab[outPushMap.size()] = MessageManager.ITF_NAME; 128 return tab; 129 } 130 131 135 public synchronized void bindFc(String clientItfName, Object serverItf) 136 throws NoSuchInterfaceException, IllegalBindingException, 137 IllegalLifeCycleException 138 { 139 super.bindFc(clientItfName, serverItf); 140 if (clientItfName.startsWith(OUT_PUSH_ITF_NAME)) 141 { 142 outPushMap.put(clientItfName, serverItf); 143 initialized = false; 144 } 145 else if (clientItfName.equals(DEFAULT_OUT_PUSH_ITF_NAME)) 146 { 147 defaultOutPushItf = (Push) serverItf; 148 initialized = false; 149 } 150 else if (clientItfName.equals(MessageManager.ITF_NAME)) 151 { 152 messageManagerItf = (MessageManager) serverItf; 153 } 154 } 155 156 159 public synchronized void unbindFc(String clientItfName) 160 throws NoSuchInterfaceException, IllegalBindingException, 161 IllegalLifeCycleException 162 { 163 super.unbindFc(clientItfName); 164 if (clientItfName.startsWith(OUT_PUSH_ITF_NAME)) 165 { 166 outPushMap.remove(clientItfName); 167 initialized = false; 168 } 169 else if (clientItfName.equals(DEFAULT_OUT_PUSH_ITF_NAME)) 170 { 171 defaultOutPushItf = null; 172 initialized = false; 173 } 174 } 175 } | Popular Tags |