1 18 package org.apache.activemq.transport.multicast; 19 20 import org.apache.activemq.command.Command; 21 import org.apache.activemq.command.Endpoint; 22 import org.apache.activemq.transport.udp.DatagramEndpoint; 23 import org.apache.activemq.transport.udp.DatagramHeaderMarshaller; 24 25 import java.net.SocketAddress ; 26 import java.nio.ByteBuffer ; 27 28 32 public class MulticastDatagramHeaderMarshaller extends DatagramHeaderMarshaller { 33 34 private final String localUri; 35 private final byte[] localUriAsBytes; 36 37 public MulticastDatagramHeaderMarshaller(String localUri) { 38 this.localUri = localUri; 39 this.localUriAsBytes = localUri.getBytes(); 40 } 41 42 public Endpoint createEndpoint(ByteBuffer readBuffer, SocketAddress address) { 43 int size = readBuffer.getInt(); 44 byte[] data = new byte[size]; 45 readBuffer.get(data); 46 return new DatagramEndpoint(new String (data), address); 47 } 48 49 public void writeHeader(Command command, ByteBuffer writeBuffer) { 50 writeBuffer.putInt(localUriAsBytes.length); 51 writeBuffer.put(localUriAsBytes); 52 super.writeHeader(command, writeBuffer); 53 } 54 55 } 56 | Popular Tags |