1 24 25 package org.objectweb.dream.channel; 26 27 import java.net.InetAddress ; 28 import java.net.UnknownHostException ; 29 import java.util.Map ; 30 31 import org.objectweb.dream.PushException; 32 import org.objectweb.dream.PushPushDreamComponent; 33 import org.objectweb.dream.message.ChunkAlreadyExistsException; 34 import org.objectweb.dream.message.ExtensibleMessage; 35 import org.objectweb.dream.message.Message; 36 import org.objectweb.dream.message.manager.MessageManager; 37 import org.objectweb.fractal.api.NoSuchInterfaceException; 38 import org.objectweb.fractal.api.control.IllegalBindingException; 39 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 40 import org.objectweb.util.monolog.api.BasicLevel; 41 42 52 public class AddIPChannelDestinationChunkImpl extends PushPushDreamComponent 53 implements 54 AddIPChannelAttributeController 55 { 56 57 58 protected MessageManager messageManagerItf; 59 60 64 protected String chunkName = IPChannelDestinationChunk.DEFAULT_NAME; 65 66 67 protected InetAddress inetAddress; 68 69 70 protected int port; 71 72 75 public void push(Message message, Map context) throws PushException 76 { 77 IPChannelDestinationChunk chunk = (IPChannelDestinationChunk) message 78 .getChunk(chunkName); 79 if (chunk == null) 80 { 81 if (message instanceof ExtensibleMessage) 82 { 83 chunk = (IPChannelDestinationChunk) messageManagerItf 84 .createChunk(IPChannelDestinationChunk.TYPE); 85 try 86 { 87 ((ExtensibleMessage) message).addChunk(chunkName, 88 IPChannelDestinationChunk.TYPE, chunk); 89 } 90 catch (ChunkAlreadyExistsException e) 91 { 92 } 94 } 95 else 96 { 97 logger.log(BasicLevel.ERROR, "Invalid message : not extensible"); 98 throw new InternalError ("Invalid message : not extensible"); 99 } 100 } 101 chunk.setChannelDestinationAddr(inetAddress); 102 chunk.setChannelDestinationPort(port); 103 outPushItf.push(message, context); 104 } 105 106 110 113 public String getChunkName() 114 { 115 return chunkName; 116 } 117 118 121 public void setChunkName(String chunkName) 122 { 123 this.chunkName = chunkName; 124 } 125 126 129 public String getInetAddress() 130 { 131 return inetAddress.getCanonicalHostName(); 132 } 133 134 137 public void setInetAddress(String inetAddress) throws UnknownHostException 138 { 139 this.inetAddress = InetAddress.getByName(inetAddress); 140 } 141 142 145 public int getPort() 146 { 147 return port; 148 } 149 150 153 public void setPort(int port) 154 { 155 this.port = port; 156 } 157 158 162 165 public String [] listFc() 166 { 167 return new String []{OUT_PUSH_ITF_NAME, MessageManager.ITF_NAME}; 168 } 169 170 174 public synchronized void bindFc(String clientItfName, Object serverItf) 175 throws NoSuchInterfaceException, IllegalBindingException, 176 IllegalLifeCycleException 177 { 178 super.bindFc(clientItfName, serverItf); 179 if (clientItfName.equals(MessageManager.ITF_NAME)) 180 { 181 messageManagerItf = (MessageManager) serverItf; 182 } 183 } 184 185 189 192 public void startFc() throws IllegalLifeCycleException 193 { 194 super.startFc(); 195 if (inetAddress == null) 196 { 197 try 198 { 199 inetAddress = InetAddress.getLocalHost(); 200 } 201 catch (UnknownHostException e) 202 { 203 throw new IllegalLifeCycleException( 204 "Unable to get local inet address : " + e.getLocalizedMessage()); 205 } 206 } 207 } 208 } | Popular Tags |