1 23 package org.objectweb.joram.mom.dest; 24 25 import java.util.Properties ; 26 27 import org.objectweb.joram.mom.notifications.AbstractRequest; 28 import org.objectweb.joram.mom.notifications.ClientMessages; 29 import org.objectweb.joram.mom.notifications.ExceptionReply; 30 import org.objectweb.joram.mom.notifications.Monit_FreeAccess; 31 import org.objectweb.joram.mom.notifications.Monit_GetDMQSettings; 32 import org.objectweb.joram.mom.notifications.Monit_GetReaders; 33 import org.objectweb.joram.mom.notifications.Monit_GetStat; 34 import org.objectweb.joram.mom.notifications.Monit_GetWriters; 35 import org.objectweb.joram.mom.notifications.RequestGroupNot; 36 import org.objectweb.joram.mom.notifications.SetDMQRequest; 37 import org.objectweb.joram.mom.notifications.SetRightRequest; 38 import org.objectweb.joram.mom.notifications.SpecialAdminRequest; 39 import org.objectweb.joram.shared.JoramTracing; 40 import org.objectweb.joram.shared.excepts.MomException; 41 import org.objectweb.util.monolog.api.BasicLevel; 42 import org.objectweb.util.monolog.api.Logger; 43 44 import fr.dyade.aaa.agent.Agent; 45 import fr.dyade.aaa.agent.AgentId; 46 import fr.dyade.aaa.agent.Channel; 47 import fr.dyade.aaa.agent.DeleteNot; 48 import fr.dyade.aaa.agent.Notification; 49 import fr.dyade.aaa.agent.UnknownAgent; 50 import fr.dyade.aaa.agent.UnknownNotificationException; 51 import fr.dyade.aaa.util.Debug; 52 import fr.dyade.aaa.util.management.MXWrapper; 53 54 61 public abstract class Destination extends Agent implements AdminDestinationItf { 62 63 public static Logger logger = Debug.getLogger(Destination.class.getName()); 64 65 69 protected DestinationImpl destImpl; 70 71 74 public Destination() {} 75 76 81 protected Destination(String name, boolean fixed, int stamp) { 82 super(name, fixed, stamp); 83 } 84 85 92 public final void init(AgentId adminId, Properties properties) { 93 destImpl = createsImpl(adminId, properties); 94 destImpl.setAgent(this); 95 } 96 97 103 public abstract DestinationImpl createsImpl(AgentId adminId, Properties prop); 104 105 114 protected void agentInitialize(boolean firstTime) throws Exception { 115 super.agentInitialize(firstTime); 116 try { 117 MXWrapper.registerMBean(destImpl, "Joram", getMBeanName()); 118 } catch (Exception exc) { 119 JoramTracing.dbgDestination.log(BasicLevel.ERROR, 120 this + " jmx failed", exc); 121 } 122 } 123 124 125 public void agentFinalize(boolean lastTime) { 126 try { 127 MXWrapper.unregisterMBean("Joram", getMBeanName()); 128 } catch (Exception exc) { 129 if (JoramTracing.dbgProxy.isLoggable(BasicLevel.DEBUG)) 130 JoramTracing.dbgProxy.log(BasicLevel.DEBUG, "", exc); 131 } 132 super.agentFinalize(lastTime); 133 } 134 135 private String getMBeanName() { 136 return new StringBuffer () 137 .append("type=Destination") 138 .append(",name=").append((name==nullName)?getId().toString():name) 139 .toString(); 140 } 141 142 146 public void react(AgentId from, Notification not) throws Exception { 147 if (logger.isLoggable(BasicLevel.DEBUG)) 148 logger.log(BasicLevel.DEBUG, 149 "Destination.react(" + from + ',' + not + ')'); 150 151 setNoSave(); 153 154 try { 155 if (not instanceof SetRightRequest) 156 destImpl.setRightRequest(from, (SetRightRequest) not); 157 else if (not instanceof SetDMQRequest) 158 destImpl.setDMQRequest(from, (SetDMQRequest) not); 159 else if (not instanceof Monit_GetReaders) 160 destImpl.monitGetReaders(from, (Monit_GetReaders) not); 161 else if (not instanceof Monit_GetWriters) 162 destImpl.monitGetWriters(from, (Monit_GetWriters) not); 163 else if (not instanceof Monit_FreeAccess) 164 destImpl.monitFreeAccess(from, (Monit_FreeAccess) not); 165 else if (not instanceof Monit_GetDMQSettings) 166 destImpl.monitGetDMQSettings(from, (Monit_GetDMQSettings) not); 167 else if (not instanceof Monit_GetStat) 168 destImpl.monitGetStat(from, (Monit_GetStat) not); 169 else if (not instanceof SpecialAdminRequest) 170 destImpl.specialAdminRequest(from, (SpecialAdminRequest) not); 171 else if (not instanceof ClientMessages) 172 destImpl.clientMessages(from, (ClientMessages) not); 173 else if (not instanceof UnknownAgent) 174 destImpl.unknownAgent(from, (UnknownAgent) not); 175 else if (not instanceof DeleteNot) 176 destImpl.deleteNot(from, (DeleteNot) not); 177 else if (not instanceof RequestGroupNot) 178 destImpl.requestGroupNot(from, (RequestGroupNot)not); 179 else if (not instanceof DeleteNot && destImpl.canBeDeleted()) 180 super.react(from, not); 184 else 185 throw new UnknownNotificationException(not.getClass().getName()); 186 } catch (MomException exc) { 187 if (logger.isLoggable(BasicLevel.WARN)) 189 logger.log(BasicLevel.WARN, this + ".react()", exc); 190 191 AbstractRequest req = (AbstractRequest) not; 192 Channel.sendTo(from, new ExceptionReply(req, exc)); 193 } catch (UnknownNotificationException exc) { 194 super.react(from, not); 195 } 196 } 197 198 199 protected void setNoSave() { 200 if (JoramTracing.dbgDestination.isLoggable(BasicLevel.DEBUG)) 201 JoramTracing.dbgDestination.log(BasicLevel.DEBUG, 202 this + ": setNoSave()."); 203 super.setNoSave(); 204 } 205 206 protected void setSave() { 207 if (JoramTracing.dbgDestination.isLoggable(BasicLevel.DEBUG)) 208 JoramTracing.dbgDestination.log(BasicLevel.DEBUG, 209 this + ": setSave()."); 210 super.setSave(); 211 } 212 } 213 | Popular Tags |