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.Push; 31 import org.objectweb.dream.PushException; 32 import org.objectweb.dream.message.Message; 33 import org.objectweb.dream.message.codec.MessageCodec; 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 43 public class GenericPushChannelInImpl extends AbstractComponent 44 implements 45 OpenedSocket 46 { 47 48 52 public static final String SEND_ACK_OPT_ITF_NAME = "send-ack-opt"; 53 54 58 protected Push outPushItf; 59 protected MessageManager messageManagerItf; 60 protected MessageCodec messageCodecItf; 61 protected SendByte sendAckOptItf; 62 63 67 70 public void openedSocket(SocketState socket) throws IOException 71 { 72 Message message = messageCodecItf.decode(socket); 73 74 logger.log(BasicLevel.DEBUG, "msg received"); 75 try 76 { 77 outPushItf.push(message, null); 78 } 79 catch (PushException e) 80 { 81 if (sendAckOptItf != null) 82 { 83 logger.log(BasicLevel.ERROR, "A push exception occurs. Send a nack", e); 84 sendAckOptItf.sendByte(socket.getOutput(), 1); 85 } 86 else 87 { 88 logger.log(BasicLevel.ERROR, "A push exception occurs", e); 89 } 90 messageManagerItf.deleteMessage(message); 91 return; 92 } 93 94 if (sendAckOptItf != null) 96 { 97 logger.log(BasicLevel.DEBUG, "send ack"); 98 sendAckOptItf.sendByte(socket.getOutput(), 0); 99 } 100 } 101 102 106 109 public String [] listFc() 110 { 111 return new String []{MessageManager.ITF_NAME, MessageCodec.ITF_NAME, 112 Push.OUT_PUSH_ITF_NAME, SEND_ACK_OPT_ITF_NAME}; 113 } 114 115 119 public void bindFc(String clientItfName, Object serverItf) 120 throws NoSuchInterfaceException, IllegalBindingException, 121 IllegalLifeCycleException 122 { 123 super.bindFc(clientItfName, serverItf); 124 if (clientItfName.equals(Push.OUT_PUSH_ITF_NAME)) 125 { 126 outPushItf = (Push) serverItf; 127 } 128 else if (clientItfName.equals(MessageManager.ITF_NAME)) 129 { 130 messageManagerItf = (MessageManager) serverItf; 131 } 132 else if (clientItfName.equals(MessageCodec.ITF_NAME)) 133 { 134 messageCodecItf = (MessageCodec) serverItf; 135 } 136 else if (clientItfName.equals(SEND_ACK_OPT_ITF_NAME)) 137 { 138 sendAckOptItf = (SendByte) serverItf; 139 } 140 } 141 142 145 public void unbindFc(String clientItfName) throws NoSuchInterfaceException, 146 IllegalBindingException, IllegalLifeCycleException 147 { 148 super.unbindFc(clientItfName); 149 if (clientItfName.equals(SEND_ACK_OPT_ITF_NAME)) 150 { 151 sendAckOptItf = null; 152 } 153 } 154 } | Popular Tags |