1 package org.sapia.ubik.rmi.server.transport.udp; 2 3 import org.sapia.ubik.net.udp.ObjectStreamFactory; 4 import org.sapia.ubik.net.udp.UDPConnection; 5 import org.sapia.ubik.net.udp.UDPServerAddress; 6 import org.sapia.ubik.rmi.server.VmId; 7 import org.sapia.ubik.rmi.server.transport.MarshalOutputStream; 8 import org.sapia.ubik.rmi.server.transport.RmiConnection; 9 10 import java.io.ByteArrayOutputStream ; 11 import java.io.IOException ; 12 import java.io.ObjectOutputStream ; 13 import java.io.OutputStream ; 14 15 import java.net.DatagramPacket ; 16 import java.net.DatagramSocket ; 17 18 import java.rmi.RemoteException ; 19 20 21 25 public class UdpRmiConnection extends UDPConnection implements RmiConnection { 26 private ObjectStreamFactory _fac = new UdpObjectStreamFactory(); 27 28 34 public UdpRmiConnection(UDPServerAddress addr, int bufsz, int timeout) { 35 super(addr, bufsz, timeout); 36 } 37 38 45 public UdpRmiConnection(DatagramSocket localServer, DatagramPacket pack, 46 int bufsz, int timeout) { 47 super(localServer, pack, bufsz, timeout); 48 } 49 50 53 public void send(Object o, VmId associated, String transportType) 54 throws IOException , RemoteException { 55 ByteArrayOutputStream bos = new ByteArrayOutputStream (_bufsz); 56 MarshalOutputStream ous = (MarshalOutputStream) _fac.toOutput(bos); 57 ous.setUp(associated, transportType); 58 ous.writeObject(o); 59 ous.flush(); 60 ous.close(); 61 super.send(bos.toByteArray()); 62 } 63 64 67 protected ObjectStreamFactory getFactory() { 68 return _fac; 69 } 70 71 74 public static final class UdpObjectStreamFactory 75 implements ObjectStreamFactory { 76 79 public ObjectOutputStream toOutput(OutputStream os) 80 throws IOException { 81 return new MarshalOutputStream(os); 82 } 83 } 84 } 85 | Popular Tags |