1 24 25 package org.objectweb.dream.channel; 26 27 import java.io.IOException ; 28 29 import org.objectweb.dream.AbstractComponent; 30 import org.objectweb.dream.message.ExtensibleMessage; 31 import org.objectweb.dream.message.Message; 32 import org.objectweb.dream.message.manager.MessageManager; 33 import org.objectweb.fractal.api.NoSuchInterfaceException; 34 import org.objectweb.fractal.api.control.IllegalBindingException; 35 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 36 37 41 public class SocketManagerIPChunkBasedImpl extends AbstractComponent 42 implements 43 SocketManager, 44 SocketManagerIPChunkBasedAttributeController 45 { 46 47 51 protected boolean deleteChunk = true; 52 protected String destinationChunkName; 53 54 58 protected MessageManager messageManagerItf; 59 protected IPSocketManager delegateSocketManagerItf; 60 61 65 68 public SocketState getSocket(Message message) throws IOException , 69 InterruptedException 70 { 71 IPChannelDestinationChunk chunk = (IPChannelDestinationChunk) message 72 .getChunk(destinationChunkName); 73 if (chunk == null) 74 { 75 throw new IOException ("Unable to find \"" + destinationChunkName 76 + "\" chunk in message"); 77 } 78 SocketState socketState = delegateSocketManagerItf.getSocket(chunk 79 .getChannelDestinationAddr(), chunk.getChannelDestinationPort()); 80 if (deleteChunk && (message instanceof ExtensibleMessage)) 81 { 82 ((ExtensibleMessage) message).removeChunk(destinationChunkName); 83 messageManagerItf.deleteChunk(chunk); 84 } 85 return socketState; 86 } 87 88 91 public void releaseSocket(SocketState socketState, boolean error) 92 { 93 delegateSocketManagerItf.releaseSocket(socketState, error); 94 } 95 96 100 103 public boolean getDeleteChunk() 104 { 105 return deleteChunk; 106 } 107 108 111 public void setDeleteChunk(boolean deleteChunk) 112 { 113 this.deleteChunk = deleteChunk; 114 } 115 116 119 public String getDestinationChunkName() 120 { 121 return destinationChunkName; 122 } 123 124 127 public void setDestinationChunkName(String destinationChunkName) 128 { 129 this.destinationChunkName = destinationChunkName; 130 } 131 132 136 139 public String [] listFc() 140 { 141 return new String []{MessageManager.ITF_NAME, IPSocketManager.ITF_NAME}; 142 } 143 144 148 public synchronized void bindFc(String clientItfName, Object serverItf) 149 throws NoSuchInterfaceException, IllegalBindingException, 150 IllegalLifeCycleException 151 { 152 super.bindFc(clientItfName, serverItf); 153 if (clientItfName.equals(MessageManager.ITF_NAME)) 154 { 155 messageManagerItf = (MessageManager) serverItf; 156 } 157 else if (clientItfName.equals(IPSocketManager.ITF_NAME)) 158 { 159 delegateSocketManagerItf = (IPSocketManager) serverItf; 160 } 161 } 162 } | Popular Tags |