/*
* 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.ServiceModel;
using System.ServiceModel.Channels;
namespace Apache.NMS.WCF
{
///
/// Base class for NMS output channels.
///
public abstract class NmsOutputChannelBase : ChannelBase
{
#region Constructors
///
/// Initializes a new instance of the class.
///
/// The factory that created the channel.
/// The remote address for the channel.
/// The URI that contains the transport address to which messages are sent on the output channel.
/// The buffer manager.
/// The encoder factory.
/// The name of the ActiveMQ destination.
/// The type of the ActiveMQ destination (either a queue or a topic, permanent or temporary).
internal NmsOutputChannelBase(ChannelManagerBase factory, EndpointAddress remoteAddress, Uri via, BufferManager bufferManager, MessageEncoderFactory encoderFactory, string destination, DestinationType destinationType)
: base(factory)
{
_remoteAddress = remoteAddress;
_via = via;
_bufferManager = bufferManager;
_encoder = encoderFactory;
_destination = destination;
_destinationType = destinationType;
}
#endregion
#region NullRequestContextCollection
//public NmsAsyncRequestContextCollection PendingRequests
//{
// get { return _pendingRequests; }
//}
#endregion
#region Public properties
///
/// Gets the remote address.
///
/// The remote address.
public EndpointAddress RemoteAddress
{
get { return _remoteAddress; }
}
///
/// Gets the routing address.
///
/// The routing address.
public Uri Via
{
get { return _via; }
}
///
/// Gets the buffer manager.
///
/// The buffer manager.
public BufferManager BufferManager
{
get { return _bufferManager; }
}
///
/// Gets the encoder.
///
/// The encoder.
public MessageEncoder Encoder
{
get { return _encoder.Encoder; }
}
///
/// Gets the name of the destination (either a queue or a topic).
///
/// The name of the destination.
public string Destination
{
get { return _destination; }
}
///
/// Gets the type of the destination.
///
/// The type of the destination.
public DestinationType DestinationType
{
get { return _destinationType; }
}
#endregion
#region Abort
///
/// Inserts processing on a communication object after it transitions to the closing state due to the invocation of a synchronous abort operation.
///
protected override void OnAbort()
{
//_pendingRequests.AbortAll();
}
#endregion
#region Close
///
/// Inserts processing after a communication object transitions to the closing state due to the invocation of an asynchronous close operation.
///
/// The that specifies how long the on close operation has to complete before timing out.
/// The delegate that receives notification of the completion of the asynchronous on close operation.
/// An object, specified by the application, that contains state information associated with the asynchronous on close operation.
///
/// The that references the asynchronous on close operation.
///
///
/// is less than zero.
protected override IAsyncResult OnBeginClose(TimeSpan timeout, AsyncCallback callback, object state)
{
OnClose(timeout);
return new CompletedAsyncResult(callback, state);
}
///
/// Inserts processing on a communication object after it transitions to the closing state due to the invocation of a synchronous close operation.
///
/// The that specifies how long the on close operation has to complete before timing out.
///
/// is less than zero.
protected override void OnClose(TimeSpan timeout)
{
//_pendingRequests.AbortAll();
}
///
/// Completes an asynchronous operation on the close of a communication object.
///
/// The that is returned by a call to the method.
/// The interval of time specified by timeout parameter to OnBeginClose() that was allotted for the operation was exceeded before the operation was completed.
protected override void OnEndClose(IAsyncResult result)
{
CompletedAsyncResult.End(result);
}
#endregion
#region Open
///
/// Inserts processing on a communication object after it transitions to the opening state due to the invocation of an asynchronous open operation.
///
/// The that specifies how long the on open operation has to complete before timing out.
/// The delegate that receives notification of the completion of the asynchronous on open operation.
/// An object, specified by the application, that contains state information associated with the asynchronous on open operation.
///
/// The that references the asynchronous on open operation.
///
///
/// is less than zero.
protected override IAsyncResult OnBeginOpen(TimeSpan timeout, AsyncCallback callback, object state)
{
OnOpen(timeout);
return new CompletedAsyncResult(callback, state);
}
///
/// Inserts processing on a communication object after it transitions into the opening state which must complete within a specified interval of time.
///
/// The that specifies how long the on open operation has to complete before timing out.
///
/// is less than zero.
/// The interval of time specified by that was allotted for the operation was exceeded before the operation was completed.
protected override void OnOpen(TimeSpan timeout)
{
}
///
/// Completes an asynchronous operation on the open of a communication object.
///
/// The that is returned by a call to the method.
/// The interval of time specified by timeout parameter to OnBeginOpen() that was allotted for the operation was exceeded before the operation was completed.
protected override void OnEndOpen(IAsyncResult result)
{
CompletedAsyncResult.End(result);
}
#endregion
#region GetProperty
///
/// Gets the property.
///
///
///
public override T GetProperty()
{
if(typeof(T) == typeof(FaultConverter))
{
return FaultConverter.GetDefaultFaultConverter(MessageVersion.Soap12WSAddressing10) as T;
}
return base.GetProperty();
}
#endregion
#region Private members
private EndpointAddress _remoteAddress;
private Uri _via;
private BufferManager _bufferManager;
private MessageEncoderFactory _encoder;
private string _destination;
private DestinationType _destinationType;
// for request/reply pattern
//NullAsyncRequestContextCollection _pendingRequests = new NullAsyncRequestContextCollection();
#endregion
}
}