private void ProcessDestinationInfo(DestinationInfo destInfo) { ActiveMQDestination dest = destInfo.Destination; if (!dest.IsTemporary) { return; } ActiveMQTempDestination tempDest = dest as ActiveMQTempDestination; if (destInfo.OperationType == DestinationInfo.ADD_OPERATION_TYPE) { if (Tracer.IsDebugEnabled) { Tracer.Debug("AdvisoryConsumer adding: " + tempDest); } this.connection.AddTempDestination(tempDest); } else if (destInfo.OperationType == DestinationInfo.REMOVE_OPERATION_TYPE) { if (Tracer.IsDebugEnabled) { Tracer.Debug("AdvisoryConsumer removing: " + tempDest); } this.connection.RemoveTempDestination(tempDest); } }
private void WaitForTempDestinationDelete(IDestination tempDestination) { const int MaxLoopCount = 200; int loopCount = 0; bool destinationDeleted = false; ActiveMQTempDestination amqTempDestination = tempDestination as ActiveMQTempDestination; while (!destinationDeleted) { loopCount++; if (loopCount > MaxLoopCount) { Assert.Fail(string.Format("Timeout waiting for Delete of {0}", amqTempDestination.PhysicalName)); } Thread.Sleep(10); lock (this.tempDestsRemoved.SyncRoot) { foreach (ActiveMQTempDestination tempDest in this.tempDestsRemoved) { if (0 == string.Compare(tempDest.PhysicalName, amqTempDestination.PhysicalName, true)) { destinationDeleted = true; break; } } } } }
public ActiveMQTempDestination CreateTemporaryDestination(bool topic) { ActiveMQTempDestination destination = null; if (topic) { destination = new ActiveMQTempTopic( info.ConnectionId.Value + ":" + Interlocked.Increment(ref temporaryDestinationCounter)); } else { destination = new ActiveMQTempQueue( info.ConnectionId.Value + ":" + Interlocked.Increment(ref temporaryDestinationCounter)); } DestinationInfo command = new DestinationInfo(); command.ConnectionId = ConnectionId; command.OperationType = DestinationInfo.ADD_OPERATION_TYPE; // 0 is add command.Destination = destination; this.SyncRequest(command); destination.Connection = this; this.AddTempDestination(destination); return(destination); }
// // Write the booleans that this object uses to a BooleanStream // public override int TightMarshal1(OpenWireFormat wireFormat, Object o, BooleanStream bs) { ActiveMQTempDestination info = (ActiveMQTempDestination)o; int rc = base.TightMarshal1(wireFormat, info, bs); return(rc + 0); }
internal bool IsTempDestinationActive(ActiveMQTempDestination dest) { if (this.advisoryConsumer == null) { return(true); } return(this.tempDests.Contains(dest)); }
internal void AddTempDestination(ActiveMQTempDestination dest) { // .NET lacks a putIfAbsent operation for Maps. lock (tempDests.SyncRoot) { if (!this.tempDests.Contains(dest)) { this.tempDests.Add(dest, dest); } } }
internal bool IsInUse(ActiveMQTempDestination dest) { using (this.consumersLock.Lock()) { foreach (MessageConsumer consumer in this.consumers.Values) { if (consumer.IsInUse(dest)) { return(true); } } } return(false); }
public void DeleteTemporaryDestination(IDestination destination) { CheckClosedOrFailed(); ActiveMQTempDestination temp = destination as ActiveMQTempDestination; foreach (Session session in this.sessions) { if (session.IsInUse(temp)) { throw new NMSException("A consumer is consuming from the temporary destination"); } } this.tempDests.Remove(destination as ActiveMQTempDestination); this.DeleteDestination(destination); }
internal ActiveMQTempDestination AddTempDestination(ActiveMQTempDestination dest) { ActiveMQTempDestination addedDest = dest; // .NET lacks a putIfAbsent operation for Maps. lock (tempDests.SyncRoot) { if (!this.tempDests.Contains(dest)) { this.tempDests.Add(dest, dest); } else { addedDest = this.tempDests[dest] as ActiveMQTempDestination; } } return(addedDest); }
private void OnAdvisoryMessage(IMessage msg) { Message message = msg as Message; DestinationInfo destInfo = message.DataStructure as DestinationInfo; if (destInfo != null) { ActiveMQDestination dest = destInfo.Destination; if (!dest.IsTemporary) { return; } ActiveMQTempDestination tempDest = dest as ActiveMQTempDestination; if (destInfo.OperationType == DestinationInfo.ADD_OPERATION_TYPE) { if (Tracer.IsDebugEnabled) { Tracer.Debug("Connection adding: " + tempDest); } lock (this.tempDestsAdded.SyncRoot) { this.tempDestsAdded.Add(tempDest); } } else if (destInfo.OperationType == DestinationInfo.REMOVE_OPERATION_TYPE) { if (Tracer.IsDebugEnabled) { Tracer.Debug("Connection removing: " + tempDest); } lock (this.tempDestsRemoved.SyncRoot) { this.tempDestsRemoved.Add(tempDest); } } } }
internal void RemoveTempDestination(ActiveMQTempDestination dest) { this.tempDests.Remove(dest); }
internal bool IsInUse(ActiveMQTempDestination dest) { return(this.info.Destination.Equals(dest)); }
public void Close() { if (!this.closed.Value && !transportFailed.Value) { this.Stop(); } lock (myLock) { if (this.closed.Value) { return; } try { Tracer.InfoFormat("Connection[{0}]: Closing Connection Now.", this.ConnectionId); this.closing.Value = true; if (this.advisoryConsumer != null) { this.advisoryConsumer.Dispose(); this.advisoryConsumer = null; } lock (sessions.SyncRoot) { foreach (Session session in sessions) { session.Shutdown(); } } sessions.Clear(); if (this.tempDests.Count > 0) { // Make a copy of the destinations to delete, because the act of deleting // them will modify the collection. ActiveMQTempDestination[] tempDestsToDelete = new ActiveMQTempDestination[this.tempDests.Count]; this.tempDests.Values.CopyTo(tempDestsToDelete, 0); foreach (ActiveMQTempDestination dest in tempDestsToDelete) { dest.Delete(); } } // Connected is true only when we've successfully sent our ConnectionInfo // to the broker, so if we haven't announced ourselves there's no need to // inform the broker of a remove, and if the transport is failed, why bother. if (connected.Value && !transportFailed.Value) { DisposeOf(ConnectionId); ShutdownInfo shutdowninfo = new ShutdownInfo(); transport.Oneway(shutdowninfo); } executor.Shutdown(); Tracer.DebugFormat("Connection[{0}]: Disposing of the Transport.", this.ConnectionId); transport.Stop(); transport.Dispose(); } catch (Exception ex) { Tracer.ErrorFormat("Connection[{0}]: Error during connection close: {1}", ConnectionId, ex); } finally { if (executor != null) { executor.Shutdown(); } this.transport = null; this.closed.Value = true; this.connected.Value = false; this.closing.Value = false; } } }