Author: gaohoward
Date: 2010-10-14 23:55:57 -0400 (Thu, 14 Oct 2010)
New Revision: 9789
Added:
branches/hornetq-416/src/main/org/hornetq/core/protocol/core/impl/wireformat/SessionAddMetaDataMessage.java
Modified:
branches/hornetq-416/src/main/org/hornetq/api/core/client/ClientSession.java
branches/hornetq-416/src/main/org/hornetq/core/client/impl/ClientSessionImpl.java
branches/hornetq-416/src/main/org/hornetq/core/client/impl/DelegatingSession.java
branches/hornetq-416/src/main/org/hornetq/core/protocol/core/ServerSessionPacketHandler.java
branches/hornetq-416/src/main/org/hornetq/core/protocol/core/impl/PacketDecoder.java
branches/hornetq-416/src/main/org/hornetq/core/protocol/core/impl/PacketImpl.java
branches/hornetq-416/src/main/org/hornetq/core/remoting/server/RemotingService.java
branches/hornetq-416/src/main/org/hornetq/core/remoting/server/impl/RemotingServiceImpl.java
branches/hornetq-416/src/main/org/hornetq/core/server/ServerSession.java
branches/hornetq-416/src/main/org/hornetq/core/server/impl/ServerSessionImpl.java
branches/hornetq-416/src/main/org/hornetq/jms/client/HornetQConnection.java
branches/hornetq-416/src/main/org/hornetq/jms/management/impl/JMSServerControlImpl.java
branches/hornetq-416/src/main/org/hornetq/spi/core/protocol/RemotingConnection.java
branches/hornetq-416/tests/jms-tests/src/org/hornetq/jms/tests/message/MessageHeaderTest.java
Log:
refactor setclientid
Modified: branches/hornetq-416/src/main/org/hornetq/api/core/client/ClientSession.java
===================================================================
---
branches/hornetq-416/src/main/org/hornetq/api/core/client/ClientSession.java 2010-10-15
01:18:33 UTC (rev 9788)
+++
branches/hornetq-416/src/main/org/hornetq/api/core/client/ClientSession.java 2010-10-15
03:55:57 UTC (rev 9789)
@@ -563,9 +563,8 @@
void setSendAcknowledgementHandler(SendAcknowledgementHandler handler);
/**
- * Sets ClientID of the associated JMS connection.
- * @param clientID the client ID
+ * Attach any metadata to the session.
+ * @throws HornetQException
*/
- void setClientID(String clientID);
-
+ void addMetaData(String key, String data) throws HornetQException;
}
Modified:
branches/hornetq-416/src/main/org/hornetq/core/client/impl/ClientSessionImpl.java
===================================================================
---
branches/hornetq-416/src/main/org/hornetq/core/client/impl/ClientSessionImpl.java 2010-10-15
01:18:33 UTC (rev 9788)
+++
branches/hornetq-416/src/main/org/hornetq/core/client/impl/ClientSessionImpl.java 2010-10-15
03:55:57 UTC (rev 9789)
@@ -39,13 +39,13 @@
import org.hornetq.core.protocol.core.CoreRemotingConnection;
import org.hornetq.core.protocol.core.Packet;
import org.hornetq.core.protocol.core.impl.PacketImpl;
-import org.hornetq.core.protocol.core.impl.wireformat.ConnectionSetClientIDMessage;
import org.hornetq.core.protocol.core.impl.wireformat.CreateQueueMessage;
import org.hornetq.core.protocol.core.impl.wireformat.CreateSessionMessage;
import org.hornetq.core.protocol.core.impl.wireformat.ReattachSessionMessage;
import org.hornetq.core.protocol.core.impl.wireformat.ReattachSessionResponseMessage;
import org.hornetq.core.protocol.core.impl.wireformat.RollbackMessage;
import org.hornetq.core.protocol.core.impl.wireformat.SessionAcknowledgeMessage;
+import org.hornetq.core.protocol.core.impl.wireformat.SessionAddMetaDataMessage;
import org.hornetq.core.protocol.core.impl.wireformat.SessionBindingQueryMessage;
import
org.hornetq.core.protocol.core.impl.wireformat.SessionBindingQueryResponseMessage;
import org.hornetq.core.protocol.core.impl.wireformat.SessionCloseMessage;
@@ -1812,9 +1812,8 @@
}
- public void setClientID(String clientID)
+ public void addMetaData(String key, String data) throws HornetQException
{
- ConnectionSetClientIDMessage msg = new ConnectionSetClientIDMessage(clientID);
- channel.send(msg);
+ channel.sendBlocking(new SessionAddMetaDataMessage(key, data));
}
}
Modified:
branches/hornetq-416/src/main/org/hornetq/core/client/impl/DelegatingSession.java
===================================================================
---
branches/hornetq-416/src/main/org/hornetq/core/client/impl/DelegatingSession.java 2010-10-15
01:18:33 UTC (rev 9788)
+++
branches/hornetq-416/src/main/org/hornetq/core/client/impl/DelegatingSession.java 2010-10-15
03:55:57 UTC (rev 9789)
@@ -556,8 +556,8 @@
session.setPacketSize(packetSize);
}
- public void setClientID(String clientID)
+ public void addMetaData(String key, String data) throws HornetQException
{
- session.setClientID(clientID);
+ session.addMetaData(key, data);
}
}
Modified:
branches/hornetq-416/src/main/org/hornetq/core/protocol/core/ServerSessionPacketHandler.java
===================================================================
---
branches/hornetq-416/src/main/org/hornetq/core/protocol/core/ServerSessionPacketHandler.java 2010-10-15
01:18:33 UTC (rev 9788)
+++
branches/hornetq-416/src/main/org/hornetq/core/protocol/core/ServerSessionPacketHandler.java 2010-10-15
03:55:57 UTC (rev 9789)
@@ -57,12 +57,12 @@
import org.hornetq.core.persistence.OperationContext;
import org.hornetq.core.persistence.StorageManager;
import org.hornetq.core.protocol.core.impl.PacketImpl;
-import org.hornetq.core.protocol.core.impl.wireformat.ConnectionSetClientIDMessage;
import org.hornetq.core.protocol.core.impl.wireformat.CreateQueueMessage;
import org.hornetq.core.protocol.core.impl.wireformat.HornetQExceptionMessage;
import org.hornetq.core.protocol.core.impl.wireformat.NullResponseMessage;
import org.hornetq.core.protocol.core.impl.wireformat.RollbackMessage;
import org.hornetq.core.protocol.core.impl.wireformat.SessionAcknowledgeMessage;
+import org.hornetq.core.protocol.core.impl.wireformat.SessionAddMetaDataMessage;
import org.hornetq.core.protocol.core.impl.wireformat.SessionBindingQueryMessage;
import
org.hornetq.core.protocol.core.impl.wireformat.SessionBindingQueryResponseMessage;
import org.hornetq.core.protocol.core.impl.wireformat.SessionConsumerCloseMessage;
@@ -461,10 +461,11 @@
session.requestProducerCredits(message.getAddress(),
message.getCredits());
break;
}
- case PacketImpl.CONNECTION_SET_CLIENTID:
+ case PacketImpl.SESS_ADD_METADATA:
{
- ConnectionSetClientIDMessage message =
(ConnectionSetClientIDMessage)packet;
- session.setConnectionClientID(message.getClientID());
+ SessionAddMetaDataMessage message = (SessionAddMetaDataMessage)packet;
+ session.addMetaData(message.getKey(), message.getData());
+ break;
}
}
}
Modified:
branches/hornetq-416/src/main/org/hornetq/core/protocol/core/impl/PacketDecoder.java
===================================================================
---
branches/hornetq-416/src/main/org/hornetq/core/protocol/core/impl/PacketDecoder.java 2010-10-15
01:18:33 UTC (rev 9788)
+++
branches/hornetq-416/src/main/org/hornetq/core/protocol/core/impl/PacketDecoder.java 2010-10-15
03:55:57 UTC (rev 9789)
@@ -78,12 +78,11 @@
import static org.hornetq.core.protocol.core.impl.PacketImpl.SESS_XA_SET_TIMEOUT_RESP;
import static org.hornetq.core.protocol.core.impl.PacketImpl.SESS_XA_START;
import static org.hornetq.core.protocol.core.impl.PacketImpl.SESS_XA_SUSPEND;
-import static org.hornetq.core.protocol.core.impl.PacketImpl.CONNECTION_SET_CLIENTID;
+import static org.hornetq.core.protocol.core.impl.PacketImpl.SESS_ADD_METADATA;
import org.hornetq.api.core.HornetQBuffer;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.protocol.core.Packet;
-import org.hornetq.core.protocol.core.impl.wireformat.ConnectionSetClientIDMessage;
import org.hornetq.core.protocol.core.impl.wireformat.CreateQueueMessage;
import org.hornetq.core.protocol.core.impl.wireformat.CreateReplicationSessionMessage;
import org.hornetq.core.protocol.core.impl.wireformat.CreateSessionMessage;
@@ -109,6 +108,7 @@
import org.hornetq.core.protocol.core.impl.wireformat.ReplicationResponseMessage;
import org.hornetq.core.protocol.core.impl.wireformat.RollbackMessage;
import org.hornetq.core.protocol.core.impl.wireformat.SessionAcknowledgeMessage;
+import org.hornetq.core.protocol.core.impl.wireformat.SessionAddMetaDataMessage;
import org.hornetq.core.protocol.core.impl.wireformat.SessionBindingQueryMessage;
import
org.hornetq.core.protocol.core.impl.wireformat.SessionBindingQueryResponseMessage;
import org.hornetq.core.protocol.core.impl.wireformat.SessionCloseMessage;
@@ -488,9 +488,9 @@
packet = new SessionForceConsumerDelivery();
break;
}
- case CONNECTION_SET_CLIENTID:
+ case SESS_ADD_METADATA:
{
- packet = new ConnectionSetClientIDMessage();
+ packet = new SessionAddMetaDataMessage();
break;
}
default:
Modified:
branches/hornetq-416/src/main/org/hornetq/core/protocol/core/impl/PacketImpl.java
===================================================================
---
branches/hornetq-416/src/main/org/hornetq/core/protocol/core/impl/PacketImpl.java 2010-10-15
01:18:33 UTC (rev 9788)
+++
branches/hornetq-416/src/main/org/hornetq/core/protocol/core/impl/PacketImpl.java 2010-10-15
03:55:57 UTC (rev 9789)
@@ -182,7 +182,7 @@
public static final byte REPLICATION_SYNC = 103;
- public static final byte CONNECTION_SET_CLIENTID = 104;
+ public static final byte SESS_ADD_METADATA = 104;
// Static --------------------------------------------------------
Added:
branches/hornetq-416/src/main/org/hornetq/core/protocol/core/impl/wireformat/SessionAddMetaDataMessage.java
===================================================================
---
branches/hornetq-416/src/main/org/hornetq/core/protocol/core/impl/wireformat/SessionAddMetaDataMessage.java
(rev 0)
+++
branches/hornetq-416/src/main/org/hornetq/core/protocol/core/impl/wireformat/SessionAddMetaDataMessage.java 2010-10-15
03:55:57 UTC (rev 9789)
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2010 Red Hat, Inc.
+ * Red Hat licenses this file to you under the Apache License, version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+package org.hornetq.core.protocol.core.impl.wireformat;
+
+import org.hornetq.api.core.HornetQBuffer;
+import org.hornetq.core.protocol.core.impl.PacketImpl;
+
+/**
+ * A SessionAddMetaDataMessage
+ *
+ * @author howard
+ *
+ *
+ */
+public class SessionAddMetaDataMessage extends PacketImpl
+{
+ private String key;
+ private String data;
+
+ public SessionAddMetaDataMessage()
+ {
+ super(PacketImpl.SESS_ADD_METADATA);
+ }
+
+ public SessionAddMetaDataMessage(String k, String d)
+ {
+ this();
+ key = k;
+ data = d;
+ }
+
+ @Override
+ public void encodeRest(final HornetQBuffer buffer)
+ {
+ buffer.writeString(key);
+ buffer.writeString(data);
+ }
+
+ @Override
+ public void decodeRest(final HornetQBuffer buffer)
+ {
+ key = buffer.readString();
+ data = buffer.readString();
+ }
+
+ public String getKey()
+ {
+ return key;
+ }
+
+ public String getData()
+ {
+ return data;
+ }
+
+}
Modified:
branches/hornetq-416/src/main/org/hornetq/core/remoting/server/RemotingService.java
===================================================================
---
branches/hornetq-416/src/main/org/hornetq/core/remoting/server/RemotingService.java 2010-10-15
01:18:33 UTC (rev 9788)
+++
branches/hornetq-416/src/main/org/hornetq/core/remoting/server/RemotingService.java 2010-10-15
03:55:57 UTC (rev 9789)
@@ -45,6 +45,4 @@
void freeze();
RemotingConnection getServerSideReplicatingConnection();
-
- void setConnectionClientID(Object connID, String clientID);
}
Modified:
branches/hornetq-416/src/main/org/hornetq/core/remoting/server/impl/RemotingServiceImpl.java
===================================================================
---
branches/hornetq-416/src/main/org/hornetq/core/remoting/server/impl/RemotingServiceImpl.java 2010-10-15
01:18:33 UTC (rev 9788)
+++
branches/hornetq-416/src/main/org/hornetq/core/remoting/server/impl/RemotingServiceImpl.java 2010-10-15
03:55:57 UTC (rev 9789)
@@ -571,9 +571,4 @@
}
}
- public void setConnectionClientID(Object connID, String clientID)
- {
- ConnectionEntry conn = connections.get(connID);
- conn.connection.setClientID(clientID);
- }
}
\ No newline at end of file
Modified: branches/hornetq-416/src/main/org/hornetq/core/server/ServerSession.java
===================================================================
--- branches/hornetq-416/src/main/org/hornetq/core/server/ServerSession.java 2010-10-15
01:18:33 UTC (rev 9788)
+++ branches/hornetq-416/src/main/org/hornetq/core/server/ServerSession.java 2010-10-15
03:55:57 UTC (rev 9789)
@@ -114,5 +114,7 @@
Set<ServerConsumer> getServerConsumers();
- void setConnectionClientID(String clientID);
+ void addMetaData(String key, String data);
+
+ String getMetaData(String key);
}
Modified:
branches/hornetq-416/src/main/org/hornetq/core/server/impl/ServerSessionImpl.java
===================================================================
---
branches/hornetq-416/src/main/org/hornetq/core/server/impl/ServerSessionImpl.java 2010-10-15
01:18:33 UTC (rev 9788)
+++
branches/hornetq-416/src/main/org/hornetq/core/server/impl/ServerSessionImpl.java 2010-10-15
03:55:57 UTC (rev 9789)
@@ -136,6 +136,8 @@
private volatile SimpleString defaultAddress;
private volatile int timeoutSeconds;
+
+ private Map<String, String> metaData;
// Constructors
---------------------------------------------------------------------------------
@@ -1183,9 +1185,23 @@
routingContext.clear();
}
- public void setConnectionClientID(String clientID)
+ public void addMetaData(String key, String data)
{
- this.server.getRemotingService().setConnectionClientID(this.getConnectionID(),
clientID);
+ if (metaData == null)
+ {
+ metaData = new HashMap<String, String>();
+ }
+ metaData.put(key, data);
}
+ public String getMetaData(String key)
+ {
+ String data = null;
+ if (metaData != null)
+ {
+ data = metaData.get(key);
+ }
+ return data;
+ }
+
}
Modified: branches/hornetq-416/src/main/org/hornetq/jms/client/HornetQConnection.java
===================================================================
--- branches/hornetq-416/src/main/org/hornetq/jms/client/HornetQConnection.java 2010-10-15
01:18:33 UTC (rev 9788)
+++ branches/hornetq-416/src/main/org/hornetq/jms/client/HornetQConnection.java 2010-10-15
03:55:57 UTC (rev 9789)
@@ -181,7 +181,16 @@
}
this.clientID = clientID;
- initialSession.setClientID(clientID);
+ try
+ {
+ initialSession.addMetaData("jms-client-id", clientID);
+ }
+ catch (HornetQException e)
+ {
+ JMSException ex = new JMSException("Internal erro setting metadata
jms-client-id");
+ ex.setLinkedException(e);
+ throw ex;
+ }
justCreated = false;
}
@@ -562,6 +571,9 @@
try
{
initialSession = sessionFactory.createSession(username, password, false, false,
false, false, 0);
+ //mark it is a jms initial session
+ initialSession.addMetaData("jms-initial-session", "");
+ initialSession.addMetaData("jms-username", username);
initialSession.addFailureListener(listener);
}
Modified:
branches/hornetq-416/src/main/org/hornetq/jms/management/impl/JMSServerControlImpl.java
===================================================================
---
branches/hornetq-416/src/main/org/hornetq/jms/management/impl/JMSServerControlImpl.java 2010-10-15
01:18:33 UTC (rev 9788)
+++
branches/hornetq-416/src/main/org/hornetq/jms/management/impl/JMSServerControlImpl.java 2010-10-15
03:55:57 UTC (rev 9789)
@@ -14,6 +14,7 @@
package org.hornetq.jms.management.impl;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -736,13 +737,22 @@
JSONArray array = new JSONArray();
Set<RemotingConnection> connections =
server.getHornetQServer().getRemotingService().getConnections();
+
+ Set<ServerSession> sessions = server.getHornetQServer().getSessions();
+ Map<Object, String> clientIDs = new HashMap<Object, String>();
+ for (ServerSession session : sessions)
+ {
+ if (session.getMetaData("jms-initial-session") != null) {
+ clientIDs.put(session.getConnectionID(),
session.getMetaData("jms-client-id"));
+ }
+ }
for (RemotingConnection connection : connections)
{
JSONObject obj = new JSONObject();
obj.put("connectionID", connection.getID().toString());
obj.put("clientAddress", connection.getRemoteAddress());
obj.put("creationTime", connection.getCreationTime());
- obj.put("clientID", connection.getClientID());
+ obj.put("clientID", clientIDs.get(connection.getID()));
array.put(obj);
}
return array.toString();
Modified:
branches/hornetq-416/src/main/org/hornetq/spi/core/protocol/RemotingConnection.java
===================================================================
---
branches/hornetq-416/src/main/org/hornetq/spi/core/protocol/RemotingConnection.java 2010-10-15
01:18:33 UTC (rev 9788)
+++
branches/hornetq-416/src/main/org/hornetq/spi/core/protocol/RemotingConnection.java 2010-10-15
03:55:57 UTC (rev 9789)
@@ -166,17 +166,4 @@
*/
void flush();
- /**
- * set the connections's clientID
- *
- * @param clientID the clientID
- */
- void setClientID(String clientID);
-
- /**
- * get the client id
- * @return the clientID
- */
- String getClientID();
-
}
Modified:
branches/hornetq-416/tests/jms-tests/src/org/hornetq/jms/tests/message/MessageHeaderTest.java
===================================================================
---
branches/hornetq-416/tests/jms-tests/src/org/hornetq/jms/tests/message/MessageHeaderTest.java 2010-10-15
01:18:33 UTC (rev 9788)
+++
branches/hornetq-416/tests/jms-tests/src/org/hornetq/jms/tests/message/MessageHeaderTest.java 2010-10-15
03:55:57 UTC (rev 9789)
@@ -1399,6 +1399,15 @@
// TODO Auto-generated method stub
}
+
+ /* (non-Javadoc)
+ * @see org.hornetq.api.core.client.ClientSession#addMetaData(java.lang.String,
java.lang.String)
+ */
+ public void addMetaData(String key, String data) throws HornetQException
+ {
+ // TODO Auto-generated method stub
+
+ }
}
}