mirror of https://github.com/apache/activemq.git
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:
parent
98f3545303
commit
0462d1d3d0
|
@ -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 bool UseLogging {
|
||||||
|
get { return useLogging; }
|
||||||
|
set { useLogging = value; }
|
||||||
|
}
|
||||||
|
|
||||||
public ITransport CreateTransport(Uri location) {
|
public ITransport CreateTransport(Uri location) {
|
||||||
|
|
||||||
// Console.WriteLine("Opening socket to: " + host + " on port: " + port);
|
// Console.WriteLine("Opening socket to: " + host + " on port: " + port);
|
||||||
Socket socket = Connect(location.Host, location.Port);
|
Socket socket = Connect(location.Host, location.Port);
|
||||||
ITransport rc = new TcpTransport(socket);
|
ITransport rc = new TcpTransport(socket);
|
||||||
// TODO: use URI query string to enable the LoggingTransport
|
|
||||||
|
// 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 LoggingTransport(rc);
|
||||||
|
}
|
||||||
rc = new ResponseCorrelator(rc);
|
rc = new ResponseCorrelator(rc);
|
||||||
rc = new MutexTransport(rc);
|
rc = new MutexTransport(rc);
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Socket Connect(string host, int port)
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue