Skip to content
Permalink
Browse files
https://issues.apache.org/activemq/browse/AMQNET-284
Initial changes for Stomp v1.1 adds the proper headers to the CONNECT frame to activate 1.1 on brokers that support it, and reads off the headers from CONNECTED when 1.1 is indicated.  Adds the Read check to the current Inactivity monitor.  Handles multiple header values by keeping only the first one read and discarding the rest.
  • Loading branch information
Timothy A. Bish committed Nov 5, 2010
1 parent c75140f commit 9f8547bf1f8c84f972bb1f4be348fbaed8a66103
Showing 10 changed files with 446 additions and 101 deletions.
@@ -209,6 +209,14 @@ public virtual bool IsKeepAliveInfo
}
}

public virtual bool IsWireFormatInfo
{
get
{
return false;
}
}

public virtual bool ResponseRequired
{
get
@@ -92,6 +92,11 @@ bool IsShutdownInfo
get;
}

bool IsWireFormatInfo
{
get;
}

Response visit(ICommandVisitor visitor);
}
}
@@ -22,31 +22,34 @@ namespace Apache.NMS.Stomp.Commands
public class ConnectionInfo : BaseCommand
{
ConnectionId connectionId;
string host;
string clientId;
string password;
string userName;

///
long maxInactivityDuration = 30000;
long maxInactivityDurationInitialDelay = 10000;

/// <summery>
/// Get the unique identifier that this object and its own
/// Marshaler share.
/// Get the unique identifier that this object and its own
/// Marshaler share.
/// </summery>
///
public override byte GetDataStructureType()
{
return DataStructureTypes.ConnectionInfoType;
}

///
/// <summery>
/// Returns a string containing the information for this DataStructure
/// such as its type and value of its elements.
/// Returns a string containing the information for this DataStructure
/// such as its type and value of its elements.
/// </summery>
///
public override string ToString()
{
return GetType().Name + "[" +
"ConnectionId=" + ConnectionId + ", " +
"Host=" + Host + ", " +
"MaxInactivityDuration=" + MaxInactivityDuration + ", " +
"MaxInactivityDurationInitialDelay=" + MaxInactivityDurationInitialDelay + ", " +
"ClientId=" + ClientId + ", " +
"Password=" + Password + ", " +
"UserName=" + UserName +
@@ -59,6 +62,12 @@ public ConnectionId ConnectionId
set { this.connectionId = value; }
}

public string Host
{
get { return host; }
set { this.host = value; }
}

public string ClientId
{
get { return clientId; }
@@ -77,11 +86,31 @@ public string UserName
set { this.userName = value; }
}

///
public long MaxInactivityDuration
{
get { return this.maxInactivityDuration; }
set { this.maxInactivityDuration = value; }
}

public long MaxInactivityDurationInitialDelay
{
get { return this.maxInactivityDurationInitialDelay; }
set { this.maxInactivityDurationInitialDelay = value; }
}

public long ReadCheckInterval
{
get { return this.MaxInactivityDuration; }
}

public long WriteCheckInterval
{
get { return maxInactivityDuration > 3 ? maxInactivityDuration / 3 : maxInactivityDuration; }
}

/// <summery>
/// Return an answer of true to the isConnectionInfo() query.
/// Return an answer of true to the isConnectionInfo() query.
/// </summery>
///
public override bool IsConnectionInfo
{
get
@@ -50,7 +50,8 @@ public class DataStructureTypes
public const byte RemoveSubscriptionInfoType = 26;
public const byte ErrorResponseType = 27;
public const byte KeepAliveInfoType = 28;

public const byte WireFormatInfoType = 29;

public const byte DestinationType = 48;
public const byte TempDestinationType = 49;
public const byte TopicType = 50;
@@ -132,6 +133,9 @@ public static String GetDataStructureTypeAsString(int type)
case KeepAliveInfoType:
packetTypeStr = "KeepAliveInfoType";
break;
case WireFormatInfoType:
packetTypeStr = "WireFormatInfoType";
break;
case DestinationType:
packetTypeStr = "DestinationType";
break;
@@ -0,0 +1,99 @@
// /*
// * Licensed to the Apache Software Foundation (ASF) under one or more
// * contributor license agreements. See the NOTICE file distributed with
// * this work for additional information regarding copyright ownership.
// * The ASF 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.
// */
//
using System;

using Apache.NMS.Stomp.State;

namespace Apache.NMS.Stomp.Commands
{
public class WireFormatInfo : BaseCommand
{
private long writeCheckInterval = 0;
private long readCheckInterval = 0;
private float version = 1.0f;
private string session;

public WireFormatInfo()
{
}

public long WriteCheckInterval
{
get { return this.writeCheckInterval; }
set { this.writeCheckInterval = value; }
}

public long ReadCheckInterval
{
get { return this.readCheckInterval; }
set { this.readCheckInterval = value; }
}

public float Version
{
get { return this.version; }
set { this.version = value; }
}

public string Session
{
get { return this.session; }
set { this.session = value; }
}

/// <summery>
/// Get the unique identifier that this object and its own
/// Marshaler share.
/// </summery>
public override byte GetDataStructureType()
{
return DataStructureTypes.TransactionInfoType;
}

/// <summery>
/// Returns a string containing the information for this DataStructure
/// such as its type and value of its elements.
/// </summery>
public override string ToString()
{
return GetType().Name + "[" +
"WriteCheckInterval=" + WriteCheckInterval + ", " +
"ReadCheckInterval=" + ReadCheckInterval + ", " +
"Session=" + Session + ", " +
"Version=" + Version +
"]";
}

/// <summery>
/// Return an answer of true to the IsWireFormatInfo() query.
/// </summery>
public override bool IsWireFormatInfo
{
get
{
return true;
}
}

public override Response visit(ICommandVisitor visitor)
{
return null;
}
}
}

@@ -563,14 +563,17 @@ protected void CheckConnected()
/// <param name="command">A Command</param>
protected void OnCommand(ITransport commandTransport, Command command)
{
if(command is MessageDispatch)
if(command.IsMessageDispatch)
{
// We wait if the Connection is still processing interruption
// code to reset the MessageConsumers.
WaitForTransportInterruptionProcessingToComplete();
DispatchMessage((MessageDispatch) command);
}
else if(command is ConnectionError)
else if(command.IsWireFormatInfo)
{
}
else if(command.IsErrorCommand)
{
if(!closing && !closed)
{
@@ -166,8 +166,14 @@ private void ReadHeaders(BinaryReader dataIn)
{
string key = line.Substring(0, idx);
string value = line.Substring(idx + 1);

this.properties[key] = value;

// Stomp v1.1+ allows multiple copies of a property, the first
// one is considered to be the newest, we could figure out how
// to store them all but for now we just throw the rest out.
if(!this.properties.Contains(value))
{
this.properties[key] = value;
}
}
else
{
@@ -31,6 +31,7 @@ public class StompWireFormat : IWireFormat
private Encoding encoder = new UTF8Encoding();
private IPrimitiveMapMarshaler mapMarshaler = new XmlPrimitiveMapMarshaler();
private ITransport transport;
private WireFormatInfo remoteWireFormatInfo;

public StompWireFormat()
{
@@ -125,7 +126,7 @@ protected virtual Object CreateCommand(StompFrame frame)
{
string command = frame.Command;

if(command == "RECEIPT" || command == "CONNECTED")
if(command == "RECEIPT")
{
string text = frame.RemoveProperty("receipt-id");
if(text != null)
@@ -141,19 +142,11 @@ protected virtual Object CreateCommand(StompFrame frame)
answer.CorrelationId = Int32.Parse(text);
return answer;
}
else if(command == "CONNECTED")
{
text = frame.RemoveProperty("response-id");

Tracer.Debug("StompWireFormat - Received CONNECTED command: ResponseId = " + text);

if(text != null)
{
Response answer = new Response();
answer.CorrelationId = Int32.Parse(text);
return answer;
}
}
}
else if(command == "CONNECTED")
{
Tracer.Debug("StompWireFormat - Received CONNECTED command");
return ReadConnected(frame);
}
else if(command == "ERROR")
{
@@ -192,6 +185,50 @@ protected virtual Object CreateCommand(StompFrame frame)
return null;
}

protected virtual Command ReadConnected(StompFrame frame)
{
string responseId = frame.RemoveProperty("response-id");

this.remoteWireFormatInfo = new WireFormatInfo();

if(frame.HasProperty("version"))
{
remoteWireFormatInfo.Version = Int32.Parse(frame.RemoveProperty("version"));

if(frame.HasProperty("session"))
{
remoteWireFormatInfo.Session = frame.RemoveProperty("session");
}

if(frame.HasProperty("heart-beat"))
{
string[] hearBeats = frame.RemoveProperty("heart-beat").Split(",".ToCharArray());
if(hearBeats.Length != 2)
{
throw new IOException("Malformed heartbeat property in Connected Frame.");
}

remoteWireFormatInfo.WriteCheckInterval = Int32.Parse(hearBeats[0].Trim());
remoteWireFormatInfo.ReadCheckInterval = Int32.Parse(hearBeats[1].Trim());
}
}
else
{
remoteWireFormatInfo.ReadCheckInterval = 0;
remoteWireFormatInfo.WriteCheckInterval = 0;
remoteWireFormatInfo.Version = 1.0f;
}

if(responseId != null)
{
Response answer = new Response();
answer.CorrelationId = Int32.Parse(responseId);
SendCommand(answer);
}

return remoteWireFormatInfo;
}

protected virtual Command ReadMessage(StompFrame frame)
{
Message message = null;
@@ -400,6 +437,13 @@ protected virtual void WriteConnectionInfo(ConnectionInfo command, BinaryWriter
frame.SetProperty("login", command.UserName);
frame.SetProperty("passcode", command.Password);
frame.SetProperty("request-id", command.CommandId);
frame.SetProperty("host", command.Host);
frame.SetProperty("accept-version", "1.0,1.1");

if(command.MaxInactivityDuration != 0)
{
frame.SetProperty("heart-beat", command.WriteCheckInterval + "," + command.ReadCheckInterval);
}

frame.ToStream(dataOut);
}

0 comments on commit 9f8547b

Please sign in to comment.