1 28 package org.objectweb.carol.rmi.multi; 29 30 import java.io.IOException ; 31 import java.io.ObjectInput ; 32 import java.io.ObjectOutput ; 33 34 import java.util.Collection ; 35 import java.util.Iterator ; 36 import java.util.Properties ; 37 38 import org.objectweb.carol.irmi.PRO; 39 import org.objectweb.carol.irmi.Interceptor; 40 import org.objectweb.carol.irmi.ClientInterceptor; 41 import org.objectweb.carol.irmi.Server; 42 import org.objectweb.carol.rmi.jrmp.interceptor.JClientRequestInfo; 43 import org.objectweb.carol.rmi.jrmp.interceptor.JClientRequestInterceptor; 44 import org.objectweb.carol.rmi.jrmp.interceptor.JInterceptorStore; 45 import org.objectweb.carol.rmi.jrmp.interceptor.JRMPClientRequestInfoImpl; 46 import org.objectweb.carol.rmi.jrmp.interceptor.JRMPServerRequestInfoImpl; 47 import org.objectweb.carol.rmi.jrmp.interceptor.JServerRequestInfo; 48 import org.objectweb.carol.rmi.jrmp.interceptor.JServerRequestInterceptor; 49 import org.objectweb.carol.rmi.jrmp.interceptor.JServiceContext; 50 import org.objectweb.carol.rmi.jrmp.server.JUnicastRemoteObject; 51 import org.objectweb.carol.rmi.util.PortNumber; 52 import org.objectweb.carol.util.configuration.CarolDefaultValues; 53 import org.objectweb.carol.util.configuration.ConfigurationRepository; 54 55 60 61 public class IrmiPRODelegate extends PRO { 62 63 private static class ServerInterceptorImpl implements Interceptor { 64 65 private JServerRequestInterceptor[] sis; 66 67 public ServerInterceptorImpl(JServerRequestInterceptor[] sis) { 68 this.sis = sis; 69 } 70 71 public void receive(byte code, ObjectInput in) 72 throws IOException , ClassNotFoundException { 73 JServerRequestInfo info = new JRMPServerRequestInfoImpl(); 74 int len = in.readShort(); 75 for (int i = 0; i < len; i++) { 76 info.add_reply_service_context((JServiceContext) in.readObject()); 77 } 78 for (int i = 0; i < sis.length; i++) { 79 sis[i].receive_request(info); 80 } 81 } 82 83 public void send(byte code, ObjectOutput out) throws IOException { 84 JServerRequestInfo info = new JRMPServerRequestInfoImpl(); 85 for (int i = 0; i < sis.length; i++) { 86 switch (code) { 87 case METHOD_RESULT: 88 sis[i].send_reply(info); 89 break; 90 case METHOD_ERROR: 91 case SYSTEM_ERROR: 92 sis[i].send_exception(info); 93 break; 94 } 95 } 96 Collection c = info.get_all_reply_service_context(); 97 out.writeShort(c.size()); 98 for (Iterator it = c.iterator(); it.hasNext(); ) { 99 out.writeObject(it.next()); 100 } 101 } 102 103 } 104 105 private static class ClientInterceptorImpl implements ClientInterceptor { 106 107 private JClientRequestInterceptor[] cis; 108 109 public ClientInterceptorImpl(JClientRequestInterceptor[] cis) { 110 this.cis = cis; 111 } 112 113 public void send(byte code, ObjectOutput out) throws IOException { 114 JClientRequestInfo info = new JRMPClientRequestInfoImpl(); 115 for (int i = 0; i < cis.length; i++) { 116 cis[i].send_request(info); 117 } 118 Collection c = info.get_all_request_service_context(); 119 out.writeShort(c.size()); 120 for (Iterator it = c.iterator(); it.hasNext(); ) { 121 out.writeObject(it.next()); 122 } 123 } 124 125 public void receive(byte code, ObjectInput in) 126 throws IOException , ClassNotFoundException { 127 JClientRequestInfo info = new JRMPClientRequestInfoImpl(); 128 int len = in.readShort(); 129 for (int i = 0; i < len; i++) { 130 info.add_request_service_context((JServiceContext) in.readObject()); 131 } 132 for (int i = 0; i < cis.length; i++) { 133 switch (code) { 134 case METHOD_RESULT: 135 cis[i].receive_reply(info); 136 break; 137 case METHOD_ERROR: 138 case SYSTEM_ERROR: 139 cis[i].receive_exception(info); 140 break; 141 } 142 } 143 } 144 145 } 146 147 private static Server getServer(boolean usingCmi) { 148 int port = 0; 149 Properties prop = ConfigurationRepository.getProperties(); 150 if (!usingCmi && prop != null) { 151 String propertyName = CarolDefaultValues.SERVER_JRMP_PORT; 152 port = PortNumber.strToint(prop.getProperty(propertyName, "0"), propertyName); 153 } 154 return new Server(port, new ClientInterceptorImpl(JInterceptorStore.getLocalClientInterceptors()), 155 new ServerInterceptorImpl(JInterceptorStore.getLocalServerInterceptors())); 156 } 157 158 public IrmiPRODelegate(boolean usingCmi) { 159 super(getServer(usingCmi)); 160 } 161 162 public IrmiPRODelegate() { 163 this(false); 164 } 165 166 } 167 | Popular Tags |