1 package org.jacorb.notification.impl; 2 3 23 24 import org.apache.avalon.framework.configuration.Configuration; 25 import org.jacorb.notification.AnyMessage; 26 import org.jacorb.notification.MessageFactory; 27 import org.jacorb.notification.StructuredEventMessage; 28 import org.jacorb.notification.TypedEventMessage; 29 import org.jacorb.notification.interfaces.Disposable; 30 import org.jacorb.notification.interfaces.Message; 31 import org.jacorb.notification.servant.AbstractProxyConsumerI; 32 import org.jacorb.notification.util.AbstractObjectPool; 33 import org.jacorb.notification.util.AbstractPoolablePool; 34 import org.omg.CORBA.Any ; 35 import org.omg.CORBA.Bounds ; 36 import org.omg.CORBA.NVList ; 37 import org.omg.CORBA.NamedValue ; 38 import org.omg.CosNotification.Property; 39 import org.omg.CosNotification.StructuredEvent; 40 import org.omg.CosNotification.StructuredEventHelper; 41 42 46 47 public class DefaultMessageFactory implements Disposable, MessageFactory 48 { 49 private final AbstractObjectPool typedEventMessagePool_ = new AbstractPoolablePool( 50 "TypedEventMessagePool") 51 { 52 public Object newInstance() 53 { 54 return new TypedEventMessage(); 55 } 56 }; 57 58 private final AbstractObjectPool anyMessagePool_ = new AbstractPoolablePool("AnyMessagePool") 59 { 60 public Object newInstance() 61 { 62 return new AnyMessage(); 63 } 64 }; 65 66 private final AbstractObjectPool structuredEventMessagePool_ = new AbstractPoolablePool( 67 "StructuredEventMessagePool") 68 { 69 public Object newInstance() 70 { 71 return new StructuredEventMessage(); 72 } 73 }; 74 75 public DefaultMessageFactory(Configuration conf) 76 { 77 anyMessagePool_.configure(conf); 78 79 structuredEventMessagePool_.configure(conf); 80 81 typedEventMessagePool_.configure(conf); 82 } 83 84 public void dispose() 85 { 86 structuredEventMessagePool_.dispose(); 87 88 anyMessagePool_.dispose(); 89 90 typedEventMessagePool_.dispose(); 91 } 92 93 public String getControllerName() 94 { 95 return "org.jacorb.notification.jmx.MessageFactoryControl"; 96 } 97 98 100 102 105 public Message newMessage(Any any, AbstractProxyConsumerI consumer) 106 { 107 if (StructuredEventHelper.type().equals(any.type())) 108 { 109 return newMessage(StructuredEventHelper.extract(any), consumer); 112 } 113 114 AnyMessage _mesg = newAnyMessage(any); 115 116 _mesg.setFilterStage(consumer.getFirstStage()); 117 118 return _mesg.getHandle(); 119 } 120 121 124 public Message newMessage(StructuredEvent structuredEvent, AbstractProxyConsumerI consumer) 125 { 126 final String _typeName = structuredEvent.header.fixed_header.event_type.type_name; 127 128 if (AnyMessage.TYPE_NAME.equals(_typeName)) 129 { 130 return newMessage(structuredEvent.remainder_of_body, consumer); 133 } 134 135 StructuredEventMessage _mesg = (StructuredEventMessage) structuredEventMessagePool_ 136 .lendObject(); 137 138 _mesg.setFilterStage(consumer.getFirstStage()); 139 140 _mesg.setStructuredEvent(structuredEvent, consumer.isStartTimeSupported(), consumer 141 .isTimeOutSupported()); 142 143 return _mesg.getHandle(); 144 } 145 146 149 public Message newMessage(String interfaceName, String operationName, NVList args, 150 AbstractProxyConsumerI consumer) 151 { 152 try 153 { 154 TypedEventMessage _mesg = (TypedEventMessage) typedEventMessagePool_.lendObject(); 155 156 Property[] _props = new Property[args.count()]; 157 158 for (int x = 0; x < _props.length; ++x) 159 { 160 NamedValue _nv = args.item(x); 161 162 _props[x] = new Property(_nv.name(), _nv.value()); 163 } 164 165 _mesg.setTypedEvent(interfaceName, operationName, _props); 166 167 _mesg.setFilterStage(consumer.getFirstStage()); 168 169 return _mesg.getHandle(); 170 } catch (Bounds e) 171 { 172 throw new RuntimeException (e.getMessage()); 174 } 175 } 176 177 179 181 184 public Message newMessage(Property[] props) 185 { 186 TypedEventMessage _mesg = (TypedEventMessage) typedEventMessagePool_.lendObject(); 187 188 _mesg.setTypedEvent(props); 189 190 return _mesg.getHandle(); 191 } 192 193 196 public Message newMessage(Any any) 197 { 198 if (StructuredEventHelper.type().equals(any.type())) 199 { 200 return newMessage(StructuredEventHelper.extract(any)); 201 } 202 203 AnyMessage _mesg = newAnyMessage(any); 204 205 return _mesg.getHandle(); 206 } 207 208 private AnyMessage newAnyMessage(Any any) 209 { 210 AnyMessage _mesg = (AnyMessage) anyMessagePool_.lendObject(); 211 212 _mesg.setAny(any); 213 214 return _mesg; 215 } 216 217 220 public Message newMessage(StructuredEvent structuredEvent) 221 { 222 String _typeName = structuredEvent.header.fixed_header.event_type.type_name; 223 224 if (AnyMessage.TYPE_NAME.equals(_typeName)) 225 { 226 return newMessage(structuredEvent.remainder_of_body); 227 } 228 229 StructuredEventMessage _mesg = (StructuredEventMessage) structuredEventMessagePool_ 230 .lendObject(); 231 232 _mesg.setStructuredEvent(structuredEvent, false, false); 233 234 return _mesg.getHandle(); 235 } 236 } | Popular Tags |