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
* 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.
*/
* 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 System.Net;
using System.Net.Sockets;
using ActiveMQ.Transport;
namespace ActiveMQ.Transport.Tcp
{
public class TcpTransportFactory : ITransportFactory
{
public ITransport CreateTransport(Uri location) {
// Console.WriteLine("Opening socket to: " + host + " on port: " + port);
Socket socket = Connect(location.Host, location.Port);
ITransport rc = new TcpTransport(socket);
// TODO: use URI query string to enable the LoggingTransport
rc = new LoggingTransport(rc);
rc = new ResponseCorrelator(rc);
rc = new MutexTransport(rc);
return rc;
}
protected Socket Connect(string host, int port)
{
namespace ActiveMQ.Transport.Tcp {
public class TcpTransportFactory : ITransportFactory {
private bool useLogging = false;
public bool UseLogging {
get { return useLogging; }
set { useLogging = value; }
}
public ITransport CreateTransport(Uri location) {
// Console.WriteLine("Opening socket to: " + host + " on port: " + port);
Socket socket = Connect(location.Host, location.Port);
ITransport rc = new TcpTransport(socket);
// TODO use URI query string to configure properties on this object
// 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
// (IPv4, IPv6 and whatever else may be available).
IPHostEntry hostEntry = Dns.Resolve(host);
foreach (IPAddress address in hostEntry.AddressList)
{
Socket socket = new Socket(
address.AddressFamily,
SocketType.Stream,
ProtocolType.Tcp);
foreach (IPAddress address in hostEntry.AddressList) {
Socket socket = new Socket(address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
socket.Connect(new IPEndPoint(address, port));
if (socket.Connected)
{
if (socket.Connected) {
return socket;
}
}
throw new SocketException();
}
}
}
}