public void TestMessagingProtocol() { IChannel channel0 = connection.GetChannel(0); IMessageFactory factory = channel0.MessageFactory; IProtocol protocol = factory.Protocol; Assert.IsNotNull(protocol); Assert.IsInstanceOf(typeof(Initiator.MessagingProtocol), protocol); Assert.AreEqual(protocol.CurrentVersion, 3); Assert.AreEqual(protocol.SupportedVersion, 2); Assert.AreEqual(protocol.Name, Initiator.MessagingProtocol.PROTOCOL_NAME); IMessageFactory factory2 = protocol.GetMessageFactory(3); Assert.AreEqual(factory, factory2); }
/// <summary> /// Execute the action specific to the Message implementation. /// </summary> public override void Run() { Channel channel0 = (Channel)Channel; Debug.Assert(channel0.Id == 0); Connection connection = (Connection)channel0.Connection; if (IsFailure) { connection.CloseInternal(false, Result as Exception, -1); return; } Initiator module = (Initiator)channel0.Receiver; object[] ao = (object[])Result; Debug.Assert(ao != null && ao.Length == 2); // extract the "Channel0" configuration from the OpenConnectionRequest OpenConnectionRequest request = (OpenConnectionRequest)channel0.GetRequest(RequestId); Debug.Assert(request != null); connection.Id = (UUID)ao[0]; connection.Member = request.Member; connection.PeerId = (UUID)ao[1]; channel0.Principal = request.Principal; // configure the MessageFactory map for the Connection IDictionary mapProtocol = module.ProtocolMap; IDictionary mapFactory = new HashDictionary(mapProtocol.Count); IDictionary mapVersion = ProtocolVersionMap; if (mapVersion != null) { foreach (DictionaryEntry entry in mapVersion) { String name = (String)entry.Key; Int32 version = (Int32)entry.Value; IProtocol protocol = (Protocol)mapProtocol[name]; mapFactory.Add(name, protocol.GetMessageFactory(version)); } } foreach (DictionaryEntry entry in mapProtocol) { String name = (String)entry.Key; if (!mapFactory.Contains(name)) { IProtocol protocol = (Protocol)entry.Value; mapFactory.Add(name, protocol.GetMessageFactory(protocol.CurrentVersion)); } } connection.MessageFactoryMap = mapFactory; // the Connection is now ready for use module.OnConnectionOpened(connection); }