Skip to content
Permalink
Browse files
refactor the InactivityMonitor setting code for inactivity duration values.
  • Loading branch information
Timothy A. Bish committed Aug 8, 2012
1 parent e776329 commit e5c0d265e5c659c051f081827668c8c43809bbae
Showing 5 changed files with 35 additions and 41 deletions.
@@ -27,9 +27,6 @@ public class ConnectionInfo : BaseCommand
string password;
string userName;

long maxInactivityDuration = 30000;
long maxInactivityDurationInitialDelay = 0;

/// <summery>
/// Get the unique identifier that this object and its own
/// Marshaler share.
@@ -48,10 +45,6 @@ public override string ToString()
return GetType().Name + "[" +
"ConnectionId=" + ConnectionId + ", " +
"Host=" + Host + ", " +
"MaxInactivityDuration=" + MaxInactivityDuration + ", " +
"ReadCheckInterval=" + ReadCheckInterval + ", " +
"WriteCheckInterval=" + WriteCheckInterval + ", " +
"MaxInactivityDurationInitialDelay=" + MaxInactivityDurationInitialDelay + ", " +
"ClientId=" + ClientId + ", " +
"Password=" + Password + ", " +
"UserName=" + UserName +
@@ -88,28 +81,6 @@ 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.
/// </summery>
@@ -34,6 +34,8 @@ public class StompWireFormat : IWireFormat
private WireFormatInfo remoteWireFormatInfo;
private int connectedResponseId = -1;
private bool encodeHeaders = false;
private int maxInactivityDuration = 30000;
private int maxInactivityDurationInitialDelay = 0;

public StompWireFormat()
{
@@ -62,6 +64,28 @@ public IPrimitiveMapMarshaler MapMarshaler
set { this.mapMarshaler = value; }
}

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

public int 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; }
}

public void Marshal(Object o, BinaryWriter dataOut)
{
Tracer.Debug("StompWireFormat - Marshaling: " + o);
@@ -468,9 +492,9 @@ protected virtual void WriteConnectionInfo(ConnectionInfo command, BinaryWriter
frame.SetProperty("host", command.Host);
frame.SetProperty("accept-version", "1.0,1.1");

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

if(Tracer.IsDebugEnabled)
@@ -20,6 +20,7 @@
using Apache.NMS.Stomp.Commands;
using Apache.NMS.Stomp.Threads;
using Apache.NMS.Stomp.Util;
using Apache.NMS.Stomp.Protocol;
using Apache.NMS.Util;

namespace Apache.NMS.Stomp.Transport
@@ -76,17 +77,19 @@ public long InitialDelayTime
}

// Local and remote Wire Format Information
private ConnectionInfo localWireFormatInfo;
private StompWireFormat localWireFormatInfo;
private WireFormatInfo remoteWireFormatInfo;

/// <summary>
/// Constructor or the Inactivity Monitor
/// </summary>
/// <param name="next"></param>
public InactivityMonitor(ITransport next)
/// <param name="wireFormat"></param>
public InactivityMonitor(ITransport next, StompWireFormat wireFormat)
: base(next)
{
this.instanceId = ++id;
this.localWireFormatInfo = wireFormat;
Tracer.Debug("Creating Inactivity Monitor: " + instanceId);
}

@@ -260,7 +263,6 @@ public override void Oneway(Command command)
{
lock(monitor)
{
localWireFormatInfo = command as ConnectionInfo;
StartMonitorThreads();
}
}
@@ -313,7 +315,7 @@ private void StartMonitorThreads()
{
readCheckTime =
Math.Max(
localWireFormatInfo.ReadCheckInterval,
localWireFormatInfo.MaxInactivityDuration,
remoteWireFormatInfo.WriteCheckInterval);

this.asyncErrorTask = new AsyncSignalReadErrorkTask(this, next.RemoteAddress);
@@ -324,7 +326,7 @@ private void StartMonitorThreads()
if(remoteWireFormatInfo.Version > 1.0)
{
writeCheckTime =
Math.Max(localWireFormatInfo.WriteCheckInterval,
Math.Max(localWireFormatInfo.MaxInactivityDuration,
remoteWireFormatInfo.ReadCheckInterval);
}
else
@@ -115,7 +115,7 @@ public ITransport CompositeConnect(Uri location, SetTransport setTransport)
socket.SendTimeout = SendTimeout;
#endif

IWireFormat wireformat = new StompWireFormat();
StompWireFormat wireformat = new StompWireFormat();
// Set wireformat. properties on the wireformat owned by the tcpTransport
URISupport.SetProperties(wireformat, map, "wireFormat.");
ITransport transport = DoCreateTransport(location, socket, wireformat);
@@ -129,7 +129,7 @@ public ITransport CompositeConnect(Uri location, SetTransport setTransport)

if(UseInactivityMonitor)
{
transport = new InactivityMonitor(transport);
transport = new InactivityMonitor(transport, wireformat);
}

if(setTransport != null)
@@ -27,15 +27,12 @@ namespace Apache.NMS.Stomp.Test
public class SpecialCharactersTest : NMSTestSupport
{
private Connection connection;
private int counter;
private ISession session;

[SetUp]
public override void SetUp()
{
this.connection = (Connection) CreateConnection();

this.counter = 0;
}

[TearDown]

0 comments on commit e5c0d26

Please sign in to comment.