disabled logging by default but allow it to be specified via a URI query argument of tcp://localhost:port?logging=true

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@428225 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James Strachan 2006-08-03 04:08:06 +00:00
parent 98f3545303
commit 0462d1d3d0
1 changed files with 50 additions and 45 deletions

View File

@ -1,62 +1,67 @@
/* /*
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0 * 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 not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
using System; using System;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
using ActiveMQ.Transport; using ActiveMQ.Transport;
namespace ActiveMQ.Transport.Tcp namespace ActiveMQ.Transport.Tcp {
{ public class TcpTransportFactory : ITransportFactory {
public class TcpTransportFactory : ITransportFactory private bool useLogging = false;
{
public ITransport CreateTransport(Uri location) { public bool UseLogging {
get { return useLogging; }
// Console.WriteLine("Opening socket to: " + host + " on port: " + port); set { useLogging = value; }
Socket socket = Connect(location.Host, location.Port); }
ITransport rc = new TcpTransport(socket);
// TODO: use URI query string to enable the LoggingTransport public ITransport CreateTransport(Uri location) {
rc = new LoggingTransport(rc);
rc = new ResponseCorrelator(rc); // Console.WriteLine("Opening socket to: " + host + " on port: " + port);
rc = new MutexTransport(rc); Socket socket = Connect(location.Host, location.Port);
return rc; ITransport rc = new TcpTransport(socket);
} // TODO use URI query string to configure properties on this object
protected Socket Connect(string host, int port) // TODO - dirty hack - replace with better URI query parsing later
{ if (location.Query.IndexOf("logging=true") >= 0) {
UseLogging = true;
}
if (UseLogging) {
rc = new LoggingTransport(rc);
}
rc = new ResponseCorrelator(rc);
rc = new MutexTransport(rc);
return rc;
}
protected Socket Connect(string host, int port) {
// Looping through the AddressList allows different type of connections to be tried // Looping through the AddressList allows different type of connections to be tried
// (IPv4, IPv6 and whatever else may be available). // (IPv4, IPv6 and whatever else may be available).
IPHostEntry hostEntry = Dns.Resolve(host); IPHostEntry hostEntry = Dns.Resolve(host);
foreach (IPAddress address in hostEntry.AddressList) foreach (IPAddress address in hostEntry.AddressList) {
{ Socket socket = new Socket(address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
Socket socket = new Socket(
address.AddressFamily,
SocketType.Stream,
ProtocolType.Tcp);
socket.Connect(new IPEndPoint(address, port)); socket.Connect(new IPEndPoint(address, port));
if (socket.Connected) if (socket.Connected) {
{
return socket; return socket;
} }
} }
throw new SocketException(); throw new SocketException();
} }
}
}
} }