activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r386196 - /incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/udp/DatagramHeaderMarshaller.java
Date Wed, 15 Mar 2006 22:41:55 GMT
Author: jstrachan
Date: Wed Mar 15 14:41:53 2006
New Revision: 386196

URL: http://svn.apache.org/viewcvs?rev=386196&view=rev
Log:
cache around endpoints so that they are reused - so that networks using brokerIds & brokerInfos
can store the state on the endpoint

Modified:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/udp/DatagramHeaderMarshaller.java

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/udp/DatagramHeaderMarshaller.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/udp/DatagramHeaderMarshaller.java?rev=386196&r1=386195&r2=386196&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/udp/DatagramHeaderMarshaller.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/udp/DatagramHeaderMarshaller.java
Wed Mar 15 14:41:53 2006
@@ -25,6 +25,8 @@
 import java.net.DatagramPacket;
 import java.net.SocketAddress;
 import java.nio.ByteBuffer;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * 
@@ -32,16 +34,20 @@
  */
 public class DatagramHeaderMarshaller {
 
+    // TODO for large dynamic networks
+    // we may want to evict endpoints that disconnect
+    // from a transport - e.g. for multicast
+    private Map endpoints = new HashMap();
+    
     /**
      * Reads any header if applicable and then creates an endpoint object
      */
     public Endpoint createEndpoint(ByteBuffer readBuffer, SocketAddress address) {
-        return new DatagramEndpoint(address.toString(), address);
+        return getEndpoint(address);
     }
 
     public Endpoint createEndpoint(DatagramPacket datagram, DataInputStream dataIn) {
-        SocketAddress address = datagram.getSocketAddress();
-        return new DatagramEndpoint(address.toString(), address);
+        return getEndpoint(datagram.getSocketAddress());
     }
 
     public void writeHeader(Command command, ByteBuffer writeBuffer) {
@@ -57,4 +63,23 @@
     public void writeHeader(Command command, DataOutputStream dataOut) {
     }
 
+    /**
+     * Gets the current endpoint object for this address or creates one if not available.
+     * 
+     * Note that this method does not need to be synchronized as its only ever going to be
+     * used by the already-synchronized read() method of a CommandChannel 
+     * 
+     */
+    protected Endpoint getEndpoint(SocketAddress address) {
+        Endpoint endpoint = (Endpoint) endpoints.get(address);
+        if (endpoint == null) {
+            endpoint = createEndpoint(address);
+            endpoints.put(address, endpoint);
+        }
+        return endpoint;
+    }
+
+    protected Endpoint createEndpoint(SocketAddress address) {
+        return new DatagramEndpoint(address.toString(), address);
+    }
 }



Mime
View raw message